Skip to content

Commit

Permalink
add commonLabels to customizable values (#1404)
Browse files Browse the repository at this point in the history
**Description of the change**

Helm Chart only update, add new value `commonLabels` that functions the
same as `commonAnnotations` by adding labels to `_helpers.tpl` in
`sealed-secrets.labels`

**Benefits**

* Ability to add custom labels to all resources for any organization
compliance

**Possible drawbacks**

N/A

**Applicable issues**
- fixes #1373

**Additional information**

My current organization requires adding a custom label to all resources,
thus the PR.
The changes in the PR were tested on a local Kubernetes installation
with both `commonLabels: {}` and `commonLabels: {x: 'y'}`

---------

Signed-off-by: M Essam Hamed <[email protected]>
  • Loading branch information
mohamed-essam authored Dec 22, 2023
1 parent f7196bb commit 5e2233c
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions helm/sealed-secrets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The command removes all the Kubernetes components associated with the chart and
| `namespace` | Namespace where to deploy the Sealed Secrets controller | `""` |
| `extraDeploy` | Array of extra objects to deploy with the release | `[]` |
| `commonAnnotations` | Annotations to add to all deployed resources | `{}` |
| `commonLabels` | Labels to add to all deployed resources | `{}` |

### Sealed Secrets Parameters

Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/templates/cluster-role-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ metadata:
{{- if .Values.rbac.labels }}
{{- include "sealed-secrets.render" ( dict "value" .Values.rbac.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/templates/cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ metadata:
{{- if .Values.rbac.labels }}
{{- include "sealed-secrets.render" ( dict "value" .Values.rbac.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
rules:
- apiGroups:
- bitnami.com
Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/templates/configmap-dashboards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ metadata:
{{- if $.Values.metrics.dashboards.labels }}
{{- include "sealed-secrets.render" ( dict "value" $.Values.metrics.dashboards.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
annotations:
{{- if $.Values.metrics.dashboards.annotations }}
{{- include "sealed-secrets.render" ( dict "value" $.Values.metrics.dashboards.annotations "context" $) | nindent 4 }}
Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
name: {{ include "sealed-secrets.fullname" . }}
namespace: {{ include "sealed-secrets.namespace" . }}
labels: {{- include "sealed-secrets.labels" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- toYaml .Values.commonAnnotations | nindent 4 }}
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
name: {{ include "sealed-secrets.fullname" . }}
namespace: {{ include "sealed-secrets.namespace" . }}
labels: {{- include "sealed-secrets.labels" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.ingress.annotations }}
annotations:
{{- if .Values.ingress.annotations }}
Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/templates/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
name: {{ include "sealed-secrets.fullname" . }}
namespace: {{ include "sealed-secrets.namespace" . }}
labels: {{- include "sealed-secrets.labels" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
spec:
podSelector:
matchLabels: {{- include "sealed-secrets.matchLabels" . | nindent 6 }}
Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/templates/pdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
name: {{ include "sealed-secrets.fullname" . }}
namespace: {{ include "sealed-secrets.namespace" . }}
labels: {{- include "sealed-secrets.labels" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- toYaml .Values.commonAnnotations | nindent 4 }}
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/templates/psp-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ metadata:
{{- if .Values.rbac.labels }}
{{- include "sealed-secrets.render" ( dict "value" .Values.rbac.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
rules:
- apiGroups: ['extensions']
resources: ['podsecuritypolicies']
Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/templates/psp-clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ metadata:
{{- if .Values.rbac.labels }}
{{- include "sealed-secrets.render" ( dict "value" .Values.rbac.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/templates/psp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ kind: PodSecurityPolicy
metadata:
name: {{ include "sealed-secrets.fullname" . }}
labels: {{- include "sealed-secrets.labels" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
spec:
privileged: false
allowPrivilegeEscalation: false
Expand Down
6 changes: 6 additions & 0 deletions helm/sealed-secrets/templates/role-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ metadata:
{{- if .Values.rbac.labels }}
{{- include "sealed-secrets.render" ( dict "value" .Values.rbac.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
Expand All @@ -27,6 +30,9 @@ metadata:
{{- if .Values.rbac.labels }}
{{- include "sealed-secrets.render" ( dict "value" .Values.rbac.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
Expand Down
6 changes: 6 additions & 0 deletions helm/sealed-secrets/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ metadata:
{{- if .Values.rbac.labels }}
{{- include "sealed-secrets.render" ( dict "value" .Values.rbac.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
rules:
- apiGroups:
- ""
Expand All @@ -34,6 +37,9 @@ metadata:
{{- if .Values.rbac.labels }}
{{- include "sealed-secrets.render" ( dict "value" .Values.rbac.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
rules:
- apiGroups:
- ""
Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/templates/service-account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ metadata:
{{- if .Values.serviceAccount.labels }}
{{- include "sealed-secrets.render" ( dict "value" .Values.serviceAccount.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
{{ end }}
6 changes: 6 additions & 0 deletions helm/sealed-secrets/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ metadata:
{{- if .Values.service.labels }}
{{- include "sealed-secrets.render" ( dict "value" .Values.service.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.service.type }}
ports:
Expand Down Expand Up @@ -48,6 +51,9 @@ metadata:
{{- if .Values.metrics.service.labels }}
{{- include "sealed-secrets.render" ( dict "value" .Values.metrics.service.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.metrics.service.type }}
ports:
Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ metadata:
{{- if .Values.metrics.serviceMonitor.labels }}
{{- include "sealed-secrets.render" ( dict "value" .Values.metrics.serviceMonitor.labels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.metrics.serviceMonitor.annotations }}
annotations: {{- include "sealed-secrets.render" (dict "value" .Values.metrics.serviceMonitor.annotations "context" $) | nindent 4 }}
{{- end }}
Expand Down
6 changes: 6 additions & 0 deletions helm/sealed-secrets/templates/tls-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ metadata:
name: {{ .name }}
namespace: {{ include "sealed-secrets.namespace" $ | quote }}
labels: {{- include "sealed-secrets.labels" $ | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
type: kubernetes.io/tls
data:
tls.crt: {{ .certificate | b64enc }}
Expand All @@ -23,6 +26,9 @@ metadata:
name: {{ printf "%s-tls" .Values.ingress.hostname }}
namespace: {{ include "sealed-secrets.namespace" . }}
labels: {{- include "sealed-secrets.labels" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
type: kubernetes.io/tls
data:
tls.crt: {{ $cert.Cert | b64enc | quote }}
Expand Down
5 changes: 5 additions & 0 deletions helm/sealed-secrets/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ extraDeploy: []
##
commonAnnotations: {}

## @param commonLabels [ojbect] Labels to add to all deployed resources
## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
##
commonLabels: {}

## @section Sealed Secrets Parameters

## Sealed Secrets image
Expand Down

0 comments on commit 5e2233c

Please sign in to comment.