-
Notifications
You must be signed in to change notification settings - Fork 331
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
Fix potential --kubeconfig
redefined error
#2855
Fix potential --kubeconfig
redefined error
#2855
Conversation
b8ebbc8
to
5e094c0
Compare
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2855 +/- ##
==========================================
- Coverage 81.86% 81.80% -0.07%
==========================================
Files 167 167
Lines 10224 10227 +3
==========================================
- Hits 8370 8366 -4
- Misses 1608 1614 +6
- Partials 246 247 +1
☔ View full report in Codecov by Sentry. |
Failed downstream test is unrelated. The
|
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.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dsimansk, pierDipi The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
fs.StringVar(&c.Kubeconfig, "kubeconfig", os.Getenv("KUBECONFIG"), | ||
"Path to a kubeconfig. Only required if out-of-cluster.") | ||
if f := fs.Lookup("kubeconfig"); f != nil { | ||
c.Kubeconfig = f.Value.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.
usually we call InitFlags method then a flags.Parse
gets called
Given we're setting c.Kubeconfig here - i don't think it will update after flags.Parse is called.
So this config will have a different value
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, indeed c.Kubeconfig
will set as default value of first defined --kubeconfig
. Not reflecting values provided as args and flags.Parse()
call.
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.
Would you prefer a revert here? There are several places in knative/pkg
that call flags.Parse() and could be refactored to isolated flatset, but that's probably not worth it.
flags := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
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.
Would you prefer a revert here?
I think so - otherwise it's a subtle bug that I will be difficult to discover.
There are several places in knative/pkg that call flags.Parse() and could be refactored to isolated flatset, but that's probably not worth it.
Yeah a lot of the test code had that - hence why I pulled out this resource into a separate package that doesn't call Parse
I don't have a good solution for you to mix this with kubebuilder. You may want to initialize your own flagset and configure each configuration yourself
)" This reverts commit bae23eb.
Changes
The
--kubeconfing
flag is a popular one. I've run into a case withsigs.k8s.io/controller-runtime
&/pkg
when vendoring together there'sflag redefined
error thrown. Depending on the order of package inits.This change should make
/pkg
safer to use alongside other K8s libs.