<commit_before>locals {
  agent_fsroot     = "/j"
  app_name         = "jenkins"
  app_version      = "1.0.0"
  dockergc_grace   = "3600"
  docker_host_name = "localhost"
  docker_host_port = "2375"
  docker_host      = "tcp://${local.docker_tuple}"
  docker_tuple     = "${local.docker_host_name}:${local.docker_host_port}"
  jmx_host         = "localhost"
  jmx_port         = "8080"
  jmx_tuple        = "${local.jmx_host}:${local.jmx_port}"
}

resource "kubernetes_secret" "jenkins_agent" {
  metadata {
    namespace = "${var.k8s_namespace}"
    name      = "${var.name}"

    labels {
      "app.k8s.io/name"       = "${var.name}"
      "app.k8s.io/instance"   = "${var.env_name}"
      "app.k8s.io/version"    = "${local.app_version}"
      "app.k8s.io/component"  = "agent"
      "app.k8s.io/part-of"    = "jenkins"
      "app.k8s.io/managed-by" = "terraform"
    }
  }

  data {
    JSWARM_USERNAME = "${var.agent_user}"
    JSWARM_PASSWORD = "${<PASSWORD>}"
  }
}

# headless service required by statefulset
resource "kubernetes_service" "jenkins_agent" {
  metadata {
    namespace = "${var.k8s_namespace}"
    name      = "${var.name}"

    labels {
      "app.k8s.io/name"       = "${var.name}"
      "app.k8s.io/instance"   = "${var.env_name}"
      "app.k8s.io/version"    = "${local.app_version}"
      "app.k8s.io/component"  = "agent"
      "app.k8s.io/part-of"    = "jenkins"
      "app.k8s.io/managed-by" = "terraform"
    }
  }

  spec {
    selector {
      "app.k8s.io/name"      = "${var.name}"
      "app.k8s.io/instance"  = "${var.env_name}"
      "app.k8s.io/version"   = "${local.app_version}"
      "app.k8s.io/component" = "agent"
      "app.k8s.io/part-of"   = "jenkins"
    }

    cluster_ip = "None"
  }
}

resource "kubernetes_stateful_set" "jenkins_agent" {
  metadata {
    namespace = "${var.k8s_namespace}"
    name      = "${var.name}"

    labels {
      "app.k8s.io/name"       = "${var.name}"
      "app.k8s.io/instance"   = "${var.env_name}"
      "app.k8s.io/version"    = "${local.app_version}"
      "app.k8s.io/component"  = "agent"
      "app.k8s.io/part-of"    = "jenkins"
      "app.k8s.io/managed-by" = "terraform"
    }
  }

  spec {
    pod_management_policy  = "Parallel"
    replicas               = "${var.agent_replicas}"
    revision_history_limit = 10

    selector {
      match_labels {
        "app.k8s.io/name"      = "${var.name}"
        "app.k8s.io/instance"  = "${var.env_name}"
        "app.k8s.io/version"   = "${local.app_version}"
        "app.k8s.io/component" = "agent"
        "app.k8s.io/part-of"   = "jenkins"
      }
    }

    service_name = "${kubernetes_service.jenkins_agent.metadata.0.name}"

    update_strategy {
      type = "RollingUpdate"

      #rolling_update {
      #  max_surge       = "${ceil(var.replicas * 1.5)}"
      #  max_unavailable = "${floor(var.replicas * 0.5)}"
      #}
    }

    template {
      metadata {
        labels {
          "app.k8s.io/name"       = "${var.name}"
          "app.k8s.io/instance"   = "${var.env_name}"
          "app.k8s.io/version"    = "${local.app_version}"
          "app.k8s.io/component"  = "agent"
          "app.k8s.io/part-of"    = "jenkins"
          "app.k8s.io/managed-by" = "terraform"
        }
      }

      spec {
        security_context {
          # intended primary for dind; can not set fs_group at container level
          fs_group = "${var.agent_gid}"
        }

        container {
          name              = "dind"
          image             = "${var.dind_image}"
          image_pull_policy = "Always"
          command           = ["/usr/local/bin/dockerd"]
          args              = ["--host=${local.docker_host}"]

          security_context {
            privileged = true
          }

          env {
            name  = "DOCKER_HOST"
            value = "${local.docker_host}"
          }

          volume_mount {
            name       = "docker-graph-storage"
            mount_path = "/var/lib/docker"
          }

          volume_mount {
            name       = "ws"
            mount_path = "${local.agent_fsroot}"
          }

          resources {
            limits {
              cpu    = "32"
              memory = "96Gi"<commit_msg>do not schedule on lsst-kub005<commit_after>locals {
  agent_fsroot     = "/j"
  app_name         = "jenkins"
  app_version      = "1.0.0"
  dockergc_grace   = "3600"
  docker_host_name = "localhost"
  docker_host_port = "2375"
  docker_host      = "tcp://${local.docker_tuple}"
  docker_tuple     = "${local.docker_host_name}:${local.docker_host_port}"
  jmx_host         = "localhost"
  jmx_port         = "8080"
  jmx_tuple        = "${local.jmx_host}:${local.jmx_port}"
}

resource "kubernetes_secret" "jenkins_agent" {
  metadata {
    namespace = "${var.k8s_namespace}"
    name      = "${var.name}"

    labels {
      "app.k8s.io/name"       = "${var.name}"
      "app.k8s.io/instance"   = "${var.env_name}"
      "app.k8s.io/version"    = "${local.app_version}"
      "app.k8s.io/component"  = "agent"
      "app.k8s.io/part-of"    = "jenkins"
      "app.k8s.io/managed-by" = "terraform"
    }
  }

  data {
    JSWARM_USERNAME = "${var.agent_user}"
    JSWARM_PASSWORD = "${<PASSWORD>}"
  }
}

# headless service required by statefulset
resource "kubernetes_service" "jenkins_agent" {
  metadata {
    namespace = "${var.k8s_namespace}"
    name      = "${var.name}"

    labels {
      "app.k8s.io/name"       = "${var.name}"
      "app.k8s.io/instance"   = "${var.env_name}"
      "app.k8s.io/version"    = "${local.app_version}"
      "app.k8s.io/component"  = "agent"
      "app.k8s.io/part-of"    = "jenkins"
      "app.k8s.io/managed-by" = "terraform"
    }
  }

  spec {
    selector {
      "app.k8s.io/name"      = "${var.name}"
      "app.k8s.io/instance"  = "${var.env_name}"
      "app.k8s.io/version"   = "${local.app_version}"
      "app.k8s.io/component" = "agent"
      "app.k8s.io/part-of"   = "jenkins"
    }

    cluster_ip = "None"
  }
}

resource "kubernetes_stateful_set" "jenkins_agent" {
  metadata {
    namespace = "${var.k8s_namespace}"
    name      = "${var.name}"

    labels {
      "app.k8s.io/name"       = "${var.name}"
      "app.k8s.io/instance"   = "${var.env_name}"
      "app.k8s.io/version"    = "${local.app_version}"
      "app.k8s.io/component"  = "agent"
      "app.k8s.io/part-of"    = "jenkins"
      "app.k8s.io/managed-by" = "terraform"
    }
  }

  spec {
    pod_management_policy  = "Parallel"
    replicas               = "${var.agent_replicas}"
    revision_history_limit = 10

    selector {
      match_labels {
        "app.k8s.io/name"      = "${var.name}"
        "app.k8s.io/instance"  = "${var.env_name}"
        "app.k8s.io/version"   = "${local.app_version}"
        "app.k8s.io/component" = "agent"
        "app.k8s.io/part-of"   = "jenkins"
      }
    }

    service_name = "${kubernetes_service.jenkins_agent.metadata.0.name}"

    update_strategy {
      type = "RollingUpdate"

      #rolling_update {
      #  max_surge       = "${ceil(var.replicas * 1.5)}"
      #  max_unavailable = "${floor(var.replicas * 0.5)}"
      #}
    }

    template {
      metadata {
        labels {
          "app.k8s.io/name"       = "${var.name}"
          "app.k8s.io/instance"   = "${var.env_name}"
          "app.k8s.io/version"    = "${local.app_version}"
          "app.k8s.io/component"  = "agent"
          "app.k8s.io/part-of"    = "jenkins"
          "app.k8s.io/managed-by" = "terraform"
        }
      }

      spec {
        security_context {
          # intended primary for dind; can not set fs_group at container level
          fs_group = "${var.agent_gid}"
        }

        affinity {
          node_affinity {
            required_during_scheduling_ignored_during_execution {
              node_selector_term {
                match_expressions {
                  key      = "kubernetes.io/hostname"
                  operator = "NotIn"
                  values   = ["lsst-kub005"]
                }
              }
            }
          }
        }

        container {
          name              = "dind"
          image             = "${var.dind_image}"
          image_pull_policy = "Always"
          command           = ["/usr/local/bin/dockerd"]
          args              = ["--host=${local.docker_host}"]

          security_context {
            privileged = true
          }

          env {
            name  = "DOCKER_HOST"
            value = "${local.docker_host}"
          }

          volume_mount {
            name       = "docker-graph-storage"
            mount_path = "/var/lib/docker"
          }

          volume_mount {
            name       = "ws"
            mount_path = "${local.agent_fsroot}"
          }

          resources {
            limits {
              cpu    = "32"
              memory = "96Gi"
{'fraction_non_alphanumeric': 0.1553321283325802, 'fraction_numerical': 0.0149118843199277, 'mean_word_length': 1.691699604743083, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6693580', 'n_tokens_mistral': 3269, 'n_tokens_neox': 3163, 'n_words': 426}