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:
Otto Bittner 2023-02-20 10:50:55 +01:00 committed by GitHub
parent b6b353c53e
commit c0a62a52d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 4 deletions

View file

@ -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 {