如何根据values.yaml中的输入使头盔释放失败 [英] How to fail a helm release based on inputs in values.yaml
问题描述
我正在使用helm install
命令安装头盔图表.我有values.yaml
,它需要用户输入一些信息. values.yaml
中的键之一是 action ,该键只能采用三个预定义的值(假设 action1 , action2 和 action3 )作为输入.除此之外的其他任何值都是无效的.
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.
当用户在values.yaml
中向action字段提供值并触发helm install
命令时,我需要检查的第一件事是 action 键是否具有有效值.如果 action 值无效,我希望发布失败并显示正确的错误消息.
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.
例如:如果用户给出了action: action4
,则此操作无效,并且发布应失败,因为.Values.action
只能是 action1 , action2 或 action3 .
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?
推荐答案
我能够通过以下更改实现用例. 在_helpers.tpl
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 -}}
从.tpl文件中调用此函数,如下所示:-
Invoked this function from a .tpl file like this:-
{{ include "actionValidate" . | required "Action value is incorrect. The valid values are 'action1', 'action2', 'action3' " }}
这篇关于如何根据values.yaml中的输入使头盔释放失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!