MCPcopy
hub / github.com/apecloud/kubeblocks / updateOwnerReference

Function updateOwnerReference

controllers/parameters/parameter_util.go:300–327  ·  view source on GitHub ↗
(reqCtx intctrlutil.RequestCtx, cli client.Client, cluster *appsv1.Cluster, parameter *parametersv1alpha1.Parameter)

Source from the content-addressed store, hash-verified

298}
299
300func updateOwnerReference(reqCtx intctrlutil.RequestCtx, cli client.Client, cluster *appsv1.Cluster, parameter *parametersv1alpha1.Parameter) (*ctrl.Result, error) {
301 hasValidateOwnershop := func(obj client.Object) bool {
302 // Check if the `parameter` object has a controller reference(Operation CR) or if the `cluster` is its owner.
303 // If neither condition is true, attempt to set the `cluster` as the owner of the `parameter`.
304 // This ensures proper ownership and garbage collection behavior in Kubernetes.
305 return controllerutil.HasControllerReference(obj) || model.IsOwnerOf(cluster, obj)
306 }
307
308 clusterName := parameter.Labels[constant.AppInstanceLabelKey]
309 if clusterName == parameter.Spec.ClusterName && hasValidateOwnershop(parameter) {
310 return nil, nil
311 }
312
313 patch := client.MergeFrom(parameter.DeepCopy())
314 if parameter.Labels == nil {
315 parameter.Labels = make(map[string]string)
316 }
317 if !hasValidateOwnershop(parameter) {
318 if err := intctrlutil.SetOwnerReference(cluster, parameter); err != nil {
319 return intctrlutil.ResultToP(intctrlutil.CheckedRequeueWithError(err, reqCtx.Log, ""))
320 }
321 }
322 parameter.Labels[constant.AppInstanceLabelKey] = parameter.Spec.ClusterName
323 if err := cli.Patch(reqCtx.Ctx, parameter, patch); err != nil {
324 return intctrlutil.ResultToP(intctrlutil.CheckedRequeueWithError(err, reqCtx.Log, ""))
325 }
326 return intctrlutil.ResultToP(intctrlutil.Reconciled())
327}

Callers 1

handleClusterDeletedFunction · 0.85

Calls 4

IsOwnerOfFunction · 0.92
MergeFromMethod · 0.65
DeepCopyMethod · 0.65
PatchMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…