diff --git a/api/core/v1alpha1/cnclaim_types.go b/api/core/v1alpha1/cnclaim_types.go index 90e5b6aa..b8610cc3 100644 --- a/api/core/v1alpha1/cnclaim_types.go +++ b/api/core/v1alpha1/cnclaim_types.go @@ -27,7 +27,7 @@ const ( CNClaimPhaseOutdated CNClaimPhase = "Outdated" - ClaimOwnerNameLabel = "matrixorigin.io/claim-owner" + PodOwnerNameLabel = "matrixorigin.io/owner" ) type CNClaimSpec struct { diff --git a/pkg/controllers/cnclaim/controller.go b/pkg/controllers/cnclaim/controller.go index 86142669..9b2587fc 100644 --- a/pkg/controllers/cnclaim/controller.go +++ b/pkg/controllers/cnclaim/controller.go @@ -160,7 +160,7 @@ func (r *Actor) doClaimCN(ctx *recon.Context[*v1alpha1.CNClaim], orphans []corev pod.Labels[v1alpha1.CNPodPhaseLabel] = v1alpha1.CNPodPhaseBound pod.Labels[v1alpha1.PodClaimedByLabel] = c.Name if c.Spec.OwnerName != nil { - pod.Labels[v1alpha1.ClaimOwnerNameLabel] = *c.Spec.OwnerName + pod.Labels[v1alpha1.PodOwnerNameLabel] = *c.Spec.OwnerName } // atomic operation with optimistic concurrency control, succeed means claimed if err := ctx.Update(pod); err != nil { @@ -362,7 +362,7 @@ func priorityFunc(c *v1alpha1.CNClaim) func(a, b corev1.Pod) int { } func previouslyOwned(c *v1alpha1.CNClaim, p corev1.Pod) int { - if c.Spec.OwnerName != nil && p.Labels[v1alpha1.ClaimOwnerNameLabel] == *c.Spec.OwnerName { + if c.Spec.OwnerName != nil && p.Labels[v1alpha1.PodOwnerNameLabel] == *c.Spec.OwnerName { return 0 } return 1 diff --git a/pkg/controllers/cnclaim/controller_test.go b/pkg/controllers/cnclaim/controller_test.go index b0f83f5e..055f4771 100644 --- a/pkg/controllers/cnclaim/controller_test.go +++ b/pkg/controllers/cnclaim/controller_test.go @@ -52,8 +52,8 @@ func Test_sortCNByPriority(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "previously-claimed", Labels: map[string]string{ - v1alpha1.CNPodPhaseLabel: v1alpha1.CNPodPhaseIdle, - v1alpha1.ClaimOwnerNameLabel: "set1", + v1alpha1.CNPodPhaseLabel: v1alpha1.CNPodPhaseIdle, + v1alpha1.PodOwnerNameLabel: "set1", }, CreationTimestamp: metav1.Unix(10, 0), }, @@ -62,8 +62,8 @@ func Test_sortCNByPriority(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "previously-claimed-by-other-set", Labels: map[string]string{ - v1alpha1.CNPodPhaseLabel: v1alpha1.CNPodPhaseIdle, - v1alpha1.ClaimOwnerNameLabel: "set2", + v1alpha1.CNPodPhaseLabel: v1alpha1.CNPodPhaseIdle, + v1alpha1.PodOwnerNameLabel: "set2", }, CreationTimestamp: metav1.Unix(10, 0), }, diff --git a/pkg/controllers/cnclaimset/controller.go b/pkg/controllers/cnclaimset/controller.go index 79441e10..b8dd465c 100644 --- a/pkg/controllers/cnclaimset/controller.go +++ b/pkg/controllers/cnclaimset/controller.go @@ -116,8 +116,8 @@ func (r *Actor) Sync(ctx *recon.Context[*v1alpha1.CNClaimSet]) error { } // used to resolve all CN pods belonged to this CNSet podSelector := common.MustAsSelector(&metav1.LabelSelector{MatchLabels: map[string]string{ - v1alpha1.ClaimOwnerNameLabel: s.Name, - v1alpha1.CNPodPhaseLabel: v1alpha1.CNPodPhaseBound, + v1alpha1.PodOwnerNameLabel: s.Name, + v1alpha1.CNPodPhaseLabel: v1alpha1.CNPodPhaseBound, }}) s.Status.ReadyReplicas = readyReplicas s.Status.Claims = claimStatuses @@ -184,7 +184,10 @@ func makeClaim(cs *v1alpha1.CNClaimSet, id string) *v1alpha1.CNClaim { tpl := cs.Spec.Template labels := tpl.Labels labels[ClaimInstanceIDLabel] = id - tpl.Spec.OwnerName = &cs.Name + // allow client to override ownerName in claimTemplate + if tpl.Spec.OwnerName == nil { + tpl.Spec.OwnerName = &cs.Name + } return &v1alpha1.CNClaim{ ObjectMeta: metav1.ObjectMeta{ Namespace: cs.Namespace,