fix config nil error
This commit is contained in:
@@ -8,11 +8,9 @@ import (
|
|||||||
"kubesphere.io/kubesphere/pkg/simple/client/devops"
|
"kubesphere.io/kubesphere/pkg/simple/client/devops"
|
||||||
esclient "kubesphere.io/kubesphere/pkg/simple/client/elasticsearch"
|
esclient "kubesphere.io/kubesphere/pkg/simple/client/elasticsearch"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
|
"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/mysql"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/prometheus"
|
"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/s2is3"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/servicemesh"
|
"kubesphere.io/kubesphere/pkg/simple/client/servicemesh"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/sonarqube"
|
"kubesphere.io/kubesphere/pkg/simple/client/sonarqube"
|
||||||
@@ -28,9 +26,7 @@ type ServerRunOptions struct {
|
|||||||
ServiceMeshOptions *servicemesh.ServiceMeshOptions
|
ServiceMeshOptions *servicemesh.ServiceMeshOptions
|
||||||
MySQLOptions *mysql.MySQLOptions
|
MySQLOptions *mysql.MySQLOptions
|
||||||
MonitoringOptions *prometheus.PrometheusOptions
|
MonitoringOptions *prometheus.PrometheusOptions
|
||||||
LdapOptions *ldap.LdapOptions
|
|
||||||
S3Options *s2is3.S3Options
|
S3Options *s2is3.S3Options
|
||||||
RedisOptions *redis.RedisOptions
|
|
||||||
OpenPitrixOptions *openpitrix.OpenPitrixOptions
|
OpenPitrixOptions *openpitrix.OpenPitrixOptions
|
||||||
LoggingOptions *esclient.ElasticSearchOptions
|
LoggingOptions *esclient.ElasticSearchOptions
|
||||||
}
|
}
|
||||||
@@ -45,9 +41,7 @@ func NewServerRunOptions() *ServerRunOptions {
|
|||||||
ServiceMeshOptions: servicemesh.NewServiceMeshOptions(),
|
ServiceMeshOptions: servicemesh.NewServiceMeshOptions(),
|
||||||
MySQLOptions: mysql.NewMySQLOptions(),
|
MySQLOptions: mysql.NewMySQLOptions(),
|
||||||
MonitoringOptions: prometheus.NewPrometheusOptions(),
|
MonitoringOptions: prometheus.NewPrometheusOptions(),
|
||||||
LdapOptions: ldap.NewLdapOptions(),
|
|
||||||
S3Options: s2is3.NewS3Options(),
|
S3Options: s2is3.NewS3Options(),
|
||||||
RedisOptions: redis.NewRedisOptions(),
|
|
||||||
OpenPitrixOptions: openpitrix.NewOpenPitrixOptions(),
|
OpenPitrixOptions: openpitrix.NewOpenPitrixOptions(),
|
||||||
LoggingOptions: esclient.NewElasticSearchOptions(),
|
LoggingOptions: esclient.NewElasticSearchOptions(),
|
||||||
}
|
}
|
||||||
@@ -59,12 +53,10 @@ func (s *ServerRunOptions) Flags() (fss cliflag.NamedFlagSets) {
|
|||||||
|
|
||||||
s.GenericServerRunOptions.AddFlags(fss.FlagSet("generic"))
|
s.GenericServerRunOptions.AddFlags(fss.FlagSet("generic"))
|
||||||
s.KubernetesOptions.AddFlags(fss.FlagSet("kubernetes"))
|
s.KubernetesOptions.AddFlags(fss.FlagSet("kubernetes"))
|
||||||
s.LdapOptions.AddFlags(fss.FlagSet("ldap"))
|
|
||||||
s.MySQLOptions.AddFlags(fss.FlagSet("mysql"))
|
s.MySQLOptions.AddFlags(fss.FlagSet("mysql"))
|
||||||
s.DevopsOptions.AddFlags(fss.FlagSet("devops"))
|
s.DevopsOptions.AddFlags(fss.FlagSet("devops"))
|
||||||
s.SonarQubeOptions.AddFlags(fss.FlagSet("sonarqube"))
|
s.SonarQubeOptions.AddFlags(fss.FlagSet("sonarqube"))
|
||||||
s.S3Options.AddFlags(fss.FlagSet("s3"))
|
s.S3Options.AddFlags(fss.FlagSet("s3"))
|
||||||
s.RedisOptions.AddFlags(fss.FlagSet("redis"))
|
|
||||||
s.OpenPitrixOptions.AddFlags(fss.FlagSet("openpitrix"))
|
s.OpenPitrixOptions.AddFlags(fss.FlagSet("openpitrix"))
|
||||||
s.ServiceMeshOptions.AddFlags(fss.FlagSet("servicemesh"))
|
s.ServiceMeshOptions.AddFlags(fss.FlagSet("servicemesh"))
|
||||||
s.MonitoringOptions.AddFlags(fss.FlagSet("monitoring"))
|
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.ServiceMeshOptions.Validate()...)
|
||||||
errors = append(errors, s.MonitoringOptions.Validate()...)
|
errors = append(errors, s.MonitoringOptions.Validate()...)
|
||||||
errors = append(errors, s.SonarQubeOptions.Validate()...)
|
errors = append(errors, s.SonarQubeOptions.Validate()...)
|
||||||
errors = append(errors, s.LdapOptions.Validate()...)
|
|
||||||
errors = append(errors, s.S3Options.Validate()...)
|
errors = append(errors, s.S3Options.Validate()...)
|
||||||
errors = append(errors, s.RedisOptions.Validate()...)
|
|
||||||
errors = append(errors, s.OpenPitrixOptions.Validate()...)
|
errors = append(errors, s.OpenPitrixOptions.Validate()...)
|
||||||
errors = append(errors, s.LoggingOptions.Validate()...)
|
errors = append(errors, s.LoggingOptions.Validate()...)
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,6 @@ func CreateClientSet(conf *apiserverconfig.Config, stopCh <-chan struct{}) error
|
|||||||
SetS3Options(conf.S3Options).
|
SetS3Options(conf.S3Options).
|
||||||
SetOpenPitrixOptions(conf.OpenPitrixOptions).
|
SetOpenPitrixOptions(conf.OpenPitrixOptions).
|
||||||
SetPrometheusOptions(conf.MonitoringOptions).
|
SetPrometheusOptions(conf.MonitoringOptions).
|
||||||
SetRedisOptions(conf.RedisOptions).
|
|
||||||
SetKubeSphereOptions(conf.KubeSphereOptions).
|
SetKubeSphereOptions(conf.KubeSphereOptions).
|
||||||
SetElasticSearchOptions(conf.LoggingOptions)
|
SetElasticSearchOptions(conf.LoggingOptions)
|
||||||
|
|
||||||
@@ -276,8 +275,6 @@ func Complete(s *options.ServerRunOptions) error {
|
|||||||
KubernetesOptions: s.KubernetesOptions,
|
KubernetesOptions: s.KubernetesOptions,
|
||||||
ServiceMeshOptions: s.ServiceMeshOptions,
|
ServiceMeshOptions: s.ServiceMeshOptions,
|
||||||
MonitoringOptions: s.MonitoringOptions,
|
MonitoringOptions: s.MonitoringOptions,
|
||||||
LdapOptions: s.LdapOptions,
|
|
||||||
RedisOptions: s.RedisOptions,
|
|
||||||
S3Options: s.S3Options,
|
S3Options: s.S3Options,
|
||||||
OpenPitrixOptions: s.OpenPitrixOptions,
|
OpenPitrixOptions: s.OpenPitrixOptions,
|
||||||
LoggingOptions: s.LoggingOptions,
|
LoggingOptions: s.LoggingOptions,
|
||||||
@@ -291,8 +288,6 @@ func Complete(s *options.ServerRunOptions) error {
|
|||||||
ServiceMeshOptions: conf.ServiceMeshOptions,
|
ServiceMeshOptions: conf.ServiceMeshOptions,
|
||||||
MySQLOptions: conf.MySQLOptions,
|
MySQLOptions: conf.MySQLOptions,
|
||||||
MonitoringOptions: conf.MonitoringOptions,
|
MonitoringOptions: conf.MonitoringOptions,
|
||||||
LdapOptions: conf.LdapOptions,
|
|
||||||
RedisOptions: conf.RedisOptions,
|
|
||||||
S3Options: conf.S3Options,
|
S3Options: conf.S3Options,
|
||||||
OpenPitrixOptions: conf.OpenPitrixOptions,
|
OpenPitrixOptions: conf.OpenPitrixOptions,
|
||||||
LoggingOptions: conf.LoggingOptions,
|
LoggingOptions: conf.LoggingOptions,
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ func NewAlertingOptions() *AlertingOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *AlertingOptions) ApplyTo(options *AlertingOptions) {
|
func (s *AlertingOptions) ApplyTo(options *AlertingOptions) {
|
||||||
|
if options == nil {
|
||||||
|
options = s
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if s.Endpoint != "" {
|
if s.Endpoint != "" {
|
||||||
options.Endpoint = s.Endpoint
|
options.Endpoint = s.Endpoint
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,12 @@ 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 s.Host != "" && options != nil {
|
if options == nil {
|
||||||
|
options = s
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.Host != "" {
|
||||||
reflectutils.Override(options, s)
|
reflectutils.Override(options, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ 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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ 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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ 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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ func NewNotificationOptions() *NotificationOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *NotificationOptions) ApplyTo(options *NotificationOptions) {
|
func (s *NotificationOptions) ApplyTo(options *NotificationOptions) {
|
||||||
|
if options == nil {
|
||||||
|
options = s
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if s.Endpoint != "" {
|
if s.Endpoint != "" {
|
||||||
options.Endpoint = s.Endpoint
|
options.Endpoint = s.Endpoint
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ 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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ 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,6 +44,11 @@ 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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ 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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ func (s *ServiceMeshOptions) Validate() []error {
|
|||||||
|
|
||||||
func (s *ServiceMeshOptions) ApplyTo(options *ServiceMeshOptions) {
|
func (s *ServiceMeshOptions) ApplyTo(options *ServiceMeshOptions) {
|
||||||
if options == nil {
|
if options == nil {
|
||||||
|
options = s
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ func (s *SonarQubeOptions) Validate() []error {
|
|||||||
|
|
||||||
func (s *SonarQubeOptions) ApplyTo(options *SonarQubeOptions) {
|
func (s *SonarQubeOptions) ApplyTo(options *SonarQubeOptions) {
|
||||||
if options == nil {
|
if options == nil {
|
||||||
|
options = s
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,22 +37,23 @@ func In(value interface{}, container interface{}) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Override(left interface{}, right interface{}) {
|
func Override(left interface{}, right interface{}) {
|
||||||
if left == nil || right == nil {
|
if reflect.ValueOf(left).IsNil() || reflect.ValueOf(right).IsNil() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if reflect.ValueOf(left).Type().Kind() != reflect.Ptr ||
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
old := reflect.ValueOf(left).Elem()
|
oldVal := reflect.ValueOf(left).Elem()
|
||||||
new := reflect.ValueOf(right).Elem()
|
newVal := reflect.ValueOf(right).Elem()
|
||||||
|
|
||||||
for i := 0; i < old.NumField(); i++ {
|
for i := 0; i < oldVal.NumField(); i++ {
|
||||||
val := new.Field(i).Interface()
|
val := newVal.Field(i).Interface()
|
||||||
if !reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user