Skip to content

Commit

Permalink
get lint passing
Browse files Browse the repository at this point in the history
  • Loading branch information
kannon92 committed Oct 13, 2024
1 parent 88631bd commit 7990066
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 14 deletions.
1 change: 0 additions & 1 deletion config/components/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ rules:
- apiGroups:
- resource.k8s.io
resources:
- deviceclasses
- resourceclaimtemplates
verbs:
- get
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

apiVersion: kueue.x-k8s.io/v1beta1
kind: ResourceFlavor
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# One pod, one container
# Asking for 2 distinct GPUs

---
apiVersion: resource.k8s.io/v1alpha3
kind: ResourceClaimTemplate
metadata:
namespace: gpu-test2
name: multiple-gpus
spec:
spec:
devices:
requests:
- name: gpus
deviceClassName: gpu.example.com
allocationMode: ExactCount
count: 2

---
apiVersion: batch/v1
kind: Job
metadata:
namespace: gpu-test2
name: job0
labels:
app: job
kueue.x-k8s.io/queue-name: user-queue-gpu-test2
spec:
template:
spec:
restartPolicy: Never
containers:
- name: ctr0
image: ubuntu:22.04
command: ["bash", "-c"]
args: ["export; sleep 9999"]
resources:
claims:
- name: gpus
resourceClaims:
- name: gpus
resourceClaimTemplateName: multiple-gpus
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

apiVersion: kueue.x-k8s.io/v1beta1
kind: LocalQueue
metadata:
namespace: "gpu-test2"
name: "user-queue-gpu-test2"
spec:
clusterQueue: "cluster-queue"

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# One pod, two containers
# Each asking for shared access to a single GPU

---
apiVersion: v1
kind: Namespace
metadata:
name: gpu-test3

---
apiVersion: resource.k8s.io/v1alpha3
kind: ResourceClaimTemplate
metadata:
namespace: gpu-test3
name: single-gpu
spec:
spec:
devices:
requests:
- name: gpu
deviceClassName: gpu.example.com

---

apiVersion: batch/v1
kind: Job
metadata:
namespace: gpu-test3
name: job0
labels:
app: job
kueue.x-k8s.io/queue-name: "user-queue-gpu-test3"
spec:
parallelism: 1
completions: 1
template:
spec:
restartPolicy: Never
containers:
- name: ctr0
image: ubuntu:22.04
command: ["bash", "-c"]
args: ["export; sleep 9999"]
resources:
claims:
- name: shared-gpu
- name: ctr1
image: ubuntu:22.04
command: ["bash", "-c"]
args: ["export; sleep 9999"]
resources:
claims:
- name: shared-gpu
resourceClaims:
- name: shared-gpu
resourceClaimTemplateName: single-gpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

apiVersion: kueue.x-k8s.io/v1beta1
kind: LocalQueue
metadata:
namespace: "gpu-test3"
name: "user-queue-gpu-test3"
spec:
clusterQueue: "cluster-queue"

1 change: 0 additions & 1 deletion pkg/controller/core/clusterqueue_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ func NewClusterQueueReconciler(
// +kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=events,verbs=create;watch;update;patch
// +kubebuilder:rbac:groups=resource.k8s.io,resources=resourceclaimtemplates,verbs=get;list;watch
// +kubebuilder:rbac:groups=resource.k8s.io,resources=deviceclasses,verbs=get;list;watch
// +kubebuilder:rbac:groups=kueue.x-k8s.io,resources=clusterqueues,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=kueue.x-k8s.io,resources=clusterqueues/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=kueue.x-k8s.io,resources=clusterqueues/finalizers,verbs=update
Expand Down
16 changes: 8 additions & 8 deletions pkg/util/limitrange/limitrange.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/utils/ptr"

k8sresource "k8s.io/apimachinery/pkg/api/resource"

"sigs.k8s.io/kueue/pkg/util/resource"
)

Expand Down Expand Up @@ -150,32 +151,31 @@ func calculatePodClaims(ps *corev1.PodSpec) corev1.ResourceList {
// We want to track the number of claims for the pod.
for i := range ps.Containers {
for _, val := range containers[i].Resources.Claims {
totalClaims[val.Name] = totalClaims[val.Name] + 1
totalClaims[val.Name]++
}
}
for i := range initContainers {
for _, val := range initContainers[i].Resources.Claims {
totalClaims[val.Name] = totalClaims[val.Name] + 1
totalClaims[val.Name]++
}
}
for i := range initContainers {
if isSidecarContainer(initContainers[i]) {
for _, val := range initContainers[i].Resources.Claims {
totalClaims[val.Name] = totalClaims[val.Name] + 1
totalClaims[val.Name]++
}
}
}
for _, val := range ps.ResourceClaims {
_, ok := totalClaims[val.Name]
if ok {
keyName := ""
if ptr.Deref(val.ResourceClaimName, "") != "" {
switch {
case ptr.Deref(val.ResourceClaimName, "") != "":
keyName = *val.ResourceClaimName
} else if ptr.Deref(val.ResourceClaimTemplateName, "") != "" {
case ptr.Deref(val.ResourceClaimTemplateName, "") != "":
keyName = *val.ResourceClaimTemplateName
} else {
// TODO: figure out what to do in this case
// DRA API says this is not allowed
default:
return totalResourceClaimTemplate
}
countOfClaims, ok := totalResourceClaimTemplate[corev1.ResourceName(keyName)]
Expand Down
6 changes: 3 additions & 3 deletions pkg/workload/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
nodev1 "k8s.io/api/node/v1"
dra "k8s.io/api/resource/v1alpha3"
"k8s.io/apimachinery/pkg/api/resource"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1"
Expand Down Expand Up @@ -497,7 +497,7 @@ func TestAddDeviceClassesToContainerRequests(t *testing.T) {
enableDRAGate: false,
resourceClaimTemplate: []dra.ResourceClaimTemplate{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "single-gpu",
Namespace: "",
},
Expand Down Expand Up @@ -548,7 +548,7 @@ func TestAddDeviceClassesToContainerRequests(t *testing.T) {
enableDRAGate: true,
resourceClaimTemplate: []dra.ResourceClaimTemplate{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "single-gpu",
Namespace: "",
},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/config/common/manager_e2e_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
value: IfNotPresent
- op: add
path: /spec/template/spec/containers/0/args/-
value: --feature-gates=MultiKueue=true,MultiKueueBatchJobWithManagedBy=true
value: --feature-gates=VisibilityOnDemand=true,MultiKueue=true,MultiKueueBatchJobWithManagedBy=true,DynamicResourceStructuredParameters=true

0 comments on commit 7990066

Please sign in to comment.