Skip to content

Commit

Permalink
Add DNS entry for ovsdbserver-sb- services
Browse files Browse the repository at this point in the history
When the ovsdbserver-sb pod gets deleted we can't ensure that it will
be recreated with the same internalapi IP, since that IP is popullated
to the EDPM nodes during ansibleee-deployment_phase, if the IP changes
during reboot of the pod EDPM won't know until user retriggers
ansibleee-deployment_phase. This will mean that meanwhile ovn_controller
and neutron-ovn-metadata won't have connectivity to the SB DB.

In order to fix this instead of using a string of IPs on the ovn-remote
a single DNS entry will be used. Every service will add two entries to
the openstack-dnsmasq:
 - ovsdbserver-sb-x.openstack.svc (where x = replica/service number)
 - ovsdbserver-sb.openstack.svc

The last one will be the one popullated to the EDPM node, as querying
it will return one IP from all the SB pods initialized at that moment
(dns will use sequential round-robin to fulfill the request).
  • Loading branch information
averdagu committed Nov 14, 2023
1 parent 5dc920d commit 3f4ac62
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 2 deletions.
5 changes: 4 additions & 1 deletion api/v1beta1/ovndbcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,8 @@ func (instance OVNDBCluster) GetExternalEndpoint() (string, error) {
if instance.Status.DBAddress == "" {
return "", fmt.Errorf("external DBEndpoint not ready yet for %s", instance.Spec.DBType)
}
return instance.Status.DBAddress, nil
//return instance.Status.DBAddress, nil
//return "tcp:ovsdbserver-sb.openstack.svc:6642", nil
dns_hostname := "tcp:ovsdbserver-sb." + instance.Namespace + ".svc:6642"
return dns_hostname, nil
}
1 change: 1 addition & 0 deletions controllers/ovncontroller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ func (r *OVNControllerReconciler) generateExternalConfigMaps(
}

externalTemplateParameters := make(map[string]interface{})
// TODO change externalEndpoint to DNS
externalTemplateParameters["OvnRemote"] = externalEndpoint
externalTemplateParameters["OvnEncapType"] = instance.Spec.ExternalIDS.OvnEncapType

Expand Down
85 changes: 84 additions & 1 deletion controllers/ovndbcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ import (
"strings"
"time"

"github.com/go-logr/logr"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/go-logr/logr"
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"
"github.com/openstack-k8s-operators/lib-common/modules/common/configmap"
Expand Down Expand Up @@ -519,6 +521,10 @@ func (r *OVNDBClusterReconciler) reconcileServices(
if err != nil {
return ctrl.Result{}, err
}
// averdagu I don't think it's needed, maybe will delete later
headlesssvc.AddAnnotation(map[string]string{
service.AnnotationHostnameKey: headlesssvc.GetServiceHostname(),
})

ctrlResult, err := headlesssvc.CreateOrPatch(ctx, helper)
if err != nil {
Expand Down Expand Up @@ -548,6 +554,9 @@ func (r *OVNDBClusterReconciler) reconcileServices(
if err != nil {
return ctrl.Result{}, err
}
svc.AddAnnotation(map[string]string{
service.AnnotationHostnameKey: svc.GetServiceHostname(),
})
ctrlResult, err := svc.CreateOrPatch(ctx, helper)
if err != nil {
return ctrl.Result{}, err
Expand All @@ -557,6 +566,7 @@ func (r *OVNDBClusterReconciler) reconcileServices(
// create service - end
}

// TODO: Delete also DNS info if exists
// Delete any extra services left after scale down
svcList, err := service.GetServicesListWithLabel(
ctx,
Expand All @@ -581,6 +591,79 @@ func (r *OVNDBClusterReconciler) reconcileServices(
}
}
}

Log.Info("DNS Starts here")
if instance.Spec.DBType == v1beta1.SBDBType {
Log.Info("Only doing it for SB pods")
serviceName = ovndbcluster.ServiceNameSB
serviceLabels = map[string]string{
common.AppSelector: serviceName,
}
podList, err = ovndbcluster.OVNDBPods(ctx, instance, helper, serviceLabels)
if err != nil {
return ctrl.Result{}, err
}
for _, ovnPod := range podList.Items {
Log.Info(fmt.Sprintf("Using Pod: %v", ovnPod.Name))
var dnsName string
var dnsIP string
var hostnames []string
dnsName = "dns-" + ovnPod.Name
// Get Hostname
svc, _ := service.GetServiceWithName(
ctx,
helper,
ovnPod.Name,
ovnPod.Namespace,
)
hostname := svc.ObjectMeta.Annotations[infranetworkv1.AnnotationHostnameKey]
hostnames = append(hostnames, hostname)

// Get IP
net_stat, _ := nad.GetNetworkStatusFromAnnotation(ovnPod.Annotations)
for _, v := range net_stat {
if v.Interface == instance.Spec.NetworkAttachment {
dnsIP = v.IPs[0]
}
}

// Create DNSRecord
var DNSRecords []infranetworkv1.DNSHost
// ovsdbserver-sb-x entry
DNSRecord := infranetworkv1.DNSHost{}
DNSRecord.IP = dnsIP
DNSRecord.Hostnames = hostnames
// ovsdbserver-sb entry
headless_dns_hostname := ovndbcluster.ServiceNameSB + "." + instance.Namespace + ".svc"
DNSRecordCname := infranetworkv1.DNSHost{}
DNSRecordCname.IP = dnsIP
DNSRecordCname.Hostnames = append(DNSRecordCname.Hostnames, headless_dns_hostname)
DNSRecords = append(DNSRecords, DNSRecord)
DNSRecords = append(DNSRecords, DNSRecordCname)

// Create DNSData
DNSData := &infranetworkv1.DNSData{
ObjectMeta: metav1.ObjectMeta{
Name: dnsName,
Namespace: ovnPod.Namespace,
},
}
_, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), DNSData, func() error {
DNSData.Spec.Hosts = DNSRecords
DNSData.Spec.DNSDataLabelSelectorValue = "dnsdata"
err := controllerutil.SetControllerReference(helper.GetBeforeObject(), DNSData, helper.GetScheme())
if err != nil {
Log.Info(fmt.Sprintf("Inside CreateOrPatch error: %v", err))
}
return err
})
if err != nil {
Log.Info(fmt.Sprintf("Outside CreateOrPatch error: %v", err))
}

}
}

Log.Info("Reconciled OVN DB Cluster Service successfully")
return ctrl.Result{}, nil
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0
github.com/onsi/ginkgo/v2 v2.13.0
github.com/onsi/gomega v1.29.0
github.com/openstack-k8s-operators/infra-operator/apis v0.3.0
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20231102083359-58e12a1299b2
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20231102083359-58e12a1299b2
github.com/openstack-k8s-operators/ovn-operator/api v0.0.0-20230418071801-b5843d9e05fb
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,14 @@ github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7 h1:rncLxJBpFGqBztyxCMwNRnMjhhIDOWHJowi6q8G6koI=
github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7/go.mod h1:ctXNyWanKEjGj8sss1KjjHQ3ENKFm33FFnS5BKaIPh4=
github.com/openstack-k8s-operators/infra-operator/apis v0.3.0 h1:omqNm2mG5YOXdNLuUs4fNCvi/2B13njLXfbS2Z4GNUE=
github.com/openstack-k8s-operators/infra-operator/apis v0.3.0/go.mod h1:zqFs5MrBKeaE4HQroUgMWwIkBwmmcygg6sghcidSdCA=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20231011150636-e8a0540a3c32 h1:r24jE5tdacLivcZczb3t6RvbvHp6kXQrW2ECuekzgH8=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20231011150636-e8a0540a3c32/go.mod h1:xXAuy7HtWN4p7LF5Q+NHLkwAsKVh0KrzpnuPYIG3XaA=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20231102083359-58e12a1299b2 h1:U4hwPDoo9k2wo6PldPyJbgfvo9Mdyuhum7vLWTHez1c=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20231102083359-58e12a1299b2/go.mod h1:NvjAETczXby5m3IvylR3YaOiEBWkmWbHBx/UrnUVtfA=
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20231011150636-e8a0540a3c32 h1:JCMXaDSjy46ZaHLHb1j2uzGIy2RUmYRCsbtSPkuEUV8=
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20231011150636-e8a0540a3c32/go.mod h1:Apy5OTK60yj9cQgVZ0HcGq+CDsLDaaEydJtj8ca0IBk=
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20231102083359-58e12a1299b2 h1:9RHkP3OSPkZsGbCCbX5YetA4sNxRkFsWmNiDfokB1KQ=
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20231102083359-58e12a1299b2/go.mod h1:St2fdpMneNUq5XTamRLSgI5iKPm096JFGSFit5FjJ/4=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1"

ovnv1 "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1"
"github.com/openstack-k8s-operators/ovn-operator/controllers"
Expand All @@ -53,6 +54,7 @@ func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(ovnv1.AddToScheme(scheme))
utilruntime.Must(networkv1.AddToScheme(scheme))
utilruntime.Must(infranetworkv1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

Expand Down

0 comments on commit 3f4ac62

Please sign in to comment.