Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Improve patch helper error handling #2865

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/serviceaccount_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
// Create the patch helper.
patchHelper, err := patch.NewHelper(vsphereCluster, r.Client)
if err != nil {
return reconcile.Result{}, errors.Wrapf(err, "failed to initialize patch helper")
return reconcile.Result{}, err

Check warning on line 168 in controllers/serviceaccount_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/serviceaccount_controller.go#L168

Added line #L168 was not covered by tests
}

// Create the cluster context for this request.
Expand Down
2 changes: 1 addition & 1 deletion controllers/servicediscovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
// Create the patch helper.
patchHelper, err := patch.NewHelper(vsphereCluster, r.Client)
if err != nil {
return reconcile.Result{}, errors.Wrapf(err, "failed to initialize patch helper")
return reconcile.Result{}, err

Check warning on line 176 in controllers/servicediscovery_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/servicediscovery_controller.go#L176

Added line #L176 was not covered by tests
}

// Create the cluster context for this request.
Expand Down
2 changes: 1 addition & 1 deletion controllers/vmware/vspherecluster_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
// Build the patch helper.
patchHelper, err := patch.NewHelper(vsphereCluster, r.Client)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to initialize patch helper")
return reconcile.Result{}, err

Check warning on line 105 in controllers/vmware/vspherecluster_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/vmware/vspherecluster_reconciler.go#L105

Added line #L105 was not covered by tests
}

// Build the cluster context.
Expand Down
8 changes: 2 additions & 6 deletions controllers/vspherecluster_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
// Create the patch helper.
patchHelper, err := patch.NewHelper(vsphereCluster, r.Client)
if err != nil {
return reconcile.Result{}, pkgerrors.Wrap(err, "failed to initialize patch helper")
return reconcile.Result{}, err

Check warning on line 94 in controllers/vspherecluster_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/vspherecluster_reconciler.go#L94

Added line #L94 was not covered by tests
}

// Create the cluster context for this request.
Expand Down Expand Up @@ -264,12 +264,8 @@
if !ctrlutil.ContainsFinalizer(secret, infrav1.SecretIdentitySetFinalizer) {
ctrlutil.AddFinalizer(secret, infrav1.SecretIdentitySetFinalizer)
}
err = helper.Patch(ctx, secret)
if err != nil {
return pkgerrors.Wrapf(err, "Failed to patch secret %s", klog.KObj(secret))
}

return nil
return helper.Patch(ctx, secret)
}

func (r *clusterReconciler) reconcileVCenterConnectivity(ctx context.Context, clusterCtx *capvcontext.ClusterContext) (*session.Session, error) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/vsphereclusteridentity_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
// Create the patch helper.
patchHelper, err := patch.NewHelper(identity, r.Client)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to initialize patch helper")
return reconcile.Result{}, err

Check warning on line 93 in controllers/vsphereclusteridentity_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/vsphereclusteridentity_controller.go#L93

Added line #L93 was not covered by tests
}

defer func() {
Expand Down
11 changes: 4 additions & 7 deletions controllers/vspheredeploymentzone_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@

patchHelper, err := patch.NewHelper(vsphereDeploymentZone, r.Client)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to initialize patch helper")
return reconcile.Result{}, err

Check warning on line 108 in controllers/vspheredeploymentzone_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/vspheredeploymentzone_controller.go#L108

Added line #L108 was not covered by tests
}

vsphereDeploymentZoneContext := &capvcontext.VSphereDeploymentZoneContext{
Expand Down Expand Up @@ -287,17 +287,14 @@
func updateOwnerReferences(ctx context.Context, obj client.Object, client client.Client, ownerRefFunc func() []metav1.OwnerReference) error {
patchHelper, err := patch.NewHelper(obj, client)
if err != nil {
return errors.Wrapf(err, "failed to init patch helper for %s %s",
obj.GetObjectKind(),
obj.GetName())
return err

Check warning on line 290 in controllers/vspheredeploymentzone_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/vspheredeploymentzone_controller.go#L290

Added line #L290 was not covered by tests
}

obj.SetOwnerReferences(ownerRefFunc())
if err := patchHelper.Patch(ctx, obj); err != nil {
return errors.Wrapf(err, "failed to patch object %s %s",
obj.GetObjectKind(),
obj.GetName())
return errors.Wrapf(err, "failed to update OwnerReferences")

Check warning on line 295 in controllers/vspheredeploymentzone_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/vspheredeploymentzone_controller.go#L295

Added line #L295 was not covered by tests
chrischdi marked this conversation as resolved.
Show resolved Hide resolved
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/vspheremachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
// Create the patch helper.
patchHelper, err := patch.NewHelper(machineContext.GetVSphereMachine(), r.Client)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to initialize patch helper")
return reconcile.Result{}, err

Check warning on line 234 in controllers/vspheremachine_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/vspheremachine_controller.go#L234

Added line #L234 was not covered by tests
}
machineContext.SetBaseMachineContext(&capvcontext.BaseMachineContext{
Cluster: cluster,
Expand Down
2 changes: 1 addition & 1 deletion controllers/vspherevm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
// Create the patch helper.
patchHelper, err := patch.NewHelper(vsphereVM, r.Client)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to initialize patch helper")
return reconcile.Result{}, err

Check warning on line 175 in controllers/vspherevm_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/vspherevm_controller.go#L175

Added line #L175 was not covered by tests
}

authSession, err := r.retrieveVcenterSession(ctx, vsphereVM)
Expand Down
4 changes: 2 additions & 2 deletions pkg/services/govmomi/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@

virtualMachineCtx.VSphereVM.Status.TaskRef = task.Reference().Value
if err = virtualMachineCtx.Patch(ctx); err != nil {
return reconcile.Result{}, vm, errors.Wrapf(err, "failed to patch VSphereVM")
return reconcile.Result{}, vm, err

Check warning on line 254 in pkg/services/govmomi/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/govmomi/service.go#L254

Added line #L254 was not covered by tests
}

log.Info("Wait for VM to be powered off")
Expand Down Expand Up @@ -363,7 +363,7 @@
// Update the VSphereVM.Status.TaskRef to track the power-on task.
virtualMachineCtx.VSphereVM.Status.TaskRef = task.Reference().Value
if err = virtualMachineCtx.Patch(ctx); err != nil {
return false, errors.Wrapf(err, "failed to patch VSphereVM")
return false, err

Check warning on line 366 in pkg/services/govmomi/service.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/govmomi/service.go#L366

Added line #L366 was not covered by tests
}

// Once the VM is successfully powered on, a reconcile request should be
Expand Down
Loading