I want to implement a conditional template for Deployment resources through helm which can be enabled or disabled as per the environment. Something like the below which in not working. Or can we achieve the same through a different method.
resources:
enabled: true
requests:
cpu: 100m
memory: 128Mi
CodePudding user response:
you can add condition in the deployment template
{{- if .Values.resources_limit.enabled }}
resources:
{{- toYaml .Values.resources_limit.resources | nindent 12 }}
{{- end }}
and the value file should be like this
resources_limit:
enabled: true
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
to disable, for example, develop-values.yaml
resources_limit:
enabled: false
CodePudding user response:
You can also check directly on resource value without adding the If condition or introducing a new variable in values.yaml
resources:
{{- toYaml .Values.resources | nindent 12 }}
values.yaml if values added in values.yaml
they will get applied to the template else will get ignored.
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
Disable it
resources: {}