diff --git a/pkg/mcclient/options/k8s/cluster.go b/pkg/mcclient/options/k8s/cluster.go index b790f609c5..f0fc7740bd 100644 --- a/pkg/mcclient/options/k8s/cluster.go +++ b/pkg/mcclient/options/k8s/cluster.go @@ -17,6 +17,7 @@ package k8s import ( "fmt" "io/ioutil" + "os" "strings" "yunion.io/x/jsonutils" @@ -60,6 +61,7 @@ type AddMachineOptions struct { type K8SClusterCreateOptions struct { NAME string `help:"Name of cluster"` + File string `help:"JSON file of create body"` // ClusterType string `help:"Cluster cluster type" choices:"default|serverless"` ResourceType string `help:"Cluster cluster type" choices:"host|guest"` // CloudType string `help:"Cluster cloud type" choices:"private|public|hybrid"` @@ -148,6 +150,17 @@ func (o K8SClusterCreateOptions) getAddonsConfig() (jsonutils.JSONObject, error) } func (o K8SClusterCreateOptions) Params() (jsonutils.JSONObject, error) { + if o.File != "" { + content, err := os.ReadFile(o.File) + if err != nil { + return nil, errors.Wrapf(err, "read file: %s", o.File) + } + obj, err := jsonutils.Parse(content) + if err != nil { + return nil, errors.Wrapf(err, "parse file %s content: %s", o.File, content) + } + return obj, nil + } params := jsonutils.NewDict() params.Add(jsonutils.NewString(o.NAME), "name") /*