Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding exception for init container resource checks #126

Merged
merged 1 commit into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/validator/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func ValidateContainer(cnConf *conf.Configuration, container *corev1.Container,
}

func (cv *ContainerValidation) validateResources(resConf *conf.Resources) {
// Only validate resources for primary containers. Although it can
// be helpful to set these in certain cases, it usually isn't
if cv.IsInitContainer {
return
}

category := messages.CategoryResources
res := cv.Container.Resources

Expand Down
21 changes: 21 additions & 0 deletions pkg/validator/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,27 @@ func TestValidateResourcesPartiallyValid(t *testing.T) {
testValidateResources(t, &container, &resourceConf1, &expectedErrors, &expectedWarnings)
}

func TestValidateResourcesInit(t *testing.T) {
cvEmpty := ContainerValidation{
Container: &corev1.Container{},
ResourceValidation: &ResourceValidation{},
}
cvInit := ContainerValidation{
Container: &corev1.Container{},
ResourceValidation: &ResourceValidation{},
IsInitContainer: true,
}

parsedConf, err := conf.Parse([]byte(resourceConf1))
assert.NoError(t, err, "Expected no error when parsing config")

cvEmpty.validateResources(&parsedConf.Resources)
assert.Len(t, cvEmpty.Errors, 4)

cvInit.validateResources(&parsedConf.Resources)
assert.Len(t, cvInit.Errors, 0)
}

func TestValidateResourcesFullyValid(t *testing.T) {
cpuRequest, err := resource.ParseQuantity("300m")
assert.NoError(t, err, "Error parsing quantity")
Expand Down