Skip to content

Commit

Permalink
fix: address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Tarun Gupta Akirala <[email protected]>
  • Loading branch information
takirala committed Apr 5, 2023
1 parent d6b1414 commit a8b898f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmd/clusterctl/client/cluster/mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,22 +637,33 @@ func pauseClusterClass(proxy Proxy, n *node, pause bool, mutators ...ResourceMut
return errors.Wrap(err, "error creating client")
}

// Since the patch has been generated already in caller of this function, the ONLY affect that mutators can have
// here is on namespace of the resource.
clusterClass, err := applyMutators(&clusterv1.ClusterClass{
// Get a mutated copy of the ClusterClass to identify the target namespace.
// The ClusterClass could have been moved to a different namespace after the move.
mutatedClusterClass, err := applyMutators(&clusterv1.ClusterClass{
TypeMeta: metav1.TypeMeta{
Kind: clusterv1.ClusterClassKind,
APIVersion: clusterv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: n.identity.Name,
Namespace: n.identity.Namespace,
},
}, mutators...)
}}, mutators...)
if err != nil {
return err
}

clusterClass := &clusterv1.ClusterClass{}
// Construct an object key using the mutatedClusterClass reflecting any changes to the namespace.
clusterClassObjKey := client.ObjectKey{
Name: mutatedClusterClass.GetName(),
Namespace: mutatedClusterClass.GetNamespace(),
}
// Get a copy of the ClusterClass.
// This will ensure that any other changes from the mutator are ignored here as we work with a fresh copy of the cluster class.
if err := cFrom.Get(ctx, clusterClassObjKey, clusterClass); err != nil {
return errors.Wrapf(err, "error reading ClusterClass %s/%s", n.identity.Namespace, n.identity.Name)
}

patchHelper, err := patch.NewHelper(clusterClass, cFrom)
if err != nil {
return errors.Wrapf(err, "error creating patcher for ClusterClass %s/%s", n.identity.Namespace, n.identity.Name)
Expand Down

0 comments on commit a8b898f

Please sign in to comment.