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

Remove implicit magic with flag registration in generators #80

Merged
merged 1 commit into from
Oct 4, 2017

Conversation

sttts
Copy link
Contributor

@sttts sttts commented Sep 28, 2017

This blocks further work on a Golang variant of kubernetes/kubernetes#52186
because we cannot instantiate multiple generators in one process.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 28, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 28, 2017
@sttts
Copy link
Contributor Author

sttts commented Sep 28, 2017

/assign @thockin

@@ -76,6 +78,11 @@ func main() {
"Comma-separated list of import paths which bound the types for which deep-copies will be generated.")
arguments.CustomArgs = customArgs

// Register default flags.
Copy link
Member

Choose a reason for hiding this comment

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

The point of the args package was so callers can do this boilerplate in like 1 line. Can you find a way to do this such that callers only add one line, or none (like, a function they can call on the thing that Default() returns)?

Copy link
Member

Choose a reason for hiding this comment

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

ACK the goal, but flag processing really belongs to the app, and the fact that gengo knows pflag is sort of awful.

But this is a breaking change, and it obviously doesn't catch all callers. If we're going to factor this way, we should add a new method that doesn't change flags, or at least rename the Default function so callers don't suddenly stop getting flags registered. Or pass a FlagAdder interface to Default which will similarly break compilation, but let us inject pflag from caller.

Copy link
Contributor Author

@sttts sttts Sep 28, 2017

Choose a reason for hiding this comment

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

Backwards compatibility is a good point. An interface sounds overkill. Will add another func.

Copy link
Member

Choose a reason for hiding this comment

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

If adding the interface means we can get rid of one hard dep on pflag, I think we should do it.

I don't care a ton about API compat here (I know that is evil, but this is a niche lib). Simply adding an arg will force callers to adapt explicitly. I just dont' want to have callers compile but not work any more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did a minimal version now with a WithoutDefaultFlagParsing() method, disabling the current behaviour, completely optional, keeping @lavalamp's one-liner semantics by default. The old generators are unchanged.

I also tried with interfaces, but everything I came up with was ugly. Moreover, with an AddFlags method we have to keep flags as dependency somewhere. Moreover, due to StringSliceVar we cannot even easily switch to Golang's flag without breaking backwards code compatiblity. I don't care enough about the pflag dependency to uglify the types for the sake of removing the pflag import.

@lavalamp
Copy link
Member

lavalamp commented Sep 28, 2017 via email

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 4, 2017
@thockin
Copy link
Member

thockin commented Oct 4, 2017

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 4, 2017
@thockin thockin merged commit 70ad626 into kubernetes:master Oct 4, 2017
k8s-github-robot pushed a commit to kubernetes/kubernetes that referenced this pull request Oct 6, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes #53522.
sttts pushed a commit to sttts/client-go that referenced this pull request Oct 7, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/kube-aggregator that referenced this pull request Oct 7, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/sample-apiserver that referenced this pull request Oct 7, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/apiextensions-apiserver that referenced this pull request Oct 7, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/metrics that referenced this pull request Oct 7, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/code-generator that referenced this pull request Oct 7, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/client-go that referenced this pull request Oct 13, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/kube-aggregator that referenced this pull request Oct 13, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/sample-apiserver that referenced this pull request Oct 13, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/apiextensions-apiserver that referenced this pull request Oct 13, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/metrics that referenced this pull request Oct 13, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/client-go that referenced this pull request Oct 14, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/kube-aggregator that referenced this pull request Oct 14, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/sample-apiserver that referenced this pull request Oct 14, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/apiextensions-apiserver that referenced this pull request Oct 14, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/metrics that referenced this pull request Oct 14, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/code-generator that referenced this pull request Oct 14, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/client-go that referenced this pull request Oct 16, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/kube-aggregator that referenced this pull request Oct 16, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/sample-apiserver that referenced this pull request Oct 16, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/apiextensions-apiserver that referenced this pull request Oct 16, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/metrics that referenced this pull request Oct 16, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
sttts pushed a commit to sttts/code-generator that referenced this pull request Oct 16, 2017
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants