fix: --container-manager flag doesn't work

Signed-off-by: Leo Li <jacksama@foxmail.com>
This commit is contained in:
Leo Li 2021-12-21 12:54:49 +08:00
parent 2fb0649193
commit 288efcca28
3 changed files with 22 additions and 4 deletions

View File

@ -55,6 +55,7 @@ func NewCmdCreateCluster() *cobra.Command {
Short: "Create a Kubernetes or KubeSphere cluster",
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(o.Complete(cmd, args))
util.CheckErr(o.Validate(cmd, args))
util.CheckErr(o.Run())
},
}
@ -78,6 +79,15 @@ func (o *CreateClusterOptions) Complete(cmd *cobra.Command, args []string) error
return nil
}
func (o *CreateClusterOptions) Validate(cmd *cobra.Command, args []string) error {
switch o.ContainerManager {
case common.Docker, common.Conatinerd, common.Crio, common.Isula:
default:
return fmt.Errorf("unsupport container runtime [%s]", o.ContainerManager)
}
return nil
}
func (o *CreateClusterOptions) Run() error {
arg := common.Argument{
FilePath: o.ClusterCfgFile,

View File

@ -65,9 +65,6 @@ func NewKubeRuntime(flag string, arg Argument) (*KubeRuntime, error) {
if err != nil {
return nil, err
}
if arg.ContainerManager != Docker && arg.ContainerManager != "" {
defaultCluster.Kubernetes.ContainerManager = arg.ContainerManager
}
base := connector.NewBaseRuntime(cluster.Name, connector.NewDialer(), arg.Debug, arg.IgnoreErr)
for _, v := range hostGroups.All {

View File

@ -55,6 +55,7 @@ func NewLoader(flag string, arg Argument) Loader {
}
type DefaultLoader struct {
arg Argument
KubernetesVersion string
KubeSphereVersion string
KubeSphereEnable bool
@ -62,6 +63,7 @@ type DefaultLoader struct {
func NewDefaultLoader(arg Argument) *DefaultLoader {
return &DefaultLoader{
arg: arg,
KubernetesVersion: arg.KubernetesVersion,
KubeSphereVersion: arg.KsVersion,
KubeSphereEnable: arg.KsEnable,
@ -127,13 +129,17 @@ func (d *DefaultLoader) Load() (*kubekeyapiv1alpha2.Cluster, error) {
}
}
if d.arg.ContainerManager != "" && d.arg.ContainerManager != Docker {
allInOne.Spec.Kubernetes.ContainerManager = d.arg.ContainerManager
}
// must be a lower case
allInOne.Name = "kubekey" + time.Now().Format("2006-01-02")
return &allInOne, nil
}
type FileLoader struct {
arg Argument
FilePath string
KubernetesVersion string
KubeSphereVersion string
@ -142,6 +148,7 @@ type FileLoader struct {
func NewFileLoader(arg Argument) *FileLoader {
return &FileLoader{
arg: arg,
FilePath: arg.FilePath,
KubernetesVersion: arg.KubernetesVersion,
KubeSphereVersion: arg.KsVersion,
@ -236,6 +243,10 @@ func (f FileLoader) Load() (*kubekeyapiv1alpha2.Cluster, error) {
}
}
if f.arg.ContainerManager != "" && f.arg.ContainerManager != Docker {
clusterCfg.Spec.Kubernetes.ContainerManager = f.arg.ContainerManager
}
clusterCfg.Name = objName
return &clusterCfg, nil
}