Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

postpone connecting to remote cluster until when needed #2402

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions addons/controllers/clusterbootstrap_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,15 @@ func (r *ClusterBootstrapReconciler) Reconcile(ctx context.Context, req ctrl.Req

log.Info("Reconciling cluster")

remoteClient, err := util.GetClusterClient(r.context, r.Client, r.Scheme, clusterapiutil.ObjectKey(cluster))
if err != nil {
log.Error(err, "Error getting remote cluster client")
return ctrl.Result{Requeue: true}, err
}
// if deletion timestamp is set, handle cluster deletion
if !cluster.GetDeletionTimestamp().IsZero() {
return r.reconcileDelete(cluster, remoteClient, log)
return r.reconcileDelete(cluster, log)
}
return r.reconcileNormal(cluster, remoteClient, log)
return r.reconcileNormal(cluster, log)
}

// reconcileNormal reconciles the ClusterBootstrap object
func (r *ClusterBootstrapReconciler) reconcileNormal(cluster *clusterapiv1beta1.Cluster, remoteClient client.Client, log logr.Logger) (ctrl.Result, error) {
func (r *ClusterBootstrapReconciler) reconcileNormal(cluster *clusterapiv1beta1.Cluster, log logr.Logger) (ctrl.Result, error) {
// get or clone or patch from template
clusterBootstrap, err := r.createOrPatchClusterBootstrapFromTemplate(cluster, log)
if err != nil {
Expand Down Expand Up @@ -213,6 +208,11 @@ func (r *ClusterBootstrapReconciler) reconcileNormal(cluster *clusterapiv1beta1.
return ctrl.Result{}, err
}

remoteClient, err := util.GetClusterClient(r.context, r.Client, r.Scheme, clusterapiutil.ObjectKey(cluster))
if err != nil {
return ctrl.Result{RequeueAfter: constants.RequeueAfterDuration}, fmt.Errorf("failed to get remote cluster client: %w", err)
}

if err := r.prepareRemoteCluster(cluster, remoteClient); err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -1285,10 +1285,15 @@ func (r *ClusterBootstrapReconciler) removeFinalizersFromClusterResources(cluste
return nil
}

func (r *ClusterBootstrapReconciler) reconcileDelete(cluster *clusterapiv1beta1.Cluster, remoteClient client.Client, log logr.Logger) (ctrl.Result, error) {
func (r *ClusterBootstrapReconciler) reconcileDelete(cluster *clusterapiv1beta1.Cluster, log logr.Logger) (ctrl.Result, error) {
okToRemoveFinalizers := false
var err error

remoteClient, err := util.GetClusterClient(r.context, r.Client, r.Scheme, clusterapiutil.ObjectKey(cluster))
if err != nil {
return ctrl.Result{RequeueAfter: constants.RequeueAfterDuration}, fmt.Errorf("failed to get remote cluster client: %w", err)
}

timeOutReached := time.Now().After(cluster.GetDeletionTimestamp().Add(r.Config.ClusterDeleteTimeout))
if timeOutReached {
okToRemoveFinalizers = true
Expand Down