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

Add possibility to add resource request/limit to initContainer #121

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

moandersson
Copy link

This commit enables user to configure resource request and limit for cpu and memory on the "setup-ca-certs" initContainer.

By not being able to set resources it blocks creation of the Pod if a namespace has a ResourceQuota in place.

Copy link
Collaborator

@chenbh chenbh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add some tests?

@@ -8,6 +8,7 @@ import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/pkg/errors"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing import for resource.MustParse()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed MustParse()

if resources.Requests == nil {
resources.Requests = corev1.ResourceList{}
}
resources.Requests[corev1.ResourceCPU] = resource.MustParse(cpuRequest)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MustParse will cause the controller to panic if the env var is misconfigured, we should use the form that returns an error and handle that instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a helper function to parse the envvar and handle the exception if it fails. However, I am not sure how we should handle the exception, currently it will just print a warning message, but maybe we would like to not configure the resources if any of the inputs are misconfigured?

This commit enables user to configure resource request and limit for cpu
and memory on the "setup-ca-certs" initContainer.

By not being able to set resources it blocks creation of the Pod if a
namespace has a ResourceQuota in place.

Signed-off-by: Mattias Andersson <[email protected]>
@moandersson moandersson force-pushed the feature/add_resource_to_initcontainer branch from 08fc149 to 290c27e Compare January 30, 2025 23:16
@moandersson
Copy link
Author

Can you also add some tests?

I've added some tests. Let me know if anything is missing

@moandersson moandersson requested a review from chenbh February 12, 2025 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants