label-allowed-namespaces.yaml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. {{- if .Values.allowedNamespaces }}
  2. {{- $allowedNamespaces := regexSplit " " (include "allowedNamespaces" .) -1 }}
  3. apiVersion: batch/v1
  4. kind: Job
  5. metadata:
  6. namespace: {{ .Release.Namespace }}
  7. name: "{{ .Release.Name }}-annotate-namespaces"
  8. labels:
  9. app: stackgres-operator-init
  10. job: annotate-namespaces
  11. annotations:
  12. "helm.sh/hook": pre-install,pre-upgrade
  13. "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
  14. "helm.sh/hook-weight": "10"
  15. {{- with .Values.jobs.annotations }}
  16. {{- toYaml . | nindent 4 }}
  17. {{- end }}
  18. spec:
  19. ttlSecondsAfterFinished: 3600
  20. template:
  21. metadata:
  22. labels:
  23. app: stackgres-operator-init
  24. job: annotate-namespaces
  25. spec:
  26. serviceAccountName: {{ .Release.Name }}-init
  27. restartPolicy: OnFailure
  28. terminationGracePeriodSeconds: 0
  29. {{- with .Values.jobs.affinity}}
  30. affinity:
  31. {{- toYaml . | nindent 8 }}
  32. {{- end}}
  33. {{- with .Values.jobs.nodeSelector}}
  34. nodeSelector:
  35. {{- toYaml . | nindent 8 }}
  36. {{- end }}
  37. {{- with .Values.jobs.tolerations }}
  38. tolerations:
  39. {{- toYaml . | nindent 8 }}
  40. {{- end }}
  41. containers:
  42. - name: "annotate-namespaces"
  43. image: {{ template "kubectl-image" . }}
  44. imagePullPolicy: "IfNotPresent"
  45. {{- with .Values.jobs.resources }}
  46. resources:
  47. {{- toYaml . | nindent 10 }}
  48. {{- end }}
  49. command:
  50. - "/bin/bash"
  51. - "-ecx"
  52. - |
  53. {{- range $namespace := $allowedNamespaces }}
  54. kubectl label namespace "{{ $namespace }}" --overwrite stackgres.io/scope={{ $.Release.Namespace }}.{{ $.Release.Name }}
  55. {{- end }}
  56. {{- end }}