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

Kubectl support for validating nested objects with different ApiGroups #25172

Merged
merged 1 commit into from
May 11, 2016

Conversation

pwittrock
Copy link
Member

@pwittrock pwittrock commented May 4, 2016

Pull Request Guidelines

  1. Please read our contributor guidelines.
  2. See our developer guide.
  3. Follow the instructions for labeling and writing a release note for this PR in the block below.
kubectl now supports validation of nested objects with different ApiGroups (e.g. objects in a List)

Analytics
#24089

@pwittrock pwittrock added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label May 4, 2016
@pwittrock pwittrock added this to the v1.3 milestone May 4, 2016
@pwittrock
Copy link
Member Author

cc @nikhiljindal

@lavalamp Is this something you should also take a look at?

types := []runtime.Object{&api.Pod{}, &extensions.Deployment{}, &api.Service{}}
t := types[c.Rand.Intn(len(types))]
c.Fuzz(t)
by, _ := json.Marshal(t)
Copy link
Member Author

Choose a reason for hiding this comment

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

Should I panic if I get an error here?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, and you shouldn't use json, you should use runtime.Encode. Raw JSON encoding won't set the api version & kind on the wire, which will make the object uninterpretable.

Copy link
Member Author

Choose a reason for hiding this comment

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

SGTM. Done.

@k8s-github-robot k8s-github-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 4, 2016
@pwittrock
Copy link
Member Author

Still need to add tests for this but, wanted to make sure the approach is correct.

@lavalamp
Copy link
Member

lavalamp commented May 5, 2016

general idea lgtm, thanks!

@pwittrock pwittrock force-pushed the kubectl-apiversion branch 4 times, most recently from c66c978 to 9ec208f Compare May 5, 2016 01:50
@pwittrock
Copy link
Member Author

Added the tests. Janet I think this is ready for review.

@pwittrock pwittrock force-pushed the kubectl-apiversion branch 3 times, most recently from 8f6c73e to 77fe815 Compare May 5, 2016 20:30
@pwittrock pwittrock added the release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. label May 5, 2016
@pwittrock
Copy link
Member Author

cc @kubernetes/kubectl

@pwittrock
Copy link
Member Author

All tests passing

@janetkuo janetkuo changed the title Kubectl support for validating nested objects with different ApiGroup… Kubectl support for validating nested objects with different ApiGroups May 5, 2016
@@ -62,27 +62,36 @@ type NullSchema struct{}
func (NullSchema) ValidateBytes(data []byte) error { return nil }

type SwaggerSchema struct {
api swagger.ApiDeclaration
api swagger.ApiDeclaration
factory Schema // For delegating to other api groups
Copy link
Member

@janetkuo janetkuo May 6, 2016

Choose a reason for hiding this comment

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

I'm curious about why name it factory instead of something like delegate?

Copy link
Member

Choose a reason for hiding this comment

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

There's a redundant whitespace in the comment

Copy link
Member Author

Choose a reason for hiding this comment

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

I can change it to delegate. It is named factory because that is the name of the Schema type that it actually delegates to. WDYT?

@janetkuo
Copy link
Member

janetkuo commented May 6, 2016

Suggest adding a test in hack/test-cmd.sh for this case also

return schema, nil
}

// validateList unpacks a list and validate every item in the list.
// It return nil if every item is ok.
// Otherwise it return an error list contain errors of every item.
// validateList unpacks a list and validate every item in the list.
// It return nil if every item is ok.
// Otherwise it return an error list contain errors of every item.
Copy link
Member

Choose a reason for hiding this comment

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

redundant comments here

Copy link
Member Author

Choose a reason for hiding this comment

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

:P Done

// The SwaggerSchema will not be able to process objects in different ApiVersions unless they are vendored.
func (s *SwaggerSchema) isDifferentApiVersion(obj interface{}) bool {
groupVersion := obj.(map[string]interface{})["apiVersion"]
return groupVersion.(string) != "" && s.api.ApiVersion != groupVersion.(string)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: use len(string) == 0 for empty checks as per our style guide

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

@pwittrock pwittrock force-pushed the kubectl-apiversion branch from 77fe815 to 09780c9 Compare May 6, 2016 20:35
@pwittrock
Copy link
Member Author

Add hack/test-cmd.sh test case

@pwittrock
Copy link
Member Author

PTAL

@@ -62,27 +63,33 @@ type NullSchema struct{}
func (NullSchema) ValidateBytes(data []byte) error { return nil }

type SwaggerSchema struct {
api swagger.ApiDeclaration
api swagger.ApiDeclaration
delegate Schema // For delegating to other api groups
Copy link
Member

Choose a reason for hiding this comment

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

nit: the comment has a redundant space here: to other

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

@janetkuo
Copy link
Member

janetkuo commented May 9, 2016

Only nits

@pwittrock pwittrock force-pushed the kubectl-apiversion branch 2 times, most recently from 7263f75 to f4c814b Compare May 9, 2016 21:03
@pwittrock
Copy link
Member Author

PTAL

@janetkuo
Copy link
Member

LGTM. Please squash and feel free to apply the tag.

@pwittrock pwittrock removed the release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. label May 10, 2016
…s (e.g. Lists containing objects in different api groups). Closes kubernetes#24089
@pwittrock pwittrock force-pushed the kubectl-apiversion branch from 42a12ef to 680b2b9 Compare May 10, 2016 02:44
@pwittrock
Copy link
Member Author

SGTM. Squashed. Will apply lgtm when all tests pass.

@pwittrock
Copy link
Member Author

@k8s-bot test this issue: #IGNORE

@pwittrock pwittrock added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 10, 2016
@pwittrock
Copy link
Member Author

Applied the 'lgtm' label per-Janet's comment.

@pwittrock
Copy link
Member Author

Applying 'p1' because this is blocking downstream PRs

@pwittrock pwittrock added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label May 10, 2016
@pwittrock
Copy link
Member Author

@k8s-bot test this issue: #25479

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented May 11, 2016

GCE e2e build/test passed for commit 680b2b9.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 7ae1dab into kubernetes:master May 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged. 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. 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.

8 participants