forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathversion.go
More file actions
51 lines (41 loc) · 1.66 KB
/
version.go
File metadata and controls
51 lines (41 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package kubernetesversion
import (
"fmt"
"os"
logf "sigs.k8s.io/controller-runtime/pkg/log"
versionutils "github.com/gardener/gardener/pkg/utils/version"
)
// SupportedVersions is the list of supported Kubernetes versions for all runtime and target clusters, i.e. all gardens,
// seeds, and shoots.
var SupportedVersions = []string{
"1.32",
"1.33",
"1.34",
"1.35",
}
// envExperimentalDisableKubernetesVersionCheck holds the name of the environment variable to prevent a crash
// if the detected k8s version is not in the list of supported k8s versions.
// This should only be used if you know exactly what you are doing and on your own risk.
const envExperimentalDisableKubernetesVersionCheck = "EXPERIMENTAL_DISABLE_KUBERNETES_VERSION_CHECK"
// CheckIfSupported checks if the provided version is part of the supported Kubernetes versions list.
// Experimental: If the environment variable `EXPERIMENTAL_DISABLE_KUBERNETES_VERSION_CHECK` is set to "true",
// the check will be skipped.
func CheckIfSupported(gitVersion string) error {
if os.Getenv(envExperimentalDisableKubernetesVersionCheck) == "true" {
logf.Log.Info("Skipping the check if the Kubernetes version is supported because flag is set to true", "flag", envExperimentalDisableKubernetesVersionCheck)
return nil
}
for _, supportedVersion := range SupportedVersions {
ok, err := versionutils.CompareVersions(gitVersion, "~", supportedVersion)
if err != nil {
return err
}
if ok {
return nil
}
}
return fmt.Errorf("unsupported kubernetes version %q", gitVersion)
}