Terraform-provider-kubernetes: Implement topologySpreadConstraint in pod spec schema

Created on 8 Sep 2020  ·  5Comments  ·  Source: hashicorp/terraform-provider-kubernetes

Description

Pod Spec (in at least K8S 1.16) includes an array of TopologySpreadConstraint (v1 core) under the field topologySpreadConstraints to enable enhanced scheduling control beyond taints/affinity and this feature would be beneficial to one of my projects that use the kubernetes provider.

Potential Terraform Configuration

resource "kubernetes_pod" "test" {
  metadata {
    name = "terraform-example"
    labels = {
      "app.kubernetes.io/instance" = "terraform-example"
    }
  }

  spec {
    topology_spread_constraint {
      max_skew = 1
      topology_key = "failure-domain.beta.kubernetes.io/zone"
      when_unsatisfiable = "DoNotSchedule"
      label_selector {
        match_labels = {
          "app.kubernetes.io/instance" = "terraform-example"
        }
      }
    }
    topology_spread_constraint {
      max_skew = 1
      topology_key = "kubernetes.io/hostname"
      when_unsatisfiable = "DoNotSchedule"
      label_selector {
        match_labels = {
          "app.kubernetes.io/instance" = "terraform-example"
        }
      }
    }
    container {
      image = "nginx:1.7.9"
      name  = "example"

      env {
        name  = "environment"
        value = "test"
      }

      port {
        container_port = 8080
      }
    }
  }
}

References


https://v1-17.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#topologyspreadconstraint-v1-core

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
enhancement help wanted sizM themcoverage

Most helpful comment

what's the status on implementing this feature? kind of needed now that 1.18 is out.

All 5 comments

Thanks for writing this up! This would be a good feature to have. Here is an example of a similar PR that merged recently. It shows a new field being added to the PodSpec schema, and some new tests added to cover it: https://github.com/hashicorp/terraform-provider-kubernetes/pull/938/files

In addition to the type of tests in that PR (acceptance tests), we're now starting to look for unit tests to cover any flatteners/expanders modified by PRs.

Here are the flatteners and expanders for PodSpec:
https://github.com/hashicorp/terraform-provider-kubernetes/blob/604a64429b9ee48a1d8b3f2ccfba7c72349d8008/kubernetes/structures_pod.go

And here are the unit tests for PodSpec's flatteners and expanders:
https://github.com/hashicorp/terraform-provider-kubernetes/blob/604a64429b9ee48a1d8b3f2ccfba7c72349d8008/kubernetes/structures_pod_test.go

This might help too, since the topologySpreadConstraint contains a LabelSelector. https://github.com/hashicorp/terraform-provider-kubernetes/blob/master/kubernetes/schema_affinity_spec.go#L151-L158

what's the status on implementing this feature? kind of needed now that 1.18 is out.

this needs support. anyone working on a PR?

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings