-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Do not set default values when unsupported multiple containers are defined #4709
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nak3: 0 warnings.
In response to this:
Proposed Changes
If multiple containers are defined but one container is returned after
setting default values, inappropriate error happens.To fix it, this patch stops setting default values when unsupported
multiple containers are defined./lint
Fixes #4706
Proposed Changes
- Do not set default values when unsupported multiple containers are defined
Release Note
NONE
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
Hi @nak3. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
cc @dgerd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ok-to-test
Could you provide the error message that's returned now?
Sure, here is the error message:
(I have added it to my PR description as well.) |
/assign @dgerd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect some test to change. Should we have a unit test that calls SetDefaults
and then Validate
to confirm this works as expected? Maybe our validation tests should call SetDefaults
anyway because that's ultimately the flow it's used in real code.
Thank you. Agreed. Current unit test already has the check, but we get wrong error actually.
Updated. |
The following is the coverage report on pkg/.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -36,6 +36,13 @@ func (rts *RevisionTemplateSpec) SetDefaults(ctx context.Context) { | |||
|
|||
// SetDefaults implements apis.Defaultable | |||
func (rs *RevisionSpec) SetDefaults(ctx context.Context) { | |||
// More than one container is not allowed for now. Do not set default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this works, it might be more appropriate to instead make it so that the code below sets defaults for all containers passed in through rs.PodSpec.Containers
.
This change creates coupling between defaulting and validation. If we have the defaulter just apply defaults to the array of containers passed in we keep the separation of concerns between the defaulter and the validator.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I was debating to post a similar thing.
001ed32
to
874906f
Compare
Thank you @dgerd and @markusthoemmes for the advice. I agreed and updated this PR. |
if len(rs.PodSpec.Containers) == 1 { | ||
container = rs.PodSpec.Containers[0] | ||
if len(rs.PodSpec.Containers) == 0 { | ||
rs.PodSpec.Containers = make([]corev1.Container, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am feeling that we do not need to set defaults when no container is specified, because it fails eventually due to missing image. But I added this as current code does so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree with you here. Just because we used to do it doesn't mean we should keep doing it. This seems unnecessary and I would be okay removing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the change to the test was swallowed somewhere? Care to add that back in?
Sure, thank you! I added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. I think you can remove the 0 container special case and just rebase.
Can you also double check we have sufficient test coverage in the validator unit tests for empty container and multi-containers now that we are not adding the SetDefaults() before the test.
if len(rs.PodSpec.Containers) == 1 { | ||
container = rs.PodSpec.Containers[0] | ||
if len(rs.PodSpec.Containers) == 0 { | ||
rs.PodSpec.Containers = make([]corev1.Container, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree with you here. Just because we used to do it doesn't mean we should keep doing it. This seems unnecessary and I would be okay removing it.
…fined If multiple containers are defined but one container is returned after setting default values, inappropriate error happens. To fix it, this patch stops setting default values when unsupported multiple containers are defined.
Thank you. Updated.
Yes, I checked we have the unit tests in both k8s validation and revision validation so it is sufficiently covered.
|
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dgerd, markusthoemmes, nak3 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Proposed Changes
If multiple containers are defined but one container is returned after
setting default values, inappropriate error happens.
To fix it, this patch stops setting default values when unsupported
multiple containers are defined.
/lint
Fixes #4706
After this PR, we will get the error as:
Proposed Changes
Release Note