@@ -98,19 +98,15 @@ func (r *Reconciler) reconcileClusterShim(ctx context.Context, s *scope.Scope) e
9898 // creating InfrastructureCluster/ControlPlane objects and updating the Cluster with the
9999 // references to above objects.
100100 if s .Current .InfrastructureCluster == nil || s .Current .ControlPlane .Object == nil {
101- // Note: we are using Patch instead of create for ensuring consistency in managedFields for the entire controller
102- // but in this case it isn't strictly necessary given that we are not using server side apply for modifying the
103- // object afterwards.
104- helper , err := r .patchHelperFactory (ctx , nil , shim )
105- if err != nil {
106- return errors .Wrap (err , "failed to create the patch helper for the cluster shim object" )
107- }
108- if err := helper .Patch (ctx ); err != nil {
109- return errors .Wrap (err , "failed to create the cluster shim object" )
110- }
111-
112- if err := r .APIReader .Get (ctx , client .ObjectKeyFromObject (shim ), shim ); err != nil {
113- return errors .Wrap (err , "get shim after creation" )
101+ // Given that the cluster shim is a temporary object which is only modified
102+ // by this controller, it is not necessary to use the SSA patch helper.
103+ if err := r .Client .Create (ctx , shim ); err != nil {
104+ if ! apierrors .IsAlreadyExists (err ) {
105+ return errors .Wrap (err , "failed to create the cluster shim object" )
106+ }
107+ if err := r .Client .Get (ctx , client .ObjectKeyFromObject (shim ), shim ); err != nil {
108+ return errors .Wrapf (err , "failed to read the cluster shim object" )
109+ }
114110 }
115111
116112 // Enforce type meta back given that it gets blanked out by Get.
@@ -656,7 +652,7 @@ func (r *Reconciler) reconcileReferencedObject(ctx context.Context, in reconcile
656652 // If there is no current object, create it.
657653 if in .current == nil {
658654 log .Infof ("Creating %s" , tlog.KObj {Obj : in .desired })
659- helper , err := r .patchHelperFactory (ctx , nil , in .desired )
655+ helper , err := r .patchHelperFactory (ctx , nil , in .desired , structuredmerge . IgnorePaths ( in . ignorePaths ) )
660656 if err != nil {
661657 return errors .Wrap (createErrorWithoutObjectName (err , in .desired ), "failed to create patch helper" )
662658 }
0 commit comments