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

Support mixed case Kind #1133

Merged
merged 1 commit into from
Feb 3, 2020
Merged

Support mixed case Kind #1133

merged 1 commit into from
Feb 3, 2020

Conversation

mariantalla
Copy link
Contributor

@mariantalla mariantalla commented Oct 28, 2019

This PR should address issues #1019 and #1091.

The implementation uses the validation logic that runs against Kind in
apimachinery; i.e. allows any Kind value that, when converted to
lowercase, is a valid DNS-1035 label.

Reusing that logic instead of reimplementing it helps with ensuring that
the two (i.e. Kind validation in core Kubernetes and Kind validation
in kubebuilder) are as similar as possible.

Would love feedback on:

  • The choice to use k8s.io/apimachinery logic vs continuing to extend the validation logic in kubebuilder.
  • If the above does sound like a good idea, is it worth refactoring Validate() more broadly, to use available logic in k8s.io/apimachinery?
  • There were more changes than I expected in go.mod 😅 I'll take an extra look at that.

Remaining work in this PR:
(once the approach seems reasonable)

  • Refactor tests to describe successful & failed validation more succinctly (at the moment there's duplication and missing test cases while the PR is in progress)
  • Ensure any logging and error messages are descriptive of the validation that takes place.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 28, 2019
go.mod Outdated Show resolved Hide resolved
@mariantalla
Copy link
Contributor Author

/hold
(while there's open TODO items)

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 28, 2019
@mariantalla
Copy link
Contributor Author

pkg/scaffold/v1/resource/resource.go Outdated Show resolved Hide resolved
pkg/scaffold/v1/resource/resource_test.go Outdated Show resolved Hide resolved
go.mod Outdated
@@ -3,19 +3,17 @@ module sigs.k8s.io/kubebuilder
go 1.12

require (
Copy link
Member

Choose a reason for hiding this comment

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

Update the go.mo and go.sum shows not be part of the scope of this PR.
I'd recommend you revert it and ensure that your branch is rebased with the master.

Copy link
Member

@camilamacedo86 camilamacedo86 Feb 3, 2020

Choose a reason for hiding this comment

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

Hi @mariantalla,

I still not getting why the modules need to be updated with these changes. So, I'd suggest to you:

  • Ensure that the branch is rebased with master
  • Revert the changes of go.mod and go.sum

Also, has nothing here to update the testdata. But, in order to test/check the change and be ensure I'd run make generate as well.

@mariantalla
Copy link
Contributor Author

mariantalla commented Nov 5, 2019

Thanks everyone for the comments. There's indeed a couple of follow-ups before this is on its way to merge (I've updated the PR description so it's clearer what work is left).

At the moment I was curious to hear how folks felt towards using k8s.io/apimachinery code for validation (as opposed to continuing to extend the validation that kubebuilder is doing). Once there's consensus in that, error messages and test cases are pretty straightforward to change.

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 11, 2019
@mariantalla
Copy link
Contributor Author

Following the advice in #1048 (comment) (thanks @camilamacedo86 for the pointer), we've removed dependencies on apimachinery.

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 11, 2019
@Adirio
Copy link
Contributor

Adirio commented Nov 11, 2019

The Travis error seems not to be related to this PR but to #1169

@mariantalla
Copy link
Contributor Author

oops, forgot to
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 13, 2019
It("should fail if the Kind is not pascal cased", func() {
// Base case
instance := &Resource{Group: "crew", Kind: "FirstMate", Version: "v1"}
It("should succeed if the Kind is valid, according to core Kubernetes", func() {
Copy link
Member

Choose a reason for hiding this comment

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

IHMO the existent KInds check should pass.
Here for example : #1019 is for we allow AWSCluster

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed; this PR relaxes Kind validation (to bring it in line with the way it happens in core k8s). Previous passing tests continue to pass, and some previously failing should no longer fail (e.g. this one). Or am I missing something? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

The validation obtained is not the correct one for we check the kinds. If you use the correct one the only change here will be adding more one test to ensure that AWSCluster will pass. Also, note that is required to remove the pascalze as well since it is not something check-in k8s API too.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Following my suggestion to solve it.

@mariantalla
Copy link
Contributor Author

Thanks for the comments @camilamacedo86 ! I've responded inline; but just to make sure I got your last suggestion right:

Remove the Pascalize

I think this is happening here; where there other spots it needs to change?

Use the func ... from apimachinery

Kind validation now uses IsDns1350Label, same as in core kubernetes

Then, add a unit test

I think this test covers that case, is there something missing?

@mariantalla
Copy link
Contributor Author

👋 Is there anything else missing here?

@Adirio
Copy link
Contributor

Adirio commented Jan 20, 2020

I think you may want to rebase to solve the Travis issue and benefit from all the added lint checks that were added in the meantime.

@DirectXMan12
Copy link
Contributor

whoops, lost track of this. Can merge after rebase.

/assign @mengqiy
please do the rebase and we'll get this merge.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 31, 2020
@mengqiy
Copy link
Member

mengqiy commented Feb 1, 2020

@mariantalla Sorry for the delay on this PR.
Can you please rebase, so we can get this merged.
Some files have been refactored recently by @Adirio, it may require a little more work to rebase.

@Adirio
Copy link
Contributor

Adirio commented Feb 1, 2020

With the recent scaffolding it may be easier to branch from master and copy-paste your checks. pkg/model/resource/options.go should be where the check for Kind is placed, in the Validate method. pkg/model/resource/options_test.go should be where the additional tests go. Want some help?

@mariantalla
Copy link
Contributor Author

Thanks! I'll make a start at rebasing, will poke you if it all goes wrong @Adirio :)

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 3, 2020
@mariantalla
Copy link
Contributor Author

Did a go mod tidy too, which brought in the changes to go.mod and go.sum; let me know if we don't want these in.

@Adirio
Copy link
Contributor

Adirio commented Feb 3, 2020

Did a go mod tidy too, which brought in the changes to go.mod and go.sum; let me know if we don't want these in.

We should probably add a test to Travis that checks that go mod tidy was executed so that we do not forget about it.

Copy link
Contributor

@Adirio Adirio left a comment

Choose a reason for hiding this comment

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

I ended up wondering why 2 different DNS RFCs are used. Is Kubernetes using both or did it change to one of them and we still have the outdated version?

go.mod Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
pkg/model/resource/options_test.go Show resolved Hide resolved
pkg/model/resource/options_test.go Outdated Show resolved Hide resolved
pkg/model/resource/options_test.go Outdated Show resolved Hide resolved
pkg/model/resource/options_test.go Show resolved Hide resolved
pkg/model/resource/options_test.go Outdated Show resolved Hide resolved
pkg/model/resource/options_test.go Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 3, 2020
@Adirio
Copy link
Contributor

Adirio commented Feb 3, 2020

Otherwise, LGTM.

The implementation
* uses the same validation logic that runs against `Kind` in
apimachinery; i.e. allows any `Kind` value that, when converted to
lowercase, is a valid DNS-1035 label.
* additionally requires that `Kind`s  start with an uppercase character,
  to ensure they map to exported types.

Co-Authored-By: Hannes Hörl <[email protected]>
Co-Authored-By: Camila Macedo <[email protected]>
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Feb 3, 2020

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

Test name Commit Details Rerun command
pull-kubebuilder-e2e 5742ddd link /test pull-kubebuilder-e2e

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.

@mariantalla
Copy link
Contributor Author

/retest

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm
for me wdyt @DirectXMan12 and @mengqiy ?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 3, 2020
Copy link
Member

@mengqiy mengqiy left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mariantalla, mengqiy

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 3, 2020
@k8s-ci-robot k8s-ci-robot merged commit 6c6ab03 into kubernetes-sigs:master Feb 3, 2020
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants