Skip to content

fix: honour legacy 'source' config key as alias for 'container-engine'#691

Open
ricardbejarano wants to merge 1 commit into
wagoodman:mainfrom
bejaratommy:fix/issue-643-container-engine-legacy-source-config
Open

fix: honour legacy 'source' config key as alias for 'container-engine'#691
ricardbejarano wants to merge 1 commit into
wagoodman:mainfrom
bejaratommy:fix/issue-643-container-engine-legacy-source-config

Conversation

@ricardbejarano
Copy link
Copy Markdown

Summary

Closes #643.

Before the CLI refactor in #587 (v0.14), dive read the container engine from a viper key named source. Config files with source: podman worked correctly in v0.13.x.

After the refactor the struct field was wired up with the mapstructure tag container-engine, so the canonical config key became container-engine. The legacy source key is now silently ignored, breaking existing configs for users who upgrade from v0.13.x.

Root cause

In the old viper-based CLI, the --source flag was bound to the viper key source and the config file consumed that same key:

viper.BindPFlag("source", rootCmd.PersistentFlags().Lookup("source"))

After the refactor, the --source flag still exists (for backward CLI compatibility) but it is now bound via fangs to the struct field ContainerEngine which carries the mapstructure tag container-engine. Config files using the old source: key are therefore silently ignored.

Fix

Add an unexported LegacySource field with mapstructure:"source" so that viper still reads the old key. In PostLoad(), when container-engine is still at its default value and source was explicitly set, promote the legacy value and emit a single deprecation warning. If both keys are present, container-engine takes precedence.

This mirrors the pattern already used by CIRules for its legacy camelCase keys.

Testing

Added unit tests in cmd/dive/cli/internal/options/analysis_test.go covering:

  • container-engine: podman (current key) resolves correctly
  • default (container-engine: docker) resolves correctly
  • scheme prefix on the image (e.g. docker://...) overrides the config value
  • legacy source: podman resolves to podman engine with a deprecation warning
  • when both keys are present, container-engine wins

Before the CLI refactor introduced in wagoodman#587 (v0.14), dive read the container
engine from a viper key named 'source'. Config files with 'source: podman'
therefore worked correctly in v0.13.x.

After the refactor the struct field was wired up with mapstructure tag
'container-engine', so the canonical key in config became 'container-engine'.
The old 'source' key is now silently ignored, breaking existing configs.

Fix: read the legacy 'source' key via an unexported struct field and, when
'container-engine' is still at its default value, promote the legacy value
with a deprecation warning.  If both keys are present 'container-engine'
takes precedence, matching the documented behaviour.

Tests: add unit tests covering the current key, the legacy key, the
precedence rule, and the scheme-prefix override.

Fixes wagoodman#643

Signed-off-by: Tommy <tommy@bejarano.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

container-engine configuration not affecting operation

1 participant