Skip to content

Commit

Permalink
Update DNS before API and Ingress
Browse files Browse the repository at this point in the history
  • Loading branch information
loganmc10 committed Jul 8, 2023
1 parent 1302f4e commit 09f9427
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ rules:
- patch
- update
- watch
- apiGroups:
- machineconfiguration.openshift.io
resources:
- machineconfigpools
verbs:
- get
- list
- watch
- apiGroups:
- machineconfiguration.openshift.io
resources:
Expand Down
12 changes: 6 additions & 6 deletions controllers/clusterrelocation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,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())
Expand Down Expand Up @@ -219,12 +225,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,
Expand Down
28 changes: 28 additions & 0 deletions internal/dns/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"time"

rhsysenggithubiov1beta1 "github.com/RHsyseng/cluster-relocation-operator/api/v1beta1"
"github.com/go-logr/logr"
machineconfigurationv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
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"
)
Expand All @@ -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{}
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 09f9427

Please sign in to comment.