|
6 | 6 | "errors"
|
7 | 7 | "fmt"
|
8 | 8 | "io/ioutil"
|
9 |
| - "math" |
10 | 9 | "net/http"
|
11 | 10 | "sort"
|
12 | 11 | "strconv"
|
@@ -478,66 +477,35 @@ func addResourceLimits(tpl *corev1.PodTemplateSpec, namespace string, gpuRequire
|
478 | 477 | Value: t["limits"],
|
479 | 478 | })
|
480 | 479 | }
|
481 |
| - if typeKey == constants.VirtAiTechVGPU { |
482 |
| - gmem := int(math.Ceil(gpuRequired.AsApproximateFloat64() / 1024 / 1024)) |
483 |
| - envNames := make([]string, 0) |
484 |
| - for envIdx, env := range container.Env { |
485 |
| - if env.Name == constants.EnvOrionVGPU { |
486 |
| - envNames = append(envNames, env.Name) |
487 |
| - patch = append(patch, genPatchesForEnv(constants.PatchOpReplace, i, envIdx, constants.EnvOrionVGPU, "1")...) |
488 |
| - } |
489 |
| - if env.Name == constants.EnvOrionClientID { |
490 |
| - envNames = append(envNames, env.Name) |
491 |
| - patch = append(patch, genPatchesForEnv(constants.PatchOpReplace, i, envIdx, constants.EnvOrionClientID, namespace)...) |
492 |
| - } |
493 |
| - if env.Name == constants.EnvOrionTaskName { |
494 |
| - envNames = append(envNames, env.Name) |
495 |
| - patch = append(patch, genPatchesForEnv(constants.PatchOpReplace, i, envIdx, constants.EnvOrionTaskName, |
496 |
| - fmt.Sprintf("%s-%s", namespace, container.Name))...) |
497 |
| - } |
498 |
| - if env.Name == constants.EnvOrionGMEM { |
499 |
| - envNames = append(envNames, env.Name) |
500 |
| - patch = append(patch, genPatchesForEnv(constants.PatchOpReplace, i, envIdx, constants.EnvOrionGMEM, strconv.Itoa(gmem))...) |
501 |
| - } |
502 |
| - if env.Name == constants.EnvOrionReserved { |
503 |
| - envNames = append(envNames, env.Name) |
504 |
| - patch = append(patch, genPatchesForEnv(constants.PatchOpReplace, i, envIdx, constants.EnvOrionReserved, "0")...) |
505 |
| - } |
506 |
| - } |
507 |
| - |
508 |
| - envs := []string{constants.EnvOrionVGPU, constants.EnvOrionClientID, constants.EnvOrionTaskName, |
509 |
| - constants.EnvOrionGMEM, constants.EnvOrionReserved} |
510 |
| - |
511 |
| - for _, name := range envs { |
512 |
| - if !funk.Contains(envNames, name) { |
513 |
| - if name == constants.EnvOrionVGPU { |
514 |
| - patch = append(patch, genPatchesForEnv(constants.PatchOpAdd, i, -1, name, "1")...) |
515 |
| - } |
516 |
| - if name == constants.EnvOrionClientID { |
517 |
| - patch = append(patch, genPatchesForEnv(constants.PatchOpAdd, i, -1, name, namespace)...) |
518 |
| - } |
519 |
| - if name == constants.EnvOrionTaskName { |
520 |
| - patch = append(patch, genPatchesForEnv(constants.PatchOpAdd, i, -1, name, |
521 |
| - fmt.Sprintf("%s-%s", namespace, container.Name))...) |
522 |
| - } |
523 |
| - if name == constants.EnvOrionGMEM { |
524 |
| - patch = append(patch, genPatchesForEnv(constants.PatchOpAdd, i, -1, name, strconv.Itoa(gmem))...) |
525 |
| - } |
526 |
| - if name == constants.EnvOrionReserved { |
527 |
| - patch = append(patch, genPatchesForEnv(constants.PatchOpAdd, i, -1, name, "0")...) |
528 |
| - } |
529 |
| - } |
530 |
| - } |
531 |
| - } |
532 | 480 | envNames := make([]string, 0)
|
533 |
| - for envIdx, env := range container.Env { |
| 481 | + if len(container.Env) == 0 { |
| 482 | + value := make([]map[string]string, 0) |
534 | 483 | for _, e := range envKeyValues {
|
535 | 484 | if e.Value == "" {
|
536 | 485 | continue
|
537 | 486 | }
|
538 |
| - if env.Name == e.Key { |
539 |
| - envNames = append(envNames, env.Name) |
540 |
| - patch = append(patch, genPatchesForEnv(constants.PatchOpReplace, i, envIdx, e.Key, e.Value)...) |
| 487 | + envNames = append(envNames, e.Key) |
| 488 | + value = append(value, map[string]string{ |
| 489 | + "name": e.Key, |
| 490 | + "value": e.Value, |
| 491 | + }) |
| 492 | + } |
| 493 | + op := patchOp{ |
| 494 | + Op: "add", |
| 495 | + Path: fmt.Sprintf("/spec/template/spec/containers/%d/env", i), |
| 496 | + Value: value, |
| 497 | + } |
| 498 | + patch = append(patch, op) |
| 499 | + } else { |
| 500 | + for envIdx, env := range container.Env { |
| 501 | + for _, e := range envKeyValues { |
| 502 | + if e.Value == "" { |
| 503 | + continue |
| 504 | + } |
| 505 | + if env.Name == e.Key { |
| 506 | + envNames = append(envNames, env.Name) |
| 507 | + patch = append(patch, genPatchesForEnv(constants.PatchOpReplace, i, envIdx, e.Key, e.Value)...) |
| 508 | + } |
541 | 509 | }
|
542 | 510 | }
|
543 | 511 | }
|
|
0 commit comments