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 flag.Parse() from avisession.go #2969

Open
dvirgilad opened this issue Jul 15, 2024 · 2 comments
Open

Remove flag.Parse() from avisession.go #2969

dvirgilad opened this issue Jul 15, 2024 · 2 comments

Comments

@dvirgilad
Copy link

dvirgilad commented Jul 15, 2024

Is your feature request related to a problem? Please describe.

Recently my team has been working on a crossplane provider for AVI, which uses the go SDK (through the terraform AVI provider). We ran into an issue with our flag parser whenever a flag was passed. We were not using the default flag package.
We traced the issue back to this function:

func NewAviSession(host string, username string, options ...func(*AviSession) error) (*AviSession, error) {
if flag.Parsed() == false {
flag.Parse()
}

Describe the solution you'd like

For an SDK, I don't really understand why it should parse flags. Considering it cannot be built into an executable (AFAIK). Would like to hear others thoughts about this.
Cheers.

Describe alternatives you've considered

For the time being, my team has implemented a solution using the default flag package.

Additional context

No response

@FSchumacher
Copy link

I would say, this is a bug, not an enhancement.

We are using the SDK to implement a cert-manager webhook for the DNS01 challenge. The problem here is the same as above. The SDK is used as a library inside a command with command line parameters. As soon, as we try to get an AVI client (the session really), the parsing of the command line parameters will crash the program (as it does not recognize the command line parameters, that are for the webhook).

Our current workaround is to parse an empty slice with the following code right before calling clients.NewAviClient(...):

if !flag.CommandLine.Parsed() {
	klog.Info("Workaround for AVI session")
	flag.CommandLine.Parse([]string{})
}
aviClient, err := clients.NewAviClient(cfg.ApiEndpoint, cfg.ApiUser, sessionOptions...)

@dvirgilad
Copy link
Author

dvirgilad commented Feb 25, 2025

I wasn't sure whether this was a bug or a feature so I might be wrong with my choice of label.
In our case, since crossplane providers by default use kingpin to parse flags, flags.parsed() would evaluate to false and then the function would throw an error because of the unrecognized flags. We solved this by changing the flag parser in the provider to the default flag package so flags.parsed() would return true.
I still have no idea why the sdk would need to parse flags, would like to hear from one of the maintainers why this was added in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants