Skip to content

Commit

Permalink
feat: support custom labels for internal service
Browse files Browse the repository at this point in the history
This change allows configuring labels specifically for the internal
service without affecting the main controller service, useful for
external-dns configuration.
  • Loading branch information
samuelarogbonlo committed Jan 16, 2025
1 parent 8da3423 commit cc2ffd3
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions charts/ingress-nginx/templates/controller-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
37 changes: 37 additions & 0 deletions charts/ingress-nginx/tests/controller-service-internal_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
33 changes: 33 additions & 0 deletions charts/ingress-nginx/tests/controller-service_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
16 changes: 9 additions & 7 deletions charts/ingress-nginx/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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: ""
Expand Down

0 comments on commit cc2ffd3

Please sign in to comment.