AmitKumarDas / fun-with-programming

ABC - Always Be Coding
2 stars 2 forks source link

r-0022 #71

Closed AmitKumarDas closed 1 year ago

AmitKumarDas commented 3 years ago
// tags: oam, k8s
//
// https://github.com/oam-dev/kubevela/
AmitKumarDas commented 3 years 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)))
AmitKumarDas commented 3 years ago
// 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
}