From d32fe499910af5c1e653d2cb73105dbffb047a9a Mon Sep 17 00:00:00 2001 From: Traian Schiau Date: Mon, 18 Mar 2024 11:29:45 +0200 Subject: [PATCH] [pod] Export `FromObject()` --- pkg/controller/jobs/pod/pod_controller.go | 6 +++--- pkg/controller/jobs/pod/pod_controller_test.go | 8 ++++---- pkg/controller/jobs/pod/pod_webhook.go | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/controller/jobs/pod/pod_controller.go b/pkg/controller/jobs/pod/pod_controller.go index 542d11473e..b6161ecaeb 100644 --- a/pkg/controller/jobs/pod/pod_controller.go +++ b/pkg/controller/jobs/pod/pod_controller.go @@ -144,7 +144,7 @@ var ( _ jobframework.ComposableJob = (*Pod)(nil) ) -func fromObject(o runtime.Object) *Pod { +func FromObject(o runtime.Object) *Pod { out := Pod{} out.pod = *o.(*corev1.Pod) return &out @@ -429,7 +429,7 @@ func (p *Pod) Stop(ctx context.Context, c client.Client, _ []podset.PodSetInfo, if !podsInGroup[i].DeletionTimestamp.IsZero() || (stopReason != jobframework.StopReasonWorkloadDeleted && podSuspended(&podsInGroup[i])) { continue } - podInGroup := fromObject(&podsInGroup[i]) + podInGroup := FromObject(&podsInGroup[i]) // The podset info is not relevant here, since this should mark the pod's end of life pCopy := &corev1.Pod{ @@ -654,7 +654,7 @@ func constructGroupPodSets(pods []corev1.Pod) ([]kueue.PodSet, error) { } if !podRoleFound { - podSet := fromObject(&podInGroup).PodSets() + podSet := FromObject(&podInGroup).PodSets() podSet[0].Name = roleHash resultPodSets = append(resultPodSets, podSet[0]) diff --git a/pkg/controller/jobs/pod/pod_controller_test.go b/pkg/controller/jobs/pod/pod_controller_test.go index c268f46838..640d7e273c 100644 --- a/pkg/controller/jobs/pod/pod_controller_test.go +++ b/pkg/controller/jobs/pod/pod_controller_test.go @@ -74,7 +74,7 @@ func TestPodsReady(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { - pod := fromObject(tc.pod) + pod := FromObject(tc.pod) got := pod.PodsReady() if tc.want != got { t.Errorf("Unexpected response (want: %v, got: %v)", tc.want, got) @@ -98,7 +98,7 @@ func TestRun(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { - pod := fromObject(&tc.pods[0]) + pod := FromObject(&tc.pods[0]) ctx, _ := utiltesting.ContextWithLog(t) clientBuilder := utiltesting.NewClientBuilder() @@ -3554,9 +3554,9 @@ func TestIsPodOwnerManagedByQueue(t *testing.T) { pod.OwnerReferences = append(pod.OwnerReferences, tc.ownerReference) - if tc.wantRes != IsPodOwnerManagedByKueue(fromObject(pod)) { + if tc.wantRes != IsPodOwnerManagedByKueue(FromObject(pod)) { t.Errorf("Unexpected 'IsPodOwnerManagedByKueue' result\n want: %t\n got: %t)", - tc.wantRes, IsPodOwnerManagedByKueue(fromObject(pod))) + tc.wantRes, IsPodOwnerManagedByKueue(FromObject(pod))) } }) } diff --git a/pkg/controller/jobs/pod/pod_webhook.go b/pkg/controller/jobs/pod/pod_webhook.go index b81ae06563..ecee0c6a90 100644 --- a/pkg/controller/jobs/pod/pod_webhook.go +++ b/pkg/controller/jobs/pod/pod_webhook.go @@ -133,7 +133,7 @@ func (p *Pod) addRoleHash() error { } func (w *PodWebhook) Default(ctx context.Context, obj runtime.Object) error { - pod := fromObject(obj) + pod := FromObject(obj) log := ctrl.LoggerFrom(ctx).WithName("pod-webhook").WithValues("pod", klog.KObj(&pod.pod)) log.V(5).Info("Applying defaults") @@ -201,7 +201,7 @@ var _ webhook.CustomValidator = &PodWebhook{} func (w *PodWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { var warnings admission.Warnings - pod := fromObject(obj) + pod := FromObject(obj) log := ctrl.LoggerFrom(ctx).WithName("pod-webhook").WithValues("pod", klog.KObj(&pod.pod)) log.V(5).Info("Validating create") allErrs := jobframework.ValidateCreateForQueueName(pod) @@ -220,8 +220,8 @@ func (w *PodWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (ad func (w *PodWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { var warnings admission.Warnings - oldPod := fromObject(oldObj) - newPod := fromObject(newObj) + oldPod := FromObject(oldObj) + newPod := FromObject(newObj) log := ctrl.LoggerFrom(ctx).WithName("pod-webhook").WithValues("pod", klog.KObj(&newPod.pod)) log.V(5).Info("Validating update") allErrs := jobframework.ValidateUpdateForQueueName(oldPod, newPod)