@@ -5,14 +5,19 @@ import (
55 "fmt"
66 "strings"
77
8+ certmgrv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
9+ "github.com/openstack-k8s-operators/lib-common/modules/certmanager"
810 "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
911 "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
12+ "github.com/openstack-k8s-operators/lib-common/modules/common/service"
13+ "github.com/openstack-k8s-operators/lib-common/modules/common/tls"
1014 mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
1115
1216 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1317
1418 corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
1519 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+ "k8s.io/utils/ptr"
1621 ctrl "sigs.k8s.io/controller-runtime"
1722)
1823
@@ -38,6 +43,34 @@ func ReconcileGaleras(
3843 var inprogress []string = []string {}
3944
4045 for name , spec := range instance .Spec .Galera .Templates {
46+ hostname := fmt .Sprintf ("%s.%s.svc" , name , instance .Namespace )
47+
48+ // Galera gets always configured to support TLS connections.
49+ // If TLS can/must be used is a per user configuration.
50+ certRequest := certmanager.CertificateRequest {
51+ IssuerName : tls .DefaultCAPrefix + string (service .EndpointInternal ),
52+ CertName : fmt .Sprintf ("galera-%s-svc" , name ),
53+ Hostnames : []string {hostname },
54+ Usages : []certmgrv1.KeyUsage {
55+ "key encipherment" ,
56+ "digital signature" ,
57+ "server auth" ,
58+ "client auth" ,
59+ },
60+ }
61+ certSecret , ctrlResult , err := certmanager .EnsureCert (
62+ ctx ,
63+ helper ,
64+ certRequest )
65+ if err != nil {
66+ return ctrlResult , err
67+ } else if (ctrlResult != ctrl.Result {}) {
68+ return ctrlResult , nil
69+ }
70+
71+ spec .TLS .Ca .CaBundleSecretName = instance .Status .TLS .CaBundleSecretName
72+ spec .TLS .SecretName = ptr .To (certSecret .Name )
73+
4174 status , err := reconcileGalera (ctx , instance , helper , name , & spec )
4275
4376 switch status {
@@ -106,6 +139,7 @@ func reconcileGalera(
106139 Log .Info ("Reconciling Galera" , "Galera.Namespace" , instance .Namespace , "Galera.Name" , name )
107140 op , err := controllerutil .CreateOrPatch (ctx , helper .GetClient (), galera , func () error {
108141 spec .DeepCopyInto (& galera .Spec )
142+
109143 err := controllerutil .SetControllerReference (helper .GetBeforeObject (), galera , helper .GetScheme ())
110144 if err != nil {
111145 return err
0 commit comments