Skip to content

Commit

Permalink
Remove statefulSetUID parameter from GetWorkloadName. (#3304)
Browse files Browse the repository at this point in the history
* Remove statefulSetUID parameter from GetWorkloadName.

* Add comment why we are using empty UID.
  • Loading branch information
mbobrovskyi authored Oct 24, 2024
1 parent e3cccaa commit 1ca7bf1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pkg/controller/jobs/statefulset/statefulset_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
apivalidation "k8s.io/apimachinery/pkg/api/validation"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -73,7 +72,7 @@ func (wh *Webhook) Default(ctx context.Context, obj runtime.Object) error {
}

ss.Spec.Template.Labels[constants.QueueLabel] = cqLabel
ss.Spec.Template.Labels[pod.GroupNameLabel] = GetWorkloadName(ss.Name, ss.UID)
ss.Spec.Template.Labels[pod.GroupNameLabel] = GetWorkloadName(ss.Name)

if ss.Spec.Template.Annotations == nil {
ss.Spec.Template.Annotations = make(map[string]string, 2)
Expand Down Expand Up @@ -138,6 +137,7 @@ func (wh *Webhook) ValidateDelete(context.Context, runtime.Object) (warnings adm
return nil, nil
}

func GetWorkloadName(statefulSetName string, statefulSetUID types.UID) string {
return jobframework.GetWorkloadNameForOwnerWithGVK(statefulSetName, statefulSetUID, gvk)
func GetWorkloadName(statefulSetName string) string {
// Passing empty UID as it is not available before object creation
return jobframework.GetWorkloadNameForOwnerWithGVK(statefulSetName, "", gvk)
}
4 changes: 2 additions & 2 deletions test/e2e/singlecluster/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var _ = ginkgo.Describe("Stateful set integration", func() {
Replicas(3).
Queue(lq.Name).
Obj()
wlLookupKey := types.NamespacedName{Name: statefulset.GetWorkloadName(statefulSet.Name, statefulSet.UID), Namespace: ns.Name}
wlLookupKey := types.NamespacedName{Name: statefulset.GetWorkloadName(statefulSet.Name), Namespace: ns.Name}
gomega.Expect(k8sClient.Create(ctx, statefulSet)).To(gomega.Succeed())

gomega.Eventually(func(g gomega.Gomega) {
Expand All @@ -113,7 +113,7 @@ var _ = ginkgo.Describe("Stateful set integration", func() {
Queue(lq.Name).
Obj()
conflictingWlLookupKey := types.NamespacedName{
Name: statefulset.GetWorkloadName(conflictingStatefulSet.Name, conflictingStatefulSet.UID),
Name: statefulset.GetWorkloadName(conflictingStatefulSet.Name),
Namespace: ns.Name,
}
gomega.Expect(k8sClient.Create(ctx, conflictingStatefulSet)).To(gomega.Succeed())
Expand Down

0 comments on commit 1ca7bf1

Please sign in to comment.