fix: Check needs with context and namespace (#1986)

* fix: Check needs with context and namespace

Signed-off-by: André Arnqvist <andrearnqvist@gmail.com>

* fix: Ensure releases have overrides

Signed-off-by: André Arnqvist <andrearnqvist@gmail.com>

* fix: Run go fmt

Signed-off-by: André Arnqvist <andrearnqvist@gmail.com>

* fix: Add tests checking needs with same name in different namespaces

Signed-off-by: André Arnqvist <andrearnqvist@gmail.com>

* fix: Simplify setting overrides

Signed-off-by: André Arnqvist <andrearnqvist@gmail.com>

---------

Signed-off-by: André Arnqvist <andrearnqvist@gmail.com>
This commit is contained in:
André Arnqvist
2025-04-07 21:57:02 +08:00
committed by GitHub
parent 2076515c5d
commit c9a2e76200
5 changed files with 133 additions and 4 deletions
+15 -4
View File
@@ -488,7 +488,17 @@ func (st *HelmState) reformat(spec *ReleaseSpec) []string {
var needs []string
releaseInstalledInfo := make(map[string]bool)
for _, r := range st.OrginReleases {
releaseInstalledInfo[r.Name] = r.Desired()
kubecontext := r.KubeContext
namespace := r.Namespace
if st.OverrideKubeContext != "" {
kubecontext = st.OverrideKubeContext
}
if st.OverrideNamespace != "" {
namespace = st.OverrideNamespace
}
releaseInstalledInfo[fmt.Sprintf("%s/%s/%s", kubecontext, namespace, r.Name)] = r.Desired()
}
// Since the representation differs between needs and id,
@@ -501,9 +511,6 @@ func (st *HelmState) reformat(spec *ReleaseSpec) []string {
components := strings.Split(n, "/")
name = components[len(components)-1]
if spec.Desired() && !releaseInstalledInfo[name] {
st.logger.Warnf("WARNING: %s", fmt.Sprintf("release %s needs %s, but %s is not installed due to installed: false. Either mark %s as installed or remove %s from %s's needs", spec.Name, name, name, name, name, spec.Name))
}
if len(components) > 1 {
ns = components[len(components)-2]
@@ -519,6 +526,10 @@ func (st *HelmState) reformat(spec *ReleaseSpec) []string {
kubecontext = spec.KubeContext
}
if spec.Desired() && !releaseInstalledInfo[fmt.Sprintf("%s/%s/%s", kubecontext, ns, name)] {
st.logger.Warnf("WARNING: %s", fmt.Sprintf("release %s needs %s, but %s is not installed due to installed: false. Either mark %s as installed or remove %s from %s's needs", spec.Name, name, name, name, name, spec.Name))
}
var componentsAfterOverride []string
if kubecontext != "" {