talos

Форк
0
/
kubernetes_version.go 
80 строк · 3.2 Кб
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4

5
package compatibility
6

7
import (
8
	"fmt"
9

10
	"github.com/blang/semver/v4"
11
	"github.com/siderolabs/gen/pair/ordered"
12

13
	"github.com/siderolabs/talos/pkg/machinery/compatibility/talos12"
14
	"github.com/siderolabs/talos/pkg/machinery/compatibility/talos13"
15
	"github.com/siderolabs/talos/pkg/machinery/compatibility/talos14"
16
	"github.com/siderolabs/talos/pkg/machinery/compatibility/talos15"
17
	"github.com/siderolabs/talos/pkg/machinery/compatibility/talos16"
18
	"github.com/siderolabs/talos/pkg/machinery/compatibility/talos17"
19
	"github.com/siderolabs/talos/pkg/machinery/compatibility/talos18"
20
)
21

22
// KubernetesVersion embeds Kubernetes version.
23
type KubernetesVersion struct {
24
	vers semver.Version
25
}
26

27
// ParseKubernetesVersion parses Kubernetes version.
28
func ParseKubernetesVersion(v string) (*KubernetesVersion, error) {
29
	parsed, err := semver.ParseTolerant(v)
30
	if err != nil {
31
		return nil, err
32
	}
33

34
	return &KubernetesVersion{
35
		vers: parsed,
36
	}, nil
37
}
38

39
func (v *KubernetesVersion) String() string {
40
	return v.vers.String()
41
}
42

43
// SupportedWith checks if the Kubernetes version is supported with specified version of Talos.
44
func (v *KubernetesVersion) SupportedWith(target *TalosVersion) error {
45
	var minK8sVersion, maxK8sVersion semver.Version
46

47
	switch target.majorMinor {
48
	case talos12.MajorMinor: // upgrades to 1.2.x
49
		minK8sVersion, maxK8sVersion = talos12.MinimumKubernetesVersion, talos12.MaximumKubernetesVersion
50
	case talos13.MajorMinor: // upgrades to 1.3.x
51
		minK8sVersion, maxK8sVersion = talos13.MinimumKubernetesVersion, talos13.MaximumKubernetesVersion
52
	case talos14.MajorMinor: // upgrades to 1.4.x
53
		minK8sVersion, maxK8sVersion = talos14.MinimumKubernetesVersion, talos14.MaximumKubernetesVersion
54
	case talos15.MajorMinor: // upgrades to 1.5.x
55
		minK8sVersion, maxK8sVersion = talos15.MinimumKubernetesVersion, talos15.MaximumKubernetesVersion
56
	case talos16.MajorMinor: // upgrades to 1.6.x
57
		minK8sVersion, maxK8sVersion = talos16.MinimumKubernetesVersion, talos16.MaximumKubernetesVersion
58
	case talos17.MajorMinor: // upgrades to 1.7.x
59
		minK8sVersion, maxK8sVersion = talos17.MinimumKubernetesVersion, talos17.MaximumKubernetesVersion
60
	case talos18.MajorMinor: // upgrades to 1.8.x
61
		minK8sVersion, maxK8sVersion = talos18.MinimumKubernetesVersion, talos18.MaximumKubernetesVersion
62
	default:
63
		return fmt.Errorf("compatibility with version %s is not supported", target.String())
64
	}
65

66
	core := ordered.MakeTriple(v.vers.Major, v.vers.Minor, v.vers.Patch)
67
	minK8sVersionCore := ordered.MakeTriple(minK8sVersion.Major, minK8sVersion.Minor, minK8sVersion.Patch)
68

69
	if core.LessThan(minK8sVersionCore) {
70
		return fmt.Errorf("version of Kubernetes %s is too old to be used with Talos %s", v.vers.String(), target.version.String())
71
	}
72

73
	maxK8sVersionCore := ordered.MakeTriple(maxK8sVersion.Major, maxK8sVersion.Minor, maxK8sVersion.Patch)
74

75
	if core.Compare(maxK8sVersionCore) >= 0 {
76
		return fmt.Errorf("version of Kubernetes %s is too new to be used with Talos %s", v.vers.String(), target.version.String())
77
	}
78

79
	return nil
80
}
81

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.