Skip to content
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

fix: common labels merge with stack labels #9

Merged
merged 1 commit into from
Dec 13, 2024
Merged

Conversation

Gowiem
Copy link
Member

@Gowiem Gowiem commented Dec 13, 2024

what

why

  • This fixes an issue a client is having where the labels that they're providing in stacks/common.yaml are being overwritten by the stack specific labels in their stacks/<stack_file_name>.yaml, which is not desired. The labels should be concatenated together, not overwrite.

references

@Gowiem Gowiem self-assigned this Dec 13, 2024
@Gowiem Gowiem requested a review from a team as a code owner December 13, 2024 00:51
Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Walkthrough

The pull request introduces several enhancements to the configuration files related to Spacelift automation. A new package, spacelift-io/spacectl@v1.8.0, is added to the aqua.yaml file. Additionally, two YAML files, common.yaml and example.yaml, now include a new labels key under the stack_settings section. Furthermore, the Terraform configuration in main.tf has been updated to include a new parameter for label management and an attribute for local preview capabilities.

Changes

File Change Summary
aqua.yaml New package added: spacelift-io/spacectl@v1.8.0 in packages section.
examples/complete/components/spacelift-automation/stacks/common.yaml New key added: labels in stack_settings.
examples/complete/components/spacelift-automation/stacks/example.yaml New key added: labels in stack_settings.
main.tf - New variable: enable_local_preview in resource "spacelift_stack" "default".
- New parameter: append_list_enabled = true in module "deep".

Possibly related PRs

  • feat: initial version terraform-spacelift-spaces#1: This PR introduces a module for managing Spacelift Spaces, which is directly related to the changes in the main PR that adds a package for Spacelift, indicating a focus on enhancing Spacelift functionalities.

🎉 In the land of code where changes flow,
New packages and labels begin to grow.
With stacks now adorned, they stand so tall,
Terraform whispers, "Let’s manage them all!"
So here's to the updates, both big and small,
In the world of Spacelift, we’ll conquer it all! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.

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. (Experiment)
  • @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 to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai 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.

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

🧹 Outside diff range and nitpick comments (3)
examples/complete/components/spacelift-automation/stacks/common.yaml (1)

4-5: Consider using more descriptive label names

While adding labels to common.yaml is correct, consider using more descriptive names than common_label to better indicate the purpose or category of the label (e.g., environment:shared, tier:common, etc.).

main.tf (2)

229-231: LGTM! Consider documenting the behavior in variables

The implementation correctly enables list appending for labels using Cloud Posse's deep merge module. This fixes the issue where common labels were being overwritten by stack-specific labels.

Consider adding a description of this behavior in the module's variables documentation:

variable "append_list_enabled" {
  type        = bool
  default     = true
-  description = "Enable list appending in deep merge"
+  description = "Enable list appending in deep merge. When true, lists (like labels) from common.yaml will be appended to stack-specific lists instead of being overwritten."
}

Line range hint 182-195: Consider adding label format validation

The label merging logic is comprehensive, handling administrative, dependency, and folder labels correctly. To prevent issues, consider adding validation for custom labels format.

Add a validation check in the Spacelift stack resource:

resource "spacelift_stack" "default" {
  # ... existing configuration ...

+ lifecycle {
+   precondition {
+     condition     = alltrue([for label in local.labels[each.key] : can(regex("^[a-z0-9][a-z0-9-_]*[a-z0-9]$", label))])
+     error_message = "Labels must consist of lowercase alphanumeric characters, hyphens, or underscores, and must start and end with an alphanumeric character"
+   }
+ }
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8a15724 and b9e63ae.

📒 Files selected for processing (4)
  • aqua.yaml (1 hunks)
  • examples/complete/components/spacelift-automation/stacks/common.yaml (1 hunks)
  • examples/complete/components/spacelift-automation/stacks/example.yaml (1 hunks)
  • main.tf (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • examples/complete/components/spacelift-automation/stacks/example.yaml
🧰 Additional context used
📓 Path-based instructions (1)
main.tf (1)

Pattern **/*.tf: You're a Terraform expert who has thoroughly studied all the documentation from Hashicorp https://developer.hashicorp.com/terraform/docs and OpenTofu https://opentofu.org/docs/.
You have a strong grasp of Terraform syntax and prioritize providing accurate and insightful code suggestions.
As a fan of the Cloud Posse / SweetOps ecosystem, you incorporate many of their best practices https://docs.cloudposse.com/best-practices/terraform/ while balancing them with general Terraform guidelines.

🔇 Additional comments (1)
aqua.yaml (1)

16-16: LGTM! Consider checking for newer versions

The addition of spacectl is appropriate for Spacelift automation. The version is correctly pinned for reproducibility.

✅ Verification successful

Version v1.8.0 is up to date

The currently used version of spacectl (v1.8.0) matches the latest release, so no update is needed at this time.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for latest spacectl versions
gh api repos/spacelift-io/spacectl/releases/latest --jq .tag_name

Length of output: 74

@@ -226,6 +226,9 @@ module "deep" {
for_each = local._root_module_stack_configs
# Stack configuration will take precedence and overwrite the conflicting value from the common configuration (if any)
maps = [local._common_configs[each.value.root_module], each.value]

# To support merging labels from common.yaml, we need lists to append instead of overwrite
append_list_enabled = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah!

@Gowiem Gowiem merged commit de4ea6f into main Dec 13, 2024
2 checks passed
@Gowiem Gowiem deleted the fix/label-merging branch December 13, 2024 01:08
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.

2 participants