检索模板中插件的版本

huangapple go评论60阅读模式
英文:

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似乎是一个简单的字符串列表,您可以使用任何标准的listlist-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.)

huangapple
  • 本文由 发表于 2023年7月6日 22:28:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629888.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定