Skip to content

Commit 90391d2

Browse files
authored
fix: environment variable(Connection) may not exist (#14)
1 parent 0e4b60f commit 90391d2

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

internal/webhook/v1/pod_webhook.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,18 @@ func ParseTFReq(pod *corev1.Pod) []TFReq {
139139
ConnectionName: connectionNameEnv.Name,
140140
ConnectionNamespace: connectionNamespaceEnv.Name,
141141
}
142-
142+
connectionNameEnv, ok := lo.Find(container.Env, func(e corev1.EnvVar) bool {
143+
return e.Name == constants.ConnectionNameEnv
144+
})
145+
if ok {
146+
req.ConnectionName = connectionNameEnv.Name
147+
}
148+
connectionNamespaceEnv, ok := lo.Find(container.Env, func(e corev1.EnvVar) bool {
149+
return e.Name == constants.ConnectionNamespaceEnv
150+
})
151+
if ok {
152+
req.ConnectionNamespace = connectionNamespaceEnv.Name
153+
}
143154
// Parse TFLOPS requirement
144155
if hasTflops {
145156
tflops, err := resource.ParseQuantity(tflopsStr)
@@ -235,7 +246,6 @@ func (m *TensorFusionPodMutator) patchTFClient(pod *corev1.Pod, tfReq []TFReq) (
235246
}
236247

237248
// Generate JSON patch operations by comparing original and patched pod
238-
239249
strategicpatches, err := jsonpatch.CreatePatch(currentBytes, resultBytes)
240250
if err != nil {
241251
return nil, fmt.Errorf("create json patch: %v", err)

0 commit comments

Comments
 (0)