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

operator run --local: --go-ldflags not effective #2477

Closed
benoit-a opened this issue Jan 28, 2020 · 1 comment · Fixed by #2478
Closed

operator run --local: --go-ldflags not effective #2477

benoit-a opened this issue Jan 28, 2020 · 1 comment · Fixed by #2478
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@benoit-a
Copy link

Bug Report

What did you do?

I am trying to run locally an operator and pass the current version to the binary using a LDFLAG to the go build stage like this:

operator-sdk run --local --go-ldflags "-X=main.version=1.2.3.4"

What did you expect to see?

I expected the version to be set and displayed properly in the log (at start)

What did you see instead? Under which circumstances?

The operator logs the placeholder value.

Environment

  • operator-sdk version:
operator-sdk version: "v0.15.0", commit: "21a93ca379b887ab2303b0d148a399bf205c3231", go version: "go1.13.6 darwin/amd64"
  • go version:
go version go1.13.6 darwin/amd64
  • Kubernetes version information:
❯ kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.2", GitCommit:"59603c6e503c87169aea6106f57b9f242f64df89", GitTreeState:"clean", BuildDate:"2020-01-23T14:21:36Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.3", GitCommit:"2d3c76f9091b6bec110a5e63777c332469e0cba2", GitTreeState:"clean", BuildDate:"2019-08-19T11:05:50Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
  • Kubernetes cluster kind:

Installed on bare metal.

  • Are you writing your operator in ansible, helm, or go?

go

Possible Solution

After a quick review of PR #2441, I suspect this is due to the change in cmd/operator-sdk/run/local.go ; previously the flag variables were declared globally. They are now part of a new structure called runLocalArgs.

Specifically, the function addToFlags is not getting a pointer to the object but is receiving a copy and so the StringVar declaration is pointing to a copy of ldFlags

I had some success with this patch:

diff --git cmd/operator-sdk/run/local.go cmd/operator-sdk/run/local.go
index 593159c9..b570c589 100644
--- cmd/operator-sdk/run/local.go
+++ cmd/operator-sdk/run/local.go
@@ -48,7 +48,7 @@ type runLocalArgs struct {
        helmOperatorFlags    *hoflags.HelmOperatorFlags
 }

-func (c runLocalArgs) addToFlags(fs *pflag.FlagSet) {
+func (c *runLocalArgs) addToFlags(fs *pflag.FlagSet) {
        prefix := "[local only] "
        fs.StringVar(&c.operatorFlags, "operator-flags", "",
                prefix+"The flags that the operator needs. Example: \"--flag1 value1 --flag2=value2\"")
@joelanford joelanford self-assigned this Jan 28, 2020
@joelanford joelanford added the kind/bug Categorizes issue or PR as related to a bug. label Jan 28, 2020
@joelanford
Copy link
Member

Good catch. Thanks for pointing this out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants