From d0dc66cf2867e79b8ccf2d1e3670d4e2badebe1d Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 25 Sep 2019 01:16:13 +0800 Subject: [PATCH] fix servicemesh options nil bug --- cmd/ks-apiserver/app/server.go | 2 +- pkg/server/config/config.go | 2 +- pkg/server/config/config_test.go | 6 +++--- pkg/simple/client/alerting/options.go | 2 +- pkg/simple/client/devops/options.go | 13 ++++--------- pkg/simple/client/elasticsearch/options.go | 17 ++++++----------- pkg/simple/client/k8s/options.go | 10 +++------- pkg/simple/client/kubesphere/options.go | 8 ++------ pkg/simple/client/ldap/options.go | 15 +++++---------- pkg/simple/client/mysql/options.go | 16 ++++++---------- pkg/simple/client/openpitrix/options.go | 9 ++------- pkg/simple/client/prometheus/options.go | 9 ++------- pkg/simple/client/redis/options.go | 5 ----- pkg/simple/client/s2is3/options.go | 19 +++++++------------ pkg/simple/client/servicemesh/options.go | 11 +++-------- pkg/simple/client/sonarqube/options.go | 9 ++------- 16 files changed, 48 insertions(+), 105 deletions(-) diff --git a/cmd/ks-apiserver/app/server.go b/cmd/ks-apiserver/app/server.go index 305b10b97..1629a8077 100644 --- a/cmd/ks-apiserver/app/server.go +++ b/cmd/ks-apiserver/app/server.go @@ -280,7 +280,7 @@ func Complete(s *options.ServerRunOptions) error { LoggingOptions: s.LoggingOptions, }) - s = &options.ServerRunOptions{ + *s = options.ServerRunOptions{ GenericServerRunOptions: s.GenericServerRunOptions, KubernetesOptions: conf.KubernetesOptions, DevopsOptions: conf.DevopsOptions, diff --git a/pkg/server/config/config.go b/pkg/server/config/config.go index 2de5266e5..4e593f278 100644 --- a/pkg/server/config/config.go +++ b/pkg/server/config/config.go @@ -91,7 +91,7 @@ func Load() error { } } - conf := &Config{} + conf := newConfig() if err := viper.Unmarshal(conf); err != nil { klog.Error(fmt.Errorf("error unmarshal configuration %v", err)) return err diff --git a/pkg/server/config/config_test.go b/pkg/server/config/config_test.go index de2c04e2d..f5d837232 100644 --- a/pkg/server/config/config_test.go +++ b/pkg/server/config/config_test.go @@ -70,8 +70,8 @@ func newTestConfig() *Config { }, S3Options: &s2is3.S3Options{ Endpoint: "http://minio.openpitrix-system.svc", - Region: "us-east-1", - DisableSSL: true, + Region: "", + DisableSSL: false, ForcePathStyle: false, AccessKeyID: "ABCDEFGHIJKLMN", SecretAccessKey: "OPQRSTUVWXYZ", @@ -137,7 +137,7 @@ func cleanTestConfig(t *testing.T) { func TestGet(t *testing.T) { conf := newTestConfig() saveTestConfig(t, conf) - //defer cleanTestConfig(t) + defer cleanTestConfig(t) err := Load() if err != nil { diff --git a/pkg/simple/client/alerting/options.go b/pkg/simple/client/alerting/options.go index 6a417a6ff..5cb9edd70 100644 --- a/pkg/simple/client/alerting/options.go +++ b/pkg/simple/client/alerting/options.go @@ -1,7 +1,7 @@ package alerting type AlertingOptions struct { - Endpoint string + Endpoint string `json:"endpoint" yaml:"endpoint"` } func NewAlertingOptions() *AlertingOptions { diff --git a/pkg/simple/client/devops/options.go b/pkg/simple/client/devops/options.go index 2f8a5efe9..3919fadd8 100644 --- a/pkg/simple/client/devops/options.go +++ b/pkg/simple/client/devops/options.go @@ -7,10 +7,10 @@ import ( ) type DevopsOptions struct { - Host string `json:",omitempty" yaml:",omitempty" description:"Jenkins service host address"` - Username string `json:",omitempty" yaml:",omitempty" description:"Jenkins admin username"` - Password string `json:",omitempty" yaml:",omitempty" description:"Jenkins admin password"` - MaxConnections int `json:"maxConnections,omitempty" yaml:"maxConnections,omitempty" description:"Maximum connections allowed to connect to Jenkins"` + Host string `json:",omitempty" yaml:"host" description:"Jenkins service host address"` + Username string `json:",omitempty" yaml:"username" description:"Jenkins admin username"` + Password string `json:",omitempty" yaml:"password" description:"Jenkins admin password"` + MaxConnections int `json:"maxConnections,omitempty" yaml:"maxConnections" description:"Maximum connections allowed to connect to Jenkins"` } // NewDevopsOptions returns a `zero` instance @@ -25,11 +25,6 @@ func NewDevopsOptions() *DevopsOptions { // ApplyTo apply configuration to another options func (s *DevopsOptions) ApplyTo(options *DevopsOptions) { - if options == nil { - options = s - return - } - if s.Host != "" { reflectutils.Override(options, s) } diff --git a/pkg/simple/client/elasticsearch/options.go b/pkg/simple/client/elasticsearch/options.go index e602da4b2..5de2c1e26 100644 --- a/pkg/simple/client/elasticsearch/options.go +++ b/pkg/simple/client/elasticsearch/options.go @@ -6,12 +6,12 @@ import ( ) type ElasticSearchOptions struct { - Host string `json:"host,omitempty" yaml:"host,omitempty"` - LogstashFormat bool `json:"logstashFormat,omitempty" yaml:"logstashFormat,omitempty"` - Index string `json:",omitempty" yaml:",omitempty"` - LogstashPrefix string `json:"logstashPrefix,omitempty" yaml:"logstashPrefix,omitempty"` - Match string `json:",omitempty" yaml:",omitempty"` - Version string `json:",omitempty" yaml:",omitempty"` + Host string `json:"host" yaml:"host"` + LogstashFormat bool `json:"logstashFormat" yaml:"logstashFormat"` + Index string `json:"index" yaml:"index"` + LogstashPrefix string `json:"logstashPrefix,omitempty" yaml:"logstashPrefix"` + Match string `json:"match" yaml:"match"` + Version string `json:"version" yaml:"version"` } func NewElasticSearchOptions() *ElasticSearchOptions { @@ -26,11 +26,6 @@ func NewElasticSearchOptions() *ElasticSearchOptions { } func (s *ElasticSearchOptions) ApplyTo(options *ElasticSearchOptions) { - if options == nil { - options = s - return - } - if s.Host != "" { reflectutils.Override(options, s) } diff --git a/pkg/simple/client/k8s/options.go b/pkg/simple/client/k8s/options.go index 9cc3402d6..6b0a12bdf 100644 --- a/pkg/simple/client/k8s/options.go +++ b/pkg/simple/client/k8s/options.go @@ -14,15 +14,15 @@ type KubernetesOptions struct { // kubernetes apiserver public address, used to generate kubeconfig // for downloading, default to host defined in kubeconfig // +optional - Master string `json:"master,omitempty" yaml:"master,omitempty"` + Master string `json:"master,omitempty" yaml:"master"` // kubernetes clientset qps // +optional - QPS float32 `json:"qps,omitemtpy" yaml:"qps,omitempty"` + QPS float32 `json:"qps,omitemtpy" yaml:"qps"` // kubernetes clientset burst // +optional - Burst int `json:"burst,omitempty" yaml:"burst,omitempty"` + Burst int `json:"burst,omitempty" yaml:"burst"` } // NewKubernetesOptions returns a `zero` instance @@ -46,10 +46,6 @@ func (k *KubernetesOptions) Validate() []error { } func (k *KubernetesOptions) ApplyTo(options *KubernetesOptions) { - if options == nil { - options = k - return - } reflectutils.Override(options, k) } diff --git a/pkg/simple/client/kubesphere/options.go b/pkg/simple/client/kubesphere/options.go index 5d00d0430..442e44ed9 100644 --- a/pkg/simple/client/kubesphere/options.go +++ b/pkg/simple/client/kubesphere/options.go @@ -3,8 +3,8 @@ package kubesphere import "github.com/spf13/pflag" type KubeSphereOptions struct { - APIServer string - AccountServer string + APIServer string `json:"apiServer" yaml:"apiServer"` + AccountServer string `json:"accountServer" yaml:"accountServer"` } // NewKubeSphereOptions create a default options @@ -16,10 +16,6 @@ func NewKubeSphereOptions() *KubeSphereOptions { } func (s *KubeSphereOptions) ApplyTo(options *KubeSphereOptions) { - if options == nil { - options = s - return - } if s.AccountServer != "" { options.AccountServer = s.AccountServer } diff --git a/pkg/simple/client/ldap/options.go b/pkg/simple/client/ldap/options.go index 3f00075a3..7f9408eac 100644 --- a/pkg/simple/client/ldap/options.go +++ b/pkg/simple/client/ldap/options.go @@ -6,11 +6,11 @@ import ( ) type LdapOptions struct { - Host string `json:"host,omitempty" yaml:"host,omitempty"` - ManagerDN string `json:"managerDN,omitempty" yaml:"managerDN,omitempty"` - ManagerPassword string `json:"managerPassword,omitempty" yaml:"managerPassword,omitempty"` - UserSearchBase string `json:"userSearchBase,omitempty" yaml:"userSearchBase,omitempty"` - GroupSearchBase string `json:"groupSearchBase,omitempty" yaml:"groupSearchBase,omitempty"` + Host string `json:"host,omitempty" yaml:"host"` + ManagerDN string `json:"managerDN,omitempty" yaml:"managerDN"` + ManagerPassword string `json:"managerPassword,omitempty" yaml:"managerPassword"` + UserSearchBase string `json:"userSearchBase,omitempty" yaml:"userSearchBase"` + GroupSearchBase string `json:"groupSearchBase,omitempty" yaml:"groupSearchBase"` } // NewLdapOptions return a default option @@ -31,11 +31,6 @@ func (l *LdapOptions) Validate() []error { } func (l *LdapOptions) ApplyTo(options *LdapOptions) { - if options == nil { - options = l - return - } - if l.Host != "" { reflectutils.Override(options, l) } diff --git a/pkg/simple/client/mysql/options.go b/pkg/simple/client/mysql/options.go index 777462541..359b6ad9d 100644 --- a/pkg/simple/client/mysql/options.go +++ b/pkg/simple/client/mysql/options.go @@ -7,12 +7,12 @@ import ( ) type MySQLOptions struct { - Host string `json:"host,omitempty" yaml:"host,omitempty" description:"MySQL service host address"` - Username string `json:"username,omitempty" yaml:"username,omitempty"` - Password string `json:"-" yaml:"password,omitempty"` - MaxIdleConnections int `json:"maxIdleConnections,omitempty" yaml:"maxIdleConnections,omitempty"` - MaxOpenConnections int `json:"maxOpenConnections,omitempty" yaml:"maxOpenConnections,omitempty"` - MaxConnectionLifeTime time.Duration `json:"maxConnectionLifeTime,omitempty" yaml:"maxConnectionLifeTime,omitempty"` + Host string `json:"host,omitempty" yaml:"host" description:"MySQL service host address"` + Username string `json:"username,omitempty" yaml:"username"` + Password string `json:"-" yaml:"password"` + MaxIdleConnections int `json:"maxIdleConnections,omitempty" yaml:"maxIdleConnections"` + MaxOpenConnections int `json:"maxOpenConnections,omitempty" yaml:"maxOpenConnections"` + MaxConnectionLifeTime time.Duration `json:"maxConnectionLifeTime,omitempty" yaml:"maxConnectionLifeTime"` } // NewMySQLOptions create a `zero` value instance @@ -34,10 +34,6 @@ func (m *MySQLOptions) Validate() []error { } func (m *MySQLOptions) ApplyTo(options *MySQLOptions) { - if options == nil { - options = m - return - } reflectutils.Override(options, m) } diff --git a/pkg/simple/client/openpitrix/options.go b/pkg/simple/client/openpitrix/options.go index 44004b92f..0c321504e 100644 --- a/pkg/simple/client/openpitrix/options.go +++ b/pkg/simple/client/openpitrix/options.go @@ -7,8 +7,8 @@ import ( ) type OpenPitrixOptions struct { - APIServer string `json:"apiServer,omitempty" yaml:"apiServer,omitempty"` - Token string `json:"token,omitempty" yaml:"token,omitempty"` + APIServer string `json:"apiServer,omitempty" yaml:"apiServer"` + Token string `json:"token,omitempty" yaml:"token"` } func NewOpenPitrixOptions() *OpenPitrixOptions { @@ -19,11 +19,6 @@ func NewOpenPitrixOptions() *OpenPitrixOptions { } func (s *OpenPitrixOptions) ApplyTo(options *OpenPitrixOptions) { - if options == nil { - options = s - return - } - if s.APIServer != "" { reflectutils.Override(options, s) } diff --git a/pkg/simple/client/prometheus/options.go b/pkg/simple/client/prometheus/options.go index 18e58c8a4..6ade8c720 100644 --- a/pkg/simple/client/prometheus/options.go +++ b/pkg/simple/client/prometheus/options.go @@ -5,8 +5,8 @@ import ( ) type PrometheusOptions struct { - Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"` - SecondaryEndpoint string `json:"secondaryEndpoint,omitempty" yaml:"secondaryEndpoint,omitempty"` + Endpoint string `json:"endpoint,omitempty" yaml:"endpoint"` + SecondaryEndpoint string `json:"secondaryEndpoint,omitempty" yaml:"secondaryEndpoint"` } func NewPrometheusOptions() *PrometheusOptions { @@ -23,11 +23,6 @@ func (s *PrometheusOptions) Validate() []error { } func (s *PrometheusOptions) ApplyTo(options *PrometheusOptions) { - if options == nil { - options = s - return - } - if s.Endpoint != "" { options.Endpoint = s.Endpoint } diff --git a/pkg/simple/client/redis/options.go b/pkg/simple/client/redis/options.go index 4f84fec47..a89b5bac9 100644 --- a/pkg/simple/client/redis/options.go +++ b/pkg/simple/client/redis/options.go @@ -44,11 +44,6 @@ func (r *RedisOptions) Validate() []error { // ApplyTo apply to another options if it's a enabled option(non empty host) func (r *RedisOptions) ApplyTo(options *RedisOptions) { - if options == nil { - options = r - return - } - if r.Host != "" { reflectutils.Override(options, r) } diff --git a/pkg/simple/client/s2is3/options.go b/pkg/simple/client/s2is3/options.go index c7b104d22..32b676bc4 100644 --- a/pkg/simple/client/s2is3/options.go +++ b/pkg/simple/client/s2is3/options.go @@ -7,14 +7,14 @@ import ( // S3Options contains configuration to access a s3 service type S3Options struct { - Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"` - Region string `json:"region,omitempty" yaml:"region,omitempty"` + Endpoint string `json:"endpoint,omitempty" yaml:"endpoint"` + Region string `json:"region,omitempty" yaml:"region"` DisableSSL bool `json:"disableSSL" yaml:"disableSSL"` - ForcePathStyle bool `json:"forcePathStyle" yaml:"forePathStyle"` - AccessKeyID string `json:"accessKeyID,omitempty" yaml:"accessKeyID,omitempty"` - SecretAccessKey string `json:"secretAccessKey,omitempty" yaml:"secretAccessKey,omitempty"` - SessionToken string `json:"sessionToken,omitempty" yaml:"sessionToken,omitempty"` - Bucket string `json:"bucket,omitempty" yaml:"bucket,omitempty"` + ForcePathStyle bool `json:"forcePathStyle" yaml:"forcePathStyle"` + AccessKeyID string `json:"accessKeyID,omitempty" yaml:"accessKeyID"` + SecretAccessKey string `json:"secretAccessKey,omitempty" yaml:"secretAccessKey"` + SessionToken string `json:"sessionToken,omitempty" yaml:"sessionToken"` + Bucket string `json:"bucket,omitempty" yaml:"bucket"` } // NewS3Options creates a default disabled S3Options(empty endpoint) @@ -40,11 +40,6 @@ func (s *S3Options) Validate() []error { // ApplyTo overrides options if it's valid, which endpoint is not empty func (s *S3Options) ApplyTo(options *S3Options) { - if options == nil { - options = s - return - } - if s.Endpoint != "" { reflectutils.Override(options, s) } diff --git a/pkg/simple/client/servicemesh/options.go b/pkg/simple/client/servicemesh/options.go index e02609982..7056228e8 100644 --- a/pkg/simple/client/servicemesh/options.go +++ b/pkg/simple/client/servicemesh/options.go @@ -5,13 +5,13 @@ import "github.com/spf13/pflag" type ServiceMeshOptions struct { // istio pilot discovery service url - IstioPilotHost string `json:"istioPilotHost,omitempty" yaml:"istioPilotHost,omitempty"` + IstioPilotHost string `json:"istioPilotHost,omitempty" yaml:"istioPilotHost"` // jaeger query service url - JaegerQueryHost string `json:"jaegerQueryHost,omitempty" yaml:"jaegerQueryHost,omitempty"` + JaegerQueryHost string `json:"jaegerQueryHost,omitempty" yaml:"jaegerQueryHost"` // prometheus service url for servicemesh metrics - ServicemeshPrometheusHost string `json:"servicemeshPrometheusHost,omitempty" yaml:"servicemeshPrometheusHost,omitempty"` + ServicemeshPrometheusHost string `json:"servicemeshPrometheusHost,omitempty" yaml:"servicemeshPrometheusHost"` } // NewServiceMeshOptions returns a `zero` instance @@ -30,11 +30,6 @@ func (s *ServiceMeshOptions) Validate() []error { } func (s *ServiceMeshOptions) ApplyTo(options *ServiceMeshOptions) { - if options == nil { - options = s - return - } - if s.ServicemeshPrometheusHost != "" { options.ServicemeshPrometheusHost = s.ServicemeshPrometheusHost } diff --git a/pkg/simple/client/sonarqube/options.go b/pkg/simple/client/sonarqube/options.go index fc24d1584..92343c7a1 100644 --- a/pkg/simple/client/sonarqube/options.go +++ b/pkg/simple/client/sonarqube/options.go @@ -5,8 +5,8 @@ import ( ) type SonarQubeOptions struct { - Host string `json:",omitempty" yaml:",omitempty" description:"SonarQube service host address"` - Token string `json:",omitempty" yaml:",omitempty" description:"SonarQube service token"` + Host string `json:",omitempty" yaml:"host" description:"SonarQube service host address"` + Token string `json:",omitempty" yaml:"token" description:"SonarQube service token"` } func NewSonarQubeOptions() *SonarQubeOptions { @@ -27,11 +27,6 @@ func (s *SonarQubeOptions) Validate() []error { } func (s *SonarQubeOptions) ApplyTo(options *SonarQubeOptions) { - if options == nil { - options = s - return - } - if s.Host != "" { options.Host = s.Host options.Token = s.Token