Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve DNS domain name from cluster #258

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Comment on lines +618 to +623
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it's possible or if it'll be a use case the fact that exists multiple DNS domains (besides cluster.local) and how OVN operator should handle it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the Reconcile loop of the openshift dns-operator, it only expects a DNS CR named Default, Could modify this chunk of code to get the object by name instead of getting a list and iterating over it.
https://github.com/openshift/cluster-dns-operator/blob/master/pkg/operator/controller/controller.go#L180-L184

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