patch-consoles-job.yaml 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. {{- if .Values.plugin.jobs.patchConsoles.enabled }}
  2. apiVersion: batch/v1
  3. kind: Job
  4. metadata:
  5. name: {{ template "openshift-console-plugin.patcherName" . }}
  6. namespace: {{ .Release.Namespace }}
  7. labels:
  8. {{- include "openshift-console-plugin.labels" . | nindent 4 }}
  9. annotations:
  10. helm.sh/hook: post-install,post-upgrade
  11. helm.sh/hook-delete-policy: before-hook-creation
  12. spec:
  13. parallelism: 1
  14. template:
  15. metadata:
  16. labels:
  17. {{- include "openshift-console-plugin.labels" . | nindent 8 }}
  18. spec:
  19. restartPolicy: OnFailure
  20. serviceAccountName: {{ template "openshift-console-plugin.patcherServiceAccountName" . }}
  21. {{- if and (.Values.plugin.securityContext.enabled) (.Values.plugin.jobs.patchConsoles.podSecurityContext.enabled) }}
  22. securityContext: {{ tpl (toYaml (omit .Values.plugin.jobs.patchConsoles.podSecurityContext "enabled")) $ | nindent 8 }}
  23. {{- end }}
  24. terminationGracePeriodSeconds: 400
  25. dnsPolicy: ClusterFirst
  26. containers:
  27. - name: {{ template "openshift-console-plugin.patcherName" . }}
  28. image: {{ required "Patcher image must be specified!" .Values.plugin.jobs.patchConsoles.image }}
  29. {{- if and (.Values.plugin.disableSecurityContext) (.Values.plugin.jobs.patchConsoles.containerSecurityContext.enabled) }}
  30. securityContext: {{ tpl (toYaml (omit .Values.plugin.jobs.patchConsoles.containerSecurityContext "enabled")) $ | nindent 12 }}
  31. {{- end }}
  32. resources:
  33. {{- toYaml .Values.plugin.jobs.patchConsoles.resources | nindent 12 }}
  34. command:
  35. - /bin/bash
  36. - -c
  37. - |
  38. existingPlugins=$(oc get consoles.operator.openshift.io cluster -o json | jq -c '.spec.plugins // []')
  39. mergedPlugins=$(jq --argjson existingPlugins "${existingPlugins}" --argjson consolePlugin '["{{ template "openshift-console-plugin.name" . }}"]' -c -n '$existingPlugins + $consolePlugin | unique')
  40. patchedPlugins=$(jq --argjson mergedPlugins $mergedPlugins -n -c '{ "spec": { "plugins": $mergedPlugins } }')
  41. oc patch consoles.operator.openshift.io cluster --patch $patchedPlugins --type=merge
  42. {{- end }}