提交 468f7edd 编写于 作者: J Jeff 提交者: zryfish

fix config nil error

上级 3dca9feb
......@@ -8,11 +8,9 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/devops"
esclient "kubesphere.io/kubesphere/pkg/simple/client/elasticsearch"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/ldap"
"kubesphere.io/kubesphere/pkg/simple/client/mysql"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"kubesphere.io/kubesphere/pkg/simple/client/prometheus"
"kubesphere.io/kubesphere/pkg/simple/client/redis"
"kubesphere.io/kubesphere/pkg/simple/client/s2is3"
"kubesphere.io/kubesphere/pkg/simple/client/servicemesh"
"kubesphere.io/kubesphere/pkg/simple/client/sonarqube"
......@@ -28,9 +26,7 @@ type ServerRunOptions struct {
ServiceMeshOptions *servicemesh.ServiceMeshOptions
MySQLOptions *mysql.MySQLOptions
MonitoringOptions *prometheus.PrometheusOptions
LdapOptions *ldap.LdapOptions
S3Options *s2is3.S3Options
RedisOptions *redis.RedisOptions
OpenPitrixOptions *openpitrix.OpenPitrixOptions
LoggingOptions *esclient.ElasticSearchOptions
}
......@@ -45,9 +41,7 @@ func NewServerRunOptions() *ServerRunOptions {
ServiceMeshOptions: servicemesh.NewServiceMeshOptions(),
MySQLOptions: mysql.NewMySQLOptions(),
MonitoringOptions: prometheus.NewPrometheusOptions(),
LdapOptions: ldap.NewLdapOptions(),
S3Options: s2is3.NewS3Options(),
RedisOptions: redis.NewRedisOptions(),
OpenPitrixOptions: openpitrix.NewOpenPitrixOptions(),
LoggingOptions: esclient.NewElasticSearchOptions(),
}
......@@ -59,12 +53,10 @@ func (s *ServerRunOptions) Flags() (fss cliflag.NamedFlagSets) {
s.GenericServerRunOptions.AddFlags(fss.FlagSet("generic"))
s.KubernetesOptions.AddFlags(fss.FlagSet("kubernetes"))
s.LdapOptions.AddFlags(fss.FlagSet("ldap"))
s.MySQLOptions.AddFlags(fss.FlagSet("mysql"))
s.DevopsOptions.AddFlags(fss.FlagSet("devops"))
s.SonarQubeOptions.AddFlags(fss.FlagSet("sonarqube"))
s.S3Options.AddFlags(fss.FlagSet("s3"))
s.RedisOptions.AddFlags(fss.FlagSet("redis"))
s.OpenPitrixOptions.AddFlags(fss.FlagSet("openpitrix"))
s.ServiceMeshOptions.AddFlags(fss.FlagSet("servicemesh"))
s.MonitoringOptions.AddFlags(fss.FlagSet("monitoring"))
......
......@@ -11,9 +11,7 @@ func (s *ServerRunOptions) Validate() []error {
errors = append(errors, s.ServiceMeshOptions.Validate()...)
errors = append(errors, s.MonitoringOptions.Validate()...)
errors = append(errors, s.SonarQubeOptions.Validate()...)
errors = append(errors, s.LdapOptions.Validate()...)
errors = append(errors, s.S3Options.Validate()...)
errors = append(errors, s.RedisOptions.Validate()...)
errors = append(errors, s.OpenPitrixOptions.Validate()...)
errors = append(errors, s.LoggingOptions.Validate()...)
......
......@@ -162,7 +162,6 @@ func CreateClientSet(conf *apiserverconfig.Config, stopCh <-chan struct{}) error
SetS3Options(conf.S3Options).
SetOpenPitrixOptions(conf.OpenPitrixOptions).
SetPrometheusOptions(conf.MonitoringOptions).
SetRedisOptions(conf.RedisOptions).
SetKubeSphereOptions(conf.KubeSphereOptions).
SetElasticSearchOptions(conf.LoggingOptions)
......@@ -276,8 +275,6 @@ func Complete(s *options.ServerRunOptions) error {
KubernetesOptions: s.KubernetesOptions,
ServiceMeshOptions: s.ServiceMeshOptions,
MonitoringOptions: s.MonitoringOptions,
LdapOptions: s.LdapOptions,
RedisOptions: s.RedisOptions,
S3Options: s.S3Options,
OpenPitrixOptions: s.OpenPitrixOptions,
LoggingOptions: s.LoggingOptions,
......@@ -291,8 +288,6 @@ func Complete(s *options.ServerRunOptions) error {
ServiceMeshOptions: conf.ServiceMeshOptions,
MySQLOptions: conf.MySQLOptions,
MonitoringOptions: conf.MonitoringOptions,
LdapOptions: conf.LdapOptions,
RedisOptions: conf.RedisOptions,
S3Options: conf.S3Options,
OpenPitrixOptions: conf.OpenPitrixOptions,
LoggingOptions: conf.LoggingOptions,
......
......@@ -11,6 +11,11 @@ func NewAlertingOptions() *AlertingOptions {
}
func (s *AlertingOptions) ApplyTo(options *AlertingOptions) {
if options == nil {
options = s
return
}
if s.Endpoint != "" {
options.Endpoint = s.Endpoint
}
......
......@@ -25,7 +25,12 @@ func NewDevopsOptions() *DevopsOptions {
// ApplyTo apply configuration to another options
func (s *DevopsOptions) ApplyTo(options *DevopsOptions) {
if s.Host != "" && options != nil {
if options == nil {
options = s
return
}
if s.Host != "" {
reflectutils.Override(options, s)
}
}
......
......@@ -26,6 +26,11 @@ func NewElasticSearchOptions() *ElasticSearchOptions {
}
func (s *ElasticSearchOptions) ApplyTo(options *ElasticSearchOptions) {
if options == nil {
options = s
return
}
if s.Host != "" {
reflectutils.Override(options, s)
}
......
......@@ -46,6 +46,10 @@ func (k *KubernetesOptions) Validate() []error {
}
func (k *KubernetesOptions) ApplyTo(options *KubernetesOptions) {
if options == nil {
options = k
return
}
reflectutils.Override(options, k)
}
......
......@@ -16,6 +16,10 @@ func NewKubeSphereOptions() *KubeSphereOptions {
}
func (s *KubeSphereOptions) ApplyTo(options *KubeSphereOptions) {
if options == nil {
options = s
return
}
if s.AccountServer != "" {
options.AccountServer = s.AccountServer
}
......
......@@ -31,6 +31,11 @@ func (l *LdapOptions) Validate() []error {
}
func (l *LdapOptions) ApplyTo(options *LdapOptions) {
if options == nil {
options = l
return
}
if l.Host != "" {
reflectutils.Override(options, l)
}
......
......@@ -34,6 +34,10 @@ func (m *MySQLOptions) Validate() []error {
}
func (m *MySQLOptions) ApplyTo(options *MySQLOptions) {
if options == nil {
options = m
return
}
reflectutils.Override(options, m)
}
......
......@@ -11,6 +11,11 @@ func NewNotificationOptions() *NotificationOptions {
}
func (s *NotificationOptions) ApplyTo(options *NotificationOptions) {
if options == nil {
options = s
return
}
if s.Endpoint != "" {
options.Endpoint = s.Endpoint
}
......
......@@ -19,6 +19,11 @@ func NewOpenPitrixOptions() *OpenPitrixOptions {
}
func (s *OpenPitrixOptions) ApplyTo(options *OpenPitrixOptions) {
if options == nil {
options = s
return
}
if s.APIServer != "" {
reflectutils.Override(options, s)
}
......
......@@ -23,6 +23,11 @@ func (s *PrometheusOptions) Validate() []error {
}
func (s *PrometheusOptions) ApplyTo(options *PrometheusOptions) {
if options == nil {
options = s
return
}
if s.Endpoint != "" {
options.Endpoint = s.Endpoint
}
......
......@@ -44,6 +44,11 @@ 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)
}
......
......@@ -40,6 +40,11 @@ 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)
}
......
......@@ -31,6 +31,7 @@ func (s *ServiceMeshOptions) Validate() []error {
func (s *ServiceMeshOptions) ApplyTo(options *ServiceMeshOptions) {
if options == nil {
options = s
return
}
......
......@@ -28,6 +28,7 @@ func (s *SonarQubeOptions) Validate() []error {
func (s *SonarQubeOptions) ApplyTo(options *SonarQubeOptions) {
if options == nil {
options = s
return
}
......
......@@ -37,22 +37,23 @@ func In(value interface{}, container interface{}) bool {
}
func Override(left interface{}, right interface{}) {
if left == nil || right == nil {
if reflect.ValueOf(left).IsNil() || reflect.ValueOf(right).IsNil() {
return
}
if reflect.ValueOf(left).Type().Kind() != reflect.Ptr ||
reflect.ValueOf(right).Type().Kind() != reflect.Ptr {
reflect.ValueOf(right).Type().Kind() != reflect.Ptr ||
reflect.ValueOf(left).Kind() != reflect.ValueOf(right).Kind() {
return
}
old := reflect.ValueOf(left).Elem()
new := reflect.ValueOf(right).Elem()
oldVal := reflect.ValueOf(left).Elem()
newVal := reflect.ValueOf(right).Elem()
for i := 0; i < old.NumField(); i++ {
val := new.Field(i).Interface()
for i := 0; i < oldVal.NumField(); i++ {
val := newVal.Field(i).Interface()
if !reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface()) {
old.Field(i).Set(reflect.ValueOf(val))
oldVal.Field(i).Set(reflect.ValueOf(val))
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册