diff --git a/controllers/maascluster_controller.go b/controllers/maascluster_controller.go index 557ff12..0423f04 100644 --- a/controllers/maascluster_controller.go +++ b/controllers/maascluster_controller.go @@ -149,6 +149,11 @@ func (r *MaasClusterReconciler) reconcileDelete(ctx context.Context, clusterScop } func (r *MaasClusterReconciler) reconcileDNSAttachments(clusterScope *scope.ClusterScope, dnssvc *dns.Service) error { + + if clusterScope.IsCustomEndpoint() { + return nil + } + machines, err := clusterScope.GetClusterMaasMachines() if err != nil { return errors.Wrapf(err, "Unable to list all maas machines") diff --git a/controllers/maasmachine_controller.go b/controllers/maasmachine_controller.go index 905b879..5a57dab 100644 --- a/controllers/maasmachine_controller.go +++ b/controllers/maasmachine_controller.go @@ -398,6 +398,10 @@ func (r *MaasMachineReconciler) reconcileDNSAttachment(machineScope *scope.Machi return nil } + if clusterScope.IsCustomEndpoint() { + return nil + } + dnssvc := maasdns.NewService(clusterScope) // In order to prevent sending request to a "not-ready" control plane machines, it is required to remove the machine diff --git a/pkg/maas/dns/dns.go b/pkg/maas/dns/dns.go index ed0e23f..48e9ae6 100644 --- a/pkg/maas/dns/dns.go +++ b/pkg/maas/dns/dns.go @@ -5,7 +5,6 @@ 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" - "github.com/spectrocloud/cluster-api-provider-maas/pkg/util" "github.com/spectrocloud/maas-client-go/maasclient" "k8s.io/apimachinery/pkg/util/sets" ) @@ -29,9 +28,7 @@ func NewService(clusterScope *scope.ClusterScope) *Service { func (s *Service) ReconcileDNS() error { s.scope.V(2).Info("Reconciling DNS") - if util.IsCustomEndpointPresent(s.scope.MaasCluster.GetAnnotations()) { - s.scope.GetDNSName() - s.scope.V(0).Info("custom dns is provided skipping dns reconcile", "dns", s.scope.GetDNSName()) + if s.scope.IsCustomEndpoint() { return nil } @@ -63,6 +60,11 @@ func (s *Service) ReconcileDNS() error { // UpdateAttachments reconciles the load balancers for the given cluster. func (s *Service) UpdateDNSAttachments(IPs []string) error { s.scope.V(2).Info("Updating DNS Attachments") + + if s.scope.IsCustomEndpoint() { + return nil + } + ctx := context.TODO() // get ID of loadbalancer dnsResource, err := s.GetDNSResource() @@ -96,6 +98,10 @@ func (s *Service) UpdateDNSAttachments(IPs []string) error { // InstanceIsRegisteredWithAPIServerELB returns true if the instance is already registered with the APIServer ELB. func (s *Service) MachineIsRegisteredWithAPIServerDNS(i *infrainfrav1beta1.Machine) (bool, error) { + if s.scope.IsCustomEndpoint() { + return true, nil + } + ips, err := s.GetAPIServerDNSRecords() if err != nil { return false, err @@ -111,6 +117,11 @@ func (s *Service) MachineIsRegisteredWithAPIServerDNS(i *infrainfrav1beta1.Machi } func (s *Service) GetAPIServerDNSRecords() (sets.String, error) { + + if s.scope.IsCustomEndpoint() { + return nil, nil + } + dnsResource, err := s.GetDNSResource() if err != nil { return nil, err @@ -127,6 +138,11 @@ func (s *Service) GetAPIServerDNSRecords() (sets.String, error) { } func (s *Service) GetDNSResource() (maasclient.DNSResource, error) { + + if s.scope.IsCustomEndpoint() { + return nil, nil + } + dnsName := s.scope.GetDNSName() if dnsName == "" { return nil, errors.New("No DNS on the cluster set!") diff --git a/pkg/maas/scope/cluster.go b/pkg/maas/scope/cluster.go index 8c9289e..0a7799f 100644 --- a/pkg/maas/scope/cluster.go +++ b/pkg/maas/scope/cluster.go @@ -281,3 +281,12 @@ func (s *ClusterScope) IsAPIServerOnline() (bool, error) { return err == nil, nil } + +func (s *ClusterScope) IsCustomEndpoint() bool { + if infrautil.IsCustomEndpointPresent(s.MaasCluster.GetAnnotations()) { + s.GetDNSName() + s.V(0).Info("custom dns is provided skipping dns reconcile", "dns", s.GetDNSName()) + return true + } + return false +}