sigs.k8s.io/kueue@v0.6.2/pkg/visibility/api/rest/utils.go (about)

     1  // Copyright 2023 The Kubernetes Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package rest
    16  
    17  import (
    18  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    19  
    20  	"sigs.k8s.io/kueue/apis/visibility/v1alpha1"
    21  	"sigs.k8s.io/kueue/pkg/workload"
    22  )
    23  
    24  func newPendingWorkload(wlInfo *workload.Info, positionInLq int32, positionInCq int) *v1alpha1.PendingWorkload {
    25  	ownerReferences := make([]metav1.OwnerReference, 0, len(wlInfo.Obj.OwnerReferences))
    26  	for _, ref := range wlInfo.Obj.OwnerReferences {
    27  		ownerReferences = append(ownerReferences, metav1.OwnerReference{
    28  			APIVersion: ref.APIVersion,
    29  			Kind:       ref.Kind,
    30  			Name:       ref.Name,
    31  			UID:        ref.UID,
    32  		})
    33  	}
    34  	return &v1alpha1.PendingWorkload{
    35  		ObjectMeta: metav1.ObjectMeta{
    36  			Name:              wlInfo.Obj.Name,
    37  			Namespace:         wlInfo.Obj.Namespace,
    38  			OwnerReferences:   ownerReferences,
    39  			CreationTimestamp: wlInfo.Obj.CreationTimestamp,
    40  		},
    41  		PositionInClusterQueue: int32(positionInCq),
    42  		Priority:               *wlInfo.Obj.Spec.Priority,
    43  		LocalQueueName:         wlInfo.Obj.Spec.QueueName,
    44  		PositionInLocalQueue:   positionInLq,
    45  	}
    46  }