Skip to content

fix(describe-affected): use correct context data when rendering spacelift name_template admin-stack prefix #2621

Description

@coderabbitai

Summary

In name_template mode, addAffectedSpaceliftAdminStack in internal/exec/describe_affected_utils_2.go renders both the admin-stack selector prefix (line 473) and the per-candidate stack prefix (line 512) against the same configAndStacksInfo.ComponentSection. Because both sides of the comparison always produce the same string, the adminStackContextPrefix == contextPrefix guard at line 523 is effectively a no-op, and the function can match the wrong admin stack when a component name repeats across stacks.

This is in contrast to the name_pattern else branches, which correctly use adminStackContext (the selector) for the admin-stack prefix and the candidate's own context for the per-candidate prefix.

Steps to reproduce

  1. Configure stacks.name_template (instead of stacks.name_pattern).
  2. Have two stacks that share a component name, where one stack has settings.spacelift.admin_stack_selector pointing to a specific admin component.
  3. Run atmos describe-affected --include-dependents.
  4. Observe that the admin stack may be incorrectly identified because the prefix comparison is always equal.

Expected behavior

  • The admin-stack prefix should be rendered using the selector context (adminStackContext / adminStackContextSection).
  • The per-candidate prefix should be rendered using the candidate component's own section (the iterated componentSection).

Proposed fix

- adminStackContextPrefix, err = ProcessTmpl(atmosConfig, "spacelift-admin-stack-name-template", atmosConfig.Stacks.NameTemplate, configAndStacksInfo.ComponentSection, ...)
+ adminStackTemplateData := map[string]any{
+     cfg.VarsSectionName: adminStackContextSection,
+ }
+ adminStackContextPrefix, err = ProcessTmpl(atmosConfig, "spacelift-admin-stack-name-template", atmosConfig.Stacks.NameTemplate, adminStackTemplateData, ...)
...
- contextPrefix, err = ProcessTmpl(atmosConfig, "spacelift-stack-name-template", atmosConfig.Stacks.NameTemplate, configAndStacksInfo.ComponentSection, ...)
+ contextPrefix, err = ProcessTmpl(atmosConfig, "spacelift-stack-name-template", atmosConfig.Stacks.NameTemplate, componentSection, ...)

A fixture test covering name_template + spacelift admin_stack_selector + describe-affected-with-dependents should be added.

Context

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions