cli: allow helm upgrades with old k8s patch version (#2095)

This commit is contained in:
Malte Poll 2023-07-12 12:42:51 +02:00 committed by GitHub
parent 37af5f5f50
commit 26f4a13934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View File

@ -255,7 +255,7 @@ func (c *Client) upgradeRelease(
) error {
// We need to load all values that can be statically loaded before merging them with the cluster
// values. Otherwise the templates are not rendered correctly.
k8sVersion, err := versions.NewValidK8sVersion(conf.KubernetesVersion, true)
k8sVersion, err := versions.NewValidK8sVersion(conf.KubernetesVersion, false)
if err != nil {
return fmt.Errorf("validating k8s version: %s", conf.KubernetesVersion)
}

View File

@ -42,6 +42,8 @@ type ValidK8sVersion string
// NewValidK8sVersion validates the given string and produces a new ValidK8sVersion object.
// Returns an empty string if the given version is invalid.
// strict controls whether the patch version is checked or not.
// If strict is false, the patch version is ignored and the returned
// ValidK8sVersion is a supported patch version for the given major.minor version.
func NewValidK8sVersion(k8sVersion string, strict bool) (ValidK8sVersion, error) {
var supported bool
if strict {
@ -49,11 +51,14 @@ func NewValidK8sVersion(k8sVersion string, strict bool) (ValidK8sVersion, error)
} else {
supported = isSupportedK8sVersion(k8sVersion)
}
if supported {
return ValidK8sVersion(k8sVersion), nil
if !supported {
return "", fmt.Errorf("invalid Kubernetes version: %s", k8sVersion)
}
return "", fmt.Errorf("invalid Kubernetes version: %s", k8sVersion)
if !strict {
k8sVersion, _ = supportedVersionForMajorMinor(k8sVersion)
}
return ValidK8sVersion(k8sVersion), nil
}
// IsSupportedK8sVersion checks if a given Kubernetes minor version is supported by Constellation.
@ -82,6 +87,16 @@ func IsPreviewK8sVersion(_ ValidK8sVersion) bool {
return false
}
func supportedVersionForMajorMinor(majorMinor string) (string, bool) {
majorMinor = semver.MajorMinor(majorMinor)
for _, valid := range SupportedK8sVersions() {
if semver.MajorMinor(valid) == majorMinor {
return valid, true
}
}
return "", false
}
const (
//
// Constellation images.