Skip to content

Commit

Permalink
[pod] Export FromObject()
Browse files Browse the repository at this point in the history
  • Loading branch information
trasc committed Mar 18, 2024
1 parent 3da06a2 commit c49cfd6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions pkg/controller/jobs/pod/pod_controller.go
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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])
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/jobs/pod/pod_controller_test.go
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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)))
}
})
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/jobs/pod/pod_webhook.go
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit c49cfd6

Please sign in to comment.