-
Notifications
You must be signed in to change notification settings - Fork 8
Handle configOption failures gracefully #3195
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
Handle configOption failures gracefully #3195
Conversation
Signed-off-by: Steven Crespo <screswk@gmail.com>
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.
Bug: Inconsistent Template Error Handling
templateConfigItems still propagates errors from resolveConfigItem, creating inconsistent behavior between ModeConfig and ModeGeneric. In ModeGeneric, the configOption* functions now handle resolution failures gracefully by returning empty strings/false, but in ModeConfig, the same failures cause template execution to fail. This breaks the PR's goal of gracefully handling config option failures in parity with KOTS behavior.
api/pkg/template/config.go#L46-L50
embedded-cluster/api/pkg/template/config.go
Lines 46 to 50 in 837b9c6
| for j := range cfg.Spec.Groups[i].Items { | |
| resolved, err := e.resolveConfigItem(cfg.Spec.Groups[i].Items[j].Name) | |
| if err != nil { | |
| return nil, err | |
| } |
resolved |
api/pkg/template/config.go
Outdated
| resolved, err := e.resolveConfigItem(cfg.Spec.Groups[i].Items[j].Name) | ||
| if err != nil { | ||
| return nil, err | ||
| e.logger.Debugf("templateConfigItems: failed to resolve item %q, using empty values: %v", cfg.Spec.Groups[i].Items[j].Name, err) |
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 we were to log these at a warning level would the output show up for the end user or just in a log file? if the latter i think we should log at a higher level.
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 you should use the field logger for this, for example:
| e.logger.Debugf("templateConfigItems: failed to resolve item %q, using empty values: %v", cfg.Spec.Groups[i].Items[j].Name, err) | |
| e.logger.WithError(err).WithField("item", cfg.Spec.Groups[i].Items[j].Name).Debug("templateConfigItems: failed to resolve item") |
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.
Updated the logs and changed the level to warning since it looks like we output to a file regardless of the level.
embedded-cluster/api/pkg/logger/logger.go
Line 25 in 8fe7073
| logger.SetOutput(logfile) |
api/pkg/template/config.go
Outdated
| resolved, err := e.resolveConfigItem(name) | ||
| if err != nil { | ||
| return "", fmt.Errorf("resolve config item: %w", err) | ||
| e.logger.Debugf("ConfigOption(%q) failed to resolve, returning empty string: %v", name, err) |
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.
| e.logger.Debugf("ConfigOption(%q) failed to resolve, returning empty string: %v", name, err) | |
| e.logger.WithError(err).WithField("item", name).Debug("ConfigOption: failed to resolve, returning empty string") |
…rs-instead-of-empty
* Handle configOption failures gracefully Signed-off-by: Steven Crespo <screswk@gmail.com> * f Signed-off-by: Steven Crespo <screswk@gmail.com> * f Signed-off-by: Steven Crespo <screswk@gmail.com> --------- Signed-off-by: Steven Crespo <screswk@gmail.com>
What this PR does / why we need it:
Updates existing logic in configOption item templating to handle failures gracefully in parity to KOTs behavior.
Which issue(s) this PR fixes:
https://app.shortcut.com/replicated/story/131050/configoption-returns-errors-instead-of-empty-strings-breaking-yaml-template-rendering-in-v3
Does this PR require a test?
Unit tests were added
Does this PR require a release note?
Does this PR require documentation?
NONE