在舵图中最好怎么说一个值? [英] How best to say a value is required in a helm chart?

查看:83
本文介绍了在舵图中最好怎么说一个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在这样做:

value: {{ required "A valid .Values.foo entry required!" .Values.foo }}

但是要为模板中的所有必需值提供相同的消息很麻烦,并且使模板混乱.

But to give this same message for all required values in the templates is cumbersome and clutters the templates in my opinion.

有没有更好的方法可以在模板\之外定义它?还是有一种更干净的方法可以在模板本身内进行定义?

Is there a better way where we could define it outside the template \ or a cleaner way to do it within the template itself?

推荐答案

您可以通过利用rangenull未能通过所需检查的事实来做一些事情.因此,在您的values.yaml中,您可以使用此部分以获取必需的环境变量:

You could do something by taking advantage of range and the fact that null will fail the required check. So in your values.yaml you could have this section for required env vars:

reqEnv:
 - name: "VAR1"
   value: null
 - name: "VAR2"
   value: null

然后在部署"的env部分中,您将获得:

And in the env section of the Deployment you then have:

{{- range .Values.reqEnv }}
          {{ .name }}: {{ required "A value must be entered for all reqEnv entries" .value }}
{{- end }}

然后,除非用户在其值文件中将reqEnv部分的所有必需值设置为参数或将其设置为参数,否则用户将收到错误消息.不幸的是,这样做会使您失去的是缺少var的细节.这可能就是为什么官方头盔图表似乎更喜欢使用 required就像以前一样.

Then the user gets an error unless they set all required values of the reqEnv section in their values file or as paramters. Unfortunately what you lose by doing this is the detail of which var is missing. This could be why the official helm charts seem to prefer using required in the way that you already are.

这篇关于在舵图中最好怎么说一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆