From 40cbff18479551b50ddaf3398b9f63889d95760c Mon Sep 17 00:00:00 2001 From: Rory <16801068+Rory-Z@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:04:09 +0800 Subject: [PATCH] feat: add topologySpreadConstraints for emqx CRD (#1042) fix: https://github.com/emqx/emqx-operator/issues/1041 Signed-off-by: Rory Z <16801068+Rory-Z@users.noreply.github.com> --- apis/apps/v2beta1/emqx_types.go | 2 + apis/apps/v2beta1/zz_generated.deepcopy.go | 7 ++ config/crd/bases/apps.emqx.io_emqxes.yaml | 104 ++++++++++++++++++ controllers/apps/v2beta1/add_emqx_core.go | 7 +- controllers/apps/v2beta1/add_emqx_repl.go | 7 +- deploy/charts/emqx-operator/Chart.yaml | 4 +- .../templates/crd.emqxes.apps.emqx.io.yaml | 104 ++++++++++++++++++ docs/en_US/reference/v2beta1-reference.md | 2 + docs/zh_CN/reference/v2beta1-reference.md | 2 + 9 files changed, 231 insertions(+), 8 deletions(-) diff --git a/apis/apps/v2beta1/emqx_types.go b/apis/apps/v2beta1/emqx_types.go index 496859125..3f5b6e860 100644 --- a/apis/apps/v2beta1/emqx_types.go +++ b/apis/apps/v2beta1/emqx_types.go @@ -196,6 +196,8 @@ type EMQXReplicantTemplateSpec struct { // If specified, the pod's tolerations. // The pod this Toleration is attached to tolerates any taint that matches the triple using the matching operator . Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + //// TopologySpreadConstraint specifies how to spread matching pods among the given topology. + TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"` // Replicas is the desired number of replicas of the given Template. // These are replicas in the sense that they are instantiations of the // same Template, but individual replicas also have a consistent identity. diff --git a/apis/apps/v2beta1/zz_generated.deepcopy.go b/apis/apps/v2beta1/zz_generated.deepcopy.go index fa7f984aa..503b9d792 100644 --- a/apis/apps/v2beta1/zz_generated.deepcopy.go +++ b/apis/apps/v2beta1/zz_generated.deepcopy.go @@ -236,6 +236,13 @@ func (in *EMQXReplicantTemplateSpec) DeepCopyInto(out *EMQXReplicantTemplateSpec (*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.Replicas != nil { in, out := &in.Replicas, &out.Replicas *out = new(int32) diff --git a/config/crd/bases/apps.emqx.io_emqxes.yaml b/config/crd/bases/apps.emqx.io_emqxes.yaml index 02cdf4b94..e7306326a 100644 --- a/config/crd/bases/apps.emqx.io_emqxes.yaml +++ b/config/crd/bases/apps.emqx.io_emqxes.yaml @@ -10100,6 +10100,58 @@ spec: type: string type: object type: array + topologySpreadConstraints: + items: + properties: + labelSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + items: + type: string + type: array + x-kubernetes-list-type: atomic + maxSkew: + format: int32 + type: integer + minDomains: + format: int32 + type: integer + nodeAffinityPolicy: + type: string + nodeTaintsPolicy: + type: string + topologyKey: + type: string + whenUnsatisfiable: + type: string + required: + - maxSkew + - topologyKey + - whenUnsatisfiable + type: object + type: array volumeClaimTemplates: properties: accessModes: @@ -13593,6 +13645,58 @@ spec: type: string type: object type: array + topologySpreadConstraints: + items: + properties: + labelSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + items: + type: string + type: array + x-kubernetes-list-type: atomic + maxSkew: + format: int32 + type: integer + minDomains: + format: int32 + type: integer + nodeAffinityPolicy: + type: string + nodeTaintsPolicy: + type: string + topologyKey: + type: string + whenUnsatisfiable: + type: string + required: + - maxSkew + - topologyKey + - whenUnsatisfiable + type: object + type: array type: object type: object revisionHistoryLimit: diff --git a/controllers/apps/v2beta1/add_emqx_core.go b/controllers/apps/v2beta1/add_emqx_core.go index 8c30f0726..2c364e860 100644 --- a/controllers/apps/v2beta1/add_emqx_core.go +++ b/controllers/apps/v2beta1/add_emqx_core.go @@ -185,9 +185,10 @@ func generateStatefulSet(instance *appsv2beta1.EMQX) *appsv1.StatefulSet { // TODO: just for compatible with old version, will remove in future instance.Spec.CoreTemplate.Spec.ToleRations..., ), - NodeName: instance.Spec.CoreTemplate.Spec.NodeName, - NodeSelector: instance.Spec.CoreTemplate.Spec.NodeSelector, - InitContainers: instance.Spec.CoreTemplate.Spec.InitContainers, + TopologySpreadConstraints: instance.Spec.CoreTemplate.Spec.TopologySpreadConstraints, + NodeName: instance.Spec.CoreTemplate.Spec.NodeName, + NodeSelector: instance.Spec.CoreTemplate.Spec.NodeSelector, + InitContainers: instance.Spec.CoreTemplate.Spec.InitContainers, Containers: append([]corev1.Container{ { Name: appsv2beta1.DefaultContainerName, diff --git a/controllers/apps/v2beta1/add_emqx_repl.go b/controllers/apps/v2beta1/add_emqx_repl.go index d94f55fda..8b38dc491 100644 --- a/controllers/apps/v2beta1/add_emqx_repl.go +++ b/controllers/apps/v2beta1/add_emqx_repl.go @@ -191,9 +191,10 @@ func generateReplicaSet(instance *appsv2beta1.EMQX) *appsv1.ReplicaSet { // TODO: just for compatible with old version, will remove in future instance.Spec.ReplicantTemplate.Spec.ToleRations..., ), - NodeName: instance.Spec.ReplicantTemplate.Spec.NodeName, - NodeSelector: instance.Spec.ReplicantTemplate.Spec.NodeSelector, - InitContainers: instance.Spec.ReplicantTemplate.Spec.InitContainers, + TopologySpreadConstraints: instance.Spec.CoreTemplate.Spec.TopologySpreadConstraints, + NodeName: instance.Spec.ReplicantTemplate.Spec.NodeName, + NodeSelector: instance.Spec.ReplicantTemplate.Spec.NodeSelector, + InitContainers: instance.Spec.ReplicantTemplate.Spec.InitContainers, Containers: append([]corev1.Container{ { Name: appsv2beta1.DefaultContainerName, diff --git a/deploy/charts/emqx-operator/Chart.yaml b/deploy/charts/emqx-operator/Chart.yaml index c92c255e4..7f286d19b 100644 --- a/deploy/charts/emqx-operator/Chart.yaml +++ b/deploy/charts/emqx-operator/Chart.yaml @@ -15,12 +15,12 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 2.2.20 +version: 2.2.21 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. -appVersion: 2.2.20 +appVersion: 2.2.21 sources: - https://github.com/emqx/emqx-operator/tree/main/deploy/charts/emqx-operator diff --git a/deploy/charts/emqx-operator/templates/crd.emqxes.apps.emqx.io.yaml b/deploy/charts/emqx-operator/templates/crd.emqxes.apps.emqx.io.yaml index 38f3649a5..d38e9326f 100644 --- a/deploy/charts/emqx-operator/templates/crd.emqxes.apps.emqx.io.yaml +++ b/deploy/charts/emqx-operator/templates/crd.emqxes.apps.emqx.io.yaml @@ -10112,6 +10112,58 @@ spec: type: string type: object type: array + topologySpreadConstraints: + items: + properties: + labelSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + items: + type: string + type: array + x-kubernetes-list-type: atomic + maxSkew: + format: int32 + type: integer + minDomains: + format: int32 + type: integer + nodeAffinityPolicy: + type: string + nodeTaintsPolicy: + type: string + topologyKey: + type: string + whenUnsatisfiable: + type: string + required: + - maxSkew + - topologyKey + - whenUnsatisfiable + type: object + type: array volumeClaimTemplates: properties: accessModes: @@ -13605,6 +13657,58 @@ spec: type: string type: object type: array + topologySpreadConstraints: + items: + properties: + labelSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + items: + type: string + type: array + x-kubernetes-list-type: atomic + maxSkew: + format: int32 + type: integer + minDomains: + format: int32 + type: integer + nodeAffinityPolicy: + type: string + nodeTaintsPolicy: + type: string + topologyKey: + type: string + whenUnsatisfiable: + type: string + required: + - maxSkew + - topologyKey + - whenUnsatisfiable + type: object + type: array type: object type: object revisionHistoryLimit: diff --git a/docs/en_US/reference/v2beta1-reference.md b/docs/en_US/reference/v2beta1-reference.md index b71c61559..445fd2a81 100644 --- a/docs/en_US/reference/v2beta1-reference.md +++ b/docs/en_US/reference/v2beta1-reference.md @@ -106,6 +106,7 @@ _Appears in:_ | `affinity` _[Affinity](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#affinity-v1-core)_ | Affinity for pod assignment
ref: https://kubernetes.io/docs/concepts/config/assign-pod-node/#affinity-and-anti-affinity | | | | `toleRations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#toleration-v1-core) array_ | If specified, the pod's tolerations.
The pod this Toleration is attached to tolerates any taint that matches the triple using the matching operator .
TODO: should use `tolerations` instead, this field just for compatible with old version, will delete in future. | | | | `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#toleration-v1-core) array_ | If specified, the pod's tolerations.
The pod this Toleration is attached to tolerates any taint that matches the triple using the matching operator . | | | +| `topologySpreadConstraints` _[TopologySpreadConstraint](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#topologyspreadconstraint-v1-core) array_ | // TopologySpreadConstraint specifies how to spread matching pods among the given topology. | | | | `replicas` _integer_ | Replicas is the desired number of replicas of the given Template.
These are replicas in the sense that they are instantiations of the
same Template, but individual replicas also have a consistent identity.
Defaults to 2. | 2 | | | `command` _string array_ | Entrypoint array. Not executed within a shell.
The container image's ENTRYPOINT is used if this is not provided.
Variable references $(VAR_NAME) are expanded using the container's environment. If a variable
cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced
to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will
produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless
of whether the variable exists or not. Cannot be updated.
More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell | | | | `args` _string array_ | Arguments to the entrypoint.
The container image's CMD is used if this is not provided.
Variable references $(VAR_NAME) are expanded using the container's environment. If a variable
cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced
to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will
produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless
of whether the variable exists or not. Cannot be updated.
More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell | | | @@ -228,6 +229,7 @@ _Appears in:_ | `affinity` _[Affinity](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#affinity-v1-core)_ | Affinity for pod assignment
ref: https://kubernetes.io/docs/concepts/config/assign-pod-node/#affinity-and-anti-affinity | | | | `toleRations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#toleration-v1-core) array_ | If specified, the pod's tolerations.
The pod this Toleration is attached to tolerates any taint that matches the triple using the matching operator .
TODO: should use `tolerations` instead, this field just for compatible with old version, will delete in future. | | | | `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#toleration-v1-core) array_ | If specified, the pod's tolerations.
The pod this Toleration is attached to tolerates any taint that matches the triple using the matching operator . | | | +| `topologySpreadConstraints` _[TopologySpreadConstraint](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#topologyspreadconstraint-v1-core) array_ | // TopologySpreadConstraint specifies how to spread matching pods among the given topology. | | | | `replicas` _integer_ | Replicas is the desired number of replicas of the given Template.
These are replicas in the sense that they are instantiations of the
same Template, but individual replicas also have a consistent identity.
Defaults to 2. | 2 | | | `command` _string array_ | Entrypoint array. Not executed within a shell.
The container image's ENTRYPOINT is used if this is not provided.
Variable references $(VAR_NAME) are expanded using the container's environment. If a variable
cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced
to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will
produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless
of whether the variable exists or not. Cannot be updated.
More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell | | | | `args` _string array_ | Arguments to the entrypoint.
The container image's CMD is used if this is not provided.
Variable references $(VAR_NAME) are expanded using the container's environment. If a variable
cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced
to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will
produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless
of whether the variable exists or not. Cannot be updated.
More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell | | | diff --git a/docs/zh_CN/reference/v2beta1-reference.md b/docs/zh_CN/reference/v2beta1-reference.md index b71c61559..445fd2a81 100644 --- a/docs/zh_CN/reference/v2beta1-reference.md +++ b/docs/zh_CN/reference/v2beta1-reference.md @@ -106,6 +106,7 @@ _Appears in:_ | `affinity` _[Affinity](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#affinity-v1-core)_ | Affinity for pod assignment
ref: https://kubernetes.io/docs/concepts/config/assign-pod-node/#affinity-and-anti-affinity | | | | `toleRations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#toleration-v1-core) array_ | If specified, the pod's tolerations.
The pod this Toleration is attached to tolerates any taint that matches the triple using the matching operator .
TODO: should use `tolerations` instead, this field just for compatible with old version, will delete in future. | | | | `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#toleration-v1-core) array_ | If specified, the pod's tolerations.
The pod this Toleration is attached to tolerates any taint that matches the triple using the matching operator . | | | +| `topologySpreadConstraints` _[TopologySpreadConstraint](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#topologyspreadconstraint-v1-core) array_ | // TopologySpreadConstraint specifies how to spread matching pods among the given topology. | | | | `replicas` _integer_ | Replicas is the desired number of replicas of the given Template.
These are replicas in the sense that they are instantiations of the
same Template, but individual replicas also have a consistent identity.
Defaults to 2. | 2 | | | `command` _string array_ | Entrypoint array. Not executed within a shell.
The container image's ENTRYPOINT is used if this is not provided.
Variable references $(VAR_NAME) are expanded using the container's environment. If a variable
cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced
to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will
produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless
of whether the variable exists or not. Cannot be updated.
More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell | | | | `args` _string array_ | Arguments to the entrypoint.
The container image's CMD is used if this is not provided.
Variable references $(VAR_NAME) are expanded using the container's environment. If a variable
cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced
to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will
produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless
of whether the variable exists or not. Cannot be updated.
More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell | | | @@ -228,6 +229,7 @@ _Appears in:_ | `affinity` _[Affinity](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#affinity-v1-core)_ | Affinity for pod assignment
ref: https://kubernetes.io/docs/concepts/config/assign-pod-node/#affinity-and-anti-affinity | | | | `toleRations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#toleration-v1-core) array_ | If specified, the pod's tolerations.
The pod this Toleration is attached to tolerates any taint that matches the triple using the matching operator .
TODO: should use `tolerations` instead, this field just for compatible with old version, will delete in future. | | | | `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#toleration-v1-core) array_ | If specified, the pod's tolerations.
The pod this Toleration is attached to tolerates any taint that matches the triple using the matching operator . | | | +| `topologySpreadConstraints` _[TopologySpreadConstraint](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#topologyspreadconstraint-v1-core) array_ | // TopologySpreadConstraint specifies how to spread matching pods among the given topology. | | | | `replicas` _integer_ | Replicas is the desired number of replicas of the given Template.
These are replicas in the sense that they are instantiations of the
same Template, but individual replicas also have a consistent identity.
Defaults to 2. | 2 | | | `command` _string array_ | Entrypoint array. Not executed within a shell.
The container image's ENTRYPOINT is used if this is not provided.
Variable references $(VAR_NAME) are expanded using the container's environment. If a variable
cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced
to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will
produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless
of whether the variable exists or not. Cannot be updated.
More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell | | | | `args` _string array_ | Arguments to the entrypoint.
The container image's CMD is used if this is not provided.
Variable references $(VAR_NAME) are expanded using the container's environment. If a variable
cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced
to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will
produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless
of whether the variable exists or not. Cannot be updated.
More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell | | |