Skip to content

Commit

Permalink
Custom endpoint: skip dns attachment reconcile (#134)
Browse files Browse the repository at this point in the history
* Custom endpoint: skip dns attachment reconcile

* code refactor (#135)
  • Loading branch information
AmitSahastra authored Feb 1, 2024
1 parent 2f4b1de commit 75814d1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
5 changes: 5 additions & 0 deletions controllers/maascluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions controllers/maasmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions pkg/maas/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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!")
Expand Down
9 changes: 9 additions & 0 deletions pkg/maas/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 75814d1

Please sign in to comment.