func (c *Cluster) ClientConfig() (*clientv3.Config, error) {
	e := c.etcd

	// ensure service exist
	_, err := c.svcLister.Services(e.Namespace).Get(helpers.NameForAccessService(e))
	if err != nil {
		return nil, err
	}

	cfg := &clientv3.Config{
		Endpoints:   []string{helpers.AccessURL(e)},
		DialTimeout: 15 * time.Second,
	}
	// tls config
	if helpers.IsClientSecure(e) {
		// get client cert
		var secret *corev1.Secret
		if e.Spec.Secure.TLS.ExternalCerts != nil && e.Spec.Secure.TLS.ExternalCerts.ClientSecret != "" {
			secret, err = c.secretLister.Secrets(e.Namespace).Get(e.Spec.Secure.TLS.ExternalCerts.ClientSecret)
		} else if e.Spec.Secure.TLS.AutoTLSCert != nil && e.Spec.Secure.TLS.AutoTLSCert.AutoGenerateClientCert {
			secret, err = c.secretLister.Secrets(e.Namespace).Get(secure.NameForEtcdCertSecret(e.Name, secure.EtcdClientCert))
		}
		if err != nil {
			return nil, err
		}

		tlsConfig, err := utils.NewTLSFromString(string(secret.Data[secure.EtcdCACertName]), string(secret.Data[secure.EtcdClientCertName]), string(secret.Data[secure.EtcdClientKeyName]))
		if err != nil {
			return nil, err
		}
		cfg.TLS = tlsConfig
	}

	// password authorization
	if e.Spec.Secure != nil && e.Spec.Secure.Auth != nil && e.Spec.Secure.Auth.CredentialSecretRef != nil {
		ref := e.Spec.Secure.Auth.CredentialSecretRef
		secret, err := c.secretLister.Secrets(ref.Namespace).Get(ref.Name)
		if err != nil {
			return nil, err
		}
		if cred := secure.CredentialFromSecret(secret); cred != nil {
			cfg.Username = cred.Username
			cfg.Password = cred.Password
		}
	}
	return cfg, nil
}
// ClientConfig return an etcd client config, for the operator to access etcd cluster
ClientConfig return an etcd client config, for the operator to access etcd cluster
// ClientConfig return an etcd client config for the operator to access etcd cluster
func (c *Cluster) ClientConfig() (*clientv3.Config, error) {
	e := c.etcd
	_, err := c.svcLister.Services(e.Namespace).Get(helpers.NameForAccessService(e))
	if err != nil {
		return nil, err
	}
	cfg := &clientv3.Config{
		Endpoints:   []string{helpers.AccessURL(e)},
		DialTimeout: 15 * time.Second,
	}
	if helpers.IsClientSecure(e) {
		var secret *corev1.Secret
		if e.Spec.Secure.TLS.ExternalCerts != nil && e.Spec.Secure.TLS.ExternalCerts.ClientSecret != "" {
			secret, err = c.secretLister.Secrets(e.Namespace).Get(e.Spec.Secure.TLS.ExternalCerts.ClientSecret)
		} else if e.Spec.Secure.TLS.AutoTLSCert != nil && e.Spec.Secure.TLS.AutoTLSCert.AutoGenerateClientCert {
			secret, err = c.secretLister.Secrets(e.Namespace).Get(secure.NameForEtcdCertSecret(e.Name, secure.EtcdClientCert))
		}
		if err != nil {
			return nil, err
		}
		tlsConfig, err := utils.NewTLSFromString(string(secret.Data[secure.EtcdCACertName]), string(secret.Data[secure.EtcdClientCertName]), string(secret.Data[secure.EtcdClientKeyName]))
		if err != nil {
			return nil, err
		}
		cfg.TLS = tlsConfig
	}
	if e.Spec.Secure != nil && e.Spec.Secure.Auth != nil && e.Spec.Secure.Auth.CredentialSecretRef != nil {
		ref := e.Spec.Secure.Auth.CredentialSecretRef
		secret, err := c.secretLister.Secrets(ref.Namespace).Get(ref.Name)
		if err != nil {
			return nil, err
		}
		if cred := secure.CredentialFromSecret(secret); cred != nil {
			cfg.Username = cred.Username
			cfg.Password = cred.Password
		}
	}
	return cfg, nil
}
func ( c * Cluster ) ClientConfig ( ) ( * clientv3 . Config , error ) { e := c . etcd _ , err := c . svcLister . Services ( e . Namespace ) . Get ( helpers . NameForAccessService ( e ) ) if err != nil { return nil , err } cfg := & clientv3 . Config { Endpoints : [ ] string { helpers . AccessURL ( e ) } , DialTimeout : 15 * time . Second , } if helpers . IsClientSecure ( e ) { var secret * corev1 . Secret if e . Spec . Secure . TLS . ExternalCerts != nil && e . Spec . Secure . TLS . ExternalCerts . ClientSecret != " " { secret , err = c . secretLister . Secrets ( e . Namespace ) . Get ( e . Spec . Secure . TLS . ExternalCerts . ClientSecret ) } else if e . Spec . Secure . TLS . AutoTLSCert != nil && e . Spec . Secure . TLS . AutoTLSCert . AutoGenerateClientCert { secret , err = c . secretLister . Secrets ( e . Namespace ) . Get ( secure . NameForEtcdCertSecret ( e . Name , secure . EtcdClientCert ) ) } if err != nil { return nil , err } tlsConfig , err := utils . NewTLSFromString ( string ( secret . Data [ secure . EtcdCACertName ] ) , string ( secret . Data [ secure . EtcdClientCertName ] ) , string ( secret . Data [ secure . EtcdClientKeyName ] ) ) if err != nil { return nil , err } cfg . TLS = tlsConfig } if e . Spec . Secure != nil && e . Spec . Secure . Auth != nil && e . Spec . Secure . Auth . CredentialSecretRef != nil { ref := e . Spec . Secure . Auth . CredentialSecretRef secret , err := c . secretLister . Secrets ( ref . Namespace ) . Get ( ref . Name ) if err != nil { return nil , err } if cred := secure . CredentialFromSecret ( secret ) ; cred != nil { cfg . Username = cred . Username cfg . Password = cred . Password } } return cfg , nil }
ClientConfig return an etcd client config, for the operator to access etcd cluster
ClientConfig return an etcd client config for the operator to access etcd cluster
// ensure service exist // tls config // get client cert // password authorization