Skip to content

Commit

Permalink
feat: common labels for all resources
Browse files Browse the repository at this point in the history
  • Loading branch information
project0 committed Apr 28, 2023
1 parent b11f486 commit 71be847
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
3 changes: 3 additions & 0 deletions traefik/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ app.kubernetes.io/instance: {{ template "traefik.instance-name" . }}
{{ include "traefik.labelselector" . }}
helm.sh/chart: {{ template "traefik.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Values.commonLabels }}
{{ toYaml .Values.commonLabels }}
{{- end }}
{{- end }}

{{/*
Expand Down
2 changes: 2 additions & 0 deletions traefik/templates/gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ kind: Gateway
metadata:
name: traefik-gateway
namespace: {{ default (include "traefik.namespace" .) .Values.experimental.kubernetesGateway.namespace }}
labels:
{{- include "traefik.labels" . | nindent 4 }}
{{- with .Values.experimental.kubernetesGateway.gateway.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
2 changes: 2 additions & 0 deletions traefik/templates/gatewayclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ apiVersion: gateway.networking.k8s.io/v1alpha2
kind: GatewayClass
metadata:
name: traefik
labels:
{{- include "traefik.labels" . | nindent 4 }}
spec:
controllerName: traefik.io/gateway-controller
{{- end }}
62 changes: 62 additions & 0 deletions traefik/tests/common-metadata_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
suite: Resources contains metadata
templates:
- dashboard-ingressroute.yaml
- deployment.yaml
- gatewayclass.yaml
- gateway.yaml
- hpa.yaml
- ingressclass.yaml
- poddisruptionbudget.yaml
- prometheusrules.yaml
- pvc.yaml
- service-hub.yaml
- service-internal.yaml
- servicemonitor.yaml
- service.yaml
- tlsoption.yaml
- tlsstore.yaml
- rbac/clusterrole.yaml
- rbac/clusterrolebinding.yaml
- rbac/podsecuritypolicy.yaml
- rbac/role.yaml
- rbac/rolebinding.yaml
- rbac/serviceaccount.yaml

tests:
- it: "should contains labels metadata"
set:
experimental.kubernetesGateway.enabled: true
experimental.kubernetesGateway.gateway.enabled: true
autoscaling.enabled: true
autoscaling.maxReplicas: 10
podDisruptionBudget.enabled: true
metrics.prometheus.prometheusRule.namespace: test
metrics.prometheus.serviceMonitor.namespace: test
metrics.prometheus.service.enabled: true
service.internal.a: {}
persistence.enabled: true
hub.enabled: enabled
tlsStore.a: {}
tlsOptions.a: {}
podSecurityPolicy.enabled: true
rbac.enabled: true
rbac.namespaced: true
commonLabels:
globalLabel: isConfigured
capabilities:
majorVersion: 1
minorVersion: 16
apiVersions:
- monitoring.coreos.com/v1
- autoscaling/v2beta1
asserts:
- isNotEmpty:
path: metadata.labels
- isSubset:
path: metadata.labels
content:
app.kubernetes.io/managed-by: Helm
- isSubset:
path: metadata.labels
content:
globalLabel: isConfigured
4 changes: 4 additions & 0 deletions traefik/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ image:
tag: ""
pullPolicy: IfNotPresent

# Add additional label to all resources
# commonLabels:
# key: value

#
# Configure integration with Traefik Hub
#
Expand Down

0 comments on commit 71be847

Please sign in to comment.