From d0e0de41413c0e9b822097d1b8b9ca3f0036a74e Mon Sep 17 00:00:00 2001 From: Christopher Tineo Date: Wed, 12 Nov 2025 15:33:11 -0500 Subject: [PATCH] Refactor kube compatibility check Signed-off-by: Christopher Tineo --- pkg/action/action.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/pkg/action/action.go b/pkg/action/action.go index 9555006be..c546d6b14 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -228,10 +228,8 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values common.Values, return hs, b, "", err } - if ch.Metadata.KubeVersion != "" { - if !chartutil.IsCompatibleRange(ch.Metadata.KubeVersion, caps.KubeVersion.String()) { - return hs, b, "", fmt.Errorf("chart requires kubeVersion: %s which is incompatible with Kubernetes %s", ch.Metadata.KubeVersion, caps.KubeVersion.String()) - } + if err := ensureKubeCompatibility(ch, caps); err != nil { + return hs, b, "", err } var files map[string]string @@ -372,6 +370,29 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values common.Values, return hs, b, notes, nil } +// ensureKubeCompatibility verifies the chart's kubeVersion requirement. +func ensureKubeCompatibility(ch *chart.Chart, caps *common.Capabilities) error { + if ch == nil || caps == nil { + return nil + } + meta := ch.Metadata + if meta == nil { + return nil + } + kubeReq := meta.KubeVersion + if kubeReq == "" { + return nil + } + + kubeVer := caps.KubeVersion.String() + + if chartutil.IsCompatibleRange(kubeReq, kubeVer) { + return nil + } + + return fmt.Errorf("chart requires kubeVersion: %s which is incompatible with Kubernetes %s", kubeReq, kubeVer) +} + // RESTClientGetter gets the rest client type RESTClientGetter interface { ToRESTConfig() (*rest.Config, error)