@@ -637,22 +637,33 @@ func pauseClusterClass(proxy Proxy, n *node, pause bool, mutators ...ResourceMut
637
637
return errors .Wrap (err , "error creating client" )
638
638
}
639
639
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 {
643
643
TypeMeta : metav1.TypeMeta {
644
644
Kind : clusterv1 .ClusterClassKind ,
645
645
APIVersion : clusterv1 .GroupVersion .String (),
646
646
},
647
647
ObjectMeta : metav1.ObjectMeta {
648
648
Name : n .identity .Name ,
649
649
Namespace : n .identity .Namespace ,
650
- },
651
- }, mutators ... )
650
+ }}, mutators ... )
652
651
if err != nil {
653
652
return err
654
653
}
655
654
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
+
656
667
patchHelper , err := patch .NewHelper (clusterClass , cFrom )
657
668
if err != nil {
658
669
return errors .Wrapf (err , "error creating patcher for ClusterClass %s/%s" , n .identity .Namespace , n .identity .Name )
0 commit comments