Skip to content

Commit

Permalink
Merge pull request #6914 from sbueringer/pr-minor-fixes
Browse files Browse the repository at this point in the history
馃悰 SSA: create cluster-shim with regular client, use ignorePaths on create
  • Loading branch information
k8s-ci-robot committed Jul 13, 2022
2 parents 57f04eb + 0b48593 commit ef7172a
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions internal/controllers/topology/cluster/reconcile_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,15 @@ func (r *Reconciler) reconcileClusterShim(ctx context.Context, s *scope.Scope) e
// creating InfrastructureCluster/ControlPlane objects and updating the Cluster with the
// references to above objects.
if s.Current.InfrastructureCluster == nil || s.Current.ControlPlane.Object == nil {
// Note: we are using Patch instead of create for ensuring consistency in managedFields for the entire controller
// but in this case it isn't strictly necessary given that we are not using server side apply for modifying the
// object afterwards.
helper, err := r.patchHelperFactory(ctx, nil, shim)
if err != nil {
return errors.Wrap(err, "failed to create the patch helper for the cluster shim object")
}
if err := helper.Patch(ctx); err != nil {
return errors.Wrap(err, "failed to create the cluster shim object")
}

if err := r.APIReader.Get(ctx, client.ObjectKeyFromObject(shim), shim); err != nil {
return errors.Wrap(err, "get shim after creation")
// Given that the cluster shim is a temporary object which is only modified
// by this controller, it is not necessary to use the SSA patch helper.
if err := r.Client.Create(ctx, shim); err != nil {
if !apierrors.IsAlreadyExists(err) {
return errors.Wrap(err, "failed to create the cluster shim object")
}
if err := r.Client.Get(ctx, client.ObjectKeyFromObject(shim), shim); err != nil {
return errors.Wrapf(err, "failed to read the cluster shim object")
}
}

// Enforce type meta back given that it gets blanked out by Get.
Expand Down Expand Up @@ -656,7 +652,7 @@ func (r *Reconciler) reconcileReferencedObject(ctx context.Context, in reconcile
// If there is no current object, create it.
if in.current == nil {
log.Infof("Creating %s", tlog.KObj{Obj: in.desired})
helper, err := r.patchHelperFactory(ctx, nil, in.desired)
helper, err := r.patchHelperFactory(ctx, nil, in.desired, structuredmerge.IgnorePaths(in.ignorePaths))
if err != nil {
return errors.Wrap(createErrorWithoutObjectName(err, in.desired), "failed to create patch helper")
}
Expand Down

0 comments on commit ef7172a

Please sign in to comment.