-
Notifications
You must be signed in to change notification settings - Fork 35
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
Conversation
🤖 Created branch: z_pr1332/vthapar/version-flag |
🤖 Closed branches: [z_pr1332/vthapar/version-flag] |
🤖 Created branch: z_pr1332/vthapar/version-flag |
coredns/main.go
Outdated
var version = "not-compiled-properly" | ||
var ( | ||
version = "not-compiled-properly" | ||
submVersion = false |
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.
submVersion = false | |
showVersion = false |
pkg/agent/main.go
Outdated
masterURL string | ||
kubeConfig string | ||
help = false | ||
submVersion = false |
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.
submVersion = false | |
showVersion = false |
coredns/main.go
Outdated
if submVersion { | ||
fmt.Printf("submariner-lighthouse-coredns version: %s", version) | ||
return | ||
} |
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.
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.
if submVersion { | |
fmt.Printf("submariner-lighthouse-coredns version: %s", version) | |
return | |
} | |
fmt.Printf("submariner-lighthouse-coredns version: %s", version) | |
if showVersion { | |
return | |
} |
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.
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.
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.
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.
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.
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
.
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.
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?
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.
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.
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.
@tpantelis Okay, print to stderr worked. But two issues with it:
- 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. - 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?
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.
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.
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.
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.
12355d7
to
d262725
Compare
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.
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 |
🤖 Closed branches: [z_pr1332/vthapar/version-flag] |
🤖 Created branch: z_pr1332/vthapar/version-flag |
Managed to make it work without needing a logger in As discussed on slack, will use |
🤖 Closed branches: [z_pr1332/vthapar/version-flag] |
🤖 Created branch: z_pr1332/vthapar/version-flag |
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) |
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.
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]>
🤖 Closed branches: [z_pr1332/vthapar/version-flag] |
🤖 Created branch: z_pr1332/vthapar/version-flag |
🤖 Closed branches: [z_pr1332/vthapar/version-flag] |
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