@@ -433,25 +433,36 @@ func SetNodePlacementPolicyCompact(nodepool *cspb.NodePool, tpuTopology string)
433
433
return nil
434
434
}
435
435
436
+ // addToleration adds a toleration to the pod if it doesn't already exist.
437
+ func addToleration (podSpec * v13.PodSpec , toleration v13.Toleration ) {
438
+ for _ , t := range podSpec .Tolerations {
439
+ if t == toleration {
440
+ return
441
+ }
442
+ }
443
+ podSpec .Tolerations = append (podSpec .Tolerations , toleration )
444
+ }
445
+
436
446
// ApplyPodSpec modifies a PodSpec to use this runtime.
437
447
func (t RuntimeType ) ApplyPodSpec (podSpec * v13.PodSpec ) {
438
448
switch t {
439
449
case RuntimeTypeGVisor :
440
450
podSpec .RuntimeClassName = proto .String (gvisorRuntimeClass )
441
451
podSpec .NodeSelector [NodepoolRuntimeKey ] = string (RuntimeTypeGVisor )
442
- podSpec . Tolerations = append (podSpec . Tolerations , v13.Toleration {
452
+ addToleration (podSpec , v13.Toleration {
443
453
Key : "nvidia.com/gpu" ,
444
454
Operator : v13 .TolerationOpExists ,
445
455
})
446
456
case RuntimeTypeUnsandboxed :
457
+ podSpec .RuntimeClassName = nil
447
458
podSpec .Tolerations = append (podSpec .Tolerations , v13.Toleration {
448
459
Key : "nvidia.com/gpu" ,
449
460
Operator : v13 .TolerationOpExists ,
450
461
})
451
462
// Allow the pod to schedule on gVisor nodes as well.
452
463
// This enables the use of `--test-nodepool-runtime=runc` to run
453
464
// unsandboxed benchmarks on gVisor test clusters.
454
- podSpec . Tolerations = append (podSpec . Tolerations , v13.Toleration {
465
+ addToleration (podSpec , v13.Toleration {
455
466
Effect : v13 .TaintEffectNoSchedule ,
456
467
Key : gvisorNodepoolKey ,
457
468
Operator : v13 .TolerationOpEqual ,
@@ -460,16 +471,16 @@ func (t RuntimeType) ApplyPodSpec(podSpec *v13.PodSpec) {
460
471
case RuntimeTypeGVisorTPU :
461
472
podSpec .RuntimeClassName = proto .String (gvisorRuntimeClass )
462
473
podSpec .NodeSelector [NodepoolRuntimeKey ] = string (RuntimeTypeGVisorTPU )
463
- podSpec . Tolerations = append (podSpec . Tolerations , v13.Toleration {
474
+ addToleration (podSpec , v13.Toleration {
464
475
Key : "google.com/tpu" ,
465
476
Operator : v13 .TolerationOpExists ,
466
477
})
467
478
case RuntimeTypeUnsandboxedTPU :
468
- podSpec . Tolerations = append (podSpec . Tolerations , v13.Toleration {
479
+ addToleration (podSpec , v13.Toleration {
469
480
Key : "google.com/tpu" ,
470
481
Operator : v13 .TolerationOpExists ,
471
482
})
472
- podSpec . Tolerations = append (podSpec . Tolerations , v13.Toleration {
483
+ addToleration (podSpec , v13.Toleration {
473
484
Effect : v13 .TaintEffectNoSchedule ,
474
485
Key : gvisorNodepoolKey ,
475
486
Operator : v13 .TolerationOpEqual ,
0 commit comments