@@ -3343,14 +3343,58 @@ func validateHandler(handler commonHandler, gracePeriod *int64, fldPath *field.P
3343
3343
return allErrors
3344
3344
}
3345
3345
3346
- func validateLifecycle (lifecycle * core.Lifecycle , gracePeriod * int64 , fldPath * field.Path , opts PodValidationOptions ) field.ErrorList {
3346
+ var supportedStopSignalsLinux = sets .New (
3347
+ core .SIGABRT , core .SIGALRM , core .SIGBUS , core .SIGCHLD ,
3348
+ core .SIGCLD , core .SIGCONT , core .SIGFPE , core .SIGHUP ,
3349
+ core .SIGILL , core .SIGINT , core .SIGIO , core .SIGIOT ,
3350
+ core .SIGKILL , core .SIGPIPE , core .SIGPOLL , core .SIGPROF ,
3351
+ core .SIGPWR , core .SIGQUIT , core .SIGSEGV , core .SIGSTKFLT ,
3352
+ core .SIGSTOP , core .SIGSYS , core .SIGTERM , core .SIGTRAP ,
3353
+ core .SIGTSTP , core .SIGTTIN , core .SIGTTOU , core .SIGURG ,
3354
+ core .SIGUSR1 , core .SIGUSR2 , core .SIGVTALRM , core .SIGWINCH ,
3355
+ core .SIGXCPU , core .SIGXFSZ , core .SIGRTMIN , core .SIGRTMINPLUS1 ,
3356
+ core .SIGRTMINPLUS2 , core .SIGRTMINPLUS3 , core .SIGRTMINPLUS4 ,
3357
+ core .SIGRTMINPLUS5 , core .SIGRTMINPLUS6 , core .SIGRTMINPLUS7 ,
3358
+ core .SIGRTMINPLUS8 , core .SIGRTMINPLUS9 , core .SIGRTMINPLUS10 ,
3359
+ core .SIGRTMINPLUS11 , core .SIGRTMINPLUS12 , core .SIGRTMINPLUS13 ,
3360
+ core .SIGRTMINPLUS14 , core .SIGRTMINPLUS15 , core .SIGRTMAXMINUS14 ,
3361
+ core .SIGRTMAXMINUS13 , core .SIGRTMAXMINUS12 , core .SIGRTMAXMINUS11 ,
3362
+ core .SIGRTMAXMINUS10 , core .SIGRTMAXMINUS9 , core .SIGRTMAXMINUS8 ,
3363
+ core .SIGRTMAXMINUS7 , core .SIGRTMAXMINUS6 , core .SIGRTMAXMINUS5 ,
3364
+ core .SIGRTMAXMINUS4 , core .SIGRTMAXMINUS3 , core .SIGRTMAXMINUS2 ,
3365
+ core .SIGRTMAXMINUS1 , core .SIGRTMAX )
3366
+
3367
+ var supportedStopSignalsWindows = sets .New (core .SIGKILL , core .SIGTERM )
3368
+
3369
+ func validateStopSignal (stopSignal * core.Signal , fldPath * field.Path , os * core.PodOS ) field.ErrorList {
3370
+ allErrors := field.ErrorList {}
3371
+
3372
+ if os == nil {
3373
+ allErrors = append (allErrors , field .Forbidden (fldPath , "may not be set for containers with empty `spec.os.name`" ))
3374
+ } else if os .Name == core .Windows {
3375
+ if ! supportedStopSignalsWindows .Has (* stopSignal ) {
3376
+ allErrors = append (allErrors , field .NotSupported (fldPath , stopSignal , sets .List (supportedStopSignalsWindows )))
3377
+ }
3378
+ } else if os .Name == core .Linux {
3379
+ if ! supportedStopSignalsLinux .Has (* stopSignal ) {
3380
+ allErrors = append (allErrors , field .NotSupported (fldPath , stopSignal , sets .List (supportedStopSignalsLinux )))
3381
+ }
3382
+ }
3383
+
3384
+ return allErrors
3385
+ }
3386
+
3387
+ func validateLifecycle (lifecycle * core.Lifecycle , gracePeriod * int64 , fldPath * field.Path , opts PodValidationOptions , os * core.PodOS ) field.ErrorList {
3347
3388
allErrs := field.ErrorList {}
3348
3389
if lifecycle .PostStart != nil {
3349
3390
allErrs = append (allErrs , validateHandler (handlerFromLifecycle (lifecycle .PostStart ), gracePeriod , fldPath .Child ("postStart" ), opts )... )
3350
3391
}
3351
3392
if lifecycle .PreStop != nil {
3352
3393
allErrs = append (allErrs , validateHandler (handlerFromLifecycle (lifecycle .PreStop ), gracePeriod , fldPath .Child ("preStop" ), opts )... )
3353
3394
}
3395
+ if lifecycle .StopSignal != nil {
3396
+ allErrs = append (allErrs , validateStopSignal (lifecycle .StopSignal , fldPath .Child ("stopSignal" ), os )... )
3397
+ }
3354
3398
return allErrs
3355
3399
}
3356
3400
@@ -3494,7 +3538,7 @@ func validateFieldAllowList(value interface{}, allowedFields map[string]bool, er
3494
3538
}
3495
3539
3496
3540
// validateInitContainers is called by pod spec and template validation to validate the list of init containers
3497
- func validateInitContainers (containers []core.Container , regularContainers []core.Container , volumes map [string ]core.VolumeSource , podClaimNames sets.Set [string ], gracePeriod * int64 , fldPath * field.Path , opts PodValidationOptions , podRestartPolicy * core.RestartPolicy , hostUsers bool ) field.ErrorList {
3541
+ func validateInitContainers (containers []core.Container , os * core. PodOS , regularContainers []core.Container , volumes map [string ]core.VolumeSource , podClaimNames sets.Set [string ], gracePeriod * int64 , fldPath * field.Path , opts PodValidationOptions , podRestartPolicy * core.RestartPolicy , hostUsers bool ) field.ErrorList {
3498
3542
var allErrs field.ErrorList
3499
3543
3500
3544
allNames := sets.Set [string ]{}
@@ -3528,7 +3572,7 @@ func validateInitContainers(containers []core.Container, regularContainers []cor
3528
3572
switch {
3529
3573
case restartAlways :
3530
3574
if ctr .Lifecycle != nil {
3531
- allErrs = append (allErrs , validateLifecycle (ctr .Lifecycle , gracePeriod , idxPath .Child ("lifecycle" ), opts )... )
3575
+ allErrs = append (allErrs , validateLifecycle (ctr .Lifecycle , gracePeriod , idxPath .Child ("lifecycle" ), opts , os )... )
3532
3576
}
3533
3577
allErrs = append (allErrs , validateLivenessProbe (ctr .LivenessProbe , gracePeriod , idxPath .Child ("livenessProbe" ), opts )... )
3534
3578
allErrs = append (allErrs , validateReadinessProbe (ctr .ReadinessProbe , gracePeriod , idxPath .Child ("readinessProbe" ), opts )... )
@@ -3632,7 +3676,7 @@ func validateHostUsers(spec *core.PodSpec, fldPath *field.Path) field.ErrorList
3632
3676
}
3633
3677
3634
3678
// validateContainers is called by pod spec and template validation to validate the list of regular containers.
3635
- func validateContainers (containers []core.Container , volumes map [string ]core.VolumeSource , podClaimNames sets.Set [string ], gracePeriod * int64 , fldPath * field.Path , opts PodValidationOptions , podRestartPolicy * core.RestartPolicy , hostUsers bool ) field.ErrorList {
3679
+ func validateContainers (containers []core.Container , os * core. PodOS , volumes map [string ]core.VolumeSource , podClaimNames sets.Set [string ], gracePeriod * int64 , fldPath * field.Path , opts PodValidationOptions , podRestartPolicy * core.RestartPolicy , hostUsers bool ) field.ErrorList {
3636
3680
allErrs := field.ErrorList {}
3637
3681
3638
3682
if len (containers ) == 0 {
@@ -3660,7 +3704,7 @@ func validateContainers(containers []core.Container, volumes map[string]core.Vol
3660
3704
// Regular init container and ephemeral container validation will return
3661
3705
// field.Forbidden() for these paths.
3662
3706
if ctr .Lifecycle != nil {
3663
- allErrs = append (allErrs , validateLifecycle (ctr .Lifecycle , gracePeriod , path .Child ("lifecycle" ), opts )... )
3707
+ allErrs = append (allErrs , validateLifecycle (ctr .Lifecycle , gracePeriod , path .Child ("lifecycle" ), opts , os )... )
3664
3708
}
3665
3709
allErrs = append (allErrs , validateLivenessProbe (ctr .LivenessProbe , gracePeriod , path .Child ("livenessProbe" ), opts )... )
3666
3710
allErrs = append (allErrs , validateReadinessProbe (ctr .ReadinessProbe , gracePeriod , path .Child ("readinessProbe" ), opts )... )
@@ -4207,8 +4251,8 @@ func ValidatePodSpec(spec *core.PodSpec, podMeta *metav1.ObjectMeta, fldPath *fi
4207
4251
allErrs = append (allErrs , vErrs ... )
4208
4252
podClaimNames := gatherPodResourceClaimNames (spec .ResourceClaims )
4209
4253
allErrs = append (allErrs , validatePodResourceClaims (podMeta , spec .ResourceClaims , fldPath .Child ("resourceClaims" ))... )
4210
- allErrs = append (allErrs , validateContainers (spec .Containers , vols , podClaimNames , gracePeriod , fldPath .Child ("containers" ), opts , & spec .RestartPolicy , hostUsers )... )
4211
- allErrs = append (allErrs , validateInitContainers (spec .InitContainers , spec .Containers , vols , podClaimNames , gracePeriod , fldPath .Child ("initContainers" ), opts , & spec .RestartPolicy , hostUsers )... )
4254
+ allErrs = append (allErrs , validateContainers (spec .Containers , spec . OS , vols , podClaimNames , gracePeriod , fldPath .Child ("containers" ), opts , & spec .RestartPolicy , hostUsers )... )
4255
+ allErrs = append (allErrs , validateInitContainers (spec .InitContainers , spec .OS , spec . Containers , vols , podClaimNames , gracePeriod , fldPath .Child ("initContainers" ), opts , & spec .RestartPolicy , hostUsers )... )
4212
4256
allErrs = append (allErrs , validateEphemeralContainers (spec .EphemeralContainers , spec .Containers , spec .InitContainers , vols , podClaimNames , fldPath .Child ("ephemeralContainers" ), opts , & spec .RestartPolicy , hostUsers )... )
4213
4257
4214
4258
if opts .PodLevelResourcesEnabled {
0 commit comments