提交 d0dc66cf 编写于 作者: J Jeff 提交者: zryfish

fix servicemesh options nil bug

上级 284c0d64
...@@ -280,7 +280,7 @@ func Complete(s *options.ServerRunOptions) error { ...@@ -280,7 +280,7 @@ func Complete(s *options.ServerRunOptions) error {
LoggingOptions: s.LoggingOptions, LoggingOptions: s.LoggingOptions,
}) })
s = &options.ServerRunOptions{ *s = options.ServerRunOptions{
GenericServerRunOptions: s.GenericServerRunOptions, GenericServerRunOptions: s.GenericServerRunOptions,
KubernetesOptions: conf.KubernetesOptions, KubernetesOptions: conf.KubernetesOptions,
DevopsOptions: conf.DevopsOptions, DevopsOptions: conf.DevopsOptions,
......
...@@ -91,7 +91,7 @@ func Load() error { ...@@ -91,7 +91,7 @@ func Load() error {
} }
} }
conf := &Config{} conf := newConfig()
if err := viper.Unmarshal(conf); err != nil { if err := viper.Unmarshal(conf); err != nil {
klog.Error(fmt.Errorf("error unmarshal configuration %v", err)) klog.Error(fmt.Errorf("error unmarshal configuration %v", err))
return err return err
......
...@@ -70,8 +70,8 @@ func newTestConfig() *Config { ...@@ -70,8 +70,8 @@ func newTestConfig() *Config {
}, },
S3Options: &s2is3.S3Options{ S3Options: &s2is3.S3Options{
Endpoint: "http://minio.openpitrix-system.svc", Endpoint: "http://minio.openpitrix-system.svc",
Region: "us-east-1", Region: "",
DisableSSL: true, DisableSSL: false,
ForcePathStyle: false, ForcePathStyle: false,
AccessKeyID: "ABCDEFGHIJKLMN", AccessKeyID: "ABCDEFGHIJKLMN",
SecretAccessKey: "OPQRSTUVWXYZ", SecretAccessKey: "OPQRSTUVWXYZ",
...@@ -137,7 +137,7 @@ func cleanTestConfig(t *testing.T) { ...@@ -137,7 +137,7 @@ func cleanTestConfig(t *testing.T) {
func TestGet(t *testing.T) { func TestGet(t *testing.T) {
conf := newTestConfig() conf := newTestConfig()
saveTestConfig(t, conf) saveTestConfig(t, conf)
//defer cleanTestConfig(t) defer cleanTestConfig(t)
err := Load() err := Load()
if err != nil { if err != nil {
......
package alerting package alerting
type AlertingOptions struct { type AlertingOptions struct {
Endpoint string Endpoint string `json:"endpoint" yaml:"endpoint"`
} }
func NewAlertingOptions() *AlertingOptions { func NewAlertingOptions() *AlertingOptions {
......
...@@ -7,10 +7,10 @@ import ( ...@@ -7,10 +7,10 @@ import (
) )
type DevopsOptions struct { type DevopsOptions struct {
Host string `json:",omitempty" yaml:",omitempty" description:"Jenkins service host address"` Host string `json:",omitempty" yaml:"host" description:"Jenkins service host address"`
Username string `json:",omitempty" yaml:",omitempty" description:"Jenkins admin username"` Username string `json:",omitempty" yaml:"username" description:"Jenkins admin username"`
Password string `json:",omitempty" yaml:",omitempty" description:"Jenkins admin password"` Password string `json:",omitempty" yaml:"password" description:"Jenkins admin password"`
MaxConnections int `json:"maxConnections,omitempty" yaml:"maxConnections,omitempty" description:"Maximum connections allowed to connect to Jenkins"` MaxConnections int `json:"maxConnections,omitempty" yaml:"maxConnections" description:"Maximum connections allowed to connect to Jenkins"`
} }
// NewDevopsOptions returns a `zero` instance // NewDevopsOptions returns a `zero` instance
...@@ -25,11 +25,6 @@ func NewDevopsOptions() *DevopsOptions { ...@@ -25,11 +25,6 @@ func NewDevopsOptions() *DevopsOptions {
// ApplyTo apply configuration to another options // ApplyTo apply configuration to another options
func (s *DevopsOptions) ApplyTo(options *DevopsOptions) { func (s *DevopsOptions) ApplyTo(options *DevopsOptions) {
if options == nil {
options = s
return
}
if s.Host != "" { if s.Host != "" {
reflectutils.Override(options, s) reflectutils.Override(options, s)
} }
......
...@@ -6,12 +6,12 @@ import ( ...@@ -6,12 +6,12 @@ import (
) )
type ElasticSearchOptions struct { type ElasticSearchOptions struct {
Host string `json:"host,omitempty" yaml:"host,omitempty"` Host string `json:"host" yaml:"host"`
LogstashFormat bool `json:"logstashFormat,omitempty" yaml:"logstashFormat,omitempty"` LogstashFormat bool `json:"logstashFormat" yaml:"logstashFormat"`
Index string `json:",omitempty" yaml:",omitempty"` Index string `json:"index" yaml:"index"`
LogstashPrefix string `json:"logstashPrefix,omitempty" yaml:"logstashPrefix,omitempty"` LogstashPrefix string `json:"logstashPrefix,omitempty" yaml:"logstashPrefix"`
Match string `json:",omitempty" yaml:",omitempty"` Match string `json:"match" yaml:"match"`
Version string `json:",omitempty" yaml:",omitempty"` Version string `json:"version" yaml:"version"`
} }
func NewElasticSearchOptions() *ElasticSearchOptions { func NewElasticSearchOptions() *ElasticSearchOptions {
...@@ -26,11 +26,6 @@ func NewElasticSearchOptions() *ElasticSearchOptions { ...@@ -26,11 +26,6 @@ func NewElasticSearchOptions() *ElasticSearchOptions {
} }
func (s *ElasticSearchOptions) ApplyTo(options *ElasticSearchOptions) { func (s *ElasticSearchOptions) ApplyTo(options *ElasticSearchOptions) {
if options == nil {
options = s
return
}
if s.Host != "" { if s.Host != "" {
reflectutils.Override(options, s) reflectutils.Override(options, s)
} }
......
...@@ -14,15 +14,15 @@ type KubernetesOptions struct { ...@@ -14,15 +14,15 @@ type KubernetesOptions struct {
// kubernetes apiserver public address, used to generate kubeconfig // kubernetes apiserver public address, used to generate kubeconfig
// for downloading, default to host defined in kubeconfig // for downloading, default to host defined in kubeconfig
// +optional // +optional
Master string `json:"master,omitempty" yaml:"master,omitempty"` Master string `json:"master,omitempty" yaml:"master"`
// kubernetes clientset qps // kubernetes clientset qps
// +optional // +optional
QPS float32 `json:"qps,omitemtpy" yaml:"qps,omitempty"` QPS float32 `json:"qps,omitemtpy" yaml:"qps"`
// kubernetes clientset burst // kubernetes clientset burst
// +optional // +optional
Burst int `json:"burst,omitempty" yaml:"burst,omitempty"` Burst int `json:"burst,omitempty" yaml:"burst"`
} }
// NewKubernetesOptions returns a `zero` instance // NewKubernetesOptions returns a `zero` instance
...@@ -46,10 +46,6 @@ func (k *KubernetesOptions) Validate() []error { ...@@ -46,10 +46,6 @@ func (k *KubernetesOptions) Validate() []error {
} }
func (k *KubernetesOptions) ApplyTo(options *KubernetesOptions) { func (k *KubernetesOptions) ApplyTo(options *KubernetesOptions) {
if options == nil {
options = k
return
}
reflectutils.Override(options, k) reflectutils.Override(options, k)
} }
......
...@@ -3,8 +3,8 @@ package kubesphere ...@@ -3,8 +3,8 @@ package kubesphere
import "github.com/spf13/pflag" import "github.com/spf13/pflag"
type KubeSphereOptions struct { type KubeSphereOptions struct {
APIServer string APIServer string `json:"apiServer" yaml:"apiServer"`
AccountServer string AccountServer string `json:"accountServer" yaml:"accountServer"`
} }
// NewKubeSphereOptions create a default options // NewKubeSphereOptions create a default options
...@@ -16,10 +16,6 @@ func NewKubeSphereOptions() *KubeSphereOptions { ...@@ -16,10 +16,6 @@ func NewKubeSphereOptions() *KubeSphereOptions {
} }
func (s *KubeSphereOptions) ApplyTo(options *KubeSphereOptions) { func (s *KubeSphereOptions) ApplyTo(options *KubeSphereOptions) {
if options == nil {
options = s
return
}
if s.AccountServer != "" { if s.AccountServer != "" {
options.AccountServer = s.AccountServer options.AccountServer = s.AccountServer
} }
......
...@@ -6,11 +6,11 @@ import ( ...@@ -6,11 +6,11 @@ import (
) )
type LdapOptions struct { type LdapOptions struct {
Host string `json:"host,omitempty" yaml:"host,omitempty"` Host string `json:"host,omitempty" yaml:"host"`
ManagerDN string `json:"managerDN,omitempty" yaml:"managerDN,omitempty"` ManagerDN string `json:"managerDN,omitempty" yaml:"managerDN"`
ManagerPassword string `json:"managerPassword,omitempty" yaml:"managerPassword,omitempty"` ManagerPassword string `json:"managerPassword,omitempty" yaml:"managerPassword"`
UserSearchBase string `json:"userSearchBase,omitempty" yaml:"userSearchBase,omitempty"` UserSearchBase string `json:"userSearchBase,omitempty" yaml:"userSearchBase"`
GroupSearchBase string `json:"groupSearchBase,omitempty" yaml:"groupSearchBase,omitempty"` GroupSearchBase string `json:"groupSearchBase,omitempty" yaml:"groupSearchBase"`
} }
// NewLdapOptions return a default option // NewLdapOptions return a default option
...@@ -31,11 +31,6 @@ func (l *LdapOptions) Validate() []error { ...@@ -31,11 +31,6 @@ func (l *LdapOptions) Validate() []error {
} }
func (l *LdapOptions) ApplyTo(options *LdapOptions) { func (l *LdapOptions) ApplyTo(options *LdapOptions) {
if options == nil {
options = l
return
}
if l.Host != "" { if l.Host != "" {
reflectutils.Override(options, l) reflectutils.Override(options, l)
} }
......
...@@ -7,12 +7,12 @@ import ( ...@@ -7,12 +7,12 @@ import (
) )
type MySQLOptions struct { type MySQLOptions struct {
Host string `json:"host,omitempty" yaml:"host,omitempty" description:"MySQL service host address"` Host string `json:"host,omitempty" yaml:"host" description:"MySQL service host address"`
Username string `json:"username,omitempty" yaml:"username,omitempty"` Username string `json:"username,omitempty" yaml:"username"`
Password string `json:"-" yaml:"password,omitempty"` Password string `json:"-" yaml:"password"`
MaxIdleConnections int `json:"maxIdleConnections,omitempty" yaml:"maxIdleConnections,omitempty"` MaxIdleConnections int `json:"maxIdleConnections,omitempty" yaml:"maxIdleConnections"`
MaxOpenConnections int `json:"maxOpenConnections,omitempty" yaml:"maxOpenConnections,omitempty"` MaxOpenConnections int `json:"maxOpenConnections,omitempty" yaml:"maxOpenConnections"`
MaxConnectionLifeTime time.Duration `json:"maxConnectionLifeTime,omitempty" yaml:"maxConnectionLifeTime,omitempty"` MaxConnectionLifeTime time.Duration `json:"maxConnectionLifeTime,omitempty" yaml:"maxConnectionLifeTime"`
} }
// NewMySQLOptions create a `zero` value instance // NewMySQLOptions create a `zero` value instance
...@@ -34,10 +34,6 @@ func (m *MySQLOptions) Validate() []error { ...@@ -34,10 +34,6 @@ func (m *MySQLOptions) Validate() []error {
} }
func (m *MySQLOptions) ApplyTo(options *MySQLOptions) { func (m *MySQLOptions) ApplyTo(options *MySQLOptions) {
if options == nil {
options = m
return
}
reflectutils.Override(options, m) reflectutils.Override(options, m)
} }
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
) )
type OpenPitrixOptions struct { type OpenPitrixOptions struct {
APIServer string `json:"apiServer,omitempty" yaml:"apiServer,omitempty"` APIServer string `json:"apiServer,omitempty" yaml:"apiServer"`
Token string `json:"token,omitempty" yaml:"token,omitempty"` Token string `json:"token,omitempty" yaml:"token"`
} }
func NewOpenPitrixOptions() *OpenPitrixOptions { func NewOpenPitrixOptions() *OpenPitrixOptions {
...@@ -19,11 +19,6 @@ func NewOpenPitrixOptions() *OpenPitrixOptions { ...@@ -19,11 +19,6 @@ func NewOpenPitrixOptions() *OpenPitrixOptions {
} }
func (s *OpenPitrixOptions) ApplyTo(options *OpenPitrixOptions) { func (s *OpenPitrixOptions) ApplyTo(options *OpenPitrixOptions) {
if options == nil {
options = s
return
}
if s.APIServer != "" { if s.APIServer != "" {
reflectutils.Override(options, s) reflectutils.Override(options, s)
} }
......
...@@ -5,8 +5,8 @@ import ( ...@@ -5,8 +5,8 @@ import (
) )
type PrometheusOptions struct { type PrometheusOptions struct {
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"` Endpoint string `json:"endpoint,omitempty" yaml:"endpoint"`
SecondaryEndpoint string `json:"secondaryEndpoint,omitempty" yaml:"secondaryEndpoint,omitempty"` SecondaryEndpoint string `json:"secondaryEndpoint,omitempty" yaml:"secondaryEndpoint"`
} }
func NewPrometheusOptions() *PrometheusOptions { func NewPrometheusOptions() *PrometheusOptions {
...@@ -23,11 +23,6 @@ func (s *PrometheusOptions) Validate() []error { ...@@ -23,11 +23,6 @@ func (s *PrometheusOptions) Validate() []error {
} }
func (s *PrometheusOptions) ApplyTo(options *PrometheusOptions) { func (s *PrometheusOptions) ApplyTo(options *PrometheusOptions) {
if options == nil {
options = s
return
}
if s.Endpoint != "" { if s.Endpoint != "" {
options.Endpoint = s.Endpoint options.Endpoint = s.Endpoint
} }
......
...@@ -44,11 +44,6 @@ func (r *RedisOptions) Validate() []error { ...@@ -44,11 +44,6 @@ func (r *RedisOptions) Validate() []error {
// ApplyTo apply to another options if it's a enabled option(non empty host) // ApplyTo apply to another options if it's a enabled option(non empty host)
func (r *RedisOptions) ApplyTo(options *RedisOptions) { func (r *RedisOptions) ApplyTo(options *RedisOptions) {
if options == nil {
options = r
return
}
if r.Host != "" { if r.Host != "" {
reflectutils.Override(options, r) reflectutils.Override(options, r)
} }
......
...@@ -7,14 +7,14 @@ import ( ...@@ -7,14 +7,14 @@ import (
// S3Options contains configuration to access a s3 service // S3Options contains configuration to access a s3 service
type S3Options struct { type S3Options struct {
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"` Endpoint string `json:"endpoint,omitempty" yaml:"endpoint"`
Region string `json:"region,omitempty" yaml:"region,omitempty"` Region string `json:"region,omitempty" yaml:"region"`
DisableSSL bool `json:"disableSSL" yaml:"disableSSL"` DisableSSL bool `json:"disableSSL" yaml:"disableSSL"`
ForcePathStyle bool `json:"forcePathStyle" yaml:"forePathStyle"` ForcePathStyle bool `json:"forcePathStyle" yaml:"forcePathStyle"`
AccessKeyID string `json:"accessKeyID,omitempty" yaml:"accessKeyID,omitempty"` AccessKeyID string `json:"accessKeyID,omitempty" yaml:"accessKeyID"`
SecretAccessKey string `json:"secretAccessKey,omitempty" yaml:"secretAccessKey,omitempty"` SecretAccessKey string `json:"secretAccessKey,omitempty" yaml:"secretAccessKey"`
SessionToken string `json:"sessionToken,omitempty" yaml:"sessionToken,omitempty"` SessionToken string `json:"sessionToken,omitempty" yaml:"sessionToken"`
Bucket string `json:"bucket,omitempty" yaml:"bucket,omitempty"` Bucket string `json:"bucket,omitempty" yaml:"bucket"`
} }
// NewS3Options creates a default disabled S3Options(empty endpoint) // NewS3Options creates a default disabled S3Options(empty endpoint)
...@@ -40,11 +40,6 @@ func (s *S3Options) Validate() []error { ...@@ -40,11 +40,6 @@ func (s *S3Options) Validate() []error {
// ApplyTo overrides options if it's valid, which endpoint is not empty // ApplyTo overrides options if it's valid, which endpoint is not empty
func (s *S3Options) ApplyTo(options *S3Options) { func (s *S3Options) ApplyTo(options *S3Options) {
if options == nil {
options = s
return
}
if s.Endpoint != "" { if s.Endpoint != "" {
reflectutils.Override(options, s) reflectutils.Override(options, s)
} }
......
...@@ -5,13 +5,13 @@ import "github.com/spf13/pflag" ...@@ -5,13 +5,13 @@ import "github.com/spf13/pflag"
type ServiceMeshOptions struct { type ServiceMeshOptions struct {
// istio pilot discovery service url // istio pilot discovery service url
IstioPilotHost string `json:"istioPilotHost,omitempty" yaml:"istioPilotHost,omitempty"` IstioPilotHost string `json:"istioPilotHost,omitempty" yaml:"istioPilotHost"`
// jaeger query service url // 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 // 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 // NewServiceMeshOptions returns a `zero` instance
...@@ -30,11 +30,6 @@ func (s *ServiceMeshOptions) Validate() []error { ...@@ -30,11 +30,6 @@ func (s *ServiceMeshOptions) Validate() []error {
} }
func (s *ServiceMeshOptions) ApplyTo(options *ServiceMeshOptions) { func (s *ServiceMeshOptions) ApplyTo(options *ServiceMeshOptions) {
if options == nil {
options = s
return
}
if s.ServicemeshPrometheusHost != "" { if s.ServicemeshPrometheusHost != "" {
options.ServicemeshPrometheusHost = s.ServicemeshPrometheusHost options.ServicemeshPrometheusHost = s.ServicemeshPrometheusHost
} }
......
...@@ -5,8 +5,8 @@ import ( ...@@ -5,8 +5,8 @@ import (
) )
type SonarQubeOptions struct { type SonarQubeOptions struct {
Host string `json:",omitempty" yaml:",omitempty" description:"SonarQube service host address"` Host string `json:",omitempty" yaml:"host" description:"SonarQube service host address"`
Token string `json:",omitempty" yaml:",omitempty" description:"SonarQube service token"` Token string `json:",omitempty" yaml:"token" description:"SonarQube service token"`
} }
func NewSonarQubeOptions() *SonarQubeOptions { func NewSonarQubeOptions() *SonarQubeOptions {
...@@ -27,11 +27,6 @@ func (s *SonarQubeOptions) Validate() []error { ...@@ -27,11 +27,6 @@ func (s *SonarQubeOptions) Validate() []error {
} }
func (s *SonarQubeOptions) ApplyTo(options *SonarQubeOptions) { func (s *SonarQubeOptions) ApplyTo(options *SonarQubeOptions) {
if options == nil {
options = s
return
}
if s.Host != "" { if s.Host != "" {
options.Host = s.Host options.Host = s.Host
options.Token = s.Token options.Token = s.Token
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册