mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Warn if the terminationGracePeriodSeconds is negative.
Co-authored-by: Jordan Liggitt <jordan@liggitt.net>
This commit is contained in:
parent
5e5c543b13
commit
4bdc1364ea
@ -250,5 +250,9 @@ func warningsForPodSpecAndMeta(fieldPath *field.Path, podSpec *api.PodSpec, meta
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// warn if the terminationGracePeriodSeconds is negative.
|
||||||
|
if podSpec.TerminationGracePeriodSeconds != nil && *podSpec.TerminationGracePeriodSeconds < 0 {
|
||||||
|
warnings = append(warnings, fmt.Sprintf("%s: must be >= 0; negative values are invalid and will be treated as 1", fieldPath.Child("spec", "terminationGracePeriodSeconds")))
|
||||||
|
}
|
||||||
return warnings
|
return warnings
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
api "k8s.io/kubernetes/pkg/apis/core"
|
||||||
|
utilpointer "k8s.io/utils/pointer"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkNoWarnings(b *testing.B) {
|
func BenchmarkNoWarnings(b *testing.B) {
|
||||||
@ -489,6 +490,18 @@ func TestWarnings(t *testing.T) {
|
|||||||
`spec.volumes[0].ephemeral.volumeClaimTemplate.spec.resources.requests[storage]: fractional byte value "200m" is invalid, must be an integer`,
|
`spec.volumes[0].ephemeral.volumeClaimTemplate.spec.resources.requests[storage]: fractional byte value "200m" is invalid, must be an integer`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "terminationGracePeriodSeconds is negative",
|
||||||
|
template: &api.PodTemplateSpec{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{},
|
||||||
|
Spec: api.PodSpec{
|
||||||
|
TerminationGracePeriodSeconds: utilpointer.Int64Ptr(-1),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []string{
|
||||||
|
`spec.terminationGracePeriodSeconds: must be >= 0; negative values are invalid and will be treated as 1`,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testcases {
|
for _, tc := range testcases {
|
||||||
|
Loading…
Reference in New Issue
Block a user