Skip to content

Commit

Permalink
feat: user can set PDB by himself
Browse files Browse the repository at this point in the history
Signed-off-by: Rory Z <[email protected]>
  • Loading branch information
Rory-Z committed Dec 24, 2024
1 parent cb430ee commit 9a769e5
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 6 deletions.
17 changes: 17 additions & 0 deletions apis/apps/v2beta1/emqx_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v2beta1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -168,6 +169,7 @@ type EMQXReplicantTemplate struct {
}

type EMQXCoreTemplateSpec struct {
// +kubebuilder:validation:XValidation:rule="has(self.minAvailable) && has(self.maxUnavailable) ? false : true",message="minAvailable and maxUnavailable are mutually exclusive"
EMQXReplicantTemplateSpec `json:",inline"`

// VolumeClaimTemplates is a list of claims that pods are allowed to reference.
Expand Down Expand Up @@ -198,12 +200,27 @@ type EMQXReplicantTemplateSpec struct {
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.
// Defaults to 2.
//+kubebuilder:default:=2
Replicas *int32 `json:"replicas,omitempty"`
// An eviction is allowed if at least "minAvailable" pods selected by
// "selector" will still be available after the eviction, i.e. even in the
// absence of the evicted pod. So for example you can prevent all voluntary
// evictions by specifying "100%".
// +kubebuilder:default:=1
// +kubebuilder:validation:XIntOrString
MinAvailable *intstr.IntOrString `json:"minAvailable,omitempty"`
// An eviction is allowed if at most "maxUnavailable" pods selected by
// "selector" are unavailable after the eviction, i.e. even in absence of
// the evicted pod. For example, one can prevent all voluntary evictions
// by specifying 0. This is a mutually exclusive setting with "minAvailable".
// +kubebuilder:validation:XIntOrString
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`

// 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
Expand Down
11 changes: 11 additions & 0 deletions apis/apps/v2beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions config/crd/bases/apps.emqx.io_emqxes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9797,6 +9797,17 @@ spec:
format: int32
type: integer
type: object
maxUnavailable:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
minAvailable:
anyOf:
- type: integer
- type: string
default: 1
x-kubernetes-int-or-string: true
nodeName:
type: string
nodeSelector:
Expand Down Expand Up @@ -10264,6 +10275,10 @@ spec:
type: string
type: object
type: object
x-kubernetes-validations:
- message: minAvailable and maxUnavailable are mutually exclusive
rule: 'has(self.minAvailable) && has(self.maxUnavailable) ?
false : true'
type: object
dashboardServiceTemplate:
properties:
Expand Down Expand Up @@ -13351,6 +13366,17 @@ spec:
format: int32
type: integer
type: object
maxUnavailable:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
minAvailable:
anyOf:
- type: integer
- type: string
default: 1
x-kubernetes-int-or-string: true
nodeName:
type: string
nodeSelector:
Expand Down
9 changes: 5 additions & 4 deletions controllers/apps/v2beta1/add_pdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,20 @@ func generatePodDisruptionBudget(instance *appsv2beta1.EMQX) (*policyv1.PodDisru
instance.Spec.CoreTemplate.Labels,
),
},
MinAvailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
MinAvailable: instance.Spec.CoreTemplate.Spec.MinAvailable,
MaxUnavailable: instance.Spec.CoreTemplate.Spec.MaxUnavailable,
},
}

if appsv2beta1.IsExistReplicant(instance) {
replPdb := corePdb.DeepCopy()
replPdb.Name = instance.ReplicantNamespacedName().Name
replPdb.Spec.Selector.MatchLabels = appsv2beta1.CloneAndMergeMap(
appsv2beta1.DefaultReplicantLabels(instance),
instance.Spec.ReplicantTemplate.Labels,
)
replPdb.Spec.MinAvailable = instance.Spec.ReplicantTemplate.Spec.MinAvailable
replPdb.Spec.MaxUnavailable = instance.Spec.ReplicantTemplate.Spec.MaxUnavailable
return corePdb, replPdb
}
return corePdb, nil
Expand Down
4 changes: 2 additions & 2 deletions deploy/charts/emqx-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.26-rc.1
version: 2.2.26-rc.2

# 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.26-rc.1
appVersion: 2.2.26-rc.2

sources:
- https://github.com/emqx/emqx-operator/tree/main/deploy/charts/emqx-operator
Expand Down
34 changes: 34 additions & 0 deletions deploy/charts/emqx-operator/templates/crd.emqxes.apps.emqx.io.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9810,6 +9810,23 @@ spec:
format: int32
type: integer
type: object
maxUnavailable:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
x-kubernetes-validations:
- message: This is a mutually exclusive setting with 'minAvailable'
rule: 'has(self.minAvailable) ?false : true'
minAvailable:
anyOf:
- type: integer
- type: string
default: 1
x-kubernetes-int-or-string: true
x-kubernetes-validations:
- message: This is a mutually exclusive setting with 'maxUnavailable'
rule: 'has(self.maxUnavailable) ?false : true'
nodeName:
type: string
nodeSelector:
Expand Down Expand Up @@ -13364,6 +13381,23 @@ spec:
format: int32
type: integer
type: object
maxUnavailable:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
x-kubernetes-validations:
- message: This is a mutually exclusive setting with 'minAvailable'
rule: 'has(self.minAvailable) ?false : true'
minAvailable:
anyOf:
- type: integer
- type: string
default: 1
x-kubernetes-int-or-string: true
x-kubernetes-validations:
- message: This is a mutually exclusive setting with 'maxUnavailable'
rule: 'has(self.maxUnavailable) ?false : true'
nodeName:
type: string
nodeSelector:
Expand Down
4 changes: 4 additions & 0 deletions docs/en_US/reference/v2beta1-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ _Appears in:_
| `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#toleration-v1-core) array_ | If specified, the pod's tolerations.<br />The pod this Toleration is attached to tolerates any taint that matches the triple <key,value,effect> using the matching operator . | | |
| `topologySpreadConstraints` _[TopologySpreadConstraint](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#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.<br />These are replicas in the sense that they are instantiations of the<br />same Template, but individual replicas also have a consistent identity.<br />Defaults to 2. | 2 | |
| `minAvailable` _[IntOrString](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#intorstring-intstr-util)_ | An eviction is allowed if at least "minAvailable" pods selected by<br />"selector" will still be available after the eviction, i.e. even in the<br />absence of the evicted pod. So for example you can prevent all voluntary<br />evictions by specifying "100%". | 1 | XIntOrString: \{\} <br /> |
| `maxUnavailable` _[IntOrString](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#intorstring-intstr-util)_ | An eviction is allowed if at most "maxUnavailable" pods selected by<br />"selector" are unavailable after the eviction, i.e. even in absence of<br />the evicted pod. For example, one can prevent all voluntary evictions<br />by specifying 0. This is a mutually exclusive setting with "minAvailable". | | XIntOrString: \{\} <br /> |
| `command` _string array_ | Entrypoint array. Not executed within a shell.<br />The container image's ENTRYPOINT is used if this is not provided.<br />Variable references $(VAR_NAME) are expanded using the container's environment. If a variable<br />cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced<br />to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will<br />produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless<br />of whether the variable exists or not. Cannot be updated.<br />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.<br />The container image's CMD is used if this is not provided.<br />Variable references $(VAR_NAME) are expanded using the container's environment. If a variable<br />cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced<br />to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will<br />produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless<br />of whether the variable exists or not. Cannot be updated.<br />More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell | | |
| `ports` _[ContainerPort](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#containerport-v1-core) array_ | List of ports to expose from the container. Exposing a port here gives<br />the system additional information about the network connections a<br />container uses, but is primarily informational. Not specifying a port here<br />DOES NOT prevent that port from being exposed. Any port which is<br />listening on the default "0.0.0.0" address inside a container will be<br />accessible from the network.<br />Cannot be updated. | | |
Expand Down Expand Up @@ -230,6 +232,8 @@ _Appears in:_
| `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#toleration-v1-core) array_ | If specified, the pod's tolerations.<br />The pod this Toleration is attached to tolerates any taint that matches the triple <key,value,effect> using the matching operator . | | |
| `topologySpreadConstraints` _[TopologySpreadConstraint](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#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.<br />These are replicas in the sense that they are instantiations of the<br />same Template, but individual replicas also have a consistent identity.<br />Defaults to 2. | 2 | |
| `minAvailable` _[IntOrString](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#intorstring-intstr-util)_ | An eviction is allowed if at least "minAvailable" pods selected by<br />"selector" will still be available after the eviction, i.e. even in the<br />absence of the evicted pod. So for example you can prevent all voluntary<br />evictions by specifying "100%". | 1 | XIntOrString: \{\} <br /> |
| `maxUnavailable` _[IntOrString](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#intorstring-intstr-util)_ | An eviction is allowed if at most "maxUnavailable" pods selected by<br />"selector" are unavailable after the eviction, i.e. even in absence of<br />the evicted pod. For example, one can prevent all voluntary evictions<br />by specifying 0. This is a mutually exclusive setting with "minAvailable". | | XIntOrString: \{\} <br /> |
| `command` _string array_ | Entrypoint array. Not executed within a shell.<br />The container image's ENTRYPOINT is used if this is not provided.<br />Variable references $(VAR_NAME) are expanded using the container's environment. If a variable<br />cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced<br />to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will<br />produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless<br />of whether the variable exists or not. Cannot be updated.<br />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.<br />The container image's CMD is used if this is not provided.<br />Variable references $(VAR_NAME) are expanded using the container's environment. If a variable<br />cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced<br />to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will<br />produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless<br />of whether the variable exists or not. Cannot be updated.<br />More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell | | |
| `ports` _[ContainerPort](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#containerport-v1-core) array_ | List of ports to expose from the container. Exposing a port here gives<br />the system additional information about the network connections a<br />container uses, but is primarily informational. Not specifying a port here<br />DOES NOT prevent that port from being exposed. Any port which is<br />listening on the default "0.0.0.0" address inside a container will be<br />accessible from the network.<br />Cannot be updated. | | |
Expand Down
Loading

0 comments on commit 9a769e5

Please sign in to comment.