Skip to content

Commit

Permalink
Merge pull request kubernetes#119354 from gjkim42/fix-e2e-tests-overr…
Browse files Browse the repository at this point in the history
…iding-grace-period-of-probes

Never drop the `terminationGracePeriodSeconds` of a probe
  • Loading branch information
k8s-ci-robot committed Jul 17, 2023
2 parents 1da70b0 + 6aeff13 commit f412e92
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions pkg/api/pod/util.go
Expand Up @@ -516,20 +516,6 @@ func dropDisabledFields(
}
}

if !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
})
}

// If the feature is disabled and not in use, drop the hostUsers field.
if !utilfeature.DefaultFeatureGate.Enabled(features.UserNamespacesSupport) && !hostUsersInUse(oldPodSpec) {
// Drop the field in podSpec only if SecurityContext is not nil.
Expand Down Expand Up @@ -827,27 +813,6 @@ func appArmorInUse(podAnnotations map[string]string) bool {
return false
}

// 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
}

// schedulingGatesInUse returns true if the pod spec is non-nil and it has SchedulingGates field set.
func schedulingGatesInUse(podSpec *api.PodSpec) bool {
if podSpec == nil {
Expand Down

0 comments on commit f412e92

Please sign in to comment.