diff --git a/controllers/ovndbcluster_controller.go b/controllers/ovndbcluster_controller.go index 74ae150b..cbaf208f 100644 --- a/controllers/ovndbcluster_controller.go +++ b/controllers/ovndbcluster_controller.go @@ -36,6 +36,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/reconcile" + operatorv1 "github.com/openshift/api/operator/v1" infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1" "github.com/openstack-k8s-operators/lib-common/modules/common" "github.com/openstack-k8s-operators/lib-common/modules/common/condition" @@ -580,6 +581,8 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance * internalDbAddress := []string{} var svcPort int32 scheme := "tcp" + /* Get DNS Cluster suffix */ + DNSSuffix := getDNSDomain(ctx, r.GetClient(), r.GetLogger(ctx)) if instance.Spec.TLS.Enabled() { scheme = "ssl" } @@ -588,7 +591,7 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance * // Filter out headless services if svc.Spec.ClusterIP != "None" { - internalDbAddress = append(internalDbAddress, fmt.Sprintf("%s:%s.%s.svc.%s:%d", scheme, svc.Name, svc.Namespace, ovnv1.DNSSuffix, svcPort)) + internalDbAddress = append(internalDbAddress, fmt.Sprintf("%s:%s.%s.svc.%s:%d", scheme, svc.Name, svc.Namespace, DNSSuffix, svcPort)) } } @@ -604,6 +607,23 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance * return ctrl.Result{}, nil } +func getDNSDomain(ctx context.Context, c client.Client, Log logr.Logger) string { + DNSDomain := ovnv1.DNSSuffix + DNSClusterInfoList := &operatorv1.DNSList{} + err := c.List(ctx, DNSClusterInfoList) + if err != nil { + Log.Info(fmt.Sprintf("Warning: Couldn't retrieve DNS cluster info, using default DNS Suffix: %s", DNSDomain)) + return DNSDomain + } + // Using this approach in case CP have multiple domains + // also it does not depend on the DNS CR name. + // ATM in case of multiple domains will return last one. + for _, dns := range DNSClusterInfoList.Items { + DNSDomain = dns.Status.ClusterDomain + } + return DNSDomain +} + func getPodIPInNetwork(ovnPod corev1.Pod, namespace string, networkAttachment string) (string, error) { netStat, err := nad.GetNetworkStatusFromAnnotation(ovnPod.Annotations) if err != nil { diff --git a/main.go b/main.go index 52591aac..c5e10ab8 100644 --- a/main.go +++ b/main.go @@ -40,6 +40,7 @@ import ( metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" + operatorv1 "github.com/openshift/api/operator/v1" infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1" ovnv1 "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1" @@ -57,6 +58,7 @@ func init() { utilruntime.Must(ovnv1.AddToScheme(scheme)) utilruntime.Must(networkv1.AddToScheme(scheme)) utilruntime.Must(infranetworkv1.AddToScheme(scheme)) + utilruntime.Must(operatorv1.AddToScheme(scheme)) //+kubebuilder:scaffold:scheme }