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 aff9217
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 20 deletions.
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,37 @@ The EMQX Operator includes, but is not limited to, the following features:

| EMQX Enterprise Version | EMQX Operator Version | APIVersion | Kind |
| :------------------------: | :---------------------------------------------: | :----------------------------------------------------------: | :------------: |
| 4.3.x (included) ~ 4.4 | 1.2.1, 1.2.2, 1.2.3 | [apps.emqx.io/v1beta3](./docs/en_US/reference/v1beta3-reference.md) | EmqxEnterprise |
| 4.4.6 (included) ~ 4.4.8 | 1.2.5 | [apps.emqx.io/v1beta3](./docs/en_US/reference/v1beta3-reference.md) | EmqxEnterprise |
| 4.4.8 (included) ~ 4.4.14 | 1.2.6, 1.2.7, 1.2.8, 2.0.0, 2.0.1, 2.0.2, 2.0.3 | [apps.emqx.io/v1beta3](./docs/en_US/reference/v1beta3-reference.md) | EmqxEnterprise |
| 5.6.0 (included) ~ latest | 2.2.24 ~ latest | [apps.emqx.io/v2beta1](./docs/en_US/reference/v2beta1-reference.md) | EMQX |
| 5.1.1 (included) ~ latest | 2.2.0 ~ latest | [apps.emqx.io/v2beta1](./docs/en_US/reference/v2beta1-reference.md) | EMQX |
| 5.0.0 (included) ~ 5.0.23 | 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.1.0, 2.1.1 | [apps.emqx.io/v2alpha1](./docs/en_US/reference/v2alpha1-reference.md) | EMQX |
| 4.4.14 (included) or higher 4.4.x | 2.1.0, 2.1.1 | [apps.emqx.io/v1beta4](./docs/en_US/reference/v1beta4-reference.md) | EmqxEnterprise |
| 5.0.0 (included) ~ 5.0.23 | 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.1.0, 2.1.1 | [apps.emqx.io/v2alpha1](./docs/en_US/reference/v2alpha1-reference.md) | EMQX |
| 5.1.1 or higher | 2.2.0 | [apps.emqx.io/v2beta1](./docs/en_US/reference/v2beta1-reference.md) | EMQX |
| 4.4.8 (included) ~ 4.4.14 | 1.2.6, 1.2.7, 1.2.8, 2.0.0, 2.0.1, 2.0.2, 2.0.3 | [apps.emqx.io/v1beta3](./docs/en_US/reference/v1beta3-reference.md) | EmqxEnterprise |
| 4.4.6 (included) ~ 4.4.8 | 1.2.5 | [apps.emqx.io/v1beta3](./docs/en_US/reference/v1beta3-reference.md) | EmqxEnterprise |
| 4.3.x (included) ~ 4.4 | 1.2.1, 1.2.2, 1.2.3 | [apps.emqx.io/v1beta3](./docs/en_US/reference/v1beta3-reference.md) | EmqxEnterprise |

### EMQX Open Source

| EMQX Open Source Version | EMQX Operator Version | APIVersion | Kind |
|:----------------------:|:-----------------:|-------------------|:-----------------:|
| 4.3.x (included) ~ 4.4 | 1.2.1, 1.2.2, 1.2.3 | [apps.emqx.io/v1beta3](./docs/en_US/reference/v1beta3-reference.md) | EmqxBroker |
| 5.6.0 (included) ~ latest | 2.2.24 ~ latest | [apps.emqx.io/v2beta1](./docs/en_US/reference/v2beta1-reference.md) | EMQX |
| 5.1.1 (included) ~ latest | 2.2.0 ~ latest | [apps.emqx.io/v2beta1](./docs/en_US/reference/v2beta1-reference.md) | EMQX |
| 5.0.14 (included) ~ 5.0.23 | 2.1.0, 2.1.1 | [apps.emqx.io/v2alpha1](./docs/en_US/reference/v2alpha1-reference.md) | EMQX |
| 5.0.8 (included) ~ 5.0.14 | 2.0.2 | [apps.emqx.io/v2alpha1](./docs/en_US/reference/v2alpha1-reference.md) | EMQX |
| 5.0.6 (included) ~ 5.0.8 | 2.0.0, 2.0.1, 2.0.3 | [apps.emqx.io/v2alpha1](./docs/en_US/reference/v2alpha1-reference.md) | EMQX |
| 4.4.14 or higher 4.4.x | 2.1.0, 2.1.1 | [apps.emqx.io/v1beta4](./docs/en_US/reference/v1beta4-reference.md) | EmqxBroker |
| 4.4.6 (included) ~ 4.4.8 | 1.2.5 | [apps.emqx.io/v1beta3](./docs/en_US/reference/v1beta3-reference.md) | EmqxBroker |
| 4.4.8 (included) ~ 4.4.14 | 1.2.6, 1.2.7, 1.2.8, 2.0.0, 2.0.1, 2.0.2, 2.0.3 | [apps.emqx.io/v1beta3](./docs/en_US/reference/v1beta3-reference.md) | EmqxBroker |
| 4.4.14 or higher 4.4.x | 2.1.0, 2.1.1 | [apps.emqx.io/v1beta4](./docs/en_US/reference/v1beta4-reference.md) | EmqxBroker |
| 5.0.6 (included) ~ 5.0.8 | 2.0.0, 2.0.1, 2.0.3 | [apps.emqx.io/v2alpha1](./docs/en_US/reference/v2alpha1-reference.md) | EMQX |
| 5.0.8 (included) ~ 5.0.14 | 2.0.2 | [apps.emqx.io/v2alpha1](./docs/en_US/reference/v2alpha1-reference.md) | EMQX |
| 5.0.14 (included) ~ 5.0.23 | 2.1.0, 2.1.1 | [apps.emqx.io/v2alpha1](./docs/en_US/reference/v2alpha1-reference.md) | EMQX |
| 5.1.1 or higher | 2.2.0 | [apps.emqx.io/v2beta1](./docs/en_US/reference/v2beta1-reference.md) | EMQX |
| 4.3.x (included) ~ 4.4 | 1.2.1, 1.2.2, 1.2.3 | [apps.emqx.io/v1beta3](./docs/en_US/reference/v1beta3-reference.md) | EmqxBroker |

## How to selector Kubernetes version

The EMQX Operator requires a Kubernetes cluster of version `>=1.24`.

| Kubernetes Versions | EMQX Operator Compatibility | Notes |
| ----------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| 1.24 or higher | All functions supported | |
| 1.29 (included) ~ latest | All functions supported | https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation-rules |
| 1.25 (included) ~ 1.29 | Supported, but [CustomResourceDefinition Validation Rules](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation-rules) is in beta | https://kubernetes.io/blog/2022/09/23/crd-validation-rules-beta/ |
| 1.23 (included) ~ 1.25 | Supported, except [CustomResourceDefinition Validation Rules](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation-rules) | some CRD validation rules might not worked |
| 1.22 (included) ~ 1.23 | Supported, except [MixedProtocolLBService](https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/) | EMQX cluster can only use one protocol in `LoadBalancer` type of Service, for example TCP or UDP. |
| 1.21 (included) ~ 1.22 | Supported, except [pod-deletion-cost](https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/#pod-deletion-cost) | When using EMQX Core + Replicant mode cluster, updating the EMQX cluster cannot accurately delete Pods. |
| 1.20 (included) ~ 1.21 | Supported, manual `.spec.ports[].nodePort` assignment required if using `NodePort` type of Service | For more details, please refer to [Kubernetes changelog](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.20.md#bug-or-regression-4). |
Expand Down
20 changes: 20 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 @@ -164,10 +165,14 @@ type EMQXReplicantTemplate struct {
metav1.ObjectMeta `json:"metadata,omitempty"`
// Specification of the desired behavior of the EMQX replicant node.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
// Controller tools does not support more complex validations (oneOf/anyOf/allOf/etc), so use validation rule instead. https://github.com/kubernetes-sigs/controller-tools/issues/461#issuecomment-1982741599
// +kubebuilder:validation:XValidation:rule="has(self.minAvailable) && has(self.maxUnavailable) ? false : true",message="minAvailable cannot be set when maxUnavailable is specified. These fields are mutually exclusive in PodDisruptionBudget."
Spec EMQXReplicantTemplateSpec `json:"spec,omitempty"`
}

type EMQXCoreTemplateSpec struct {
// Controller tools does not support more complex validations (oneOf/anyOf/allOf/etc), so use validation rule instead. https://github.com/kubernetes-sigs/controller-tools/issues/461#issuecomment-1982741599
// +kubebuilder:validation:XValidation:rule="has(self.minAvailable) && has(self.maxUnavailable) ? false : true",message="minAvailable cannot be set when maxUnavailable is specified. These fields are mutually exclusive in PodDisruptionBudget."
EMQXReplicantTemplateSpec `json:",inline"`

// VolumeClaimTemplates is a list of claims that pods are allowed to reference.
Expand Down Expand Up @@ -198,12 +203,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.

32 changes: 32 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,11 @@ spec:
type: string
type: object
type: object
x-kubernetes-validations:
- message: minAvailable cannot be set when maxUnavailable is specified.
These fields are mutually exclusive in PodDisruptionBudget.
rule: 'has(self.minAvailable) && has(self.maxUnavailable) ?
false : true'
type: object
dashboardServiceTemplate:
properties:
Expand Down Expand Up @@ -13351,6 +13367,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 @@ -13733,6 +13760,11 @@ spec:
type: object
type: array
type: object
x-kubernetes-validations:
- message: minAvailable cannot be set when maxUnavailable is specified.
These fields are mutually exclusive in PodDisruptionBudget.
rule: 'has(self.minAvailable) && has(self.maxUnavailable) ?
false : true'
type: object
revisionHistoryLimit:
default: 3
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
28 changes: 28 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,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 @@ -10277,6 +10288,9 @@ spec:
type: string
type: object
type: object
x-kubernetes-validations:
- message: minAvailable cannot be set when maxUnavailable is specified. These fields are mutually exclusive in PodDisruptionBudget.
rule: 'has(self.minAvailable) && has(self.maxUnavailable) ? false : true'
type: object
dashboardServiceTemplate:
properties:
Expand Down Expand Up @@ -13364,6 +13378,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 @@ -13746,6 +13771,9 @@ spec:
type: object
type: array
type: object
x-kubernetes-validations:
- message: minAvailable cannot be set when maxUnavailable is specified. These fields are mutually exclusive in PodDisruptionBudget.
rule: 'has(self.minAvailable) && has(self.maxUnavailable) ? false : true'
type: object
revisionHistoryLimit:
default: 3
Expand Down
Loading

0 comments on commit aff9217

Please sign in to comment.