Does Helm also remove the created namespace if `helm install` fails and –atomic option has been used

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

Does Helm also remove the created namespace if `helm install` fails and --atomic option has been used

问题

Helm 在使用 helm install 安装 release 时,如果使用了 --atomic 选项并且安装失败,是否也会移除已创建的命名空间?我在 Helm 帮助页面上找不到这方面的信息。

英文:

Does Helm also remove the created namespace if helm install fails and --atomic option has been used to install the release?

I am unable to find this information on Helm help pages.

答案1

得分: 1

命名空间未被删除。

在 Helm 源代码中,"helm.sh/helm/v3/pkg/action"中包含了实际运行helm install的主要逻辑。更具体地说,--atomic的处理在(*Install).failRelease()中,大致如下:

rel.SetStatus(release.StatusFailed, fmt.Sprintf("Release %q failed: %s", i.ReleaseName, err.Error()))
if i.Atomic {
	uninstall := NewUninstall(i.cfg)
	... uninstall.Run(i.ReleaseName) ...
}
i.recordRelease(rel)

这里非常重要的是最后一行。这调用了("helm.sh/helm/v3/pkg/storage".Storage).Update(),记录了失败的发布事实,helm history可以找到它。在正常的 Helm 配置中,这是在目标命名空间的一个 Secret 中。由于历史记录存储在命名空间的一个 Secret 中,因此无法删除该命名空间。

可以轻松搜索源代码以查找Atomic设置,至少在install.go中,它只执行两个操作,即隐式启用--wait并在安装失败时运行helm uninstall。但是,这两个操作都不会删除命名空间。

英文:

The namespace is not deleted.

In the Helm source, "helm.sh/helm/v3/pkg/action".Install has the main logic that helm install actually runs. The --atomic handling more specifically is in (*Install).failRelease(), which is approximately

rel.SetStatus(release.StatusFailed, fmt.Sprintf("Release %q failed: %s", i.ReleaseName, err.Error()))
if i.Atomic {
	uninstall := NewUninstall(i.cfg)
	... uninstall.Run(i.ReleaseName) ...
}
i.recordRelease(rel)

The very last line is important here. This calls through to (*"helm.sh/helm/v3/pkg/storage".Storage).Update(), which records the fact of the failed release where helm history can find it. With the normal Helm configuration, this is in a Secret in the target namespace. Since the history is recorded in a Secret in the namespace, the namespace can't be deleted.

It's easy to search the source for the Atomic setting, and at least in install.go the only two things it does are to implicitly enable --wait and to run helm uninstall if the install fails. But neither of those things delete the namespace.

huangapple
  • 本文由 发表于 2023年7月7日 01:11:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76631133.html
匿名

发表评论

匿名网友

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

确定