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

ingress: rename backend to defaultBackend for ingress v1 #80179

Closed
wants to merge 1 commit into from

Conversation

cmluciano
Copy link

@cmluciano cmluciano commented Jul 15, 2019

Signed-off-by: Christopher M. Luciano cmluciano@us.ibm.com

What type of PR is this?
/kind api-change

What this PR does / why we need it:
Per the Ingress v1 KEP, we are renaming the backend field in IngressSpec to
clarify its intended use. Appropriate defaults are added to ensure backend is
converted to the new field type.

Which issue(s) this PR fixes:
Related kubernetes/enhancements#758

Special notes for your reviewer:

  • Update APIs
  • Add conversion logic for v1beta1 & v1
  • Add conversion logic tests

Does this PR introduce a user-facing change?:

ingress: rename backend to defaultBackend for ingress v1

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jul 15, 2019
@cmluciano
Copy link
Author

cc @aledbf @bowei

@k8s-ci-robot k8s-ci-robot added sig/network Categorizes an issue or PR as relevant to SIG Network. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 15, 2019
@bowei
Copy link
Member

bowei commented Jul 17, 2019

thanks for picking this up :-)

@cmluciano
Copy link
Author

/priority important-soon
/milestone 1.16

@k8s-ci-robot
Copy link
Contributor

@cmluciano: You must be a member of the kubernetes/milestone-maintainers GitHub team to set the milestone. If you believe you should be able to issue the /milestone command, please contact your and have them propose you as an additional delegate for this responsibility.

In response to this:

/priority important-soon
/milestone 1.16

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.

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jul 18, 2019
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 18, 2019
@cmluciano
Copy link
Author

Just need to add tests tomorrow and then will flip this to "ready"

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 19, 2019
@k8s-ci-robot k8s-ci-robot modified the milestones: v1.17, v1.18 Nov 13, 2019
@cmluciano
Copy link
Author

Thanks @josiahbjorgaard we plan for this to be combined with other PRs for 1.18

@thockin
Copy link
Member

thockin commented Dec 23, 2019

Revisiting this, I still have zero idea how to solve this.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 23, 2019
@cmluciano
Copy link
Author

@thockin Jordan shared some examples at KubeCon with me. I am taking a look at how this is done in the admissionregistration package and will pull some examples out of there.

@thockin
Copy link
Member

thockin commented Jan 6, 2020

I spent time over holidays poking at this. A "real" fix might be long in coming, but @deads2k shared a cute trick.

Take a look at https://github.com/kubernetes/kubernetes/compare/master...thockin:hack-ingress-versioned-validation?expand=1

If we plumb that down, we can use it to choose a name for the error

@cmluciano
Copy link
Author

@thockin Just saw this now, thanks! I believe this is what my commit is missing to fix the tests.

@cmluciano cmluciano force-pushed the cml/ingdefaultbackend branch 2 times, most recently from e2c493a to c4d43b8 Compare January 15, 2020 19:38
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 15, 2020
@cmluciano
Copy link
Author

@liggitt I think I'm pretty close on this one. The last failure is seems to be the storage test. I think the problem might be that it is missing requestInfo details like I have in strategy.

make test WHAT=./pkg/registry/networking/ingress/storage/...
+++ [0203 16:49:40] Running tests without code coverage
I0203 16:49:43.116015   11059 client.go:361] parsed scheme: "endpoint"
I0203 16:49:43.116161   11059 endpoint.go:68] ccResolverWrapper: sending new addresses to cc: [{unix://localhost:84153270101107355820  <nil> 0 <nil>}]
I0203 16:49:43.118499   11059 client.go:361] parsed scheme: "endpoint"
I0203 16:49:43.118579   11059 endpoint.go:68] ccResolverWrapper: sending new addresses to cc: [{unix://localhost:84153270101107355820  <nil> 0 <nil>}]
I0203 16:49:43.119787   11059 client.go:361] parsed scheme: "endpoint"
I0203 16:49:43.119852   11059 endpoint.go:68] ccResolverWrapper: sending new addresses to cc: [{unix://localhost:84153270101107355820  <nil> 0 <nil>}]
--- FAIL: TestCreate (0.09s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x15d075c]

goroutine 145 [running]:
testing.tRunner.func1(0xc000506300)
	/usr/local/go/src/testing/testing.go:874 +0x3a3
panic(0x1ba77c0, 0x323af60)
	/usr/local/go/src/runtime/panic.go:679 +0x1b2
k8s.io/kubernetes/pkg/registry/networking/ingress.ingressStrategy.Validate(0x215d0e0, 0xc0001e3960, 0x21517c0, 0x3281680, 0x219cec0, 0xc0007045d0, 0x2156e20, 0xc000483080, 0x0, 0x0, ...)
	/home/cmluciano/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/pkg/registry/networking/ingress/strategy.go:79 +0x6c
k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/registry/rest.BeforeCreate(0x21ba680, 0xc0001544c0, 0x219cec0, 0xc0007045d0, 0x2156e20, 0xc000483080, 0x48, 0x1cb8440)
	/home/cmluciano/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/registry/rest/create.go:105 +0x2de
k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/registry/generic/registry.(*Store).Create(0xc000299b00, 0x219cec0, 0xc0007045d0, 0x2156e20, 0xc000483080, 0x1f1df58, 0xc0004840f0, 0xc00068a700, 0xc00068a400, 0x20, ...)
	/home/cmluciano/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/registry/generic/registry/store.go:338 +0x81
k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/registry/rest/resttest.(*Tester).testCreateHasMetadata(0xc0007043f0, 0x2156e20, 0xc000483080)
	/home/cmluciano/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/registry/rest/resttest/resttest.go:392 +0x1bb
k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/registry/rest/resttest.(*Tester).TestCreate(0xc0007043f0, 0x2156e20, 0xc000482c00, 0xc00082dd38, 0xc00082dd28, 0xc00082de40, 0x2, 0x2)
	/home/cmluciano/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/registry/rest/resttest/resttest.go:148 +0x109
k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/registry/generic/testing.(*Tester).TestCreate(0xc000c6e150, 0x2156e20, 0xc000482c00, 0xc00082de40, 0x2, 0x2)
	/home/cmluciano/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/registry/generic/testing/tester.go:79 +0xb3
k8s.io/kubernetes/pkg/registry/networking/ingress/storage.TestCreate(0xc000506300)
	/home/cmluciano/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/pkg/registry/networking/ingress/storage/storage_test.go:139 +0x411
testing.tRunner(0xc000506300, 0x1f1b500)
	/usr/local/go/src/testing/testing.go:909 +0xc9
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:960 +0x350
FAIL	k8s.io/kubernetes/pkg/registry/networking/ingress/storage	0.131s
FAIL
Makefile:185: recipe for target 'test' failed
make: *** [test] Error 1

@liggitt
Copy link
Member

liggitt commented Feb 4, 2020

I'd recommend something like this in ValidateUpdate and Validate:

var requestGV schema.GroupVersion
if requestInfo, ok := request.RequestInfoFrom(ctx); ok {
	requestGV = schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
}

}
if requestGV == networkingv1beta1.SchemeGroupVersion {
allErrs = append(allErrs, field.Invalid(fldPath, spec.Rules, "either `backend` or `rules` must be specified"))
}
Copy link
Member

@liggitt liggitt Feb 4, 2020

Choose a reason for hiding this comment

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

Assuming we are better at naming this field now than we were four years ago, something like this that assumes future versions will continue using the v1 field name might make more sense:

var defaultBackendFieldName string
switch requestGV {
case networkingv1beta1.SchemeGroupVersion, extensionsv1beta1.SchemeGroupVersion:
	defaultBackendFieldName = "backend"
default:
	defaultBackendFieldName = "defaultBackend"
}

allErrs := field.ErrorList{}
if spec.DefaultBackend != nil {
	allErrs = append(allErrs, validateIngressBackend(spec.DefaultBackend, fldPath.Child(defaultBackendFieldName))...)
} else if len(spec.Rules) == 0 {
	allErrs = append(allErrs, field.Invalid(fldPath, spec.Rules, fmt.Sprintf("either `%s` or `rules` must be specified", defaultBackendFieldName)))
}

The worse-case failure mode of that approach if we change the field name in a future version and forget to update this is that you get the wrong field name in an error message. The failure mode of the current code if we add a version and forget to update this is that we get unvalidated fields!

Copy link
Author

Choose a reason for hiding this comment

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

When I tried it this way it doesn't seem to trigger the validation error that is expected in strategy_test.go. I'm scouring the relevant files under pkg/registry/networking/ingress/* to see if I am accidentally using the old backend type but I have not found a mistake yet.

Copy link
Author

Choose a reason for hiding this comment

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

Nvm copy/paste error, I found my mistake

Copy link
Author

Choose a reason for hiding this comment

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

Actually even after fixing an indenting problem, this still doesnt work because it passes only a string to the ingressbackend validation. I kept the if/else for now.

Copy link
Member

Choose a reason for hiding this comment

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

I kept the if/else for now.

We need a fallback case that still performs validation, not one that skips validation on unknown versions

Copy link
Member

Choose a reason for hiding this comment

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

also, this code doesn't currently handle extensions/v1beta1

@cmluciano cmluciano force-pushed the cml/ingdefaultbackend branch 2 times, most recently from 83450d1 to c0e4c31 Compare February 6, 2020 17:15
@cmluciano
Copy link
Author

/retest

@robscott
Copy link
Member

/assign

@cmluciano
Copy link
Author

/retest

Per the Ingress v1 KEP, we are renaming the backend field in IngressSpec to
clarify its intended use. Appropriate defaults are added to ensure backend is
converted to the new field type.

ingress: validate backend based on schema.GroupVersion

Signed-off-by: Christopher M. Luciano <cmluciano@us.ibm.com>
@k8s-ci-robot
Copy link
Contributor

@cmluciano: The following tests failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-kubernetes-verify 95edbd5 link /test pull-kubernetes-verify
pull-kubernetes-e2e-gce 95edbd5 link /test pull-kubernetes-e2e-gce

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@liggitt
Copy link
Member

liggitt commented Feb 21, 2020

closing in favor of #88041

/close

@k8s-ci-robot
Copy link
Contributor

@liggitt: Closed this PR.

In response to this:

closing in favor of #88041

/close

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.

@liggitt liggitt removed the api-review Categorizes an issue or PR as actively needing an API review. label Feb 21, 2020
@liggitt liggitt removed this from Changes requested in API Reviews Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/network Categorizes an issue or PR as relevant to SIG Network. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants