Skip to content

Commit e3c78b7

Browse files
committed
🌱 check resource blocking clusterctl move during discovery
1 parent 82eff49 commit e3c78b7

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

cmd/clusterctl/client/cluster/mover.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,18 @@ func waitReadyForMove(ctx context.Context, proxy Proxy, nodes []*node, dryRun bo
623623
}
624624

625625
for _, n := range nodes {
626+
log := log.WithValues(
627+
"apiVersion", n.identity.GroupVersionKind(),
628+
"resource", klog.ObjectRef{
629+
Name: n.identity.Name,
630+
Namespace: n.identity.Namespace,
631+
},
632+
)
633+
if !n.blockingMove {
634+
log.V(5).Info("Resource not blocking move")
635+
continue
636+
}
637+
626638
obj := &metav1.PartialObjectMetadata{
627639
ObjectMeta: metav1.ObjectMeta{
628640
Name: n.identity.Name,
@@ -634,7 +646,6 @@ func waitReadyForMove(ctx context.Context, proxy Proxy, nodes []*node, dryRun bo
634646
},
635647
}
636648
key := client.ObjectKeyFromObject(obj)
637-
log := log.WithValues("apiVersion", obj.GroupVersionKind(), "resource", klog.KObj(obj))
638649

639650
blockLogged := false
640651
if err := retryWithExponentialBackoff(backoff, func() error {

cmd/clusterctl/client/cluster/mover_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,6 +2325,7 @@ func TestWaitReadyForMove(t *testing.T) {
23252325
tests := []struct {
23262326
name string
23272327
moveBlocked bool
2328+
doUnblock bool
23282329
wantErr bool
23292330
}{
23302331
{
@@ -2337,6 +2338,12 @@ func TestWaitReadyForMove(t *testing.T) {
23372338
moveBlocked: false,
23382339
wantErr: false,
23392340
},
2341+
{
2342+
name: "moving blocked cluster that is eventually unblocked should succeed",
2343+
moveBlocked: true,
2344+
doUnblock: true,
2345+
wantErr: false,
2346+
},
23402347
}
23412348

23422349
for _, tt := range tests {
@@ -2367,6 +2374,14 @@ func TestWaitReadyForMove(t *testing.T) {
23672374
cluster.SetAnnotations(anns)
23682375

23692376
g.Expect(c.Update(ctx, cluster)).To(Succeed())
2377+
2378+
if tt.doUnblock {
2379+
go func() {
2380+
time.Sleep(50 * time.Millisecond)
2381+
delete(cluster.Annotations, clusterctlv1.BlockMoveAnnotation)
2382+
g.Expect(c.Update(ctx, cluster)).To(Succeed())
2383+
}()
2384+
}
23702385
}
23712386

23722387
// Get all the types to be considered for discovery
@@ -2378,6 +2393,12 @@ func TestWaitReadyForMove(t *testing.T) {
23782393
backoff := wait.Backoff{
23792394
Steps: 1,
23802395
}
2396+
if tt.doUnblock {
2397+
backoff = wait.Backoff{
2398+
Duration: 20 * time.Millisecond,
2399+
Steps: 10,
2400+
}
2401+
}
23812402
err := waitReadyForMove(ctx, graph.proxy, graph.getMoveNodes(), false, backoff)
23822403
if tt.wantErr {
23832404
g.Expect(err).To(HaveOccurred())

cmd/clusterctl/client/cluster/objectgraph.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ type node struct {
9292
// E.g. for the cluster object we capture information to see if the cluster uses a manged topology
9393
// and the cluster class used.
9494
additionalInfo map[string]interface{}
95+
96+
// blockingMove is true when the object should prevent a move operation from proceeding as indicated by
97+
// the presence of the block-move annotation.
98+
blockingMove bool
9599
}
96100

97101
type discoveryTypeInfo struct {
@@ -320,6 +324,8 @@ func (o *objectGraph) objMetaToNode(obj *unstructured.Unstructured, n *node) {
320324
n.isGlobal = true
321325
}
322326
}
327+
328+
_, n.blockingMove = obj.GetAnnotations()[clusterctlv1.BlockMoveAnnotation]
323329
}
324330

325331
// getDiscoveryTypes returns the list of TypeMeta to be considered for the move discovery phase.

0 commit comments

Comments
 (0)