英文:
helm: retrieve the version of a plugin in a template
问题
I'd like to retrieve the apiversion of a given plugin, for instance certmanager, programmatically within a helm template file. Basically the third column of the output of:
[xx@xx-bnng5g3 test]$ kubectl api-resources -o wide | grep certificates
certificates cert,certs cert-manager.io/v1 true Certificate
I was thinking of achieving the result using a (lookup ...)
but I am finding more difficult than expected. Is there any simpler way to do that?
英文:
I'd like to retrieve the apiversion of a given plugin, for instance certmanager, programmatically within an helm template file.Basically the third column of the output of:
[xx@xx-bnng5g3 test]$ kubectl api-resources -o wide | grep certificates
certificates cert,certs cert-manager.io/v1 true Certificate
I was thinking of achieving the result using a (lookup ...)
but I am finding more difficult than expected. Is there any simpler way to do that ?
答案1
得分: 0
以下是已翻译的部分:
那一列显示了在Kubernetes资源中将要使用的apiVersion:
值。在Kubernetes API术语中,它是一个_组(group)_和_版本(version)_的组合。
在Helm中,有一个内置的.Capabilities
对象,其中包含有关可用API版本的详细信息。您可以测试特定版本:
{{- if .Capabilities.APIVersions.Has "cert-manager.io/v1" }}
apiVersion: cert-manager.io/v1
kind: Certificate
...
{{- end }}
查找特定API组的当前版本更具挑战性。.Capabilities.APIVersions
似乎是一个简单的字符串列表,您可以使用任何标准的list或list-of-string函数来搜索它。不过,这不包括类似Unix grep(1)的功能,可以找到以特定前缀开头的字符串。
(这种技巧对于从Kubernetes API的beta版本升级到发布版本很有用。例如,当从Kubernetes中移除apps/v1beta1
部署对象时,一些较旧的集群可能尚不支持apps/v1
部署。这使得可以说,如果有v1
版本可用,就使用它,如果没有,就使用较旧的v1beta1
版本。)
英文:
That column shows the apiVersion:
value that would be used in Kubernetes resources. In Kubernetes API terminology, it is the combination of a group and version.
In Helm, there is a built-in .Capabilities
object that includes details about the API versions available. You can test for a specific version:
{{- if .Capabilities.APIVersions.Has "cert-manager.io/v1" }}
apiVersion: cert-manager.io/v1
kind: Certificate
...
{{- end }}
Finding the current version(s) of a particular API group is more challenging. .Capabilities.APIVersions
appears to be a simple list of strings and you could search that using any of the standard list or list-of-string functions. This does not include anything like Unix grep(1) that could find strings that begin with a particular prefix, alas.
(This technique can be useful for upgrading from a beta to a released version of a Kubernetes API. When apps/v1beta1
Deployment objects were removed from Kubernetes, for example, some older clusters did not yet support apps/v1
Deployments yet. This makes it possible to say, if a v1
version is available, use it, and if not, use the older v1beta1
version.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论