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

Add version flag to LH binaries #1332

Merged
merged 1 commit into from
Aug 8, 2023
Merged

Conversation

vthapar
Copy link
Contributor

@vthapar vthapar commented Aug 1, 2023

Adds --version flag to Lighthouse Agent and --subm-version flag to Lighthouse Coredns. CoreDNS already has --version which prints CoreDNS version, so we can't use the same flag for Lighthouse version.

Refer submariner-io/enhancements#204

Fixes #1333

@submariner-bot
Copy link
Contributor

🤖 Created branch: z_pr1332/vthapar/version-flag
🚀 Full E2E won't run until the "ready-to-test" label is applied. I will add it automatically once the PR has 2 approvals, or you can add it manually.

@submariner-bot
Copy link
Contributor

🤖 Closed branches: [z_pr1332/vthapar/version-flag]

@submariner-bot
Copy link
Contributor

🤖 Created branch: z_pr1332/vthapar/version-flag
🚀 Full E2E won't run until the "ready-to-test" label is applied. I will add it automatically once the PR has 2 approvals, or you can add it manually.

coredns/main.go Outdated
var version = "not-compiled-properly"
var (
version = "not-compiled-properly"
submVersion = false
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
submVersion = false
showVersion = false

masterURL string
kubeConfig string
help = false
submVersion = false
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
submVersion = false
showVersion = false

coredns/main.go Outdated
Comment on lines 123 to 128
if submVersion {
fmt.Printf("submariner-lighthouse-coredns version: %s", version)
return
}
Copy link
Contributor

@tpantelis tpantelis Aug 1, 2023

Choose a reason for hiding this comment

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

We also log the version in setupLighthouse. How about we just print the version here (and remove the log in setupLighthouse) and exit if the version was requested? Same with the agent.

Suggested change
if submVersion {
fmt.Printf("submariner-lighthouse-coredns version: %s", version)
return
}
fmt.Printf("submariner-lighthouse-coredns version: %s", version)
if showVersion {
return
}

Copy link
Contributor Author

@vthapar vthapar Aug 1, 2023

Choose a reason for hiding this comment

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

Yeah, I thought about printing and not using logger, but what if someone is using an external logger? printf will not show up in that, right? I like idea of using common print for both coz it ensures version message will be same.

Copy link
Contributor

@tpantelis tpantelis Aug 1, 2023

Choose a reason for hiding this comment

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

How would someone use/setup an external logger? But regardless, wouldn't fmt.Printf go to the pod log no matter what? We'll scrape from that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried it out, fmt.Printf didn't show up in logs, only if we use logger. So will continue with current approach. Changed submVersion to showVersion.

Copy link
Contributor

@tpantelis tpantelis Aug 2, 2023

Choose a reason for hiding this comment

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

That’s odd. So fmt.Printf shows up when you run it with --version but not when run normally? What’s the diff? Aren’t you scraping the logs in the same manner?

Copy link
Contributor

Choose a reason for hiding this comment

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

I looked at klog code and it writes to stderr by default, ie the logtostderr flag defaults to true. In fact there’s no option to write to stdout. admiral's zerolog also writes to stderr. I think that's b/c kubectl scrapes the log from stderr. So if we do fmt.Fprintf(os.Stderr, …), it should show up in the pod logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tpantelis Okay, print to stderr worked. But two issues with it:

  1. Doesn't work for coredns For some reason any output to stdout or stderr before plugin directive is loaded results in CrashLoopBackoff on coredns. So we can't print before plugin is loaded and if we do that --version will not work coz coredns is already running so it will fail to bring it up again.
  2. Using print to stderr shows up in logs but without timestamp or line of code information:
submariner-lighthouse-agent version: devel-e7cead11fe84
2023-08-03T05:42:07.414Z INF ..e/pkg/agent/main.go:105 main                 Arguments: [/usr/local/bin/lighthouse-a
gent -alsologtostderr -v=2]

Am okay either ways but do prefer to use logger for log file so that version information shows up with timestamp et al in the logs. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't work for coredns For some reason any output to stdout or stderr before plugin directive is loaded results in CrashLoopBackoff on coredns.

That's weird. Do you get a stack trace? We can log it where we do now.

Am okay either ways but do prefer to use logger for log file so that version information shows up with timestamp et al in the logs. Thoughts?

I think it's fine w/o timestamp. It's not really needed since it's the first log entry and the pertinent info is the version. But if you want it then set up the logger beforehand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's weird. Do you get a stack trace? We can log it where we do now.

No stack trace. Only error about missing dns directive.

Copy link
Contributor

@tpantelis tpantelis left a comment

Choose a reason for hiding this comment

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

I think to be consistent we should use fmt.Fprintf in setupLighthouse as well.

@vthapar
Copy link
Contributor Author

vthapar commented Aug 3, 2023

I think to be consistent we should use fmt.Fprintf in setupLighthouse as well.

There are quite a few log statements printed from CoreDNS before setupLighthouse. It works for agent coz it is the first statement so no timestamp is fine. For setupLighthouse I prefer having the timestamp as it gives indication of when lighthouse was loaded.

Also, I think I tried it that way and got some issues, but it was probably coz I was doing printf in main.go

@tpantelis tpantelis closed this Aug 3, 2023
@submariner-bot
Copy link
Contributor

🤖 Closed branches: [z_pr1332/vthapar/version-flag]

@tpantelis tpantelis reopened this Aug 3, 2023
@submariner-bot
Copy link
Contributor

🤖 Created branch: z_pr1332/vthapar/version-flag
🚀 Full E2E won't run until the "ready-to-test" label is applied. I will add it automatically once the PR has 2 approvals, or you can add it manually.

@vthapar
Copy link
Contributor Author

vthapar commented Aug 4, 2023

Managed to make it work without needing a logger in setupLighthouse.

As discussed on slack, will use Fprintf(os.Stderr...) in main.go, remove log entry from setupLighthouse and metrics.go:init() so that version is first line in logs.

@submariner-bot submariner-bot added the ready-to-test When a PR is ready for full E2E testing label Aug 4, 2023
@tpantelis tpantelis closed this Aug 4, 2023
@tpantelis tpantelis reopened this Aug 4, 2023
@submariner-bot
Copy link
Contributor

🤖 Closed branches: [z_pr1332/vthapar/version-flag]

@submariner-bot
Copy link
Contributor

🤖 Created branch: z_pr1332/vthapar/version-flag
🚀 Full E2E won't run until the "ready-to-test" label is applied. I will add it automatically once the PR has 2 approvals, or you can add it manually.

coredns/main.go Outdated
dnsserver.Directives = directives
}

func main() {
flag.Parse()
admversion.Print(names.LighthouseCoreDNSComponent, version)
fmt.Fprintf(os.Stderr, "submariner-lighthouse-coredns version: %s\n", version)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fmt.Fprintf(os.Stderr, "submariner-lighthouse-coredns version: %s\n", version)

Adds `--version` flag to Lighthouse Agent and `--subm-version`
flag to Lighthouse Coredns. CoreDNS already has `--version` which
prints CoreDNS version, so we can't use the same flag for
Lighthouse version.

Removed a log entry from metrics.go which didn't add much value
so we can have version as first entry in log file.

Refer submariner-io/enhancements#204

Fixes submariner-io#1333

Signed-off-by: Vishal Thapar <[email protected]>
@tpantelis tpantelis closed this Aug 7, 2023
@submariner-bot
Copy link
Contributor

🤖 Closed branches: [z_pr1332/vthapar/version-flag]

@tpantelis tpantelis reopened this Aug 7, 2023
@submariner-bot
Copy link
Contributor

🤖 Created branch: z_pr1332/vthapar/version-flag
🚀 Full E2E won't run until the "ready-to-test" label is applied. I will add it automatically once the PR has 2 approvals, or you can add it manually.

@tpantelis tpantelis enabled auto-merge (rebase) August 7, 2023 14:55
@tpantelis tpantelis merged commit 7bbd6e4 into submariner-io:devel Aug 8, 2023
24 checks passed
@submariner-bot
Copy link
Contributor

🤖 Closed branches: [z_pr1332/vthapar/version-flag]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-test When a PR is ready for full E2E testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add version flag to LH binaries
4 participants