@@ -27,7 +27,7 @@ import (
2727)
2828
2929type 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
0 commit comments