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

feat: function to mutate the pod spec. #64

Merged
merged 1 commit into from Sep 29, 2022
Merged

Conversation

jvanz
Copy link
Member

@jvanz jvanz commented Sep 28, 2022

Adds a new function in the SDK to help policy developers to mutate pod spec from the high level resources (e.g. deployment, statefulset, replicaset, etc).

Fix #63

@jvanz jvanz self-assigned this Sep 28, 2022
@jvanz jvanz requested a review from a team as a code owner September 28, 2022 18:10
Copy link
Contributor

@raulcabello raulcabello left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Member

@viccuad viccuad left a comment

Choose a reason for hiding this comment

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

LGTM!

src/lib.rs Outdated
Comment on lines 68 to 70
if let Some(ref mut spec) = deployment.spec {
spec.template.spec = Some(pod_spec);
}
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit of a corner case, but if deployment.spec is None, then the mutation is not done.

I would replace the code to be something like:

let mut deployment_spec = deployment.unwrap_or_default();
deployment_spec.template.spec = Some(pod_spec);
deployment.spec = Some(deployment_spec);

The same approach applies to the other types of resources being handled

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Adds a new function in the SDK to help policy developers to mutate pod
spec from the high level resources (e.g. deployment, statefulset,
replicaset, etc).
Copy link
Member

@flavio flavio left a comment

Choose a reason for hiding this comment

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

LGTM

@jvanz jvanz merged commit 284f833 into kubewarden:main Sep 29, 2022
@jvanz jvanz deleted the issue-63 branch September 29, 2022 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a function to mutate pod sec
4 participants