(reqCtx intctrlutil.RequestCtx, cli client.Client, cluster *appsv1.Cluster, parameter *parametersv1alpha1.Parameter)
| 298 | } |
| 299 | |
| 300 | func 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 | } |
no test coverage detected
searching dependent graphs…