diff --git a/api/v1alpha1/dragonfly_types.go b/api/v1alpha1/dragonfly_types.go index e5e2162..894c01e 100644 --- a/api/v1alpha1/dragonfly_types.go +++ b/api/v1alpha1/dragonfly_types.go @@ -82,6 +82,11 @@ type DragonflySpec struct { // +kubebuilder:validation:Optional Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + // (Optional) Dragonfly pod topologySpreadConstraints + // +optional + // +kubebuilder:validation:Optional + TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"` + // (Optional) Dragonfly Authentication mechanism // +optional // +kubebuilder:validation:Optional diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index f9bf2b1..b598627 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -168,6 +168,13 @@ func (in *DragonflySpec) DeepCopyInto(out *DragonflySpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.TopologySpreadConstraints != nil { + in, out := &in.TopologySpreadConstraints, &out.TopologySpreadConstraints + *out = make([]v1.TopologySpreadConstraint, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } if in.Authentication != nil { in, out := &in.Authentication, &out.Authentication *out = new(Authentication) diff --git a/config/crd/bases/dragonflydb.io_dragonflies.yaml b/config/crd/bases/dragonflydb.io_dragonflies.yaml index ac71c15..37a10dd 100644 --- a/config/crd/bases/dragonflydb.io_dragonflies.yaml +++ b/config/crd/bases/dragonflydb.io_dragonflies.yaml @@ -1402,6 +1402,103 @@ spec: type: string type: object type: array + topologySpreadConstraints: + description: (Optional) Dragonfly pod topologySpreadConstraints + items: + description: The pod this TopologySpreadConstraints is attached + properties: + maxSkew: + description: the degree to which Pods may be unevenly distributed. + You must specify this field and the number must be greater than zero. + Its semantics differ according to the value of whenUnsatisfiable + format: int32 + type: integer + minDomains: + description: (Optional) 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 + format: int32 + type: integer + topologyKey: + description: 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. + The scheduler will try to put a balanced number of pods into each domain. + Also, we define an eligible domain as a domain whose nodes meet the + requirements of nodeAffinityPolicy and nodeTaintsPolicy. + type: string + whenUnsatisfiable: + description: 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. + 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 + required: + - key + - operator + type: object + type: array + 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: field is a beta-level field and enabled by default in 1.27. + You can disable it by disabling the MatchLabelKeysInPodTopologySpread + items: + type: string + type: array + nodeAffinityPolicy: + description: indicates how we will treat Pod's nodeAffinity/nodeSelector + when calculating pod topology spread skew. Options are Honor or Ignore + type: string + nodeTaintsPolicy: + description: indicates how we will treat node taints when calculating pod topology spread skew. Honor or Ignore + type: string + type: object + type: array type: object status: description: DragonflyStatus defines the observed state of Dragonfly diff --git a/internal/resources/resources.go b/internal/resources/resources.go index cc8b82d..27737d7 100644 --- a/internal/resources/resources.go +++ b/internal/resources/resources.go @@ -275,6 +275,10 @@ func GetDragonflyResources(ctx context.Context, df *resourcesv1.Dragonfly) ([]cl statefulset.Spec.Template.Spec.Tolerations = df.Spec.Tolerations } + if df.Spec.TopologySpreadConstraints != nil { + statefulset.Spec.Template.Spec.TopologySpreadConstraints = df.Spec.TopologySpreadConstraints + } + if df.Spec.ServiceAccountName != "" { statefulset.Spec.Template.Spec.ServiceAccountName = df.Spec.ServiceAccountName } diff --git a/manifests/crd.yaml b/manifests/crd.yaml index 34a6803..f45e977 100644 --- a/manifests/crd.yaml +++ b/manifests/crd.yaml @@ -1396,6 +1396,103 @@ spec: type: string type: object type: array + topologySpreadConstraints: + description: (Optional) Dragonfly pod topologySpreadConstraints + items: + description: The pod this TopologySpreadConstraints is attached + properties: + maxSkew: + description: the degree to which Pods may be unevenly distributed. + You must specify this field and the number must be greater than zero. + Its semantics differ according to the value of whenUnsatisfiable + format: int32 + type: integer + minDomains: + description: (Optional) 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 + format: int32 + type: integer + topologyKey: + description: 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. + The scheduler will try to put a balanced number of pods into each domain. + Also, we define an eligible domain as a domain whose nodes meet the + requirements of nodeAffinityPolicy and nodeTaintsPolicy. + type: string + whenUnsatisfiable: + description: 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. + 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 + required: + - key + - operator + type: object + type: array + 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: field is a beta-level field and enabled by default in 1.27. + You can disable it by disabling the MatchLabelKeysInPodTopologySpread + items: + type: string + type: array + nodeAffinityPolicy: + description: indicates how we will treat Pod's nodeAffinity/nodeSelector + when calculating pod topology spread skew. Options are Honor or Ignore + type: string + nodeTaintsPolicy: + description: indicates how we will treat node taints when calculating pod topology spread skew. Honor or Ignore + type: string + type: object + type: array type: object status: description: DragonflyStatus defines the observed state of Dragonfly diff --git a/manifests/dragonfly-operator.yaml b/manifests/dragonfly-operator.yaml index a4a0ad9..a9ecbb3 100644 --- a/manifests/dragonfly-operator.yaml +++ b/manifests/dragonfly-operator.yaml @@ -1409,6 +1409,103 @@ spec: type: string type: object type: array + topologySpreadConstraints: + description: (Optional) Dragonfly pod topologySpreadConstraints + items: + description: The pod this TopologySpreadConstraints is attached + properties: + maxSkew: + description: the degree to which Pods may be unevenly distributed. + You must specify this field and the number must be greater than zero. + Its semantics differ according to the value of whenUnsatisfiable + format: int32 + type: integer + minDomains: + description: (Optional) 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 + format: int32 + type: integer + topologyKey: + description: 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. + The scheduler will try to put a balanced number of pods into each domain. + Also, we define an eligible domain as a domain whose nodes meet the + requirements of nodeAffinityPolicy and nodeTaintsPolicy. + type: string + whenUnsatisfiable: + description: 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. + 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 + required: + - key + - operator + type: object + type: array + 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: field is a beta-level field and enabled by default in 1.27. + You can disable it by disabling the MatchLabelKeysInPodTopologySpread + items: + type: string + type: array + nodeAffinityPolicy: + description: indicates how we will treat Pod's nodeAffinity/nodeSelector + when calculating pod topology spread skew. Options are Honor or Ignore + type: string + nodeTaintsPolicy: + description: indicates how we will treat node taints when calculating pod topology spread skew. Honor or Ignore + type: string + type: object + type: array type: object status: description: DragonflyStatus defines the observed state of Dragonfly