@@ -600,12 +600,51 @@ func createCMCertificateConfig(ec *ecv1alpha1.EtcdCluster) *certInterface.Config
600600}
601601
602602func createAutoCertificateConfig (ec * ecv1alpha1.EtcdCluster ) * certInterface.Config {
603- // TODO
604- config := & certInterface.Config {}
603+ autoConfig := ec .Spec .TLS .ProviderCfg .AutoCfg
604+ duration , err := time .ParseDuration (autoConfig .ValidityDuration )
605+ if err != nil {
606+ log .Printf ("Failed to parse ValidityDuration: %s" , err )
607+ }
608+
609+ var getAltNames certInterface.AltNames
610+ if autoConfig .AltNames .DNSNames != nil {
611+ getAltNames = certInterface.AltNames {
612+ DNSNames : autoConfig .AltNames .DNSNames ,
613+ IPs : make ([]net.IP , len (autoConfig .AltNames .DNSNames )),
614+ }
615+ } else {
616+ defaultDNSNames := []string {fmt .Sprintf ("%s.svc.cluster.local" , autoConfig .CommonName )}
617+ getAltNames = certInterface.AltNames {
618+ DNSNames : defaultDNSNames ,
619+ }
620+ }
621+
622+ config := & certInterface.Config {
623+ CommonName : autoConfig .CommonName ,
624+ Organization : autoConfig .Organization ,
625+ ValidityDuration : duration ,
626+ AltNames : getAltNames ,
627+ }
605628 return config
606629}
607630
608631func createCertificate (ec * ecv1alpha1.EtcdCluster , ctx context.Context , c client.Client , certName string ) error {
632+ // tls field is present but spec is empty
633+ if ec .Spec .TLS .Provider == "" {
634+ log .Printf ("TLS spec is empty, using default autoConfig for certificate: %s" , certName )
635+ autoCert , err := certificate .NewProvider ("auto" , c )
636+ if err != nil {
637+ // TODO: instead of error, set default autoConfig
638+ return err
639+ }
640+ autoConfig := createAutoCertificateConfig (ec )
641+ createCertErr := autoCert .EnsureCertificateSecret (ctx , certName , ec .Namespace , autoConfig )
642+ if createCertErr != nil {
643+ log .Printf ("Error creating certificate: %s" , createCertErr )
644+ }
645+ return nil
646+ }
647+
609648 cert , certErr := certificate .NewProvider (certificate .ProviderType (ec .Spec .TLS .Provider ), c )
610649 if certErr != nil {
611650 // TODO: instead of error, set default autoConfig
@@ -617,8 +656,8 @@ func createCertificate(ec *ecv1alpha1.EtcdCluster, ctx context.Context, c client
617656 log .Printf ("Creating certificate: %s for etcd-operator: %s\n " , certName , ec .Name )
618657 switch {
619658 case ec .Spec .TLS .ProviderCfg .AutoCfg != nil :
620- cmConfig := createAutoCertificateConfig (ec )
621- createCertErr := cert .EnsureCertificateSecret (ctx , certName , ec .Namespace , cmConfig )
659+ autoConfig := createAutoCertificateConfig (ec )
660+ createCertErr := cert .EnsureCertificateSecret (ctx , certName , ec .Namespace , autoConfig )
622661 if createCertErr != nil {
623662 log .Printf ("Error creating certificate: %s" , createCertErr )
624663 }
0 commit comments