Merge pull request #17795 from zexi/automated-cherry-pick-of-#17794-upstream-master

Automated cherry pick of #17794: feat(climc): support k8s-cluster-create command getting input from file
This commit is contained in:
Zexi Li
2023-08-18 13:33:17 +08:00
committed by GitHub
+13
View File
@@ -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")
/*