Skip to content

Update stack after parsing name template in describe_stacks#1226

Merged
aknysh merged 3 commits intocloudposse:mainfrom
ohaibbq:dan/update-stack
May 1, 2025
Merged

Update stack after parsing name template in describe_stacks#1226
aknysh merged 3 commits intocloudposse:mainfrom
ohaibbq:dan/update-stack

Conversation

@ohaibbq
Copy link
Contributor

@ohaibbq ohaibbq commented Apr 30, 2025

what

  • Fixes initial stack name when using the two-arg form of !terraform.output

why

Given

# atmos.yaml
stacks:
  name_template: "{{.settings.context.project_id}}--{{.settings.context.product}}"
# stacks/apps/app/staging.yaml
settings:
  context:
    project_id: staging
    product: app
components:
  terraform:
    apps/app:
      vars:
        project_number: "{{ .settings.context.project_number }}"
        location: "{{ .settings.context.location }}"
        # Pass the `connection-name` output from our `postgres-instance` component to the jii-texting app
        cloudsql_instance: !terraform.output postgres-instance connection_name
        # The 'name' output uses the name of the first bucket, so ensure that the ETL bucket is the first one in the list
        etl_bucket_name:  !terraform.output gcs-buckets name
  postgres-instance:
    # ...

!terraform.output will fail in describe_stacks.go with the following message:

ERRO no config found for the component 'postgres-instance' in the stack manifest 'app/staging'

Note that the stack manifest referenced comes from the file name which is set when looping over stacks. As components are iterated we parse the stack name_template and assign it to stackName.

This causes a race condition where configAndStacksInfo.Stack will differ between stackFileName on the first iteration and the parsed stack on the second iteration.

We use configAndStacksInfo.Stack when processing YAML functions. An alternative change would be to use the stack from the component section, but we still probably want to fix this odd state.

references

--

I've got no clue how to approach testing this in the Atmos repo, open to any guidance there!

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Improved accuracy in displaying stack information for Terraform and Helmfile components.
  • Tests

    • Added a new test to validate stack description filtering for Helmfile components.

@ohaibbq ohaibbq requested a review from a team as a code owner April 30, 2025 20:43
@mergify mergify bot added the triage Needs triage label Apr 30, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 30, 2025

📝 Walkthrough

Walkthrough

The update introduces explicit assignments to the Stack field of the configAndStacksInfo struct within the ExecuteDescribeStacks function. This occurs in both the Terraform and Helmfile component processing loops, immediately after determining the stack name and before setting related metadata in the component section. Additionally, a new test TestDescribeStacksWithFilter8 was added to verify behavior when filtering for Helmfile components with no sections. No other logic or control flow is affected.

Changes

File(s) Change Summary
internal/exec/describe_stacks.go Added explicit assignment of the Stack field in configAndStacksInfo during stack processing loops for Terraform and Helmfile components
pkg/describe/describe_stacks_test.go Added new test TestDescribeStacksWithFilter8 to verify ExecuteDescribeStacks with Helmfile component type and "none" section filter

Suggested labels

patch

Suggested reviewers

  • osterman
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 30, 2025
@mergify mergify bot removed the triage Needs triage label Apr 30, 2025
@aknysh aknysh added the patch A minor, backward compatible change label Apr 30, 2025
@codecov
Copy link

codecov bot commented Apr 30, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 32.89%. Comparing base (150687a) to head (64b56f5).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/exec/describe_stacks.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1226   +/-   ##
=======================================
  Coverage   32.89%   32.89%           
=======================================
  Files         223      223           
  Lines       23789    23791    +2     
=======================================
+ Hits         7826     7827    +1     
- Misses      14797    14798    +1     
  Partials     1166     1166           
Flag Coverage Δ
unittests 32.89% <50.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
pkg/describe/describe_stacks_test.go (1)

179-194: Good addition of test for helmfile filtering.

The new test case follows the established pattern and ensures that filtering helmfile components with "none" sections doesn't cause errors. This complements the fix in internal/exec/describe_stacks.go where the Stack field is now properly updated.

For improved robustness, consider adding specific assertions about the returned stacks structure beyond just error checking.

 	stacks, err := ExecuteDescribeStacks(atmosConfig, "", nil, componentTypes, sections, false, false)
 	assert.Nil(t, err)
+	
+	// Verify at least some stacks were returned
+	assert.NotEmpty(t, stacks, "Should return some stacks when filtering for helmfile components")
+	
+	// Verify each stack contains only helmfile components
+	for stackName, stackContent := range stacks {
+		stack := stackContent.(map[string]any)
+		components := stack["components"].(map[string]any)
+		assert.Contains(t, components, "helmfile", "Stack %s should contain helmfile components", stackName)
+	}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8076a89 and 7f92774.

📒 Files selected for processing (1)
  • pkg/describe/describe_stacks_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
pkg/describe/describe_stacks_test.go (5)
pkg/schema/schema.go (1)
  • ConfigAndStacksInfo (372-442)
pkg/config/config.go (1)
  • InitCliConfig (25-62)
internal/exec/describe_stacks.go (1)
  • ExecuteDescribeStacks (148-691)
pkg/describe/describe_stacks.go (1)
  • ExecuteDescribeStacks (9-19)
pkg/utils/yaml_utils.go (1)
  • ConvertToYAML (85-91)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary

@aknysh aknysh added no-release Do not create a new release (wait for additional code changes) and removed patch A minor, backward compatible change labels May 1, 2025
@aknysh aknysh added minor New features that do not break anything and removed no-release Do not create a new release (wait for additional code changes) labels May 1, 2025
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

thanks @ohaibbq

@aknysh aknysh merged commit c87cd51 into cloudposse:main May 1, 2025
61 checks passed
@github-actions
Copy link

github-actions bot commented May 1, 2025

These changes were released in v1.174.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor New features that do not break anything

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants