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

flag redefined: kubeconfig: allow double vendoring this library but still register flags on behalf of users #878

Open
akoserwal opened this issue Mar 26, 2020 · 17 comments · Fixed by operator-framework/operator-sdk#2731
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.

Comments

@akoserwal
Copy link

akoserwal commented Mar 26, 2020

Error:

 /var/folders/3d/_kgky9bj61g5144z004y51qr0000gp/T/go-build652443801/b001/e2e.test flag redefined: kubeconfig
panic: /var/folders/3d/_kgky9bj61g5144z004y51qr0000gp/T/go-build652443801/b001/e2e.test flag redefined: kubeconfig

goroutine 1 [running]:
flag.(*FlagSet).Var(0xc0000d2120, 0x244c6a0, 0xc00004e250, 0x224908b, 0xa, 0x225fced, 0x12)
    /usr/local/Cellar/go/1.13.8/libexec/src/flag/flag.go:848 +0x4ae
flag.(*FlagSet).StringVar(...)
    /usr/local/Cellar/go/1.13.8/libexec/src/flag/flag.go:751
github.com/operator-framework/operator-sdk/pkg/test.(*frameworkOpts).addToFlagSet(0xc00004e240, 0xc0000d2120)
    /Users/akoserwa/go/pkg/mod/github.com/operator-framework/operator-sdk@v0.15.1/pkg/test/framework.go:102 +0x1bf
github.com/operator-framework/operator-sdk/pkg/test.MainEntry(0xc00040d280)
    /Users/akoserwa/go/pkg/mod/github.com/operator-framework/operator-sdk@v0.15.1/pkg/test/main_entry.go:27 +0x50
github.com/atlasmap/atlasmap-operator/test/e2e.TestMain(...)
       _testmain.go:42 +0x136

Using :-

framework “github.com/operator-framework/operator-sdk/pkg/test” where it is setting
> flagset.StringVar(&opts.kubeconfigPath, KubeConfigFlag, “”, “path to kubeconfig”)

And in my test case, I am using a library which is also using controller-runtime/operator-sdk
github.com/RHsyseng/operator-utils/pkg/utils/openshift

 Method I am calling: openshift.IsOpenShift(framework.KubeConfig)

controller-runtime/pkg/client/config/config.go

// TODO: Fix this to allow double vendoring this library but still register flags on behalf of users
  flag.StringVar(&kubeconfig, “kubeconfig”, “”,
    “Paths to a kubeconfig. Only required if out-of-cluster.“)

I suspect fixing TODO will resolve it? If yes, I would like to work on it.

@mengqiy
Copy link
Member

mengqiy commented Mar 26, 2020

/cc @DirectXMan12

@DirectXMan12
Copy link
Contributor

So, due to some legacy cruft, controller-runtime expects to be the thing that registers that flag. We probably shouldn't but that's a pretty serious breaking change that I don't think we want to make just yet.

cc @shawn-hurley @camilamacedo86 @joelanford @estroz any of you have insight into what the operatorsdk package is doing that it's re-registering that flag?

@DirectXMan12
Copy link
Contributor

/assign @camilamacedo86

to answer or triage elsewhere.

@estroz
Copy link
Contributor

estroz commented Mar 27, 2020

The SDK's test framework uses some client-go APIs directly and requires the kubeconfig's namespace, so it needs the kubeconfig path. While the framework could/should be refactored to use pure controller-runtime, which would allow the framework to delegate registering this flag to controller-runtime, we can use a local flagset in the mean time retrieve the value using a lookup.

PR: operator-framework/operator-sdk#2731

@akoserwal can you test my branch out to make sure it fixes your issue?

@akoserwal
Copy link
Author

akoserwal commented Mar 27, 2020

@estroz: Getting error:

flag provided but not defined: -singleNamespace
Usage of /var/folders/3d/_kgky9bj61g5144z004y51qr0000gp/T/go-build683683410/b001/e2e.test:
  -globalMan string
        path to operator manifest
  -kubeconfig string
        Paths to a kubeconfig. Only required if out-of-cluster.
  -localOperator
        enable if operator is running locally (not in cluster)
  -localOperatorArgs string
        flags that the operator needs (while using --up-local). example: "--flag1 value1 --flag2=value2"
  -master --kubeconfig

private variable:
singleNamespaceMode bool

@camilamacedo86 camilamacedo86 removed their assignment Mar 27, 2020
@camilamacedo86
Copy link
Member

Hi @estroz,

Since you are working on it already. /assign @estroz

@estroz
Copy link
Contributor

estroz commented Mar 31, 2020

@akoserwal try out SDK's master.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 29, 2020
erkanerol pushed a commit to erkanerol/hyperconverged-cluster-operator that referenced this issue Aug 26, 2021
Because of webhook codes, we have a dependency on
contoller-runtime in our api package. Api packages should
be as clean as possible. Also, we are hitting an issue*
in test when we try to consume our api package because of
this dependency.

* kubernetes-sigs/controller-runtime#878

Signed-off-by: Erkan Erol <eerol@redhat.com>
kubevirt-bot pushed a commit to kubevirt/hyperconverged-cluster-operator that referenced this issue Aug 26, 2021
Because of webhook codes, we have a dependency on
contoller-runtime in our api package. Api packages should
be as clean as possible. Also, we are hitting an issue*
in test when we try to consume our api package because of
this dependency.

* kubernetes-sigs/controller-runtime#878

Signed-off-by: Erkan Erol <eerol@redhat.com>
@lrascao
Copy link

lrascao commented Dec 28, 2021

For future reference, this is the lookup workaround mentioned by @estroz :

kubeconfig := flag.Lookup("kubeconfig").Value.String()

@mvleandro
Copy link

For future reference, this is the lookup workaround mentioned by @estroz :

kubeconfig := flag.Lookup("kubeconfig").Value.String()

Thank you!

@stevekuznetsov
Copy link
Contributor

/reopen

It's been a bit. This is still super annoying for basically anyone who happens to import any part of controller-runtime. Mutating global state in an init() in a library is fairly unpleasant - made worse by the fact that Go will only complain the second time the flag is registered, and because of init() ordering, controller-runtime is always the first one, so finding what just side-effect registered --kubeconfig is impossible.

I'd really suggest another look at this. If this were defined in some runtime code or in code that's unlikely to be imported unless by someone actually using controller-runtime, perhaps it would be less frustrating. In my case, I imported an API module that happened to use the controller-runtime Scheme builder. Really divorced from any runtime considerations.

A workaround for now is to re-set flag.CommandLine in my own init().

cc @joelanford @vincepri @alvaroaleman

@k8s-ci-robot k8s-ci-robot reopened this Jan 18, 2024
@k8s-ci-robot
Copy link
Contributor

@stevekuznetsov: Reopened this issue.

In response to this:

/reopen

It's been a bit. This is still super annoying for basically anyone who happens to import any part of controller-runtime. Mutating global state in an init() in a library is fairly unpleasant - made worse by the fact that Go will only complain the second time the flag is registered, and because of init() ordering, controller-runtime is always the first one, so finding what just side-effect registered --kubeconfig is impossible.

I'd really suggest another look at this. If this were defined in some runtime code or in code that's unlikely to be imported unless by someone actually using controller-runtime, perhaps it would be less frustrating. In my case, I imported an API module that happened to use the controller-runtime Scheme builder. Really divorced from any runtime considerations.

A workaround for now is to re-set flag.CommandLine in my own init().

cc @joelanford @vincepri @alvaroaleman

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.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 17, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

@k8s-ci-robot k8s-ci-robot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2024
@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

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.

@joelanford joelanford reopened this Mar 21, 2024
@joelanford
Copy link
Member

/label lifecycle/frozen

@k8s-ci-robot
Copy link
Contributor

@joelanford: The label(s) /label lifecycle/frozen cannot be applied. These labels are supported: api-review, tide/merge-method-merge, tide/merge-method-rebase, tide/merge-method-squash, team/katacoda, refactor. Is this label configured under labels -> additional_labels or labels -> restricted_labels in plugin.yaml?

In response to this:

/label lifecycle/frozen

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.

@joelanford joelanford added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. labels Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.