From 22cdf13d71cc1ad63ced9ecc6a769e4195109e04 Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Mon, 10 Jul 2023 09:52:44 -0700 Subject: [PATCH] Update DNS before API and Ingress (#73) --- config/rbac/role.yaml | 8 ++++++ controllers/clusterrelocation_controller.go | 12 ++++----- internal/dns/reconcile.go | 28 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index b247800..72490a1 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -169,6 +169,14 @@ rules: - patch - update - watch +- apiGroups: + - machineconfiguration.openshift.io + resources: + - machineconfigpools + verbs: + - get + - list + - watch - apiGroups: - machineconfiguration.openshift.io resources: diff --git a/controllers/clusterrelocation_controller.go b/controllers/clusterrelocation_controller.go index 5e420a0..7cbe320 100644 --- a/controllers/clusterrelocation_controller.go +++ b/controllers/clusterrelocation_controller.go @@ -159,6 +159,12 @@ func (r *ClusterRelocationReconciler) Reconcile(ctx context.Context, req ctrl.Re return ctrl.Result{Requeue: true}, nil } + // Adds new internal DNS records + if err := reconcileDNS.Reconcile(ctx, r.Client, r.Scheme, relocation, logger); err != nil { + r.setFailedStatus(relocation, rhsysenggithubiov1beta1.DNSReconciliationFailedReason, err.Error()) + return ctrl.Result{}, err + } + // Applies a new certificate and domain alias to the API server if err := reconcileAPI.Reconcile(ctx, r.Client, r.Scheme, relocation, logger); err != nil { r.setFailedStatus(relocation, rhsysenggithubiov1beta1.APIReconciliationFailedReason, err.Error()) @@ -207,12 +213,6 @@ func (r *ClusterRelocationReconciler) Reconcile(ctx context.Context, req ctrl.Re return ctrl.Result{}, err } - // Adds new internal DNS records - if err := reconcileDNS.Reconcile(ctx, r.Client, r.Scheme, relocation, logger); err != nil { - r.setFailedStatus(relocation, rhsysenggithubiov1beta1.DNSReconciliationFailedReason, err.Error()) - return ctrl.Result{}, err - } - successCondition := metav1.Condition{ Status: metav1.ConditionTrue, Reason: rhsysenggithubiov1beta1.ReconciliationSucceededReason, diff --git a/internal/dns/reconcile.go b/internal/dns/reconcile.go index 5017e1e..dd25b52 100644 --- a/internal/dns/reconcile.go +++ b/internal/dns/reconcile.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "time" rhsysenggithubiov1beta1 "github.com/RHsyseng/cluster-relocation-operator/api/v1beta1" "github.com/go-logr/logr" @@ -12,6 +13,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) @@ -35,6 +37,7 @@ type MachineConfigData struct { //+kubebuilder:rbac:groups="",resources=nodes,verbs=list;watch //+kubebuilder:rbac:groups=machineconfiguration.openshift.io,resources=machineconfigs,verbs=create;update;get;list;watch +//+kubebuilder:rbac:groups=machineconfiguration.openshift.io,resources=machineconfigpools,verbs=get;list;watch func Reconcile(ctx context.Context, c client.Client, scheme *runtime.Scheme, relocation *rhsysenggithubiov1beta1.ClusterRelocation, logger logr.Logger) error { nodes := &corev1.NodeList{} @@ -92,6 +95,31 @@ func Reconcile(ctx context.Context, c client.Client, scheme *runtime.Scheme, rel if op != controllerutil.OperationResultNone { logger.Info("Updated DNS settings", "OperationResult", op) } + + // wait for the MachineConfigPool to include our new MachineConfig, and wait for it to update + logger.Info("waiting for MachineConfigPool to update") + masterMCP := &machineconfigurationv1.MachineConfigPool{} + for { + if err := c.Get(ctx, types.NamespacedName{Name: "master"}, masterMCP); err != nil { + return err + } + found := false + for _, v := range masterMCP.Status.Configuration.Source { + if v.Name == "relocation-dns-master" { + found = true + } + } + if !found { + time.Sleep(time.Second * 10) + } else { + if machineconfigurationv1.IsMachineConfigPoolConditionPresentAndEqual(masterMCP.Status.Conditions, machineconfigurationv1.MachineConfigPoolUpdating, corev1.ConditionFalse) { + break + } else { + time.Sleep(time.Second * 10) + } + } + } + return nil }