mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-24 06:59:40 -05:00
config: allow k8s version MAJOR.MINOR for v2.6 (#1222)
To adhere to our compatibility goal of not breaking old configs, the kubernetes patch version is automatically extended for configs in the transistional version v2.6.
This commit is contained in:
parent
b6b353c53e
commit
c0a62a52d1
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user