mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Add feature flag ProbeTerminationGracePeriod, test field drop in API
This commit is contained in:
@@ -551,6 +551,20 @@ func dropDisabledFields(
|
||||
})
|
||||
}
|
||||
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.ProbeTerminationGracePeriod) && !probeGracePeriodInUse(oldPodSpec) {
|
||||
// Set pod-level terminationGracePeriodSeconds to nil if the feature is disabled and it is not used
|
||||
VisitContainers(podSpec, AllContainers, func(c *api.Container, containerType ContainerType) bool {
|
||||
if c.LivenessProbe != nil {
|
||||
c.LivenessProbe.TerminationGracePeriodSeconds = nil
|
||||
}
|
||||
if c.StartupProbe != nil {
|
||||
c.StartupProbe.TerminationGracePeriodSeconds = nil
|
||||
}
|
||||
// cannot be set for readiness probes
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
dropDisabledFSGroupFields(podSpec, oldPodSpec)
|
||||
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.PodOverhead) && !overheadInUse(oldPodSpec) {
|
||||
@@ -811,6 +825,27 @@ func subpathExprInUse(podSpec *api.PodSpec) bool {
|
||||
return inUse
|
||||
}
|
||||
|
||||
// probeGracePeriodInUse returns true if the pod spec is non-nil and has a probe that makes use
|
||||
// of the probe-level terminationGracePeriodSeconds feature
|
||||
func probeGracePeriodInUse(podSpec *api.PodSpec) bool {
|
||||
if podSpec == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
var inUse bool
|
||||
VisitContainers(podSpec, AllContainers, func(c *api.Container, containerType ContainerType) bool {
|
||||
// cannot be set for readiness probes
|
||||
if (c.LivenessProbe != nil && c.LivenessProbe.TerminationGracePeriodSeconds != nil) ||
|
||||
(c.StartupProbe != nil && c.StartupProbe.TerminationGracePeriodSeconds != nil) {
|
||||
inUse = true
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
return inUse
|
||||
}
|
||||
|
||||
// csiInUse returns true if any pod's spec include inline CSI volumes.
|
||||
func csiInUse(podSpec *api.PodSpec) bool {
|
||||
if podSpec == nil {
|
||||
|
||||
Reference in New Issue
Block a user