Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fail a helm release based on inputs in values.yaml

I'm installing up a helm chart using helm install command. I have values.yaml which takes a few inputs from the user. One of the keys in values.yaml is action, which can only take three predefined values (let's say action1, action2 and action3) as an input. Any other value other than this is invalid.

When a user provides the value to action field in values.yaml and trigger the helm install command, the first thing I need to check is that if the action key has a valid value or not. If the action value is invalid, I want the release to be failed with a proper error message.

e.g.: In case the user has given action: action4, this is not valid and release should fail as .Values.action can only be action1, action2, or action3.

How I can achieve this use case and which file should be best to handle this validation considering the helm structure?

like image 985
Saurabh Avatar asked Apr 02 '19 15:04

Saurabh


2 Answers

I was able to achieve the use case with below changes. Added the following code in _helpers.tpl

{{- define "actionValidate" -}}
  {{ $action := .Values.actions }}
  {{- if or (eq $action "action1") (eq $action "action2") (eq $action "action3") -}}
    true
  {{- end -}}
{{- end -}}

Invoked this function from a .tpl file like this:-

{{ include "actionValidate" .  | required "Action value is incorrect. The valid values are 'action1', 'action2', 'action3' " }}
like image 194
Saurabh Avatar answered Oct 08 '22 22:10

Saurabh


With HelmV3 there is now an easier way. Just specify a schema that includes your values.

For example:

 title: Values
    type: object
    properties:
        action:
            description: Some action
            type: string
            pattern: "^(action1|action2|action3)$"
like image 26
Daniel Habenicht Avatar answered Oct 08 '22 21:10

Daniel Habenicht