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

Do not set default values when unsupported multiple containers are defined #4709

Merged
merged 6 commits into from
Jul 17, 2019

Conversation

nak3
Copy link
Contributor

@nak3 nak3 commented Jul 11, 2019

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:

$ kubectl create -f test.yaml 
Error from server (InternalError): error when creating "test.yaml": Internal error occurred: admission webhook "webhook.serving.knative.dev" denied the request: mutation failed: expected exactly one, got both: spec.template.spec.containers

Proposed Changes

  • Do not set default values when unsupported multiple containers are defined

Release Note

NONE

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 11, 2019
@knative-prow-robot knative-prow-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. area/API API objects and controllers labels Jul 11, 2019
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a 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.

@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 11, 2019
@knative-prow-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@nak3
Copy link
Contributor Author

nak3 commented Jul 11, 2019

cc @dgerd

Copy link
Contributor

@markusthoemmes markusthoemmes left a 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?

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 11, 2019
@nak3
Copy link
Contributor Author

nak3 commented Jul 11, 2019

Sure, here is the error message:

$ kubectl create -f test.yaml 
Error from server (InternalError): error when creating "test.yaml": Internal error occurred: admission webhook "webhook.serving.knative.dev" denied the request: mutation failed: expected exactly one, got both: spec.template.spec.containers

(I have added it to my PR description as well.)

@markusthoemmes
Copy link
Contributor

/assign @dgerd

Copy link
Contributor

@markusthoemmes markusthoemmes left a 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.

@nak3 nak3 force-pushed the multi-container branch from 6630998 to b119c64 Compare July 11, 2019 11:03
@knative-prow-robot knative-prow-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 11, 2019
@nak3
Copy link
Contributor Author

nak3 commented Jul 11, 2019

Thank you. Agreed. Current unit test already has the check, but we get wrong error actually.

Updated.

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/serving/v1beta1/revision_defaults.go 87.5% 88.2% 0.7

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

Thanks @nak3!

/approve

Leaving for @dgerd to leave a LGTM.

@@ -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
Copy link

@dgerd dgerd Jul 11, 2019

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?

Copy link
Contributor

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.

@nak3 nak3 force-pushed the multi-container branch from b119c64 to debf139 Compare July 13, 2019 10:58
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 13, 2019
@nak3 nak3 force-pushed the multi-container branch 2 times, most recently from 001ed32 to 874906f Compare July 13, 2019 11:11
@nak3
Copy link
Contributor Author

nak3 commented Jul 13, 2019

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)
Copy link
Contributor Author

@nak3 nak3 Jul 13, 2019

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.

Copy link

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.

Copy link
Contributor

@markusthoemmes markusthoemmes left a 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?

@nak3 nak3 force-pushed the multi-container branch from 874906f to 8cadf36 Compare July 15, 2019 15:24
@nak3
Copy link
Contributor Author

nak3 commented Jul 15, 2019

Sure, thank you! I added defaulting multiple containers test into defaulter instead of SetDefaults to validator, as they should keep the separation. I hope I did not misunderstand it.

Copy link

@dgerd dgerd left a 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)
Copy link

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.

@nak3 nak3 force-pushed the multi-container branch from 8cadf36 to d25d103 Compare July 17, 2019 00:31
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 17, 2019
@nak3
Copy link
Contributor Author

nak3 commented Jul 17, 2019

Thank you. Updated.

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.

Yes, I checked we have the unit tests in both k8s validation and revision validation so it is sufficiently covered.

name: "too many containers",

name: "empty container",


@dgerd
Copy link

dgerd commented Jul 17, 2019

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 17, 2019
@knative-prow-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 17, 2019
@knative-prow-robot knative-prow-robot merged commit 6dbec1f into knative:master Jul 17, 2019
@nak3 nak3 deleted the multi-container branch July 17, 2019 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/API API objects and controllers cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad error message when multiple containers defined
6 participants