Skip to content

Commit

Permalink
Merge pull request #4578 from muraee/pause-capi-cluster
Browse files Browse the repository at this point in the history
HOSTEDCP-1868: Pause CAPI cluster when HostedCluster is paused
  • Loading branch information
openshift-merge-bot[bot] authored Aug 19, 2024
2 parents 7f265fc + 3dbda6a commit 4531612
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,9 @@ func (r *HostedClusterReconciler) reconcile(ctx context.Context, req ctrl.Reques
if err := pauseHostedControlPlane(ctx, r.Client, hcp, hcluster.Spec.PausedUntil); err != nil {
return ctrl.Result{}, err
}
if err := pauseCAPICluster(ctx, r.Client, hcp); err != nil {
return ctrl.Result{}, err
}
log.Info("Reconciliation paused", "name", req.NamespacedName, "pausedUntil", *hcluster.Spec.PausedUntil)
return ctrl.Result{RequeueAfter: duration}, nil
}
Expand Down Expand Up @@ -3036,6 +3039,8 @@ func reconcilecontrolPlaneOperatorIngressOperatorRoleBinding(binding *rbacv1.Rol
func reconcileCAPICluster(cluster *capiv1.Cluster, hcluster *hyperv1.HostedCluster, hcp *hyperv1.HostedControlPlane, infraCR client.Object) error {
// We only create this resource once and then let CAPI own it
if !cluster.CreationTimestamp.IsZero() {
// make sure cluster is not paused.
cluster.Spec.Paused = false
return nil
}
infraCRGVK, err := apiutil.GVKForObject(infraCR, api.Scheme)
Expand Down Expand Up @@ -3065,6 +3070,29 @@ func reconcileCAPICluster(cluster *capiv1.Cluster, hcluster *hyperv1.HostedClust
return nil
}

func pauseCAPICluster(ctx context.Context, c client.Client, hcp *hyperv1.HostedControlPlane) error {
if hcp == nil {
return nil
}

capiCluster := controlplaneoperator.CAPICluster(hcp.Namespace, hcp.Spec.InfraID)
err := c.Get(ctx, client.ObjectKeyFromObject(capiCluster), capiCluster)
if err != nil {
if !apierrors.IsNotFound(err) {
return fmt.Errorf("failed to get CAPI Cluster: %w", err)
}
return nil
}

if !capiCluster.Spec.Paused {
capiCluster.Spec.Paused = true
if err := c.Update(ctx, capiCluster); err != nil {
return fmt.Errorf("failed to update CAPI Cluster: %w", err)
}
}
return nil
}

func reconcileCAPIProviderDeployment(deployment *appsv1.Deployment, capiProviderDeploymentSpec *appsv1.DeploymentSpec, hcp *hyperv1.HostedControlPlane, sa *corev1.ServiceAccount, setDefaultSecurityContext bool) error {
selectorLabels := map[string]string{
"control-plane": "capi-provider-controller-manager",
Expand Down

0 comments on commit 4531612

Please sign in to comment.