Skip to content

Commit

Permalink
🌱 check resource blocking clusterctl move during discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
nojnhuh committed Sep 6, 2023
1 parent 82eff49 commit e3c78b7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/clusterctl/client/cluster/mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,18 @@ func waitReadyForMove(ctx context.Context, proxy Proxy, nodes []*node, dryRun bo
}

for _, n := range nodes {
log := log.WithValues(
"apiVersion", n.identity.GroupVersionKind(),
"resource", klog.ObjectRef{
Name: n.identity.Name,
Namespace: n.identity.Namespace,
},
)
if !n.blockingMove {
log.V(5).Info("Resource not blocking move")
continue
}

obj := &metav1.PartialObjectMetadata{
ObjectMeta: metav1.ObjectMeta{
Name: n.identity.Name,
Expand All @@ -634,7 +646,6 @@ func waitReadyForMove(ctx context.Context, proxy Proxy, nodes []*node, dryRun bo
},
}
key := client.ObjectKeyFromObject(obj)
log := log.WithValues("apiVersion", obj.GroupVersionKind(), "resource", klog.KObj(obj))

blockLogged := false
if err := retryWithExponentialBackoff(backoff, func() error {
Expand Down
21 changes: 21 additions & 0 deletions cmd/clusterctl/client/cluster/mover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,7 @@ func TestWaitReadyForMove(t *testing.T) {
tests := []struct {
name string
moveBlocked bool
doUnblock bool
wantErr bool
}{
{
Expand All @@ -2337,6 +2338,12 @@ func TestWaitReadyForMove(t *testing.T) {
moveBlocked: false,
wantErr: false,
},
{
name: "moving blocked cluster that is eventually unblocked should succeed",
moveBlocked: true,
doUnblock: true,
wantErr: false,
},
}

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

g.Expect(c.Update(ctx, cluster)).To(Succeed())

if tt.doUnblock {
go func() {
time.Sleep(50 * time.Millisecond)
delete(cluster.Annotations, clusterctlv1.BlockMoveAnnotation)
g.Expect(c.Update(ctx, cluster)).To(Succeed())
}()
}
}

// Get all the types to be considered for discovery
Expand All @@ -2378,6 +2393,12 @@ func TestWaitReadyForMove(t *testing.T) {
backoff := wait.Backoff{
Steps: 1,
}
if tt.doUnblock {
backoff = wait.Backoff{
Duration: 20 * time.Millisecond,
Steps: 10,
}
}
err := waitReadyForMove(ctx, graph.proxy, graph.getMoveNodes(), false, backoff)
if tt.wantErr {
g.Expect(err).To(HaveOccurred())
Expand Down
6 changes: 6 additions & 0 deletions cmd/clusterctl/client/cluster/objectgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ type node struct {
// E.g. for the cluster object we capture information to see if the cluster uses a manged topology
// and the cluster class used.
additionalInfo map[string]interface{}

// blockingMove is true when the object should prevent a move operation from proceeding as indicated by
// the presence of the block-move annotation.
blockingMove bool
}

type discoveryTypeInfo struct {
Expand Down Expand Up @@ -320,6 +324,8 @@ func (o *objectGraph) objMetaToNode(obj *unstructured.Unstructured, n *node) {
n.isGlobal = true
}
}

_, n.blockingMove = obj.GetAnnotations()[clusterctlv1.BlockMoveAnnotation]
}

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

0 comments on commit e3c78b7

Please sign in to comment.