-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Kubectl support for validating nested objects with different ApiGroups #25172
Conversation
@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) |
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.
Should I panic if I get an error here?
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.
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.
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.
SGTM. Done.
Still need to add tests for this but, wanted to make sure the approach is correct. |
general idea lgtm, thanks! |
c66c978
to
9ec208f
Compare
Added the tests. Janet I think this is ready for review. |
8f6c73e
to
77fe815
Compare
cc @kubernetes/kubectl |
All tests passing |
@@ -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 |
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'm curious about why name it factory
instead of something like delegate
?
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.
There's a redundant whitespace in the comment
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 can change it to delegate. It is named factory because that is the name of the Schema type that it actually delegates to. WDYT?
Suggest adding a test in |
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. |
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.
redundant comments here
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.
: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) |
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.
style: use len(string) == 0 for empty checks as per our style guide
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.
Done
77fe815
to
09780c9
Compare
Add hack/test-cmd.sh test case |
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 |
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.
nit: the comment has a redundant space here: to other
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.
Done
Only nits |
7263f75
to
f4c814b
Compare
PTAL |
LGTM. Please squash and feel free to apply the tag. |
…s (e.g. Lists containing objects in different api groups). Closes kubernetes#24089
42a12ef
to
680b2b9
Compare
SGTM. Squashed. Will apply lgtm when all tests pass. |
@k8s-bot test this issue: #IGNORE |
Applied the 'lgtm' label per-Janet's comment. |
Applying 'p1' because this is blocking downstream PRs |
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
GCE e2e build/test passed for commit 680b2b9. |
Automatic merge from submit-queue |
Pull Request Guidelines
#24089