diff --git a/charts/ingress-nginx/ci/controller-service-internal-values.yaml b/charts/ingress-nginx/ci/controller-service-internal-values.yaml index 11108fbce9..0d1a1f49a2 100644 --- a/charts/ingress-nginx/ci/controller-service-internal-values.yaml +++ b/charts/ingress-nginx/ci/controller-service-internal-values.yaml @@ -11,3 +11,5 @@ controller: enabled: true annotations: service.beta.kubernetes.io/aws-load-balancer-internal: "true" + labels: + external-dns.alpha.kubernetes.io/hostname: internal.example.com diff --git a/charts/ingress-nginx/templates/controller-service-internal.yaml b/charts/ingress-nginx/templates/controller-service-internal.yaml index 24ac032acc..8d369526da 100644 --- a/charts/ingress-nginx/templates/controller-service-internal.yaml +++ b/charts/ingress-nginx/templates/controller-service-internal.yaml @@ -12,6 +12,9 @@ metadata: {{- if .Values.controller.service.labels }} {{- toYaml .Values.controller.service.labels | nindent 4 }} {{- end }} + {{- if .Values.controller.service.internal.labels }} + {{- toYaml .Values.controller.service.internal.labels | nindent 4 }} + {{- end }} name: {{ include "ingress-nginx.controller.fullname" . }}-internal namespace: {{ include "ingress-nginx.namespace" . }} spec: diff --git a/charts/ingress-nginx/templates/controller-service.yaml b/charts/ingress-nginx/templates/controller-service.yaml index c56d957b14..36d2e48847 100644 --- a/charts/ingress-nginx/templates/controller-service.yaml +++ b/charts/ingress-nginx/templates/controller-service.yaml @@ -12,6 +12,9 @@ metadata: {{- if .Values.controller.service.labels }} {{- toYaml .Values.controller.service.labels | nindent 4 }} {{- end }} + {{- if .Values.controller.service.external.labels }} + {{- toYaml .Values.controller.service.external.labels | nindent 4 }} + {{- end }} name: {{ include "ingress-nginx.controller.fullname" . }} namespace: {{ include "ingress-nginx.namespace" . }} spec: diff --git a/charts/ingress-nginx/tests/controller-service-internal_test.yaml b/charts/ingress-nginx/tests/controller-service-internal_test.yaml index 2680894069..3356cda2d2 100644 --- a/charts/ingress-nginx/tests/controller-service-internal_test.yaml +++ b/charts/ingress-nginx/tests/controller-service-internal_test.yaml @@ -61,3 +61,40 @@ tests: - equal: path: spec.trafficDistribution value: PreferClose + + - it: should create a Service with custom labels if `controller.service.internal.labels` is set + set: + controller.service.internal.enabled: true + controller.service.internal.annotations: + test.annotation: "true" + controller.service.internal.labels: + external-dns.alpha.kubernetes.io/hostname: internal.example.com + asserts: + - hasDocuments: + count: 1 + - isKind: + of: Service + - equal: + path: metadata.labels.external-dns\.alpha\.kubernetes\.io/hostname + value: internal.example.com + + - it: should merge service labels with internal labels maintaining backward compatibility + set: + controller.service.internal.enabled: true + controller.service.internal.annotations: + test.annotation: "true" + controller.service.labels: + global-service: "true" + controller.service.internal.labels: + internal-specific: "true" + asserts: + - hasDocuments: + count: 1 + - isKind: + of: Service + - equal: + path: metadata.labels.global-service + value: "true" + - equal: + path: metadata.labels.internal-specific + value: "true" diff --git a/charts/ingress-nginx/tests/controller-service_test.yaml b/charts/ingress-nginx/tests/controller-service_test.yaml index 4741cdde9a..e072a91bd8 100644 --- a/charts/ingress-nginx/tests/controller-service_test.yaml +++ b/charts/ingress-nginx/tests/controller-service_test.yaml @@ -62,3 +62,36 @@ tests: - equal: path: spec.trafficDistribution value: PreferClose + + - it: should create a Service with custom external labels if `controller.service.external.labels` is set + set: + controller.service.external.enabled: true + controller.service.external.labels: + custom-external: test-value + asserts: + - hasDocuments: + count: 1 + - isKind: + of: Service + - equal: + path: metadata.labels.custom-external + value: test-value + + - it: should merge service labels with external labels maintaining backward compatibility + set: + controller.service.external.enabled: true + controller.service.labels: + global-service: "true" + controller.service.external.labels: + external-specific: "true" + asserts: + - hasDocuments: + count: 1 + - isKind: + of: Service + - equal: + path: metadats.labels.global-service + value: "true" + - equal: + path: metadata.labels.external-specific + value: "true" diff --git a/charts/ingress-nginx/values.yaml b/charts/ingress-nginx/values.yaml index 9875b36933..258e7dfc24 100644 --- a/charts/ingress-nginx/values.yaml +++ b/charts/ingress-nginx/values.yaml @@ -486,12 +486,12 @@ controller: external: # -- Enable the external controller service or not. Useful for internal-only deployments. enabled: true - # -- Annotations to be added to the external controller service. See `controller.service.internal.annotations` for annotations to be added to the internal controller service. - annotations: {} - # -- Labels to be added to both controller services. - labels: {} - # -- Type of the external controller service. - # Ref: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types + # -- Annotations to be added to the external controller service. See `controller.service.internal.annotations` for annotations to be added to the internal controller service. + annotations: {} + # -- Additional custom labels specifically for the external controller service + labels: {} + # -- Type of the external controller service. + # Ref: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types type: LoadBalancer # -- Pre-defined cluster internal IP address of the external controller service. Take care of collisions with existing services. # This value is immutable. Set once, it can not be changed without deleting and re-creating the service. @@ -577,7 +577,9 @@ controller: # -- Annotations to be added to the internal controller service. Mandatory for the internal controller service to be created. Varies with the cloud service. # Ref: https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer annotations: {} - # -- Type of the internal controller service. + # -- Additional custom labeles specifically for the internal controller service. + labels: {} + # -- Type of the internal controller service # Defaults to the value of `controller.service.type`. # Ref: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types type: ""