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

Fix #10012 - empty string as a parameter in etcd extra args #10018

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/daemons/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (e ETCDConfig) ToConfigFile(extraArgs []string) (string, error) {
} else if time, err := time.ParseDuration(extraArg[1]); err == nil && (strings.Contains(lowerKey, "time") || strings.Contains(lowerKey, "duration") || strings.Contains(lowerKey, "interval") || strings.Contains(lowerKey, "retention")) {
// auto-compaction-retention is either a time.Duration or int, depending on version. If it is an int, it will be caught above.
s[key] = time
} else if err := yaml.Unmarshal([]byte(extraArg[1]), &stringArr); err == nil {
} else if err := yaml.Unmarshal([]byte(extraArg[1]), &stringArr); err == nil && (len(extraArg[1]) > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this belongs up on line 97? if len(extraArg) == 2 && len(extraArg[1]) > 0

Copy link
Author

Choose a reason for hiding this comment

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

If I do that, the parameter will not be inserted into the s map (https://github.com/jordanorc/k3s/blob/a0a4885eafd39163e417601029bd19073ced7cdd/pkg/daemons/executor/executor.go#L107) and will never be overridden with an empty string.

Copy link
Contributor

@brandond brandond Apr 26, 2024

Choose a reason for hiding this comment

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

OK but what is your intent here - if the arg value is an empty string, do you want the config value set to an empty string, or do you want to ensure that the key is removed so that it takes the default value?

What you're doing here will set the value to an empty string, which may be valid for config entries that expect a string value. That is not all of them, as shown by the special handling for integer and time/duration fields.

If your intent is to get the default value by removing the key from the config, then I believe a different approach is required.

s[key] = stringArr
} else {
switch strings.ToLower(extraArg[1]) {
Expand Down