-
Notifications
You must be signed in to change notification settings - Fork 74
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
Change environment prefix from nms to nginx_agent #706
Conversation
✅ Deploy Preview for agent-public-docs canceled.
|
src/core/config/defaults.go
Outdated
OldEnvPrefix = "nms" | ||
NewEnvPrefix = "nginx_agent" |
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.
nit: I think OldEnvPrefix
should rather be called LegacyEnvPrefix
and NewEnvPrefix
just EnvPrefix
. That way we could eventually get rid of LegacyEnvPrefix
and we'd be left with EnvPrefix
.
oldKey := strings.ToUpper(OldEnvPrefix + "_" + strings.ReplaceAll(flag.Name, "-", "_")) | ||
newKey := strings.ToUpper(NewEnvPrefix + "_" + strings.ReplaceAll(flag.Name, "-", "_")) | ||
|
||
if os.Getenv(oldKey) != "" && os.Getenv(newKey) == "" { |
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.
What about the (admittedly unlikely) case where both oldKey
and newKey
are set?
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.
If both oldKey and newKey are set we assume the newKey is the one with the correct value and ignore the value from the old key
Could you add some unit tests for this? I think Go's |
src/core/config/config.go
Outdated
oldKey := strings.ToUpper(OldEnvPrefix + "_" + strings.ReplaceAll(flag.Name, "-", "_")) | ||
newKey := strings.ToUpper(NewEnvPrefix + "_" + strings.ReplaceAll(flag.Name, "-", "_")) |
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.
Generally it's good practice to use fmt.Sprintf()
for building strings instead of "string" + "another_string". However, I think your solution is more readable so it's fine here.
I would perhaps reuse theagent_config.KeyDelimiter
variable we have here:
oldKey := strings.ToUpper(OldEnvPrefix + "_" + strings.ReplaceAll(flag.Name, "-", "_")) | |
newKey := strings.ToUpper(NewEnvPrefix + "_" + strings.ReplaceAll(flag.Name, "-", "_")) | |
oldKey := strings.ToUpper( | |
OldEnvPrefix + agent_config.KeyDelimiter + strings.ReplaceAll(flag.Name, "-", agent_config.KeyDelimiter) | |
) | |
newKey := strings.ToUpper( | |
NewEnvPrefix + agent_config.KeyDelimiter + strings.ReplaceAll(flag.Name, "-", agent_config.KeyDelimiter) | |
) |
Will create task to check MigratedEnv in UnitTests in the future, otherwise LGTM |
Proposed changes
Agent now uses NGINX_AGENT as its environment prefix as opposed to NMS. If the old prefix is used, Agent migrates the value to the correct key and a message is logged warning the user to switch to the new prefix
Checklist
Before creating a PR, run through this checklist and mark each as complete.
CONTRIBUTING
documentmake install-tools
and have attached any dependency changes to this pull requestREADME.md
)