Skip to content

Commit ff1b3f0

Browse files
committed
fix merge add array k8s version
1 parent 2e652c9 commit ff1b3f0

5 files changed

Lines changed: 63 additions & 40 deletions

File tree

pkg/apply/applydriver.go

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
type Applier struct {
30-
Runtimes []v1.RuntimeConfig
30+
Runtimes []v1.RuntimeStatus
3131
DefaultFile string
3232
}
3333

@@ -74,11 +74,26 @@ func (a *Applier) WithConfigFiles(files ...string) error {
7474
if err = validationFunc(i, cfg); err != nil {
7575
return fmt.Errorf("file is %s is validation error: %+v", f, err)
7676
}
77-
setKey := fmt.Sprintf("%s-%s", cfg.Config.Runtime, cfg.Config.RuntimeVersion)
78-
if !versions.Has(setKey) {
79-
versions.Insert(setKey)
80-
a.Runtimes = append(a.Runtimes, *cfg)
77+
if cfg.Config.CRI == nil || len(cfg.Config.CRI) == 0 {
78+
cfg.Config.CRI = []string{v1.CRIContainerd, v1.CRIDocker, v1.CRICRIO}
8179
}
80+
for _, version := range cfg.Config.RuntimeVersion {
81+
for _, cri := range cfg.Config.CRI {
82+
setKey := fmt.Sprintf("%s-%s-%s", cri, cfg.Config.Runtime, version)
83+
if !versions.Has(setKey) {
84+
versions.Insert(setKey)
85+
a.Runtimes = append(a.Runtimes, v1.RuntimeStatus{
86+
RuntimeConfigDefaultComponent: cfg.Default,
87+
RuntimeStatusConfigData: &v1.RuntimeStatusConfigData{
88+
CRI: cri,
89+
Runtime: cfg.Config.Runtime,
90+
RuntimeVersion: version,
91+
},
92+
})
93+
}
94+
}
95+
}
96+
8297
}
8398
return nil
8499
}
@@ -87,34 +102,29 @@ func (a *Applier) Apply() error {
87102
statusList := &v1.RuntimeStatusList{
88103
Include: []v1.RuntimeStatus{},
89104
}
90-
for _, rt := range a.Runtimes {
91-
switch rt.Config.Runtime {
105+
for i, rt := range a.Runtimes {
106+
switch rt.Runtime {
92107
case v1.RuntimeK8s:
93-
dockerVersion, criDockerVersion := docker.FetchVersion(rt.Config.RuntimeVersion)
94-
status := &v1.RuntimeStatus{
95-
RuntimeConfigDefaultComponent: rt.Default,
96-
RuntimeConfigData: rt.Config,
97-
}
98-
status.Docker = dockerVersion
108+
dockerVersion, criDockerVersion := docker.FetchVersion(rt.RuntimeVersion)
109+
a.Runtimes[i].Docker = dockerVersion
99110
switch criDockerVersion {
100111
case docker.CRIDockerV2:
101-
status.CRIDocker = status.CRIDockerV2
112+
a.Runtimes[i].CRIDocker = a.Runtimes[i].CRIDockerV2
102113
case docker.CRIDockerV3:
103-
status.CRIDocker = status.CRIDockerV3
114+
a.Runtimes[i].CRIDocker = a.Runtimes[i].CRIDockerV3
104115
}
105-
status.CRIDockerV2 = ""
106-
status.CRIDockerV3 = ""
107-
newVersion, err := k8s.FetchFinalVersion(status.RuntimeVersion)
116+
a.Runtimes[i].CRIDockerV2 = ""
117+
a.Runtimes[i].CRIDockerV3 = ""
118+
newVersion, err := k8s.FetchFinalVersion(rt.RuntimeVersion)
108119
if err != nil {
109-
return fmt.Errorf("runtime is %s,runtime version is %s,get new version is error: %+v", status.Runtime, status.RuntimeVersion, err)
120+
return fmt.Errorf("runtime is %s,runtime version is %s,get new version is error: %+v", rt.Runtime, rt.RuntimeVersion, err)
110121
}
111-
status.RuntimeVersion = newVersion
112-
statusList.Include = append(statusList.Include, *status)
113-
122+
a.Runtimes[i].RuntimeVersion = newVersion
114123
default:
115124
return fmt.Errorf("not found runtime,current version not support")
116125
}
117126
}
127+
statusList.Include = a.Runtimes
118128
actionJSON, err := json.Marshal(statusList)
119129
if err != nil {
120130
return err

pkg/merge/testdata/config-2.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# limitations under the License.
1414

1515
config:
16-
cri: docker
16+
cri:
17+
- docker
1718
runtime: k8s
18-
runtimeVersion: 1.23
19+
runtimeVersion:
20+
- 1.24.0

pkg/merge/testdata/config.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# limitations under the License.
1414

1515
config:
16-
cri: docker
16+
cri:
17+
- docker
18+
- containerd
1719
runtime: k8s
18-
runtimeVersion: 1.23.0
20+
runtimeVersion:
21+
- 1.23.0

types/v1/runtime.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,27 @@ type RuntimeConfigDefaultComponent struct {
2727
}
2828

2929
const (
30-
RuntimeK8s string = "k8s"
30+
RuntimeK8s string = "k8s"
31+
CRIDocker string = "docker"
32+
CRIContainerd string = "containerd"
33+
CRICRIO string = "crio"
3134
)
3235

3336
type RuntimeConfigData struct {
34-
CRI string `json:"cri"`
37+
CRI []string `json:"cri,omitempty"`
38+
Runtime string `json:"runtime"`
39+
RuntimeVersion []string `json:"runtimeVersion,omitempty"`
40+
}
41+
42+
type RuntimeStatusConfigData struct {
43+
CRI string `json:"cri,omitempty"`
3544
Runtime string `json:"runtime"`
36-
RuntimeVersion string `json:"runtimeVersion"`
45+
RuntimeVersion string `json:"runtimeVersion,omitempty"`
3746
}
3847

3948
type RuntimeStatus struct {
4049
*RuntimeConfigDefaultComponent `json:",inline"`
41-
*RuntimeConfigData `json:",inline"`
50+
*RuntimeStatusConfigData `json:",inline"`
4251
}
4352

4453
type RuntimeConfig struct {

types/v1/validation.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,25 @@ func ValidationDefaultComponent(c *RuntimeConfigDefaultComponent) error {
4646
}
4747

4848
func ValidationConfigData(c *RuntimeConfigData) error {
49-
if c.CRI == "" {
50-
return fmt.Errorf("cri not set,please retry config it")
51-
}
5249
if c.Runtime == "" {
5350
return fmt.Errorf("runtime not set,please retry config it")
5451
}
55-
if c.RuntimeVersion == "" {
56-
return fmt.Errorf("runtime version not set,please retry config it")
52+
if len(c.RuntimeVersion) == 0 {
53+
return fmt.Errorf("runtime versions not set,please retry config it")
5754
}
5855
return nil
5956
}
6057

6158
func ValidationRuntimeConfig(c *RuntimeConfig) error {
6259
if c.Config.Runtime == "k8s" {
6360
//kubernetes gt 1.26
64-
if Compare(c.Config.RuntimeVersion, "v1.26") && !Compare(c.Default.Sealos, "v4.1.3") {
65-
// echo "INFO::skip $KUBE(kube>=1.26) when $SEALOS(sealos<=4.1.3)"
66-
// echo https://kubernetes.io/blog/2022/11/18/upcoming-changes-in-kubernetes-1-26/#cri-api-removal
67-
klog.Info("Please see https://kubernetes.io/blog/2022/11/18/upcoming-changes-in-kubernetes-1-26/#cri-api-removal")
68-
return fmt.Errorf("skip $KUBE(kube>=1.26) when $SEALOS(sealos<=4.1.3)")
61+
for _, v := range c.Config.RuntimeVersion {
62+
if Compare(v, "v1.26") && !Compare(c.Default.Sealos, "v4.1.3") {
63+
// echo "INFO::skip $KUBE(kube>=1.26) when $SEALOS(sealos<=4.1.3)"
64+
// echo https://kubernetes.io/blog/2022/11/18/upcoming-changes-in-kubernetes-1-26/#cri-api-removal
65+
klog.Info("Please see https://kubernetes.io/blog/2022/11/18/upcoming-changes-in-kubernetes-1-26/#cri-api-removal")
66+
return fmt.Errorf("skip $KUBE(kube>=1.26) when $SEALOS(sealos<=4.1.3)")
67+
}
6968
}
7069
}
7170
return nil

0 commit comments

Comments
 (0)