Closed AmitKumarDas closed 1 year ago
// tags: server side apply, event
applyOpts := []client.PatchOption{client.ForceOwnership, client.FieldOwner(workload.GetUID())}
err := r.Patch(ctx, deploy, client.Apply, applyOpts...)
if err != nil {
log.Error(err, "Failed to apply to a deployment")
r.record.Event(eventObj, event.Warning(errApplyDeployment, err))
return ctrl.Result{},
util.EndReconcileWithNegativeCondition(
ctx, r, &workload, cpv1alpha1.ReconcileError(errors.Wrap(err, errApplyDeployment)),
)
}
r.record.Event(eventObj, event.Normal("Deployment created",
fmt.Sprintf("Workload `%s` successfully patched a deployment `%s`",
workload.Name, deploy.Name)))
// set the controller reference so that we can watch this deployment
// and it will be deleted automatically
if err := ctrl.SetControllerReference(workload, deploy, r.Scheme); err != nil {
return nil, err
}