Skip to content

Commit

Permalink
Retrieve DNS domain name from cluster
Browse files Browse the repository at this point in the history
Jira: OSPRH-3627
  • Loading branch information
averdagu committed Jun 5, 2024
1 parent 50784a5 commit 930f64d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 21 additions & 1 deletion controllers/ovndbcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
}
Expand All @@ -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))
}
}

Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down

0 comments on commit 930f64d

Please sign in to comment.