hashicorp / terraform-provider-kubernetes

Terraform Kubernetes provider
https://www.terraform.io/docs/providers/kubernetes/
Mozilla Public License 2.0
1.56k stars 963 forks source link

Support podAntiAffinity namespaceSelector field #2532

Open kuldazbraslav opened 1 week ago

kuldazbraslav commented 1 week ago

Description

Kubernetes supports namespaceSelector in podAntiAffinity configuration:

Namespace selector FEATURE STATE: Kubernetes v1.24 [stable] You can also select matching namespaces using namespaceSelector, which is a label query over the set of namespaces. The affinity term is applied to namespaces selected by both namespaceSelector and the namespaces field. Note that an empty namespaceSelector ({}) matches all namespaces, while a null or empty namespaces list and null namespaceSelector matches the namespace of the Pod where the rule is defined.

This configuration allows matching labels across namespaces which is useful in some namespace layouts.

Potential Terraform Configuration

          pod_anti_affinity {
            required_during_scheduling_ignored_during_execution {
              topology_key = "kubernetes.io/hostname"
              label_selector {
                match_labels = {
                  "mylabel" : "mylabelvalue"
                }
              }
              # Proposed form for all namespaces:
              namespace_selector {}
              # Proposed form for specific namespaces:
              namespace_selector {
                match_labels = {
                  "mynamespacelabel" = "excludethis"
                }
              }
            }
          }

References

https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#namespace-selector

Community Note