Skip to content

Commit 350525a

Browse files
committed
feat(webhook): fix tensor fusion pod mutation handler tests
1 parent e9de902 commit 350525a

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

.github/workflows/test-e2e.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: E2E Tests
22

33
on:
4-
push:
5-
pull_request:
4+
workflow_dispatch:
5+
# push:
6+
# pull_request:
67

78
jobs:
89
test-e2e:

config/crd/bases/tensor-fusion.ai_tensorfusionconnections.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ spec:
9191
properties:
9292
connectionURL:
9393
type: string
94-
node:
94+
gpu:
9595
type: string
9696
phase:
9797
type: string

internal/webhook/v1/pod_webhook.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func (m *TensorFusionPodMutator) Handle(ctx context.Context, req admission.Reque
6767
log.Info("Mutating pod", "name", pod.Name, "namespace", pod.Namespace)
6868

6969
reqs := parseTFReq(pod)
70+
if len(reqs) == 0 {
71+
return admission.Allowed("no tensor fusion requirements found")
72+
}
73+
7074
// 1. Inject initContainer and env variables
7175
patches, err := m.patchTFClient(pod, reqs)
7276
if err != nil {
@@ -108,9 +112,14 @@ func parseTFReq(pod *corev1.Pod) []TFReq {
108112
for _, container := range pod.Spec.Containers {
109113
containerName := container.Name
110114

111-
// Check if tensor fusion is enabled for this container
112-
enableKey := fmt.Sprintf(constants.EnableContainerAnnotationFormat, containerName)
113-
if enableStr, ok := pod.Annotations[enableKey]; !ok || enableStr != "true" {
115+
// Check if TF requirements exist for this container
116+
tflopsKey := fmt.Sprintf(constants.TFLOPSContainerAnnotationFormat, containerName)
117+
vramKey := fmt.Sprintf(constants.VRAMContainerAnnotationFormat, containerName)
118+
119+
tflopsStr, hasTflops := pod.Annotations[tflopsKey]
120+
vramStr, hasVram := pod.Annotations[vramKey]
121+
122+
if !hasTflops && !hasVram {
114123
continue
115124
}
116125

@@ -119,17 +128,15 @@ func parseTFReq(pod *corev1.Pod) []TFReq {
119128
}
120129

121130
// Parse TFLOPS requirement
122-
tflopsKey := fmt.Sprintf(constants.TFLOPSContainerAnnotationFormat, containerName)
123-
if tflopsStr, ok := pod.Annotations[tflopsKey]; ok {
131+
if hasTflops {
124132
tflops, err := resource.ParseQuantity(tflopsStr)
125133
if err == nil {
126134
req.Tflops = tflops
127135
}
128136
}
129137

130138
// Parse VRAM requirement
131-
vramKey := fmt.Sprintf(constants.VRAMContainerAnnotationFormat, containerName)
132-
if vramStr, ok := pod.Annotations[vramKey]; ok {
139+
if hasVram {
133140
vram, err := resource.ParseQuantity(vramStr)
134141
if err == nil {
135142
req.Vram = vram

internal/webhook/v1/pod_webhook_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
tfv1 "github.com/NexusGPU/tensor-fusion-operator/api/v1"
2525
"github.com/NexusGPU/tensor-fusion-operator/internal/config"
26+
"github.com/NexusGPU/tensor-fusion-operator/internal/constants"
2627
. "github.com/onsi/ginkgo/v2"
2728
. "github.com/onsi/gomega"
2829
admissionv1 "k8s.io/api/admission/v1"
@@ -67,8 +68,8 @@ var _ = Describe("TensorFusionPodMutator", func() {
6768
Name: "test-pod",
6869
Namespace: "default",
6970
Annotations: map[string]string{
70-
"tf.nexusgpu.com/tflops": "100",
71-
"tf.nexusgpu.com/vram": "16Gi",
71+
constants.TensorFusionDomain + "/tflops-main": "100",
72+
constants.TensorFusionDomain + "/vram-main": "16Gi",
7273
},
7374
},
7475
Spec: corev1.PodSpec{
@@ -158,8 +159,8 @@ var _ = Describe("TensorFusionPodMutator", func() {
158159
pod := &corev1.Pod{
159160
ObjectMeta: metav1.ObjectMeta{
160161
Annotations: map[string]string{
161-
"tf.nexusgpu.com/tflops": "100",
162-
"tf.nexusgpu.com/vram": "16Gi",
162+
constants.TensorFusionDomain + "/tflops-test-container": "100",
163+
constants.TensorFusionDomain + "/vram-test-container": "16Gi",
163164
},
164165
},
165166
Spec: corev1.PodSpec{

0 commit comments

Comments
 (0)