-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Apply comments] Remove SetExternalEndpoint
This function is almost not needed at all with the changes on how the OVNDBCluster is created.
- Loading branch information
Showing
6 changed files
with
249 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package ovndbcluster | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1" | ||
"github.com/openstack-k8s-operators/lib-common/modules/common/helper" | ||
"github.com/openstack-k8s-operators/ovn-operator/api/v1beta1" | ||
ovnv1 "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
func DnsData( | ||
ctx context.Context, | ||
helper *helper.Helper, | ||
svc *corev1.Service, | ||
ip string, | ||
instance *ovnv1.OVNDBCluster, | ||
ovnPod corev1.Pod, | ||
serviceLabels map[string]string, | ||
) error { | ||
// ovsdbserver-(sb|nb) entry | ||
headlessDnsHostname := ServiceNameSB + "." + instance.Namespace + ".svc" | ||
if instance.Spec.DBType == v1beta1.NBDBType { | ||
headlessDnsHostname = ServiceNameNB + "." + instance.Namespace + ".svc" | ||
} | ||
dnsHostCname := infranetworkv1.DNSHost{ | ||
IP: ip, | ||
Hostnames: []string{ | ||
headlessDnsHostname, | ||
}, | ||
} | ||
|
||
// Create DNSData object | ||
dnsData := &infranetworkv1.DNSData{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: ovnPod.Name, | ||
Namespace: ovnPod.Namespace, | ||
Labels: serviceLabels, | ||
}, | ||
} | ||
dnsHosts := []infranetworkv1.DNSHost{dnsHostCname} | ||
|
||
_, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), dnsData, func() error { | ||
dnsData.Spec.Hosts = dnsHosts | ||
// TODO: use value from DNSMasq instance instead of hardcode | ||
dnsData.Spec.DNSDataLabelSelectorValue = "dnsdata" | ||
err := controllerutil.SetControllerReference(helper.GetBeforeObject(), dnsData, helper.GetScheme()) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Error creating DNSData %s: %w", dnsData.Name, err) | ||
} | ||
return nil | ||
} | ||
|
||
func GetDBAddress(instance *ovnv1.OVNDBCluster, svc *corev1.Service) string { | ||
if svc == nil { | ||
return "" | ||
} | ||
headlessDnsHostname := "" | ||
if instance.Spec.DBType == v1beta1.NBDBType { | ||
headlessDnsHostname = ServiceNameNB + "." + instance.Namespace + ".svc" | ||
} else { | ||
headlessDnsHostname = ServiceNameSB + "." + instance.Namespace + ".svc" | ||
} | ||
return fmt.Sprintf("tcp:%s:%d", headlessDnsHostname, svc.Spec.Ports[0].Port) | ||
} |
Oops, something went wrong.