From 9f0df58c95bba79ee683ae61eb8d180cfaa00d1c Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Fri, 8 May 2020 13:45:48 +0800 Subject: [PATCH] climc: update k8s resource cmd --- cmd/climc/shell/k8s/releases.go | 6 ++---- pkg/mcclient/modules/k8s/base.go | 2 +- pkg/mcclient/modules/k8s/helm.go | 2 +- pkg/mcclient/modules/k8s/helm_release.go | 2 +- pkg/mcclient/options/k8s/base.go | 8 +++++++- pkg/mcclient/options/k8s/charts.go | 4 ++++ pkg/mcclient/options/k8s/cluster.go | 2 -- pkg/mcclient/options/k8s/release.go | 4 ++++ pkg/mcclient/options/k8s/repo.go | 4 ++++ 9 files changed, 24 insertions(+), 10 deletions(-) diff --git a/cmd/climc/shell/k8s/releases.go b/cmd/climc/shell/k8s/releases.go index 34f1ae3ab8..0dac40db39 100644 --- a/cmd/climc/shell/k8s/releases.go +++ b/cmd/climc/shell/k8s/releases.go @@ -15,8 +15,6 @@ package k8s import ( - "fmt" - "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" o "yunion.io/x/onecloud/pkg/mcclient/options/k8s" @@ -41,11 +39,11 @@ func initRelease() { if err != nil { return err } - resources, err := ret.GetString("info", "status", "resources") + resources, err := ret.Get("resources") if err != nil { return err } - fmt.Println(resources) + printObject(resources) return nil }) diff --git a/pkg/mcclient/modules/k8s/base.go b/pkg/mcclient/modules/k8s/base.go index bf8f6434dd..e24630ca95 100644 --- a/pkg/mcclient/modules/k8s/base.go +++ b/pkg/mcclient/modules/k8s/base.go @@ -118,7 +118,7 @@ func (c Columns) Array() []string { } func NewNameCols(col ...string) *Columns { - return NewColumns("Name").Add(col...) + return NewColumns("Name", "Id").Add(col...) } func NewMetaCols(col ...string) *Columns { diff --git a/pkg/mcclient/modules/k8s/helm.go b/pkg/mcclient/modules/k8s/helm.go index 4ef52364c3..1aa5c1825d 100644 --- a/pkg/mcclient/modules/k8s/helm.go +++ b/pkg/mcclient/modules/k8s/helm.go @@ -24,7 +24,7 @@ var ( func init() { Repos = NewResourceManager("repo", "repos", - NewResourceCols("url", "is_public", "source"), + NewResourceCols("url", "is_public", "source", "type"), NewColumns(), ) modules.Register(Repos) diff --git a/pkg/mcclient/modules/k8s/helm_release.go b/pkg/mcclient/modules/k8s/helm_release.go index ff0ed5b230..34fad25514 100644 --- a/pkg/mcclient/modules/k8s/helm_release.go +++ b/pkg/mcclient/modules/k8s/helm_release.go @@ -49,7 +49,7 @@ func (m *ReleaseAppManager) Create(session *mcclient.ClientSession, params jsonu func init() { Releases = &ReleaseManager{ - NewNamespaceResourceManager("release", "releases", NewColumns(), NewColumns())} + NewNamespaceResourceManager("release", "releases", NewNamespaceCols("status", "type"), NewColumns())} dummyReleaseApps = NewReleaseAppManager("releaseapp", "releaseapps") MeterReleaseApps = NewReleaseAppManager("app_meter", "app_meters") ServicetreeReleaseApps = NewReleaseAppManager("app_servicetree", "app_servicetrees") diff --git a/pkg/mcclient/options/k8s/base.go b/pkg/mcclient/options/k8s/base.go index 079fb20ea2..d74f450281 100644 --- a/pkg/mcclient/options/k8s/base.go +++ b/pkg/mcclient/options/k8s/base.go @@ -24,7 +24,9 @@ type ClusterBaseOptions struct { func (o ClusterBaseOptions) Params() *jsonutils.JSONDict { ret := jsonutils.NewDict() - ret.Add(jsonutils.NewString(o.Cluster), "cluster") + if o.Cluster != "" { + ret.Add(jsonutils.NewString(o.Cluster), "cluster") + } return ret } @@ -47,6 +49,7 @@ type BaseListOptions struct { Limit int `default:"20" help:"Page limit"` Offset int `default:"0" help:"Page offset"` Name string `help:"Search by name"` + System *bool `help:"Show system resource"` } func (o BaseListOptions) Params() *jsonutils.JSONDict { @@ -60,6 +63,9 @@ func (o BaseListOptions) Params() *jsonutils.JSONDict { if o.Name != "" { params.Add(jsonutils.NewString(o.Name), "name") } + if o.System != nil { + params.Add(jsonutils.NewBool(*o.System), "system") + } return params } diff --git a/pkg/mcclient/options/k8s/charts.go b/pkg/mcclient/options/k8s/charts.go index a9d3afd771..4b12c11f8d 100644 --- a/pkg/mcclient/options/k8s/charts.go +++ b/pkg/mcclient/options/k8s/charts.go @@ -25,6 +25,7 @@ type ChartListOptions struct { AllVersion bool `help:"Get Chart all history versions"` Keyword string `help:"Chart keyword"` Version string `help:"Chart semver version filter"` + Type string `help:"Chart type" choices:"internal|external"` } func (o ChartListOptions) Params() *jsonutils.JSONDict { @@ -47,6 +48,9 @@ func (o ChartListOptions) Params() *jsonutils.JSONDict { if len(o.Keyword) != 0 { params.Add(jsonutils.NewString(o.Keyword), "keyword") } + if o.Type != "" { + params.Add(jsonutils.NewString(o.Type), "type") + } return params } diff --git a/pkg/mcclient/options/k8s/cluster.go b/pkg/mcclient/options/k8s/cluster.go index 495a16cfcb..89c794d880 100644 --- a/pkg/mcclient/options/k8s/cluster.go +++ b/pkg/mcclient/options/k8s/cluster.go @@ -66,7 +66,6 @@ type KubeClusterCreateOptions struct { type KubeClusterImportOptions struct { NAME string `help:"Name of cluster"` - APISERVER string `help:"API server of this cluster"` KUBECONFIG string `help:"Cluster kubeconfig file path"` } @@ -163,7 +162,6 @@ func (o KubeClusterImportOptions) Params() (*jsonutils.JSONDict, error) { params := jsonutils.NewDict() params.Add(jsonutils.NewString(o.NAME), "name") params.Add(jsonutils.NewString("import"), "mode") - params.Add(jsonutils.NewString(o.APISERVER), "api_server") params.Add(jsonutils.NewString(string(kubeconfig)), "kubeconfig") params.Add(jsonutils.NewString("external"), "provider") params.Add(jsonutils.NewString("unknown"), "resource_type") diff --git a/pkg/mcclient/options/k8s/release.go b/pkg/mcclient/options/k8s/release.go index 387c2035aa..70a17f5e24 100644 --- a/pkg/mcclient/options/k8s/release.go +++ b/pkg/mcclient/options/k8s/release.go @@ -30,6 +30,7 @@ type ReleaseListOptions struct { Failed bool `help:"Show failed status releases"` Superseded bool `help:"Show superseded status releases"` Pending bool `help:"Show pending status releases"` + Type string `help:"Release type" choices:"internal|external"` } func (o ReleaseListOptions) Params() *jsonutils.JSONDict { @@ -43,6 +44,9 @@ func (o ReleaseListOptions) Params() *jsonutils.JSONDict { if o.Name != "" { params.Add(jsonutils.NewString(o.Name), "name") } + if o.Type != "" { + params.Add(jsonutils.NewString(o.Type), "type") + } params.Add(jsonutils.JSONTrue, "all") if o.Admin { params.Add(jsonutils.JSONTrue, "admin") diff --git a/pkg/mcclient/options/k8s/repo.go b/pkg/mcclient/options/k8s/repo.go index dcc0bb28a7..425d3b27ed 100644 --- a/pkg/mcclient/options/k8s/repo.go +++ b/pkg/mcclient/options/k8s/repo.go @@ -30,6 +30,7 @@ type RepoGetOptions struct { type RepoCreateOptions struct { RepoGetOptions + Type string `help:"Repository type" choices:"internal|external"` URL string `help:"Repository url"` Public bool `help:"Make repostitory public"` } @@ -38,6 +39,9 @@ func (o RepoCreateOptions) Params() *jsonutils.JSONDict { params := jsonutils.NewDict() params.Add(jsonutils.NewString(o.NAME), "name") params.Add(jsonutils.NewString(o.URL), "url") + if o.Type != "" { + params.Add(jsonutils.NewString(o.Type), "type") + } if o.Public { params.Add(jsonutils.JSONTrue, "is_public") }