From 1f91b1d44f7e0eea607bb48159050cac267f2439 Mon Sep 17 00:00:00 2001 From: Rory Z <16801068+Rory-Z@users.noreply.github.com> Date: Thu, 17 Aug 2023 14:13:44 +0800 Subject: [PATCH] chore: change svc template type Signed-off-by: Rory Z <16801068+Rory-Z@users.noreply.github.com> --- .github/workflows/deploy.yaml | 2 + apis/apps/v2beta1/emqx_types.go | 4 +- apis/apps/v2beta1/zz_generated.deepcopy.go | 4 +- config/crd/bases/apps.emqx.io_emqxes.yaml | 154 ------------------ controllers/apps/v2beta1/add_svc.go | 15 +- controllers/apps/v2beta1/add_svc_test.go | 2 +- .../templates/crd.emqxes.apps.emqx.io.yaml | 154 ------------------ docs/en_US/reference/v2beta1-reference.md | 17 +- docs/zh_CN/reference/v2beta1-reference.md | 17 +- 9 files changed, 46 insertions(+), 323 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 87866ccf9..b7568b2c7 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -64,6 +64,8 @@ jobs: --set image.tag=${{ github.sha }} \ --namespace emqx-operator-system \ --create-namespace + - name: Enable debug + run: | kubectl patch -n emqx-operator-system deployment emqx-operator-controller-manager \ --type=json \ -p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--zap-devel=true"}]' diff --git a/apis/apps/v2beta1/emqx_types.go b/apis/apps/v2beta1/emqx_types.go index d53b614bc..5239a72c6 100644 --- a/apis/apps/v2beta1/emqx_types.go +++ b/apis/apps/v2beta1/emqx_types.go @@ -84,11 +84,11 @@ type EMQXSpec struct { // DashboardServiceTemplate is the object that describes the EMQX dashboard service that will be created // This service always selector the EMQX core node - DashboardServiceTemplate *corev1.Service `json:"dashboardServiceTemplate,omitempty"` + DashboardServiceTemplate *ServiceTemplate `json:"dashboardServiceTemplate,omitempty"` // ListenersServiceTemplate is the object that describes the EMQX listener service that will be created // If the EMQX replicant node exist, this service will selector the EMQX replicant node // Else this service will selector EMQX core node - ListenersServiceTemplate *corev1.Service `json:"listenersServiceTemplate,omitempty"` + ListenersServiceTemplate *ServiceTemplate `json:"listenersServiceTemplate,omitempty"` } type BootstrapAPIKey struct { diff --git a/apis/apps/v2beta1/zz_generated.deepcopy.go b/apis/apps/v2beta1/zz_generated.deepcopy.go index 2f4608dd3..d28cdcf89 100644 --- a/apis/apps/v2beta1/zz_generated.deepcopy.go +++ b/apis/apps/v2beta1/zz_generated.deepcopy.go @@ -352,12 +352,12 @@ func (in *EMQXSpec) DeepCopyInto(out *EMQXSpec) { } if in.DashboardServiceTemplate != nil { in, out := &in.DashboardServiceTemplate, &out.DashboardServiceTemplate - *out = new(v1.Service) + *out = new(ServiceTemplate) (*in).DeepCopyInto(*out) } if in.ListenersServiceTemplate != nil { in, out := &in.ListenersServiceTemplate, &out.ListenersServiceTemplate - *out = new(v1.Service) + *out = new(ServiceTemplate) (*in).DeepCopyInto(*out) } } diff --git a/config/crd/bases/apps.emqx.io_emqxes.yaml b/config/crd/bases/apps.emqx.io_emqxes.yaml index be7b59871..a31dd4521 100644 --- a/config/crd/bases/apps.emqx.io_emqxes.yaml +++ b/config/crd/bases/apps.emqx.io_emqxes.yaml @@ -9556,10 +9556,6 @@ spec: type: object dashboardServiceTemplate: properties: - apiVersion: - type: string - kind: - type: string metadata: properties: annotations: @@ -9668,79 +9664,6 @@ spec: type: type: string type: object - status: - properties: - conditions: - items: - properties: - lastTransitionTime: - format: date-time - type: string - message: - maxLength: 32768 - type: string - observedGeneration: - format: int64 - minimum: 0 - type: integer - reason: - maxLength: 1024 - minLength: 1 - pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ - type: string - status: - enum: - - "True" - - "False" - - Unknown - type: string - type: - maxLength: 316 - pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ - type: string - required: - - lastTransitionTime - - message - - reason - - status - - type - type: object - type: array - x-kubernetes-list-map-keys: - - type - x-kubernetes-list-type: map - loadBalancer: - properties: - ingress: - items: - properties: - hostname: - type: string - ip: - type: string - ports: - items: - properties: - error: - maxLength: 316 - pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ - type: string - port: - format: int32 - type: integer - protocol: - default: TCP - type: string - required: - - port - - protocol - type: object - type: array - x-kubernetes-list-type: atomic - type: object - type: array - type: object - type: object type: object image: type: string @@ -9756,10 +9679,6 @@ spec: type: array listenersServiceTemplate: properties: - apiVersion: - type: string - kind: - type: string metadata: properties: annotations: @@ -9868,79 +9787,6 @@ spec: type: type: string type: object - status: - properties: - conditions: - items: - properties: - lastTransitionTime: - format: date-time - type: string - message: - maxLength: 32768 - type: string - observedGeneration: - format: int64 - minimum: 0 - type: integer - reason: - maxLength: 1024 - minLength: 1 - pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ - type: string - status: - enum: - - "True" - - "False" - - Unknown - type: string - type: - maxLength: 316 - pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ - type: string - required: - - lastTransitionTime - - message - - reason - - status - - type - type: object - type: array - x-kubernetes-list-map-keys: - - type - x-kubernetes-list-type: map - loadBalancer: - properties: - ingress: - items: - properties: - hostname: - type: string - ip: - type: string - ports: - items: - properties: - error: - maxLength: 316 - pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ - type: string - port: - format: int32 - type: integer - protocol: - default: TCP - type: string - required: - - port - - protocol - type: object - type: array - x-kubernetes-list-type: atomic - type: object - type: array - type: object - type: object type: object replicantTemplate: properties: diff --git a/controllers/apps/v2beta1/add_svc.go b/controllers/apps/v2beta1/add_svc.go index f1a3ed989..91692bd97 100644 --- a/controllers/apps/v2beta1/add_svc.go +++ b/controllers/apps/v2beta1/add_svc.go @@ -83,10 +83,12 @@ func generateDashboardService(instance *appsv2beta1.EMQX, configStr string) *cor } } - svc := instance.Spec.DashboardServiceTemplate.DeepCopy() - if svc == nil { - svc = &corev1.Service{} + svc := &corev1.Service{} + if instance.Spec.DashboardServiceTemplate != nil { + svc.ObjectMeta = *instance.Spec.DashboardServiceTemplate.ObjectMeta.DeepCopy() + svc.Spec = *instance.Spec.DashboardServiceTemplate.Spec.DeepCopy() } + svc.Spec.Ports = appsv2beta1.MergeServicePorts( svc.Spec.Ports, []corev1.ServicePort{ @@ -141,9 +143,10 @@ func generateListenerService(instance *appsv2beta1.EMQX, configStr string) *core }...) } - svc := instance.Spec.ListenersServiceTemplate.DeepCopy() - if svc == nil { - svc = &corev1.Service{} + svc := &corev1.Service{} + if instance.Spec.ListenersServiceTemplate != nil { + svc.ObjectMeta = *instance.Spec.ListenersServiceTemplate.ObjectMeta.DeepCopy() + svc.Spec = *instance.Spec.ListenersServiceTemplate.Spec.DeepCopy() } svc.Spec.Ports = appsv2beta1.MergeServicePorts( diff --git a/controllers/apps/v2beta1/add_svc_test.go b/controllers/apps/v2beta1/add_svc_test.go index cde49bcdd..59d5a23f4 100644 --- a/controllers/apps/v2beta1/add_svc_test.go +++ b/controllers/apps/v2beta1/add_svc_test.go @@ -73,7 +73,7 @@ func TestGenerateDashboardService(t *testing.T) { Labels: appsv2beta1.DefaultCoreLabels(emqx), }, }, - DashboardServiceTemplate: &corev1.Service{ + DashboardServiceTemplate: &appsv2beta1.ServiceTemplate{ ObjectMeta: metav1.ObjectMeta{ Name: "emqx-dashboard", Labels: map[string]string{ 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 aaa75b03d..d75ccbe36 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 @@ -9568,10 +9568,6 @@ spec: type: object dashboardServiceTemplate: properties: - apiVersion: - type: string - kind: - type: string metadata: properties: annotations: @@ -9680,79 +9676,6 @@ spec: type: type: string type: object - status: - properties: - conditions: - items: - properties: - lastTransitionTime: - format: date-time - type: string - message: - maxLength: 32768 - type: string - observedGeneration: - format: int64 - minimum: 0 - type: integer - reason: - maxLength: 1024 - minLength: 1 - pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ - type: string - status: - enum: - - "True" - - "False" - - Unknown - type: string - type: - maxLength: 316 - pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ - type: string - required: - - lastTransitionTime - - message - - reason - - status - - type - type: object - type: array - x-kubernetes-list-map-keys: - - type - x-kubernetes-list-type: map - loadBalancer: - properties: - ingress: - items: - properties: - hostname: - type: string - ip: - type: string - ports: - items: - properties: - error: - maxLength: 316 - pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ - type: string - port: - format: int32 - type: integer - protocol: - default: TCP - type: string - required: - - port - - protocol - type: object - type: array - x-kubernetes-list-type: atomic - type: object - type: array - type: object - type: object type: object image: type: string @@ -9768,10 +9691,6 @@ spec: type: array listenersServiceTemplate: properties: - apiVersion: - type: string - kind: - type: string metadata: properties: annotations: @@ -9880,79 +9799,6 @@ spec: type: type: string type: object - status: - properties: - conditions: - items: - properties: - lastTransitionTime: - format: date-time - type: string - message: - maxLength: 32768 - type: string - observedGeneration: - format: int64 - minimum: 0 - type: integer - reason: - maxLength: 1024 - minLength: 1 - pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ - type: string - status: - enum: - - "True" - - "False" - - Unknown - type: string - type: - maxLength: 316 - pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ - type: string - required: - - lastTransitionTime - - message - - reason - - status - - type - type: object - type: array - x-kubernetes-list-map-keys: - - type - x-kubernetes-list-type: map - loadBalancer: - properties: - ingress: - items: - properties: - hostname: - type: string - ip: - type: string - ports: - items: - properties: - error: - maxLength: 316 - pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ - type: string - port: - format: int32 - type: integer - protocol: - default: TCP - type: string - required: - - port - - protocol - type: object - type: array - x-kubernetes-list-type: atomic - type: object - type: array - type: object - type: object type: object replicantTemplate: properties: diff --git a/docs/en_US/reference/v2beta1-reference.md b/docs/en_US/reference/v2beta1-reference.md index 2021a94dd..4aa188dc6 100644 --- a/docs/en_US/reference/v2beta1-reference.md +++ b/docs/en_US/reference/v2beta1-reference.md @@ -245,8 +245,8 @@ _Appears in:_ | `updateStrategy` _[UpdateStrategy](#updatestrategy)_ | UpdateStrategy is the object that describes the EMQX blue-green update strategy | | `coreTemplate` _[EMQXCoreTemplate](#emqxcoretemplate)_ | CoreTemplate is the object that describes the EMQX core node that will be created | | `replicantTemplate` _[EMQXReplicantTemplate](#emqxreplicanttemplate)_ | ReplicantTemplate is the object that describes the EMQX replicant node that will be created | -| `dashboardServiceTemplate` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#service-v1-core)_ | DashboardServiceTemplate is the object that describes the EMQX dashboard service that will be created This service always selector the EMQX core node | -| `listenersServiceTemplate` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#service-v1-core)_ | ListenersServiceTemplate is the object that describes the EMQX listener service that will be created If the EMQX replicant node exist, this service will selector the EMQX replicant node Else this service will selector EMQX core node | +| `dashboardServiceTemplate` _[ServiceTemplate](#servicetemplate)_ | DashboardServiceTemplate is the object that describes the EMQX dashboard service that will be created This service always selector the EMQX core node | +| `listenersServiceTemplate` _[ServiceTemplate](#servicetemplate)_ | ListenersServiceTemplate is the object that describes the EMQX listener service that will be created If the EMQX replicant node exist, this service will selector the EMQX replicant node Else this service will selector EMQX core node | #### EMQXStatus @@ -472,6 +472,19 @@ _Appears in:_ | `relSessThreshold` _string_ | RelSessThreshold represents the relative threshold for checking session connection balance. same to rel-sess-threshold in [EMQX Rebalancing](https://docs.emqx.com/en/enterprise/v4.4/advanced/rebalancing.html#rebalancing) the usage of float highly discouraged, as support for them varies across languages. So we define the RelSessThreshold field as string type and you not float type The value must be greater than "1.0" Defaults to "1.1". | +#### ServiceTemplate + + + + + +_Appears in:_ +- [EMQXSpec](#emqxspec) + +| Field | Description | +| --- | --- | +| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | +| `spec` _[ServiceSpec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#servicespec-v1-core)_ | Spec defines the behavior of a service. https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status | #### UpdateStrategy diff --git a/docs/zh_CN/reference/v2beta1-reference.md b/docs/zh_CN/reference/v2beta1-reference.md index 2021a94dd..4aa188dc6 100644 --- a/docs/zh_CN/reference/v2beta1-reference.md +++ b/docs/zh_CN/reference/v2beta1-reference.md @@ -245,8 +245,8 @@ _Appears in:_ | `updateStrategy` _[UpdateStrategy](#updatestrategy)_ | UpdateStrategy is the object that describes the EMQX blue-green update strategy | | `coreTemplate` _[EMQXCoreTemplate](#emqxcoretemplate)_ | CoreTemplate is the object that describes the EMQX core node that will be created | | `replicantTemplate` _[EMQXReplicantTemplate](#emqxreplicanttemplate)_ | ReplicantTemplate is the object that describes the EMQX replicant node that will be created | -| `dashboardServiceTemplate` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#service-v1-core)_ | DashboardServiceTemplate is the object that describes the EMQX dashboard service that will be created This service always selector the EMQX core node | -| `listenersServiceTemplate` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#service-v1-core)_ | ListenersServiceTemplate is the object that describes the EMQX listener service that will be created If the EMQX replicant node exist, this service will selector the EMQX replicant node Else this service will selector EMQX core node | +| `dashboardServiceTemplate` _[ServiceTemplate](#servicetemplate)_ | DashboardServiceTemplate is the object that describes the EMQX dashboard service that will be created This service always selector the EMQX core node | +| `listenersServiceTemplate` _[ServiceTemplate](#servicetemplate)_ | ListenersServiceTemplate is the object that describes the EMQX listener service that will be created If the EMQX replicant node exist, this service will selector the EMQX replicant node Else this service will selector EMQX core node | #### EMQXStatus @@ -472,6 +472,19 @@ _Appears in:_ | `relSessThreshold` _string_ | RelSessThreshold represents the relative threshold for checking session connection balance. same to rel-sess-threshold in [EMQX Rebalancing](https://docs.emqx.com/en/enterprise/v4.4/advanced/rebalancing.html#rebalancing) the usage of float highly discouraged, as support for them varies across languages. So we define the RelSessThreshold field as string type and you not float type The value must be greater than "1.0" Defaults to "1.1". | +#### ServiceTemplate + + + + + +_Appears in:_ +- [EMQXSpec](#emqxspec) + +| Field | Description | +| --- | --- | +| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | +| `spec` _[ServiceSpec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#servicespec-v1-core)_ | Spec defines the behavior of a service. https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status | #### UpdateStrategy