Skip to content

Commit

Permalink
Avoid creating Tuf objects if there is no secrets
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Vega <[email protected]>
  • Loading branch information
cvegagimenez committed Sep 26, 2024
1 parent 89630d3 commit 0bd3586
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 16 deletions.
20 changes: 20 additions & 0 deletions charts/tuf/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,24 @@ app.kubernetes.io/instance: {{ .Release.Name }}
{{- define "tuf.metaLabels" -}}
helm.sh/chart: {{ include "tuf.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Check number of TUF secrets
*/}}
{{- define "tuf.enabledSecretsCount" -}}
{{- $count := 0 -}}
{{- if (eq .Values.secrets.rekor.enabled true) -}}
{{- $count = add $count 1 -}}
{{- end -}}
{{- if (eq .Values.secrets.fulcio.enabled true) -}}
{{- $count = add $count 1 -}}
{{- end -}}
{{- if (eq .Values.secrets.ctlog.enabled true) -}}
{{- $count = add $count 1 -}}
{{- end -}}
{{- if (eq .Values.secrets.tsa.enabled true) -}}
{{- $count = add $count 1 -}}
{{- end -}}
{{- $count -}}
{{- end -}}
14 changes: 2 additions & 12 deletions charts/tuf/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if ne (include "tuf.enabledSecretsCount" .) "0" }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -80,15 +81,4 @@ spec:
imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 8 }}
{{- end }}
{{- if .Values.deployment.nodeSelector }}
nodeSelector:
{{ toYaml .Values.deployment.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.deployment.tolerations }}
tolerations:
{{ toYaml .Values.deployment.tolerations | indent 8 }}
{{- end }}
{{- if .Values.deployment.affinity }}
affinity:
{{ toYaml .Values.deployment.affinity | indent 8 }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions charts/tuf/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if .Values.ingress.create }}
{{- if ne (include "tuf.enabledSecretsCount" .) "0" }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
Expand Down Expand Up @@ -34,3 +35,4 @@ spec:
{{- end }}
{{- end -}}
{{- end -}}
{{- end -}}
2 changes: 2 additions & 0 deletions charts/tuf/templates/namespace.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{- if .Values.namespace.create }}
{{- if ne (include "tuf.enabledSecretsCount" .) "0" }}
apiVersion: v1
kind: Namespace
metadata:
name: {{ .Values.namespace.name }}
{{- end }}
{{- end }}
4 changes: 3 additions & 1 deletion charts/tuf/templates/role.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if ne (include "tuf.enabledSecretsCount" .) "0" }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
Expand All @@ -6,4 +7,5 @@ metadata:
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["create", "get", "update"]
verbs: ["create", "get", "update"]
{{- end }}
4 changes: 3 additions & 1 deletion charts/tuf/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if ne (include "tuf.enabledSecretsCount" .) "0" }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
Expand All @@ -9,4 +10,5 @@ roleRef:
name: {{ .Values.roleName }}
subjects:
- kind: ServiceAccount
name: {{ .Values.serviceAccountName }}
name: {{ .Values.serviceAccountName }}
{{- end }}
4 changes: 3 additions & 1 deletion charts/tuf/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if ne (include "tuf.enabledSecretsCount" .) "0" }}
apiVersion: v1
kind: Service
metadata:
Expand All @@ -11,4 +12,5 @@ spec:
targetPort: {{ .Values.deployment.port }}
selector:
{{- include "tuf.matchLabels" . | nindent 4 }}
type: ClusterIP
type: ClusterIP
{{- end }}
4 changes: 3 additions & 1 deletion charts/tuf/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{- if ne (include "tuf.enabledSecretsCount" .) "0" }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.serviceAccountName }}
{{ include "tuf.namespace" . | indent 2 }}
{{ include "tuf.namespace" . | indent 2 }}
{{- end }}

0 comments on commit 0bd3586

Please sign in to comment.