Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 check resource blocking clusterctl move during discovery #9246

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be helpful to have a trace level log line here, buts thats a nit.

}

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