Skip to content

Commit a8b898f

Browse files
committed
fix: address review comments
Signed-off-by: Tarun Gupta Akirala <[email protected]>
1 parent d6b1414 commit a8b898f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

cmd/clusterctl/client/cluster/mover.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,22 +637,33 @@ func pauseClusterClass(proxy Proxy, n *node, pause bool, mutators ...ResourceMut
637637
return errors.Wrap(err, "error creating client")
638638
}
639639

640-
// Since the patch has been generated already in caller of this function, the ONLY affect that mutators can have
641-
// here is on namespace of the resource.
642-
clusterClass, err := applyMutators(&clusterv1.ClusterClass{
640+
// Get a mutated copy of the ClusterClass to identify the target namespace.
641+
// The ClusterClass could have been moved to a different namespace after the move.
642+
mutatedClusterClass, err := applyMutators(&clusterv1.ClusterClass{
643643
TypeMeta: metav1.TypeMeta{
644644
Kind: clusterv1.ClusterClassKind,
645645
APIVersion: clusterv1.GroupVersion.String(),
646646
},
647647
ObjectMeta: metav1.ObjectMeta{
648648
Name: n.identity.Name,
649649
Namespace: n.identity.Namespace,
650-
},
651-
}, mutators...)
650+
}}, mutators...)
652651
if err != nil {
653652
return err
654653
}
655654

655+
clusterClass := &clusterv1.ClusterClass{}
656+
// Construct an object key using the mutatedClusterClass reflecting any changes to the namespace.
657+
clusterClassObjKey := client.ObjectKey{
658+
Name: mutatedClusterClass.GetName(),
659+
Namespace: mutatedClusterClass.GetNamespace(),
660+
}
661+
// Get a copy of the ClusterClass.
662+
// This will ensure that any other changes from the mutator are ignored here as we work with a fresh copy of the cluster class.
663+
if err := cFrom.Get(ctx, clusterClassObjKey, clusterClass); err != nil {
664+
return errors.Wrapf(err, "error reading ClusterClass %s/%s", n.identity.Namespace, n.identity.Name)
665+
}
666+
656667
patchHelper, err := patch.NewHelper(clusterClass, cFrom)
657668
if err != nil {
658669
return errors.Wrapf(err, "error creating patcher for ClusterClass %s/%s", n.identity.Namespace, n.identity.Name)

0 commit comments

Comments
 (0)