diff --git a/cmd/climc/shell/k8s/clusters.go b/cmd/climc/shell/k8s/clusters.go index b6cf032555..ed9fe6bd8e 100644 --- a/cmd/climc/shell/k8s/clusters.go +++ b/cmd/climc/shell/k8s/clusters.go @@ -24,6 +24,7 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/errors" + "yunion.io/x/onecloud/cmd/climc/shell" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" o "yunion.io/x/onecloud/pkg/mcclient/options/k8s" @@ -201,18 +202,32 @@ func initKubeCluster() { return nil }) - R(&o.ClusterEnableComponentMinioOpt{}, cmdN("component-enable-minio"), "Enable cluster minio component", func(s *mcclient.ClientSession, args *o.ClusterEnableComponentMinioOpt) error { - params, err := args.Params() - if err != nil { - return err - } - ret, err := k8s.KubeClusters.PerformAction(s, args.ID, "enable-component", params) - if err != nil { - return err - } - printObject(ret) - return nil - }) + rEnableMinio := func(opt shell.IPerformOpt, cmd string, desc string) { + R(opt, cmd, desc, func(s *mcclient.ClientSession, args shell.IPerformOpt) error { + params, err := args.Params() + if err != nil { + return err + } + ret, err := k8s.KubeClusters.PerformAction(s, args.GetId(), "enable-component", params) + if err != nil { + return err + } + printObject(ret) + return nil + }) + } + + rEnableMinio( + new(o.ClusterEnableComponentMinioOpt), + cmdN("component-enable-minio"), + "Enable cluster minio component", + ) + + rEnableMinio( + new(o.ClusterEnableComponentMonitorMinioOpt), + cmdN("component-enable-monitor-minio"), + "Enable cluster monitor stack's minio component", + ) R(&o.ClusterEnableComponentThanosOpt{}, cmdN("component-enable-thanos"), "Enable cluster thanos component", func(s *mcclient.ClientSession, args *o.ClusterEnableComponentThanosOpt) error { params, err := args.Params() @@ -260,9 +275,14 @@ func initKubeCluster() { return nil }) - R(&o.ClusterComponentType{}, cmdN("component-update"), "Update cluster component", func(s *mcclient.ClientSession, args *o.ClusterComponentType) error { + type ClusterComponentTypeUpdate struct { + o.ClusterComponentType + Force bool `help:"Force update"` + } + + R(&ClusterComponentTypeUpdate{}, cmdN("component-update"), "Update cluster component", func(s *mcclient.ClientSession, args *ClusterComponentTypeUpdate) error { // 1. get current setting - setting, err := getComponentSetting(s, args, false) + setting, err := getComponentSetting(s, &args.ClusterComponentType, false) if err != nil { return errors.Wrap(err, "get component setting") } @@ -270,8 +290,11 @@ func initKubeCluster() { // 2. edit yaml yaml, err := shellutils.Edit(setting.YAMLString()) if len(yaml) == 0 { - log.Infof("Nothing to update") - return nil + if !args.Force { + log.Infof("Nothing to update") + return nil + } + yaml = setting.YAMLString() } nowSetting, err := jsonutils.ParseYAML(yaml) if err != nil { @@ -279,6 +302,7 @@ func initKubeCluster() { } params := args.Params(args.TYPE) params.Update(nowSetting) + params.Add(jsonutils.NewBool(args.Force), "force") // 3. call update api ret, err := k8s.KubeClusters.PerformAction(s, args.ID, "update-component", params) diff --git a/pkg/mcclient/options/k8s/cluster.go b/pkg/mcclient/options/k8s/cluster.go index 2fe01b5d5d..7cfe6e424f 100644 --- a/pkg/mcclient/options/k8s/cluster.go +++ b/pkg/mcclient/options/k8s/cluster.go @@ -400,15 +400,31 @@ type ClusterComponentMonitorGrafanaTlsOpt struct { KeyFile string `help:"TLS key file" json:"-"` } +type ClusterComponentMonitorGrafanaOAuth struct { + Enabled bool `help:"Enable oauth setting" json:"enabled"` + ClientId string `help:"Client id" json:"clientId"` + ClientSecret string `help:"Client secret" json:"clientSecret"` + Scopes string `help:"Client scopes" json:"scopes"` + AuthURL string `help:"Auth url" json:"authURL"` + TokenURL string `help:"Token url" json:"tokenURL"` + ApiURL string `help:"API URL" json:"apiURL"` + AllowedDomains string `help:"Allowed domains" json:"allowedDomains"` + AllowSignUp bool `help:"Allow sign up" json:"allowSignUp"` + RoleAttributePath string `help:"Role attribute path" json:"roleAttributePath"` +} + type ClusterComponentMonitorGrafana struct { AdminUser string `help:"Grafana admin user" default:"admin" json:"adminUser"` AdminPassword string `help:"Grafana admin user password" json:"adminPassword"` Storage ClusterComponentStorage `help:"Storage setting"` PublicAddress string `help:"Grafana expose public IP address or domain hostname" json:"publicAddress"` Host string `help:"Grafana ingress host domain name" json:"host"` + EnforceDomain bool `help:"Enforce use domain" json:"enforceDomain"` Tls ClusterComponentMonitorGrafanaTlsOpt `help:"TLS setting"` DisableSubpath bool `help:"Disable grafana subpath" json:"disableSubpath"` + Subpath string `help:"Grafana subpath" default:"grafana" json:"subpath"` EnableThanosQuery bool `help:"Enable thanos query datasource" json:"enableThanosQueryDataSource"` + Oauth ClusterComponentMonitorGrafanaOAuth `help:"OAuth config" json:"oauth"` } type ObjectStoreConfig struct { @@ -663,18 +679,34 @@ type ClusterComponentMinioSetting struct { Storage ClusterComponentStorage `help:"Storage setting" json:"storage"` } -type ClusterEnableComponentMinioOpt struct { +type ClusterEnableComponentMinioBaseOpt struct { ClusterComponentOptions ClusterComponentMinioSetting } -func (o ClusterEnableComponentMinioOpt) Params() (jsonutils.JSONObject, error) { - params := o.ClusterComponentOptions.Params("minio") +func (o ClusterEnableComponentMinioBaseOpt) Params(typ string) (jsonutils.JSONObject, error) { + params := o.ClusterComponentOptions.Params(typ) setting := jsonutils.Marshal(o.ClusterComponentMinioSetting) - params.Add(setting, "minio") + params.Add(setting, typ) return params, nil } +type ClusterEnableComponentMinioOpt struct { + ClusterEnableComponentMinioBaseOpt +} + +func (o ClusterEnableComponentMinioOpt) Params() (jsonutils.JSONObject, error) { + return o.ClusterEnableComponentMinioBaseOpt.Params("minio") +} + +type ClusterEnableComponentMonitorMinioOpt struct { + ClusterEnableComponentMinioBaseOpt +} + +func (o ClusterEnableComponentMonitorMinioOpt) Params() (jsonutils.JSONObject, error) { + return o.ClusterEnableComponentMinioBaseOpt.Params("monitorMinio") +} + type ComponentThanosDnsDiscovery struct { SidecarsService string `help:"Sidecars service name to discover them using DNS discovery" default:"prometheus-operated" json:"sidecarsService"` SidecarsNamespace string `help:"Sidecars namespace to discover them using DNS discovery" default:"onecloud-monitoring" json:"sidecarsNamespace"`