Skip to content

Commit

Permalink
Maas custom endpoint support (#113)
Browse files Browse the repository at this point in the history
* Maas custom endpoint support

* Maas custom endpoint support (#114)
  • Loading branch information
AmitSahastra authored Dec 4, 2023
1 parent 61a85ff commit 9b3ef3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/maas/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/pkg/errors"
infrainfrav1beta1 "github.com/spectrocloud/cluster-api-provider-maas/api/v1beta1"
"github.com/spectrocloud/cluster-api-provider-maas/pkg/maas/scope"
util2 "github.com/spectrocloud/cluster-api-provider-maas/pkg/util"
"github.com/spectrocloud/maas-client-go/maasclient"
"k8s.io/apimachinery/pkg/util/sets"
)
Expand All @@ -27,6 +28,13 @@ func NewService(clusterScope *scope.ClusterScope) *Service {
// ReconcileDNS reconciles the load balancers for the given cluster.
func (s *Service) ReconcileDNS() error {
s.scope.V(2).Info("Reconciling DNS")

if util2.IsCustomEndpointPresent(s.scope.MaasCluster.GetAnnotations()) {
s.scope.GetDNSName()
s.scope.V(0).Info("custom dns is provided skipping dns reconcile", "dns", s.scope.GetDNSName())
return nil
}

ctx := context.TODO()

dnsResource, err := s.GetDNSResource()
Expand Down
6 changes: 6 additions & 0 deletions pkg/maas/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/google/uuid"
"github.com/pkg/errors"
infrav1beta1 "github.com/spectrocloud/cluster-api-provider-maas/api/v1beta1"
infrautil "github.com/spectrocloud/cluster-api-provider-maas/pkg/util"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -132,6 +133,11 @@ func (s *ClusterScope) SetDNSName(dnsName string) {
// GetDNSName sets the Network systemID in spec.
// This can't do a lookup on Status.Network.DNSDomain name since it's derviced from here
func (s *ClusterScope) GetDNSName() string {
if infrautil.IsCustomEndpointPresent(s.MaasCluster.GetAnnotations()) {
s.SetDNSName(s.MaasCluster.Spec.ControlPlaneEndpoint.Host)
return s.MaasCluster.Spec.ControlPlaneEndpoint.Host
}

if !s.Cluster.Spec.ControlPlaneEndpoint.IsZero() {
return s.Cluster.Spec.ControlPlaneEndpoint.Host
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/util/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package util

const (
CustomEndpointProvidedAnnotation = "spectrocloud.com/custom-dns-provided"
)

func IsCustomEndpointPresent(annotations map[string]string) bool {
_, ok := annotations[CustomEndpointProvidedAnnotation]
return ok
}

0 comments on commit 9b3ef3e

Please sign in to comment.