Skip to content

Commit

Permalink
climc: update k8s resource cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi committed May 19, 2020
1 parent 10f9188 commit 9f0df58
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 10 deletions.
6 changes: 2 additions & 4 deletions cmd/climc/shell/k8s/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/mcclient/modules/k8s/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcclient/modules/k8s/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcclient/modules/k8s/helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 7 additions & 1 deletion pkg/mcclient/options/k8s/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 {
Expand All @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/mcclient/options/k8s/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/mcclient/options/k8s/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions pkg/mcclient/options/k8s/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions pkg/mcclient/options/k8s/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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")
}
Expand Down

0 comments on commit 9f0df58

Please sign in to comment.