Skip to content

Commit

Permalink
fix: add labels to containers
Browse files Browse the repository at this point in the history
  • Loading branch information
soniqua committed Sep 24, 2024
1 parent f5bcf30 commit 40fba61
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 4 deletions.
9 changes: 8 additions & 1 deletion charts/snyk-broker/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ app.kubernetes.io/name: {{ include "snyk-broker.name" . }}{{if not .Values.disab
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Pod labels (merge normal labels and selectors)
*/}}
{{- define "snyk-broker.podLabels" -}}
{{- merge (include "snyk-broker.labels" . | fromYaml ) (include "snyk-broker.selectorLabels" . | fromYaml) | toYaml -}}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
Expand Down Expand Up @@ -113,7 +120,7 @@ Create the name of the broker service to use
{{- $serviceLength := len $service -}}
{{- $releaseNameLength := len .Release.Name -}}
{{- $truncatedLength := int (sub 63 (add $serviceLength $releaseNameLength)) -}}
{{- .Values.scmType | trunc $truncatedLength }}{{ $service }}{{ .Release.Name }}
{{- .Values.scmType | trunc $truncatedLength }}{{ $service }}{{ .Release.Name }}
{{- else }}
{{- .Values.scmType | trunc 47 }}-broker-service
{{- end -}}
Expand Down
2 changes: 1 addition & 1 deletion charts/snyk-broker/templates/broker_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "snyk-broker.selectorLabels" . | nindent 8 }}
{{- include "snyk-broker.podLabels" . | nindent 8 }}
spec:
{{- if .Values.extraPodSpecs }}
{{- toYaml .Values.extraPodSpecs | nindent 6 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ with CRA:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ with CRA:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ apprisk enabled:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ should render artifactoryUrl and brokerClientValidationUrl as secrets:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ customaccept values:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ customaccept values:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ HA mode on:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down Expand Up @@ -167,7 +169,9 @@ HA mode on with 4 replicas:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down Expand Up @@ -314,7 +318,9 @@ default values:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down Expand Up @@ -459,7 +465,9 @@ preflight checks off:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ ingress:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ ingress:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ github token pool configured:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down Expand Up @@ -178,7 +180,9 @@ github token pool configured with enabled useExternalSecretScmTokenPool:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down Expand Up @@ -328,7 +332,9 @@ gitlab token pool configured:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ HA mode on:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down Expand Up @@ -167,7 +169,9 @@ HA mode on with 4 replicas:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down Expand Up @@ -314,7 +318,9 @@ HTTPS enabled:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down Expand Up @@ -478,7 +484,9 @@ default values:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down Expand Up @@ -623,7 +631,9 @@ preflight checks off:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ default values:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ default values:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ default values:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ default values:
metadata:
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
spec:
containers:
- env:
Expand Down
19 changes: 17 additions & 2 deletions charts/snyk-broker/tests/broker_deployment_labels_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ values:

tests:
- it: handles duplicative labels and adds new labels
values:
- ./fixtures/default_values.yaml
set:
labels:
app.kubernetes.io/name: "my duplicated label"
Expand All @@ -25,3 +23,20 @@ tests:
app.kubernetes.io/name: snyk-broker-RELEASE-NAME
helm.sh/chart: snyk-broker-0.0.0
test: node1
- it: sets a label
set:
labels:
costCenter: prodsec
asserts:
- equal:
path: metadata.labels.costCenter
value: prodsec
- it: sets a label on the broker pod
set:
labels:
costCenter: prodsec
asserts:
- equal:
path: spec.template.metadata.labels.costCenter
value: prodsec
template: broker_deployment.yaml

0 comments on commit 40fba61

Please sign in to comment.