@@ -100,24 +100,26 @@ func (w *rayClusterWebhook) Default(ctx context.Context, obj runtime.Object) err
100
100
}
101
101
102
102
// WorkerGroupSpec
103
- if len (rayCluster .Spec .WorkerGroupSpecs ) != 0 {
103
+ for i := range rayCluster .Spec .WorkerGroupSpecs {
104
+ workerSpec := & rayCluster .Spec .WorkerGroupSpecs [i ]
105
+
104
106
// Append the list of environment variables for the worker container
105
107
for _ , envVar := range envVarList () {
106
- rayCluster . Spec . WorkerGroupSpecs [ 0 ]. Template .Spec .Containers [0 ].Env = upsert (rayCluster . Spec . WorkerGroupSpecs [ 0 ] .Template .Spec .Containers [0 ].Env , envVar , withEnvVarName (envVar .Name ))
108
+ workerSpec . Template .Spec .Containers [0 ].Env = upsert (workerSpec .Template .Spec .Containers [0 ].Env , envVar , withEnvVarName (envVar .Name ))
107
109
}
108
110
109
- // Append the CA volumes
110
- for _ , caVol := range caVolumes (rayCluster ) {
111
- rayCluster . Spec . WorkerGroupSpecs [ 0 ]. Template .Spec .Volumes = upsert (rayCluster . Spec . WorkerGroupSpecs [ 0 ] .Template .Spec .Volumes , caVol , withVolumeName (caVol .Name ))
112
- }
111
+ // Append the CA volumes
112
+ for _ , caVol := range caVolumes (rayCluster ) {
113
+ workerSpec . Template .Spec .Volumes = upsert (workerSpec .Template .Spec .Volumes , caVol , withVolumeName (caVol .Name ))
114
+ }
113
115
114
- // Append the certificate volume mounts
115
- for _ , mount := range certVolumeMounts () {
116
- rayCluster . Spec . WorkerGroupSpecs [ 0 ]. Template .Spec .Containers [0 ].VolumeMounts = upsert (rayCluster . Spec . WorkerGroupSpecs [ 0 ] .Template .Spec .Containers [0 ].VolumeMounts , mount , byVolumeMountName )
117
- }
116
+ // Append the certificate volume mounts
117
+ for _ , mount := range certVolumeMounts () {
118
+ workerSpec . Template .Spec .Containers [0 ].VolumeMounts = upsert (workerSpec .Template .Spec .Containers [0 ].VolumeMounts , mount , byVolumeMountName )
119
+ }
118
120
119
- // Append the create-cert Init Container
120
- rayCluster . Spec . WorkerGroupSpecs [ 0 ]. Template .Spec .InitContainers = upsert (rayCluster . Spec . WorkerGroupSpecs [ 0 ] .Template .Spec .InitContainers , rayWorkerInitContainer (w .Config ), withContainerName (initContainerName ))
121
+ // Append the create-cert Init Container
122
+ workerSpec . Template .Spec .InitContainers = upsert (workerSpec .Template .Spec .InitContainers , rayWorkerInitContainer (w .Config ), withContainerName (initContainerName ))
121
123
}
122
124
}
123
125
@@ -387,14 +389,13 @@ func validateHeadInitContainer(rayCluster *rayv1.RayCluster, config *config.Kube
387
389
func validateWorkerInitContainer (rayCluster * rayv1.RayCluster , config * config.KubeRayConfiguration ) field.ErrorList {
388
390
var allErrors field.ErrorList
389
391
390
- if len (rayCluster .Spec .WorkerGroupSpecs ) == 0 {
391
- return allErrors
392
- }
393
-
394
- if err := contains (rayCluster .Spec .WorkerGroupSpecs [0 ].Template .Spec .InitContainers , rayWorkerInitContainer (config ), byContainerName ,
395
- field .NewPath ("spec" , "workerGroupSpecs" , "0" , "template" , "spec" , "initContainers" ),
396
- "create-cert Init Container is immutable" ); err != nil {
397
- allErrors = append (allErrors , err )
392
+ for i := range rayCluster .Spec .WorkerGroupSpecs {
393
+ workerSpec := & rayCluster .Spec .WorkerGroupSpecs [i ]
394
+ if err := contains (workerSpec .Template .Spec .InitContainers , rayWorkerInitContainer (config ), byContainerName ,
395
+ field .NewPath ("spec" , "workerGroupSpecs" , strconv .Itoa (i ), "template" , "spec" , "initContainers" ),
396
+ "create-cert Init Container is immutable" ); err != nil {
397
+ allErrors = append (allErrors , err )
398
+ }
398
399
}
399
400
400
401
return allErrors
@@ -409,9 +410,10 @@ func validateCaVolumes(rayCluster *rayv1.RayCluster) field.ErrorList {
409
410
"ca-vol and server-cert Secret volumes are immutable" ); err != nil {
410
411
allErrors = append (allErrors , err )
411
412
}
412
- if len (rayCluster .Spec .WorkerGroupSpecs ) != 0 {
413
- if err := contains (rayCluster .Spec .WorkerGroupSpecs [0 ].Template .Spec .Volumes , caVol , byVolumeName ,
414
- field .NewPath ("spec" , "workerGroupSpecs" , "0" , "template" , "spec" , "volumes" ),
413
+ for i := range rayCluster .Spec .WorkerGroupSpecs {
414
+ workerSpec := & rayCluster .Spec .WorkerGroupSpecs [i ]
415
+ if err := contains (workerSpec .Template .Spec .Volumes , caVol , byVolumeName ,
416
+ field .NewPath ("spec" , "workerGroupSpecs" , strconv .Itoa (i ), "template" , "spec" , "volumes" ),
415
417
"ca-vol and server-cert Secret volumes are immutable" ); err != nil {
416
418
allErrors = append (allErrors , err )
417
419
}
@@ -438,15 +440,14 @@ func validateHeadEnvVars(rayCluster *rayv1.RayCluster) field.ErrorList {
438
440
func validateWorkerEnvVars (rayCluster * rayv1.RayCluster ) field.ErrorList {
439
441
var allErrors field.ErrorList
440
442
441
- if len (rayCluster .Spec .WorkerGroupSpecs ) == 0 {
442
- return allErrors
443
- }
444
-
445
- for _ , envVar := range envVarList () {
446
- if err := contains (rayCluster .Spec .WorkerGroupSpecs [0 ].Template .Spec .Containers [0 ].Env , envVar , byEnvVarName ,
447
- field .NewPath ("spec" , "workerGroupSpecs" , "0" , "template" , "spec" , "containers" , strconv .Itoa (0 ), "env" ),
448
- "RAY_TLS related environment variables are immutable" ); err != nil {
449
- allErrors = append (allErrors , err )
443
+ for i := range rayCluster .Spec .WorkerGroupSpecs {
444
+ workerSpec := & rayCluster .Spec .WorkerGroupSpecs [i ]
445
+ for _ , envVar := range envVarList () {
446
+ if err := contains (workerSpec .Template .Spec .Containers [0 ].Env , envVar , byEnvVarName ,
447
+ field .NewPath ("spec" , "workerGroupSpecs" , strconv .Itoa (i ), "template" , "spec" , "containers" , strconv .Itoa (0 ), "env" ),
448
+ "RAY_TLS related environment variables are immutable" ); err != nil {
449
+ allErrors = append (allErrors , err )
450
+ }
450
451
}
451
452
}
452
453
0 commit comments