From 3cd9815d2419bf431ed7b5199bfa00499f452dfd Mon Sep 17 00:00:00 2001 From: Thiago Luiz Pereira Nunes Date: Tue, 10 Dec 2024 11:00:24 -0300 Subject: [PATCH] feat: add topologySpreadConstraints to kops cluster crd --- k8s/crds/kops.k8s.io_clusters.yaml | 110 +++++++++++++++++++++++++++++ pkg/apis/kops/cluster.go | 2 + pkg/apis/kops/v1alpha2/cluster.go | 2 + pkg/apis/kops/v1alpha3/cluster.go | 2 + 4 files changed, 116 insertions(+) diff --git a/k8s/crds/kops.k8s.io_clusters.yaml b/k8s/crds/kops.k8s.io_clusters.yaml index 782ee35692309..68183e44961f5 100644 --- a/k8s/crds/kops.k8s.io_clusters.yaml +++ b/k8s/crds/kops.k8s.io_clusters.yaml @@ -3748,6 +3748,116 @@ spec: items: type: string type: array + topologySpreadConstraints: + description: |- + You can use topology spread constraints to control how Pods are spread across your cluster + among failure-domains such as regions, zones, nodes, and other user-defined topology domains. + items: + description: |- + You can define one or multiple topologySpreadConstraints entries to instruct the kube-scheduler + how to place each incoming Pod in relation to the existing Pods across your cluster. + properties: + maxSkew: + description: |- + maxSkew describes the degree to which Pods may be unevenly distributed. You must specify this field + and the number must be greater than zero. + type: integer + minDomains: + description: |- + minDomains indicates a minimum number of eligible domains. This field is optional. A domain is a particular + instance of a topology. An eligible domain is a domain whose nodes match the node selector. + type: integer + topologyKey: + description: |- + topologyKey is the key of node labels. Nodes that have a label with this key and identical values are considered + to be in the same topology. We call each instance of a topology (in other words, a pair) a domain. + type: string + whenUnsatisfiable: + description: |- + whenUnsatisfiable indicates how to deal with a Pod if it doesn't satisfy the spread constraint: + DoNotSchedule (default) tells the scheduler not to schedule it. + ScheduleAnyway tells the scheduler to still schedule it while prioritizing nodes that minimize the skew. + type: string + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default). + items: + type: string + type: array + x-kubernetes-list-type: atomic + nodeAffinityPolicy: + description: |- + nodeAffinityPolicy indicates how we will treat Pod's nodeAffinity/nodeSelector when calculating pod topology spread skew. Options are: + Honor: only nodes matching nodeAffinity/nodeSelector are included in the calculations. + Ignore: nodeAffinity/nodeSelector are ignored. All nodes are included in the calculations. + If this value is null, the behavior is equivalent to the Honor policy. + type: string + nodeTaintsPolicy: + description: |- + nodeTaintsPolicy indicates how we will treat node taints when calculating pod topology spread skew. Options are: + Honor: nodes without taints, along with tainted nodes for which the incoming pod has a toleration, are included. + Ignore: node taints are ignored. All nodes are included. + If this value is null, the behavior is equivalent to the Ignore policy. + type: string + type: object + type: array type: object kubeProxy: description: KubeProxyConfig defines the configuration for a proxy diff --git a/pkg/apis/kops/cluster.go b/pkg/apis/kops/cluster.go index 4e5a273ad94d3..4c4ff1a795793 100644 --- a/pkg/apis/kops/cluster.go +++ b/pkg/apis/kops/cluster.go @@ -599,6 +599,8 @@ type KubeDNSConfig struct { MemoryLimit *resource.Quantity `json:"memoryLimit,omitempty"` // NodeLocalDNS specifies the configuration for the node-local-dns addon NodeLocalDNS *NodeLocalDNSConfig `json:"nodeLocalDNS,omitempty"` + // TopologySpreadConstraints describes how a group of pods ought to spread across topology domains + TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"` } // NodeLocalDNSConfig are options of the node-local-dns diff --git a/pkg/apis/kops/v1alpha2/cluster.go b/pkg/apis/kops/v1alpha2/cluster.go index 1c105e623a92a..03442afbf3afe 100644 --- a/pkg/apis/kops/v1alpha2/cluster.go +++ b/pkg/apis/kops/v1alpha2/cluster.go @@ -578,6 +578,8 @@ type KubeDNSConfig struct { MemoryLimit *resource.Quantity `json:"memoryLimit,omitempty"` // NodeLocalDNS specifies the configuration for the node-local-dns addon NodeLocalDNS *NodeLocalDNSConfig `json:"nodeLocalDNS,omitempty"` + // TopologySpreadConstraints describes how a group of pods ought to spread across topology domains + TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"` } // NodeLocalDNSConfig are options of the node-local-dns diff --git a/pkg/apis/kops/v1alpha3/cluster.go b/pkg/apis/kops/v1alpha3/cluster.go index 2b5ad0b8ce8dd..5f4d59580a76b 100644 --- a/pkg/apis/kops/v1alpha3/cluster.go +++ b/pkg/apis/kops/v1alpha3/cluster.go @@ -564,6 +564,8 @@ type KubeDNSConfig struct { MemoryLimit *resource.Quantity `json:"memoryLimit,omitempty"` // NodeLocalDNS specifies the configuration for the node-local-dns addon NodeLocalDNS *NodeLocalDNSConfig `json:"nodeLocalDNS,omitempty"` + // TopologySpreadConstraints describes how a group of pods ought to spread across topology domains + TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"` } // NodeLocalDNSConfig are options of the node-local-dns