mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 18:54:06 +00:00
Merge pull request #118768 from killshotrevival/master
Fail validation if container restart policy is 'Never' and resource resize restart policy isn't 'NotRequired'
This commit is contained in:
commit
e606314f2f
@ -3165,7 +3165,7 @@ func validatePullPolicy(policy core.PullPolicy, fldPath *field.Path) field.Error
|
|||||||
var supportedResizeResources = sets.NewString(string(core.ResourceCPU), string(core.ResourceMemory))
|
var supportedResizeResources = sets.NewString(string(core.ResourceCPU), string(core.ResourceMemory))
|
||||||
var supportedResizePolicies = sets.NewString(string(core.NotRequired), string(core.RestartContainer))
|
var supportedResizePolicies = sets.NewString(string(core.NotRequired), string(core.RestartContainer))
|
||||||
|
|
||||||
func validateResizePolicy(policyList []core.ContainerResizePolicy, fldPath *field.Path) field.ErrorList {
|
func validateResizePolicy(policyList []core.ContainerResizePolicy, fldPath *field.Path, podRestartPolicy *core.RestartPolicy) field.ErrorList {
|
||||||
allErrors := field.ErrorList{}
|
allErrors := field.ErrorList{}
|
||||||
|
|
||||||
// validate that resource name is not repeated, supported resource names and policy values are specified
|
// validate that resource name is not repeated, supported resource names and policy values are specified
|
||||||
@ -3189,13 +3189,17 @@ func validateResizePolicy(policyList []core.ContainerResizePolicy, fldPath *fiel
|
|||||||
default:
|
default:
|
||||||
allErrors = append(allErrors, field.NotSupported(fldPath, p.RestartPolicy, supportedResizePolicies.List()))
|
allErrors = append(allErrors, field.NotSupported(fldPath, p.RestartPolicy, supportedResizePolicies.List()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *podRestartPolicy == core.RestartPolicyNever && p.RestartPolicy != core.NotRequired {
|
||||||
|
allErrors = append(allErrors, field.Invalid(fldPath, p.RestartPolicy, "must be 'NotRequired' when `restartPolicy` is 'Never'"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return allErrors
|
return allErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateEphemeralContainers is called by pod spec and template validation to validate the list of ephemeral containers.
|
// validateEphemeralContainers is called by pod spec and template validation to validate the list of ephemeral containers.
|
||||||
// Note that this is called for pod template even though ephemeral containers aren't allowed in pod templates.
|
// Note that this is called for pod template even though ephemeral containers aren't allowed in pod templates.
|
||||||
func validateEphemeralContainers(ephemeralContainers []core.EphemeralContainer, containers, initContainers []core.Container, volumes map[string]core.VolumeSource, podClaimNames sets.String, fldPath *field.Path, opts PodValidationOptions) field.ErrorList {
|
func validateEphemeralContainers(ephemeralContainers []core.EphemeralContainer, containers, initContainers []core.Container, volumes map[string]core.VolumeSource, podClaimNames sets.String, fldPath *field.Path, opts PodValidationOptions, podRestartPolicy *core.RestartPolicy) field.ErrorList {
|
||||||
var allErrs field.ErrorList
|
var allErrs field.ErrorList
|
||||||
|
|
||||||
if len(ephemeralContainers) == 0 {
|
if len(ephemeralContainers) == 0 {
|
||||||
@ -3216,7 +3220,7 @@ func validateEphemeralContainers(ephemeralContainers []core.EphemeralContainer,
|
|||||||
idxPath := fldPath.Index(i)
|
idxPath := fldPath.Index(i)
|
||||||
|
|
||||||
c := (*core.Container)(&ec.EphemeralContainerCommon)
|
c := (*core.Container)(&ec.EphemeralContainerCommon)
|
||||||
allErrs = append(allErrs, validateContainerCommon(c, volumes, podClaimNames, idxPath, opts)...)
|
allErrs = append(allErrs, validateContainerCommon(c, volumes, podClaimNames, idxPath, opts, podRestartPolicy)...)
|
||||||
// Ephemeral containers don't need looser constraints for pod templates, so it's convenient to apply both validations
|
// Ephemeral containers don't need looser constraints for pod templates, so it's convenient to apply both validations
|
||||||
// here where we've already converted EphemeralContainerCommon to Container.
|
// here where we've already converted EphemeralContainerCommon to Container.
|
||||||
allErrs = append(allErrs, validateContainerOnlyForPod(c, idxPath)...)
|
allErrs = append(allErrs, validateContainerOnlyForPod(c, idxPath)...)
|
||||||
@ -3278,7 +3282,7 @@ func validateFieldAllowList(value interface{}, allowedFields map[string]bool, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// validateInitContainers is called by pod spec and template validation to validate the list of init containers
|
// validateInitContainers is called by pod spec and template validation to validate the list of init containers
|
||||||
func validateInitContainers(containers []core.Container, regularContainers []core.Container, volumes map[string]core.VolumeSource, podClaimNames sets.String, fldPath *field.Path, opts PodValidationOptions) field.ErrorList {
|
func validateInitContainers(containers []core.Container, regularContainers []core.Container, volumes map[string]core.VolumeSource, podClaimNames sets.String, fldPath *field.Path, opts PodValidationOptions, podRestartPolicy *core.RestartPolicy) field.ErrorList {
|
||||||
var allErrs field.ErrorList
|
var allErrs field.ErrorList
|
||||||
|
|
||||||
allNames := sets.String{}
|
allNames := sets.String{}
|
||||||
@ -3289,7 +3293,7 @@ func validateInitContainers(containers []core.Container, regularContainers []cor
|
|||||||
idxPath := fldPath.Index(i)
|
idxPath := fldPath.Index(i)
|
||||||
|
|
||||||
// Apply the validation common to all container types
|
// Apply the validation common to all container types
|
||||||
allErrs = append(allErrs, validateContainerCommon(&ctr, volumes, podClaimNames, idxPath, opts)...)
|
allErrs = append(allErrs, validateContainerCommon(&ctr, volumes, podClaimNames, idxPath, opts, podRestartPolicy)...)
|
||||||
|
|
||||||
restartAlways := false
|
restartAlways := false
|
||||||
// Apply the validation specific to init containers
|
// Apply the validation specific to init containers
|
||||||
@ -3344,7 +3348,7 @@ func validateInitContainers(containers []core.Container, regularContainers []cor
|
|||||||
|
|
||||||
// validateContainerCommon applies validation common to all container types. It's called by regular, init, and ephemeral
|
// validateContainerCommon applies validation common to all container types. It's called by regular, init, and ephemeral
|
||||||
// container list validation to require a properly formatted name, image, etc.
|
// container list validation to require a properly formatted name, image, etc.
|
||||||
func validateContainerCommon(ctr *core.Container, volumes map[string]core.VolumeSource, podClaimNames sets.String, path *field.Path, opts PodValidationOptions) field.ErrorList {
|
func validateContainerCommon(ctr *core.Container, volumes map[string]core.VolumeSource, podClaimNames sets.String, path *field.Path, opts PodValidationOptions, podRestartPolicy *core.RestartPolicy) field.ErrorList {
|
||||||
var allErrs field.ErrorList
|
var allErrs field.ErrorList
|
||||||
|
|
||||||
namePath := path.Child("name")
|
namePath := path.Child("name")
|
||||||
@ -3382,7 +3386,7 @@ func validateContainerCommon(ctr *core.Container, volumes map[string]core.Volume
|
|||||||
allErrs = append(allErrs, ValidateVolumeDevices(ctr.VolumeDevices, volMounts, volumes, path.Child("volumeDevices"))...)
|
allErrs = append(allErrs, ValidateVolumeDevices(ctr.VolumeDevices, volMounts, volumes, path.Child("volumeDevices"))...)
|
||||||
allErrs = append(allErrs, validatePullPolicy(ctr.ImagePullPolicy, path.Child("imagePullPolicy"))...)
|
allErrs = append(allErrs, validatePullPolicy(ctr.ImagePullPolicy, path.Child("imagePullPolicy"))...)
|
||||||
allErrs = append(allErrs, ValidateResourceRequirements(&ctr.Resources, podClaimNames, path.Child("resources"), opts)...)
|
allErrs = append(allErrs, ValidateResourceRequirements(&ctr.Resources, podClaimNames, path.Child("resources"), opts)...)
|
||||||
allErrs = append(allErrs, validateResizePolicy(ctr.ResizePolicy, path.Child("resizePolicy"))...)
|
allErrs = append(allErrs, validateResizePolicy(ctr.ResizePolicy, path.Child("resizePolicy"), podRestartPolicy)...)
|
||||||
allErrs = append(allErrs, ValidateSecurityContext(ctr.SecurityContext, path.Child("securityContext"))...)
|
allErrs = append(allErrs, ValidateSecurityContext(ctr.SecurityContext, path.Child("securityContext"))...)
|
||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
@ -3416,7 +3420,7 @@ func validateHostUsers(spec *core.PodSpec, fldPath *field.Path) field.ErrorList
|
|||||||
}
|
}
|
||||||
|
|
||||||
// validateContainers is called by pod spec and template validation to validate the list of regular containers.
|
// validateContainers is called by pod spec and template validation to validate the list of regular containers.
|
||||||
func validateContainers(containers []core.Container, volumes map[string]core.VolumeSource, podClaimNames sets.String, fldPath *field.Path, opts PodValidationOptions) field.ErrorList {
|
func validateContainers(containers []core.Container, volumes map[string]core.VolumeSource, podClaimNames sets.String, fldPath *field.Path, opts PodValidationOptions, podRestartPolicy *core.RestartPolicy) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
|
|
||||||
if len(containers) == 0 {
|
if len(containers) == 0 {
|
||||||
@ -3428,7 +3432,7 @@ func validateContainers(containers []core.Container, volumes map[string]core.Vol
|
|||||||
path := fldPath.Index(i)
|
path := fldPath.Index(i)
|
||||||
|
|
||||||
// Apply validation common to all containers
|
// Apply validation common to all containers
|
||||||
allErrs = append(allErrs, validateContainerCommon(&ctr, volumes, podClaimNames, path, opts)...)
|
allErrs = append(allErrs, validateContainerCommon(&ctr, volumes, podClaimNames, path, opts, podRestartPolicy)...)
|
||||||
|
|
||||||
// Container names must be unique within the list of regular containers.
|
// Container names must be unique within the list of regular containers.
|
||||||
// Collisions with init or ephemeral container names will be detected by the init or ephemeral
|
// Collisions with init or ephemeral container names will be detected by the init or ephemeral
|
||||||
@ -3974,9 +3978,9 @@ func ValidatePodSpec(spec *core.PodSpec, podMeta *metav1.ObjectMeta, fldPath *fi
|
|||||||
allErrs = append(allErrs, vErrs...)
|
allErrs = append(allErrs, vErrs...)
|
||||||
podClaimNames := gatherPodResourceClaimNames(spec.ResourceClaims)
|
podClaimNames := gatherPodResourceClaimNames(spec.ResourceClaims)
|
||||||
allErrs = append(allErrs, validatePodResourceClaims(podMeta, spec.ResourceClaims, fldPath.Child("resourceClaims"))...)
|
allErrs = append(allErrs, validatePodResourceClaims(podMeta, spec.ResourceClaims, fldPath.Child("resourceClaims"))...)
|
||||||
allErrs = append(allErrs, validateContainers(spec.Containers, vols, podClaimNames, fldPath.Child("containers"), opts)...)
|
allErrs = append(allErrs, validateContainers(spec.Containers, vols, podClaimNames, fldPath.Child("containers"), opts, &spec.RestartPolicy)...)
|
||||||
allErrs = append(allErrs, validateInitContainers(spec.InitContainers, spec.Containers, vols, podClaimNames, fldPath.Child("initContainers"), opts)...)
|
allErrs = append(allErrs, validateInitContainers(spec.InitContainers, spec.Containers, vols, podClaimNames, fldPath.Child("initContainers"), opts, &spec.RestartPolicy)...)
|
||||||
allErrs = append(allErrs, validateEphemeralContainers(spec.EphemeralContainers, spec.Containers, spec.InitContainers, vols, podClaimNames, fldPath.Child("ephemeralContainers"), opts)...)
|
allErrs = append(allErrs, validateEphemeralContainers(spec.EphemeralContainers, spec.Containers, spec.InitContainers, vols, podClaimNames, fldPath.Child("ephemeralContainers"), opts, &spec.RestartPolicy)...)
|
||||||
allErrs = append(allErrs, validatePodHostNetworkDeps(spec, fldPath, opts)...)
|
allErrs = append(allErrs, validatePodHostNetworkDeps(spec, fldPath, opts)...)
|
||||||
allErrs = append(allErrs, validateRestartPolicy(&spec.RestartPolicy, fldPath.Child("restartPolicy"))...)
|
allErrs = append(allErrs, validateRestartPolicy(&spec.RestartPolicy, fldPath.Child("restartPolicy"))...)
|
||||||
allErrs = append(allErrs, validateDNSPolicy(&spec.DNSPolicy, fldPath.Child("dnsPolicy"))...)
|
allErrs = append(allErrs, validateDNSPolicy(&spec.DNSPolicy, fldPath.Child("dnsPolicy"))...)
|
||||||
|
@ -6828,80 +6828,127 @@ func TestValidateResizePolicy(t *testing.T) {
|
|||||||
tSupportedResizeResources := sets.NewString(string(core.ResourceCPU), string(core.ResourceMemory))
|
tSupportedResizeResources := sets.NewString(string(core.ResourceCPU), string(core.ResourceMemory))
|
||||||
tSupportedResizePolicies := sets.NewString(string(core.NotRequired), string(core.RestartContainer))
|
tSupportedResizePolicies := sets.NewString(string(core.NotRequired), string(core.RestartContainer))
|
||||||
type T struct {
|
type T struct {
|
||||||
PolicyList []core.ContainerResizePolicy
|
PolicyList []core.ContainerResizePolicy
|
||||||
ExpectError bool
|
ExpectError bool
|
||||||
Errors field.ErrorList
|
Errors field.ErrorList
|
||||||
|
PodRestartPolicy core.RestartPolicy
|
||||||
}
|
}
|
||||||
|
|
||||||
testCases := map[string]T{
|
testCases := map[string]T{
|
||||||
"ValidCPUandMemoryPolicies": {
|
"ValidCPUandMemoryPolicies": {
|
||||||
[]core.ContainerResizePolicy{
|
PolicyList: []core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", RestartPolicy: "NotRequired"},
|
{ResourceName: "cpu", RestartPolicy: "NotRequired"},
|
||||||
{ResourceName: "memory", RestartPolicy: "RestartContainer"},
|
{ResourceName: "memory", RestartPolicy: "RestartContainer"},
|
||||||
},
|
},
|
||||||
false,
|
ExpectError: false,
|
||||||
nil,
|
Errors: nil,
|
||||||
|
PodRestartPolicy: "Always",
|
||||||
},
|
},
|
||||||
"ValidCPUPolicy": {
|
"ValidCPUPolicy": {
|
||||||
[]core.ContainerResizePolicy{
|
PolicyList: []core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", RestartPolicy: "RestartContainer"},
|
{ResourceName: "cpu", RestartPolicy: "RestartContainer"},
|
||||||
},
|
},
|
||||||
false,
|
ExpectError: false,
|
||||||
nil,
|
Errors: nil,
|
||||||
|
PodRestartPolicy: "Always",
|
||||||
},
|
},
|
||||||
"ValidMemoryPolicy": {
|
"ValidMemoryPolicy": {
|
||||||
[]core.ContainerResizePolicy{
|
PolicyList: []core.ContainerResizePolicy{
|
||||||
{ResourceName: "memory", RestartPolicy: "NotRequired"},
|
{ResourceName: "memory", RestartPolicy: "NotRequired"},
|
||||||
},
|
},
|
||||||
false,
|
ExpectError: false,
|
||||||
nil,
|
Errors: nil,
|
||||||
|
PodRestartPolicy: "Always",
|
||||||
},
|
},
|
||||||
"NoPolicy": {
|
"NoPolicy": {
|
||||||
[]core.ContainerResizePolicy{},
|
PolicyList: []core.ContainerResizePolicy{},
|
||||||
false,
|
ExpectError: false,
|
||||||
nil,
|
Errors: nil,
|
||||||
|
PodRestartPolicy: "Always",
|
||||||
},
|
},
|
||||||
"ValidCPUandInvalidMemoryPolicy": {
|
"ValidCPUandInvalidMemoryPolicy": {
|
||||||
[]core.ContainerResizePolicy{
|
PolicyList: []core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", RestartPolicy: "NotRequired"},
|
{ResourceName: "cpu", RestartPolicy: "NotRequired"},
|
||||||
{ResourceName: "memory", RestartPolicy: "Restarrrt"},
|
{ResourceName: "memory", RestartPolicy: "Restarrrt"},
|
||||||
},
|
},
|
||||||
true,
|
ExpectError: true,
|
||||||
field.ErrorList{field.NotSupported(field.NewPath("field"), core.ResourceResizeRestartPolicy("Restarrrt"), tSupportedResizePolicies.List())},
|
Errors: field.ErrorList{field.NotSupported(field.NewPath("field"), core.ResourceResizeRestartPolicy("Restarrrt"), tSupportedResizePolicies.List())},
|
||||||
|
PodRestartPolicy: "Always",
|
||||||
},
|
},
|
||||||
"ValidMemoryandInvalidCPUPolicy": {
|
"ValidMemoryandInvalidCPUPolicy": {
|
||||||
[]core.ContainerResizePolicy{
|
PolicyList: []core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", RestartPolicy: "RestartNotRequirrred"},
|
{ResourceName: "cpu", RestartPolicy: "RestartNotRequirrred"},
|
||||||
{ResourceName: "memory", RestartPolicy: "RestartContainer"},
|
{ResourceName: "memory", RestartPolicy: "RestartContainer"},
|
||||||
},
|
},
|
||||||
true,
|
ExpectError: true,
|
||||||
field.ErrorList{field.NotSupported(field.NewPath("field"), core.ResourceResizeRestartPolicy("RestartNotRequirrred"), tSupportedResizePolicies.List())},
|
Errors: field.ErrorList{field.NotSupported(field.NewPath("field"), core.ResourceResizeRestartPolicy("RestartNotRequirrred"), tSupportedResizePolicies.List())},
|
||||||
|
PodRestartPolicy: "Always",
|
||||||
},
|
},
|
||||||
"InvalidResourceNameValidPolicy": {
|
"InvalidResourceNameValidPolicy": {
|
||||||
[]core.ContainerResizePolicy{
|
PolicyList: []core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpuuu", RestartPolicy: "NotRequired"},
|
{ResourceName: "cpuuu", RestartPolicy: "NotRequired"},
|
||||||
},
|
},
|
||||||
true,
|
ExpectError: true,
|
||||||
field.ErrorList{field.NotSupported(field.NewPath("field"), core.ResourceName("cpuuu"), tSupportedResizeResources.List())},
|
Errors: field.ErrorList{field.NotSupported(field.NewPath("field"), core.ResourceName("cpuuu"), tSupportedResizeResources.List())},
|
||||||
|
PodRestartPolicy: "Always",
|
||||||
},
|
},
|
||||||
"ValidResourceNameMissingPolicy": {
|
"ValidResourceNameMissingPolicy": {
|
||||||
[]core.ContainerResizePolicy{
|
PolicyList: []core.ContainerResizePolicy{
|
||||||
{ResourceName: "memory", RestartPolicy: ""},
|
{ResourceName: "memory", RestartPolicy: ""},
|
||||||
},
|
},
|
||||||
true,
|
ExpectError: true,
|
||||||
field.ErrorList{field.Required(field.NewPath("field"), "")},
|
Errors: field.ErrorList{field.Required(field.NewPath("field"), "")},
|
||||||
|
PodRestartPolicy: "Always",
|
||||||
},
|
},
|
||||||
"RepeatedPolicies": {
|
"RepeatedPolicies": {
|
||||||
[]core.ContainerResizePolicy{
|
PolicyList: []core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", RestartPolicy: "NotRequired"},
|
{ResourceName: "cpu", RestartPolicy: "NotRequired"},
|
||||||
{ResourceName: "memory", RestartPolicy: "RestartContainer"},
|
{ResourceName: "memory", RestartPolicy: "RestartContainer"},
|
||||||
{ResourceName: "cpu", RestartPolicy: "RestartContainer"},
|
{ResourceName: "cpu", RestartPolicy: "RestartContainer"},
|
||||||
},
|
},
|
||||||
true,
|
ExpectError: true,
|
||||||
field.ErrorList{field.Duplicate(field.NewPath("field").Index(2), core.ResourceCPU)},
|
Errors: field.ErrorList{field.Duplicate(field.NewPath("field").Index(2), core.ResourceCPU)},
|
||||||
|
PodRestartPolicy: "Always",
|
||||||
|
},
|
||||||
|
"InvalidCPUPolicyWithPodRestartPolicy": {
|
||||||
|
PolicyList: []core.ContainerResizePolicy{
|
||||||
|
{ResourceName: "cpu", RestartPolicy: "NotRequired"},
|
||||||
|
{ResourceName: "memory", RestartPolicy: "RestartContainer"},
|
||||||
|
},
|
||||||
|
ExpectError: true,
|
||||||
|
Errors: field.ErrorList{field.Invalid(field.NewPath("field"), core.ResourceResizeRestartPolicy("RestartContainer"), "must be 'NotRequired' when `restartPolicy` is 'Never'")},
|
||||||
|
PodRestartPolicy: "Never",
|
||||||
|
},
|
||||||
|
"InvalidMemoryPolicyWithPodRestartPolicy": {
|
||||||
|
PolicyList: []core.ContainerResizePolicy{
|
||||||
|
{ResourceName: "cpu", RestartPolicy: "RestartContainer"},
|
||||||
|
{ResourceName: "memory", RestartPolicy: "NotRequired"},
|
||||||
|
},
|
||||||
|
ExpectError: true,
|
||||||
|
Errors: field.ErrorList{field.Invalid(field.NewPath("field"), core.ResourceResizeRestartPolicy("RestartContainer"), "must be 'NotRequired' when `restartPolicy` is 'Never'")},
|
||||||
|
PodRestartPolicy: "Never",
|
||||||
|
},
|
||||||
|
"InvalidMemoryCPUPolicyWithPodRestartPolicy": {
|
||||||
|
PolicyList: []core.ContainerResizePolicy{
|
||||||
|
{ResourceName: "cpu", RestartPolicy: "RestartContainer"},
|
||||||
|
{ResourceName: "memory", RestartPolicy: "RestartContainer"},
|
||||||
|
},
|
||||||
|
ExpectError: true,
|
||||||
|
Errors: field.ErrorList{field.Invalid(field.NewPath("field"), core.ResourceResizeRestartPolicy("RestartContainer"), "must be 'NotRequired' when `restartPolicy` is 'Never'"), field.Invalid(field.NewPath("field"), core.ResourceResizeRestartPolicy("RestartContainer"), "must be 'NotRequired' when `restartPolicy` is 'Never'")},
|
||||||
|
PodRestartPolicy: "Never",
|
||||||
|
},
|
||||||
|
"ValidMemoryCPUPolicyWithPodRestartPolicy": {
|
||||||
|
PolicyList: []core.ContainerResizePolicy{
|
||||||
|
{ResourceName: "cpu", RestartPolicy: "NotRequired"},
|
||||||
|
{ResourceName: "memory", RestartPolicy: "NotRequired"},
|
||||||
|
},
|
||||||
|
ExpectError: false,
|
||||||
|
Errors: nil,
|
||||||
|
PodRestartPolicy: "Never",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for k, v := range testCases {
|
for k, v := range testCases {
|
||||||
errs := validateResizePolicy(v.PolicyList, field.NewPath("field"))
|
errs := validateResizePolicy(v.PolicyList, field.NewPath("field"), &v.PodRestartPolicy)
|
||||||
if !v.ExpectError && len(errs) > 0 {
|
if !v.ExpectError && len(errs) > 0 {
|
||||||
t.Errorf("Testcase %s - expected success, got error: %+v", k, errs)
|
t.Errorf("Testcase %s - expected success, got error: %+v", k, errs)
|
||||||
}
|
}
|
||||||
@ -6997,7 +7044,19 @@ func TestValidateEphemeralContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
} {
|
} {
|
||||||
if errs := validateEphemeralContainers(ephemeralContainers, containers, initContainers, vols, nil, field.NewPath("ephemeralContainers"), PodValidationOptions{}); len(errs) != 0 {
|
var PodRestartPolicy core.RestartPolicy
|
||||||
|
PodRestartPolicy = "Never"
|
||||||
|
if errs := validateEphemeralContainers(ephemeralContainers, containers, initContainers, vols, nil, field.NewPath("ephemeralContainers"), PodValidationOptions{}, &PodRestartPolicy); len(errs) != 0 {
|
||||||
|
t.Errorf("expected success for '%s' but got errors: %v", title, errs)
|
||||||
|
}
|
||||||
|
|
||||||
|
PodRestartPolicy = "Always"
|
||||||
|
if errs := validateEphemeralContainers(ephemeralContainers, containers, initContainers, vols, nil, field.NewPath("ephemeralContainers"), PodValidationOptions{}, &PodRestartPolicy); len(errs) != 0 {
|
||||||
|
t.Errorf("expected success for '%s' but got errors: %v", title, errs)
|
||||||
|
}
|
||||||
|
|
||||||
|
PodRestartPolicy = "OnFailure"
|
||||||
|
if errs := validateEphemeralContainers(ephemeralContainers, containers, initContainers, vols, nil, field.NewPath("ephemeralContainers"), PodValidationOptions{}, &PodRestartPolicy); len(errs) != 0 {
|
||||||
t.Errorf("expected success for '%s' but got errors: %v", title, errs)
|
t.Errorf("expected success for '%s' but got errors: %v", title, errs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7316,9 +7375,25 @@ func TestValidateEphemeralContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var PodRestartPolicy core.RestartPolicy
|
||||||
|
|
||||||
for _, tc := range tcs {
|
for _, tc := range tcs {
|
||||||
t.Run(tc.title+"__@L"+tc.line, func(t *testing.T) {
|
t.Run(tc.title+"__@L"+tc.line, func(t *testing.T) {
|
||||||
errs := validateEphemeralContainers(tc.ephemeralContainers, containers, initContainers, vols, nil, field.NewPath("ephemeralContainers"), PodValidationOptions{})
|
|
||||||
|
PodRestartPolicy = "Never"
|
||||||
|
errs := validateEphemeralContainers(tc.ephemeralContainers, containers, initContainers, vols, nil, field.NewPath("ephemeralContainers"), PodValidationOptions{}, &PodRestartPolicy)
|
||||||
|
if len(errs) == 0 {
|
||||||
|
t.Fatal("expected error but received none")
|
||||||
|
}
|
||||||
|
|
||||||
|
PodRestartPolicy = "Always"
|
||||||
|
errs = validateEphemeralContainers(tc.ephemeralContainers, containers, initContainers, vols, nil, field.NewPath("ephemeralContainers"), PodValidationOptions{}, &PodRestartPolicy)
|
||||||
|
if len(errs) == 0 {
|
||||||
|
t.Fatal("expected error but received none")
|
||||||
|
}
|
||||||
|
|
||||||
|
PodRestartPolicy = "OnFailure"
|
||||||
|
errs = validateEphemeralContainers(tc.ephemeralContainers, containers, initContainers, vols, nil, field.NewPath("ephemeralContainers"), PodValidationOptions{}, &PodRestartPolicy)
|
||||||
if len(errs) == 0 {
|
if len(errs) == 0 {
|
||||||
t.Fatal("expected error but received none")
|
t.Fatal("expected error but received none")
|
||||||
}
|
}
|
||||||
@ -7616,7 +7691,10 @@ func TestValidateContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if errs := validateContainers(successCase, volumeDevices, nil, field.NewPath("field"), PodValidationOptions{}); len(errs) != 0 {
|
|
||||||
|
var PodRestartPolicy core.RestartPolicy
|
||||||
|
PodRestartPolicy = "Always"
|
||||||
|
if errs := validateContainers(successCase, volumeDevices, nil, field.NewPath("field"), PodValidationOptions{}, &PodRestartPolicy); len(errs) != 0 {
|
||||||
t.Errorf("expected success: %v", errs)
|
t.Errorf("expected success: %v", errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8227,9 +8305,10 @@ func TestValidateContainers(t *testing.T) {
|
|||||||
field.ErrorList{{Type: field.ErrorTypeForbidden, Field: "containers[0].restartPolicy"}},
|
field.ErrorList{{Type: field.ErrorTypeForbidden, Field: "containers[0].restartPolicy"}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range errorCases {
|
for _, tc := range errorCases {
|
||||||
t.Run(tc.title+"__@L"+tc.line, func(t *testing.T) {
|
t.Run(tc.title+"__@L"+tc.line, func(t *testing.T) {
|
||||||
errs := validateContainers(tc.containers, volumeDevices, nil, field.NewPath("containers"), PodValidationOptions{})
|
errs := validateContainers(tc.containers, volumeDevices, nil, field.NewPath("containers"), PodValidationOptions{}, &PodRestartPolicy)
|
||||||
if len(errs) == 0 {
|
if len(errs) == 0 {
|
||||||
t.Fatal("expected error but received none")
|
t.Fatal("expected error but received none")
|
||||||
}
|
}
|
||||||
@ -8317,7 +8396,9 @@ func TestValidateInitContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if errs := validateInitContainers(successCase, containers, volumeDevices, nil, field.NewPath("field"), PodValidationOptions{}); len(errs) != 0 {
|
var PodRestartPolicy core.RestartPolicy
|
||||||
|
PodRestartPolicy = "Never"
|
||||||
|
if errs := validateInitContainers(successCase, containers, volumeDevices, nil, field.NewPath("field"), PodValidationOptions{}, &PodRestartPolicy); len(errs) != 0 {
|
||||||
t.Errorf("expected success: %v", errs)
|
t.Errorf("expected success: %v", errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8693,9 +8774,10 @@ func TestValidateInitContainers(t *testing.T) {
|
|||||||
field.ErrorList{{Type: field.ErrorTypeRequired, Field: "initContainers[0].lifecycle.preStop", BadValue: ""}},
|
field.ErrorList{{Type: field.ErrorTypeRequired, Field: "initContainers[0].lifecycle.preStop", BadValue: ""}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range errorCases {
|
for _, tc := range errorCases {
|
||||||
t.Run(tc.title+"__@L"+tc.line, func(t *testing.T) {
|
t.Run(tc.title+"__@L"+tc.line, func(t *testing.T) {
|
||||||
errs := validateInitContainers(tc.initContainers, containers, volumeDevices, nil, field.NewPath("initContainers"), PodValidationOptions{})
|
errs := validateInitContainers(tc.initContainers, containers, volumeDevices, nil, field.NewPath("initContainers"), PodValidationOptions{}, &PodRestartPolicy)
|
||||||
if len(errs) == 0 {
|
if len(errs) == 0 {
|
||||||
t.Fatal("expected error but received none")
|
t.Fatal("expected error but received none")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user