diff --git a/internal/config/config.go b/internal/config/config.go index c24115022..4cd99bf9d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -70,7 +70,7 @@ type Config struct { StateDiskSizeGB int `yaml:"stateDiskSizeGB" validate:"min=0"` // description: | // Kubernetes version to be installed into the cluster. - KubernetesVersion string `yaml:"kubernetesVersion" validate:"supported_k8s_version"` + KubernetesVersion string `yaml:"kubernetesVersion" validate:"required,supported_k8s_version"` // description: | // Microservice version to be installed into the cluster. Setting this value is optional until v2.7. Defaults to the version of the CLI. MicroserviceVersion string `yaml:"microserviceVersion" validate:"omitempty,version_compatibility"` @@ -543,7 +543,7 @@ func (c *Config) Validate(force bool) error { } // register custom validator with label supported_k8s_version to validate version based on available versionConfigs. - if err := validate.RegisterValidation("supported_k8s_version", validateK8sVersion); err != nil { + if err := validate.RegisterValidation("supported_k8s_version", c.validateK8sVersion); err != nil { return err } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 0629feb4f..0ea4bb33d 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -273,6 +273,26 @@ func TestValidate(t *testing.T) { return cnf }(), }, + // TODO: v2.7: remove this test as it should start breaking after v2.6 is released. + "k8s vMAJOR.MINOR is valid in v2.7": { + cnf: func() *Config { + cnf := Default() + cnf.KubernetesVersion = "v1.25" + return cnf + }(), + wantErr: true, + wantErrCount: defaultErrCount, + }, + // TODO: v2.7: remove this test as it should start breaking after v2.6 is released. + "k8s MAJOR.MINOR is valid in v2.7": { + cnf: func() *Config { + cnf := Default() + cnf.KubernetesVersion = "1.25" + return cnf + }(), + wantErr: true, + wantErrCount: defaultErrCount, + }, } for name, tc := range testCases { diff --git a/internal/config/validation.go b/internal/config/validation.go index caa166c56..fb863a1d5 100644 --- a/internal/config/validation.go +++ b/internal/config/validation.go @@ -311,8 +311,27 @@ func getPlaceholderEntries(m Measurements) []uint32 { return placeholders } -func validateK8sVersion(fl validator.FieldLevel) bool { - return versions.IsSupportedK8sVersion(compatibility.EnsurePrefixV(fl.Field().String())) +func (c *Config) validateK8sVersion(fl validator.FieldLevel) bool { + // TODO: v2.7: do not create extendedVersion variable and directly validate field from fl. + // This patch is for compatibility with configs from v2.5 only. Configs specifying k8s + // the version as MAJOR.MINOR automatically get extended with the respective patch version. + configVersion := compatibility.EnsurePrefixV(fl.Field().String()) + if !semver.IsValid(configVersion) { + return false + } + var extendedVersion string + switch semver.MajorMinor(configVersion) { + case semver.MajorMinor(string(versions.V1_24)): + extendedVersion = string(versions.V1_24) + case semver.MajorMinor(string(versions.V1_25)): + extendedVersion = string(versions.V1_25) + case semver.MajorMinor(string(versions.V1_26)): + extendedVersion = string(versions.V1_26) + default: + return false + } + c.KubernetesVersion = extendedVersion + return versions.IsSupportedK8sVersion(extendedVersion) } func registerVersionCompatibilityError(ut ut.Translator) error {