1

I am trying to create a Helm chart conditional template for a SecurityContextConstraint / SCC based whether I'm installing on an Openshift cluster or not. Because SCCs are Openshift-specific resources.

So that, on executing helm install <release-name> <chart> -n <namespace>) on an Openshift cluster, SCC should automatically get created.

Fallback option would be to use something like this:

{{ if .Values.isOpenshift }}
apiVersion: security.openshift.io/v1
kind: SecurityContextConstraints
...
{{ end }}
lprakashv
  • 1,121
  • 10
  • 19

1 Answers1

3

Helm's Built-in Objects include a .Capabilities object that can be used to inspect the cluster, and more specifically, check whether a specific API version or resource type is supported. Call .Capabilities.APIVersions.Has with the apiVersion or apiVersion/kind field(s) you want to check.

{{- if .Capabilities.APIVersions.Has "security.openshift.io/v1/SecurityContextConstraints" }}
apiVersion: security.openshift.io/v1
kind: SecurityContextConstraints
...
{{- end }}
David Maze
  • 130,717
  • 29
  • 175
  • 215