-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix if loop related lint failures in the deepcopy-gen #46
Conversation
/cc @thockin @smarterclayton - the last known changes on lint except changes we are discussing on removal of underscore in a separate PR. Also, can you please let me know what's the best way to ping you if needed on slack?, won't bug much :-). Is there a channel related to "client-gen"? Thanks! |
sw.Do("if newVal, err := c.DeepCopy(&val); err != nil {\n", nil) | ||
sw.Do("return err\n", nil) | ||
sw.Do("} else {\n", nil) | ||
sw.Do("if newVal, err := c.DeepCopy(&val); err == nil {\n", nil) |
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.
It's much more idiomatic to test err != nil - why change that? I had a hard time realizing what you changed because my eyes just skip the pattern. I'd rather see a test for != nil and a return nil
in the success path
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.
@thockin Hi Tim, lol, sorry and I agree. Honestly I didn't like it myself too but I notice use of == nil in few other places and I was getting locally scoped error with a different solution I tried few weeks back (part of an old PR which didn't go further because of underscore related changes). But seems like a possible better solution is working now, I will update the changes. Thanks!
71b8899
to
84c1873
Compare
This is an annoying and stupid lint error. The sigh |
change LGTM but fails travis |
restarted travis - 1/3 failed |
@thockin I know :( and thanks much!! It seems like no straightforward error with Travis? So I guess may be one more restart on a weekday? |
It is failing against Go tip, consistently. I am on mobile, so can't investigate.
|
It looks like something change in upstream Go wrt line numbers. Can you fold in a change (separate commit) to |
rebase and ping me |
84c1873
to
671b501
Compare
@thockin Hi Tim, I tried pinging you on slack kube-dev couple times but without much luck of talking to you :-) Just an update that this PR is passing Travis. Thanks!! |
I just restarted travis - I added tests that this will have to update.
Resync to master and look at examples/deepcopy/output_tests
…On Thu, Apr 27, 2017 at 6:47 AM, Sahdev Zala ***@***.***> wrote:
@thockin <https://github.com/thockin> Hi Tim, I tried pinging you on
slack kube-dev couple times but without much luck of talking to you :-)
Just an update that this PR is passing Travis. Thanks!!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#46 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFVgVCJ8as6bkS-rYJcf1o2lLp6p6cDiks5r0JxbgaJpZM4NDXWH>
.
|
Specifically, run `make test` in that dir.
…On Thu, Apr 27, 2017 at 9:28 AM, Tim Hockin ***@***.***> wrote:
I just restarted travis - I added tests that this will have to update.
Resync to master and look at examples/deepcopy/output_tests
On Thu, Apr 27, 2017 at 6:47 AM, Sahdev Zala ***@***.***>
wrote:
> @thockin <https://github.com/thockin> Hi Tim, I tried pinging you on
> slack kube-dev couple times but without much luck of talking to you :-)
> Just an update that this PR is passing Travis. Thanks!!
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#46 (comment)>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/AFVgVCJ8as6bkS-rYJcf1o2lLp6p6cDiks5r0JxbgaJpZM4NDXWH>
> .
>
|
Thanks Tim @thockin |
The changes in this patch takes care of lint failures due to unreachable else statements. For example one of the failures is, /zz_generated.deepcopy.go:116:10: if block ends with a return statement, so drop this else and outdent its block
671b501
to
a438c28
Compare
@thockin is there a way I can restart Travis job by adding a comment or something like that? (I did rebase and updated PR but seems like latest Travis failure is due to incomplete build job and probably need a restart) Thanks! |
like that |
Ahhh.. interesting.. Close the PR and ReOpen. Different but that's cool :-) Thanks @thockin !! |
@thockin Yay :-) it passed now. |
Curiously, no test cases exercize this. I'm going to merge it because that's not your fault, but if you want to make me extra happy, maybe you could throw together super-minimal output_test cases that expose this change? |
@thockin :-) Thanks Tim! And yes sure, I would work on it. I am traveling on business for a week and preparing for my speaking session etc but I believe there is no super rush with it right? I will be working on soon I can. Thanks much!! |
Also it should be SUPER EASY. Copy on of the directories, edit doc.g to
have a type that highlights this case, run `make test`
…On Thu, Apr 27, 2017 at 4:40 PM, Sahdev Zala ***@***.***> wrote:
@thockin <https://github.com/thockin> :-) Thanks Tim! And yes sure, I
would work on it. I am traveling on business for a week and preparing for
my speaking session etc but I believe there is no super rush with it right?
I will be working on soon I can. Thanks much!!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#46 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFVgVA_sAj0-UIqyv6oGv1u9niwdc6g2ks5r0SeJgaJpZM4NDXWH>
.
|
Awesome, thanks @thockin !! |
Add new test convering servicecatalog types related to changes made under kubernetes#46
Add new tests convering types related to changes made under kubernetes#46
Add new tests convering types related to changes made under kubernetes#46
@@ -523,11 +523,12 @@ func (g *genDeepCopy) doMap(t *types.Type, sw *generator.SnippetWriter) { | |||
sw.Do("}\n", nil) | |||
sw.Do("(*out)[key] = *newVal\n", nil) | |||
} else { | |||
sw.Do("if newVal, err := c.DeepCopy(&val); err != nil {\n", nil) | |||
sw.Do("newVal, err := c.DeepCopy(&val)\n", nil) |
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.
this PR produces code that will not compile
I0515 01:05:35.400] k8s.io/kubernetes/vendor/k8s.io/kube-apiextensions-server/pkg/apis/apiextensions/zz_generated.deepcopy.go:59: no new variables on left side of :=
func DeepCopy_apiextensions_CustomResource(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*CustomResource)
out := out.(*CustomResource)
*out = *in
newVal, err := c.DeepCopy(&in.ObjectMeta)
if err != nil {
return err
}
out.ObjectMeta = *newVal.(*v1.ObjectMeta)
newVal, err := c.DeepCopy(&in.Spec)
if err != nil {
return err
}
out.Spec = *newVal.(*CustomResourceSpec)
newVal, err := c.DeepCopy(&in.Status)
if err != nil {
return err
}
out.Status = *newVal.(*CustomResourceStatus)
return nil
}
}
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.
opened #56 to revert so master is usable (we need to bump as a prereq of kubernetes/kubernetes#45294)... can revisit this if we decide we want to jump through scoping or variable name hoops to avoid this lint error (I personally don't think it's worth it)
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.
@liggitt thanks for fixing it Jordan. My bad, in my manual verification of generated code and build I apparently didn't run into it. I guess Gengo Travis passed because the method with nil return is not in Gengo but K8s. @thockin was quick in seeing a need for tests when lint related these changes were merged and kindly created new tests but those tests still missed few scenarios. I have also create a follow up PR (#51) to add new tests. I value your opinion on spending time for lint may not worth :-) but if we can fix existing code on lint and going forward have lint complied code then that will reduce skipping lint check and produce more clean code. Thanks!!
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.
lint is a moving target (new lint criteria get added over time), and (as in this case) sometimes encourages non-idiomatic code. I don't think jumping through hoops to silence it is a good idea.
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 have also create a follow up PR (#51) to add new tests.
I don't think that test exercises this case, either... this error was caused by multiple fields in the deep-copied type resulting in newVal being redeclared multiple times in the same scope.
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.
@liggitt about lint agree as long as we try to catch it manually but at the same time I guess what can be worth is to automate test process against lint (latest) as part of the build (something similar to what's done with PEP 8 in projects like OpenStack), that should be a real solution.
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.
Add new tests convering types related to changes made under kubernetes#46
Add new tests convering types related to changes made under kubernetes#46
Add new tests convering types related to changes made under kubernetes#46
The changes in this patch takes care of lint failures due to unreachable
else statements. For example one of the failures is,
/zz_generated.deepcopy.go:116:10: if block ends with a return statement,
so drop this else and outdent its block