Skip to content

Conversation

@screspod
Copy link
Member

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?

NONE

Does this PR require documentation?

NONE

Signed-off-by: Steven Crespo <screswk@gmail.com>
@screspod screspod marked this pull request as ready for review November 11, 2025 17:02
Copy link

@cursor cursor bot left a 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

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
}

Fix in Cursor Fix in Web


f
Signed-off-by: Steven Crespo <screswk@gmail.com>
@screspod
Copy link
Member Author

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

Fix in Cursor Fix in Web

resolved

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)
Copy link
Member

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.

Copy link
Member

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:

Suggested change
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")

Copy link
Member Author

@screspod screspod Nov 11, 2025

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.

logger.SetOutput(logfile)

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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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")

f
Signed-off-by: Steven Crespo <screswk@gmail.com>
@screspod screspod requested a review from emosbaugh November 11, 2025 19:36
@screspod screspod merged commit 33bd094 into main Nov 11, 2025
26 checks passed
@screspod screspod deleted the screspod/sc-131050/configoption-returns-errors-instead-of-empty branch November 11, 2025 19:59
crdant pushed a commit that referenced this pull request Nov 12, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants