Skip to content

Commit f19403c

Browse files
committed
use improved clusteraccess library features
1 parent ec212cf commit f19403c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

internal/controllers/cluster/controller.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,24 @@ func (r *ClusterReconciler) handleDelete(ctx context.Context, c *clustersv1alpha
319319
}
320320

321321
// get access to Cluster
322+
log.Info("Updating AccessRequest to get access to Cluster")
322323
req := testutils.RequestFromObject(c)
324+
res, err := r.ClusterAccessReconciler.Reconcile(ctx, req)
325+
if err != nil {
326+
rr.ReconcileError = errutils.WithReason(fmt.Errorf("error reconciling cluster access: %w", err), clusterconst.ReasonInternalError)
327+
return rr
328+
}
329+
if res.RequeueAfter > 0 {
330+
log.Info("Requeuing because cluster access is not yet available", "after", res.RequeueAfter)
331+
rr.Result = res
332+
return rr
333+
}
323334
ar, err := r.ClusterAccessReconciler.AccessRequest(ctx, req, clusterId)
324335
if client.IgnoreNotFound(err) != nil {
325336
rr.ReconcileError = errutils.WithReason(fmt.Errorf("error getting AccessRequest: %w", err), clusterconst.ReasonInternalError)
326337
return rr
327338
}
328-
if ar != nil && ar.Status.IsGranted() {
339+
if ar != nil && ar.DeletionTimestamp.IsZero() && ar.Status.IsGranted() {
329340
access, err := r.ClusterAccessReconciler.Access(ctx, req, clusterId)
330341
if err != nil {
331342
rr.ReconcileError = errutils.WithReason(fmt.Errorf("error getting access to Cluster: %w", err), clusterconst.ReasonInternalError)
@@ -351,7 +362,7 @@ func (r *ClusterReconciler) handleDelete(ctx context.Context, c *clustersv1alpha
351362
return rr
352363
}
353364

354-
res, err := r.ClusterAccessReconciler.ReconcileDelete(ctx, req)
365+
res, err = r.ClusterAccessReconciler.ReconcileDelete(ctx, req)
355366
if err != nil {
356367
rr.ReconcileError = errutils.WithReason(fmt.Errorf("error reconciling deletion of cluster access: %w", err), clusterconst.ReasonInternalError)
357368
return rr

internal/controllers/cluster/controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func defaultTestSetup(testDirPathSegments ...string) (*testutils.Environment, ma
5454
WithReconcilerConstructor(func(c client.Client) reconcile.Reconciler {
5555
rec := cluster.NewClusterReconciler(clusters.NewTestClusterFromClient(platformCluster, c), nil, providerName, providerNamespace, environment)
5656
rec.ClusterAccessReconciler.WithFakingCallback(accesslib.FakingCallback_WaitingForAccessRequestReadiness, accesslib.FakeAccessRequestReadiness())
57+
rec.ClusterAccessReconciler.WithFakingCallback(accesslib.FakingCallback_WaitingForAccessRequestDeletion, accesslib.FakeAccessRequestDeletion([]string{"*"}, nil))
5758
rec.ClusterAccessReconciler.WithFakeClientGenerator(func(ctx context.Context, kcfgData []byte, scheme *runtime.Scheme, additionalData ...any) (client.Client, error) {
5859
if clusterRef, ok := strings.CutPrefix(string(kcfgData), "fake:cluster:"); ok {
5960
if fc, ok := fakeClientMapping[clusterRef]; ok {

0 commit comments

Comments
 (0)