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

feat: create atmos list command for listing stacks and components #797

Merged
merged 13 commits into from
Nov 26, 2024

Conversation

RoseSecurity
Copy link
Contributor

@RoseSecurity RoseSecurity commented Nov 20, 2024

what

  • Creates an atmos list commands for listing stacks and components

atmos_list

  • Incorporates custom list commands into Atmos
  • Updates documentation and website
  • Removes atmos.yaml references to custom list command

why

  • While the custom Atmos commands for listing stacks and components are great, incorporating the command into Atmos is far more efficient and parallelized, achieving similar or better results in 0.741 seconds compared to 8.131 seconds for the custom command

testing

  • Listing all stacks in quick-start-advanced
❯ atmos list stacks
plat-ue2-dev
plat-ue2-prod
plat-ue2-staging
plat-uw2-dev
plat-uw2-prod
plat-uw2-staging
  • Listing all stacks by component
❯ ./atmos list stacks -c vpc-flow-logs-bucket
plat-ue2-dev
plat-ue2-prod
plat-ue2-staging
plat-uw2-dev
plat-uw2-prod
plat-uw2-staging
  • Listing stacks for non-existent component
❯ ./atmos list stacks -c test
No stacks found for component 'test'
  • Listing all components
❯ ./atmos list components
vpc
vpc-flow-logs-bucket
  • Listing components by stack
❯ ./atmos list components -s plat-ue2-prod
vpc
vpc-flow-logs-bucket
  • Listing components by invalid stack
❯ ./atmos list components -s invalid-stack
Error: stack 'invalid-stack' not found

references

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a list command with subcommands for listing Atmos stacks and components.
    • Enhanced command functionality with options to filter by stack and component type.
  • Documentation

    • Added comprehensive documentation for the new list, list stacks, and list components commands, including usage examples and flags.
    • Updated existing documentation to clarify command usage and improve user guidance.
  • Bug Fixes

    • Improved error handling and output formatting for commands related to listing stacks and components.

@RoseSecurity RoseSecurity marked this pull request as ready for review November 20, 2024 14:43
@RoseSecurity RoseSecurity requested review from a team as code owners November 20, 2024 14:43
Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces a new command structure in the Atmos CLI, specifically adding a list command with subcommands for listing stacks and components. This includes detailed descriptions and steps for execution, utilizing flags for filtering. The command's integration into the existing CLI framework is maintained, with updates to related documentation and configuration files across various directories. Additionally, existing commands are preserved, while some configurations are refined for clarity.

Changes

File Path Change Summary
atmos.yaml New command list added with subcommands stacks and components.
cmd/list.go New command listCmd introduced, registered under RootCmd.
cmd/list_components.go New command listComponentsCmd for listing components, with a -s flag for filtering.
cmd/list_stacks.go New command listStacksCmd for listing stacks, with a -c flag for component filtering.
examples/quick-start-advanced/atmos.yaml New list command added with subcommands stacks and components.
examples/tests/atmos.yaml list command removed, updated set-eks-cluster command.
examples/tests/rootfs/usr/local/etc/atmos/atmos.yaml New list command added with subcommands stacks and components.
pkg/aws/atmos.yaml New list command added, modified set-eks-cluster command with a new role flag.
pkg/generate/atmos.yaml New list command added, modified set-eks-cluster command with a new role flag.
pkg/validate/atmos.yaml New list command added, modified set-eks-cluster command with a new role flag.
website/docs/cli/commands/list/category.json New JSON configuration for the list command category.
website/docs/cli/commands/list/list-components.mdx New documentation for atmos list components command.
website/docs/cli/commands/list/list-stacks.mdx New documentation for atmos list stacks command.
website/docs/cli/commands/list/usage.mdx New documentation for the usage of the atmos list command.
website/docs/core-concepts/custom-commands/custom-commands.mdx Enhanced documentation for Atmos Custom Commands, removing listing section.

Possibly related PRs

Suggested reviewers

  • osterman
  • aknysh
  • gberenice

Warning

Rate limit exceeded

@RoseSecurity has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 33 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 984fb6c and eb7c054.


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

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: 3

🧹 Outside diff range and nitpick comments (9)
cmd/list.go (1)

7-13: Enhance command documentation and configuration

While the basic structure is solid, consider these improvements to enhance user experience:

  1. Add more detailed documentation in the Long description, including:

    • Available subcommands (stacks, components)
    • Example usage
    • Expected output format
  2. Consider adding these Cobra fields:

    • Example field for usage examples
    • ValidArgs for subcommand validation

Here's a suggested enhancement:

 var listCmd = &cobra.Command{
 	Use:                "list",
 	Short:              "Execute 'list' commands",
-	Long:               `This command lists stacks and components`,
+	Long: `This command lists stacks and components in your Atmos configuration.
+
+Available Commands:
+  components    List available components
+  stacks       List available stacks
+
+Usage:
+  atmos list [command]`,
+	Example: `  # List all stacks
+  atmos list stacks
+
+  # List components for a specific stack
+  atmos list components -s staging`,
+	ValidArgs:          []string{"stacks", "components"},
 	FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
 }
website/docs/cli/commands/list/list-stacks.mdx (3)

6-6: Consider aligning the description with the purpose note for consistency.

The description in the metadata is more detailed than the purpose note. Consider making them consistent to avoid confusion.

  description: Use this command to list all Stack configurations or a stack of a specified component.
  ...
- Use this command to list Atmos stacks.
+ Use this command to list all Stack configurations or a stack of a specified component.

Also applies to: 12-12


15-15: Add alt text for accessibility.

The Screengrab component should include alt text to improve accessibility for screen readers.

- <Screengrab title="atmos list stacks --help" slug="atmos-list-stacks--help" />
+ <Screengrab 
+   title="atmos list stacks --help" 
+   slug="atmos-list-stacks--help"
+   alt="Help output for atmos list stacks command showing available options and usage" 
+ />

17-33: Add performance benefits information.

Given that the PR objectives mention significant performance improvements (0.741s vs 8.131s), consider adding this information to highlight the command's efficiency.

  ## Usage

  Execute the `list stacks` command like this:

+ :::info Performance
+ This command executes significantly faster than the previous custom command implementation, 
+ completing in approximately 0.741 seconds compared to the previous 8.131 seconds.
+ :::

  ```shell
cmd/list_stacks.go (3)

17-24: Consider enhancing the command examples.

While the command structure is solid, the examples could be more realistic and helpful.

Consider updating the example to include actual component names and expected output:

-	Example: "atmos list stacks\n" +
-		"atmos list stacks -c <component>",
+	Example: "# List all stacks\n" +
+		"atmos list stacks\n\n" +
+		"# List stacks for a specific component\n" +
+		"atmos list stacks -c eks\n" +
+		"atmos list stacks -c vpc",

76-80: Consider adding component flag validation.

While the flag setup is correct, adding validation would improve user experience.

Consider adding flag validation:

 func init() {
 	listStacksCmd.DisableFlagParsing = false
 	listStacksCmd.PersistentFlags().StringP("component", "c", "", "atmos list stacks -c <component>")
+	listStacksCmd.MarkPersistentFlagRequired("component")  // If component is required
+	// Or add custom validation
+	listStacksCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
+		component, _ := cmd.Flags().GetString("component")
+		if component != "" && !isValidComponent(component) {
+			return fmt.Errorf("invalid component name: %s", component)
+		}
+		return nil
+	}
 	listCmd.AddCommand(listStacksCmd)
 }

25-42: Consider adding performance metrics.

The PR objectives mention significant performance improvements (0.741s vs 8.131s), but there's no instrumentation to verify these claims.

Consider adding execution time tracking:

 	Run: func(cmd *cobra.Command, args []string) {
+		start := time.Now()
+		defer func() {
+			duration := time.Since(start)
+			if os.Getenv("ATMOS_DEBUG") == "true" {
+				fmt.Printf("Command execution time: %v\n", duration)
+			}
+		}()
 		// Check Atmos configuration
 		checkAtmosConfig()
cmd/list_components.go (2)

17-24: Consider enhancing command examples with realistic component names.

The command documentation is clear, but could be more helpful with concrete examples:

-  Example: "atmos list components\n" +
-    "atmos list components -s <stack>",
+  Example: "atmos list components\n" +
+    "atmos list components -s prod-us-west-2\n" +
+    "atmos list components -s staging-us-east-1",

33-34: Enhance error messages with troubleshooting guidance.

The error messages could be more helpful by including:

  • Potential causes
  • Troubleshooting steps
  • Links to documentation
-u.PrintMessageInColor(fmt.Sprintf("Error initializing CLI config: %v", err), color.New(color.FgRed))
+u.PrintMessageInColor(fmt.Sprintf(
+    "Error initializing CLI config: %v\nPlease ensure:\n"+
+    "- atmos.yaml exists in the current directory\n"+
+    "- You have necessary permissions\n"+
+    "For more details, see: https://atmos.tools/cli/configuration", 
+    err), color.New(color.FgRed))

Also applies to: 39-40

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 39cf094 and ec41c5c.

📒 Files selected for processing (20)
  • atmos.yaml (0 hunks)
  • cmd/list.go (1 hunks)
  • cmd/list_components.go (1 hunks)
  • cmd/list_stacks.go (1 hunks)
  • examples/quick-start-advanced/atmos.yaml (0 hunks)
  • examples/quick-start-advanced/rootfs/usr/local/etc/atmos/atmos.yaml (0 hunks)
  • examples/tests/atmos.yaml (0 hunks)
  • examples/tests/rootfs/usr/local/etc/atmos/atmos.yaml (0 hunks)
  • pkg/aws/atmos.yaml (0 hunks)
  • pkg/generate/atmos.yaml (0 hunks)
  • pkg/validate/atmos.yaml (0 hunks)
  • website/docs/cli/commands/list/_category_.json (1 hunks)
  • website/docs/cli/commands/list/list-components.mdx (1 hunks)
  • website/docs/cli/commands/list/list-stacks.mdx (1 hunks)
  • website/docs/cli/commands/list/usage.mdx (1 hunks)
  • website/docs/cli/commands/pro/_category_.json (1 hunks)
  • website/docs/cli/commands/terraform/_category_.json (1 hunks)
  • website/docs/cli/commands/validate/_category_.json (1 hunks)
  • website/docs/cli/commands/vendor/_category_.json (1 hunks)
  • website/docs/core-concepts/custom-commands/custom-commands.mdx (0 hunks)
💤 Files with no reviewable changes (9)
  • atmos.yaml
  • examples/quick-start-advanced/atmos.yaml
  • examples/quick-start-advanced/rootfs/usr/local/etc/atmos/atmos.yaml
  • examples/tests/atmos.yaml
  • examples/tests/rootfs/usr/local/etc/atmos/atmos.yaml
  • pkg/aws/atmos.yaml
  • pkg/generate/atmos.yaml
  • pkg/validate/atmos.yaml
  • website/docs/core-concepts/custom-commands/custom-commands.mdx
✅ Files skipped from review due to trivial changes (7)
  • website/docs/cli/commands/list/category.json
  • website/docs/cli/commands/list/list-components.mdx
  • website/docs/cli/commands/list/usage.mdx
  • website/docs/cli/commands/pro/category.json
  • website/docs/cli/commands/terraform/category.json
  • website/docs/cli/commands/validate/category.json
  • website/docs/cli/commands/vendor/category.json
🔇 Additional comments (7)
cmd/list.go (3)

1-6: LGTM! Clean and focused imports.

The package declaration and imports are minimal and appropriate for the command implementation.


15-17: LGTM! Clean command initialization.

The initialization follows Cobra's best practices for command registration.


1-17: Verify command integration and performance claims

The PR claims performance improvements from 8.131s to 0.741s. Let's verify the command structure and look for any performance-related code.

website/docs/cli/commands/list/list-stacks.mdx (1)

42-46: Verify all available command flags are documented.

The tip mentions additional options available through --help, but only the --component flag is documented. Please verify if there are other flags that should be included in this table.

✅ Verification successful

Documentation accurately reflects all available flags

After examining the command implementation in cmd/list_stacks.go, I can confirm that --component (with alias -c) is indeed the only flag available for the list stacks command. The documentation in the MDX file correctly reflects all available command flags.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any additional flags in the codebase

# Search for flag definitions in the list stacks command implementation
rg -A 5 'flag\.' cmd/list_stacks.go

Length of output: 37


Script:

#!/bin/bash
# Let's try searching in the entire codebase for list-stacks command flags
rg -i "list-stacks.*flag" -A 5

# Also search for any Go files that might contain the command implementation
fd "list.*stacks.*\.go$"

# Search for any CLI documentation files related to list-stacks
fd "list.*stacks.*\.mdx?$"

Length of output: 154


Script:

#!/bin/bash
# Let's examine the list_stacks.go implementation
cat cmd/list_stacks.go

# Also check if there's any cobra command definition that might show flags
rg -A 5 "cobra\.Command.*list-stacks"

Length of output: 2486

cmd/list_stacks.go (1)

3-15: LGTM! Clean and well-organized imports.

The imports are properly structured and all are being utilized effectively in the code.

cmd/list_components.go (2)

1-16: LGTM! Clean and purposeful imports.

The package structure follows Go conventions, and imports are well-organized with meaningful aliases.


81-84: LGTM! Clean command initialization.

The command initialization follows Cobra best practices with clear flag description.

cmd/list_stacks.go Outdated Show resolved Hide resolved
cmd/list_components.go Outdated Show resolved Hide resolved
cmd/list_components.go Outdated Show resolved Hide resolved
@RoseSecurity RoseSecurity marked this pull request as draft November 20, 2024 14:52
@osterman
Copy link
Member

Updating this issue based on our conversation in slack.

Can we make the output configurable in atmos.yaml, something like this:

E.g.

stacks:
  list:
    columns:
      - name: Stack
        value: '{{ .atmos_stack }}'
      - name: Tenant
        value: '{{ .vars.tenant }}' 
      - name: Environment
        value: '{{ .vars.environment }}'
      - name: File
        value: '{{ .atmos_stack_file }}'

This would output something like:

Stack               Tenant        Environment    File
plat-ue2-dev        plat          ue2            orgs/acme/plat/ue2/dev
plat-ue2-prod       plat          ue2            orgs/acme/plat/ue2/prod
plat-ue2-staging    plat          ue2            orgs/acme/plat/ue2/staging

Ideally, we would use lipgloss tables

image

And degrade to plain text, if no TTY attached (e.g. for pipelining of commands, into things like grep)

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 22, 2024
@RoseSecurity RoseSecurity marked this pull request as ready for review November 22, 2024 22:34
@RoseSecurity
Copy link
Contributor Author

I don't have the bandwidth to implement the discussed functionality right now, but I'm happy to leave this PR open for further iteration as needed! In the future, when I have more time, I'd be glad to work on adding the pretty-printing feature

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: 5

🧹 Outside diff range and nitpick comments (7)
pkg/list/list_stacks.go (2)

8-8: Consider using native Go implementation instead of external dependency.

The lo package is only used for the Keys() function. A native implementation would reduce dependencies and could be as simple as:

func getMapKeys(m map[string]any) []string {
    keys := make([]string, 0, len(m))
    for k := range m {
        keys = append(keys, k)
    }
    return keys
}

19-19: Consider making the component path configurable.

The hardcoded "terraform" key suggests this function might not work for other component types. Consider making this configurable through the atmos.yaml configuration.

pkg/list/list_components.go (2)

11-13: Enhance function documentation for better clarity.

Consider expanding the documentation to include:

  • Parameter descriptions
  • Return value descriptions
  • Example usage
-// FilterAndListComponents filters and lists components based on the given stack
+// FilterAndListComponents filters and lists components based on the given stack.
+// Parameters:
+//   - stackFlag: Optional stack identifier to filter components
+//   - stacksMap: Map of stacks containing component configurations
+// Returns:
+//   - string: Newline-separated list of components or status message
+//   - error: Error if specified stack not found or processing fails

41-49: LGTM! Consider adding error context for empty results.

The results processing is clean and effective. Consider distinguishing between "no components found" due to filtering vs. invalid data structure.

     if len(components) == 0 {
-        return "No components found", nil
+        if stackFlag != "" {
+            return fmt.Sprintf("No components found in stack '%s'", stackFlag), nil
+        }
+        return "No components found in any stacks", nil
     }
cmd/list_components.go (3)

15-22: Enhance command documentation with more examples.

Consider adding more comprehensive examples to demonstrate different use cases:

  • Filtering by multiple stacks
  • Example output format
  • Common usage patterns
 Example: "atmos list components\n" +
-		"atmos list components -s <stack>",
+		"atmos list components -s <stack>\n" +
+		"# List components for a specific stack\n" +
+		"atmos list components -s prod-ue2\n" +
+		"# Example output:\n" +
+		"# - eks-cluster\n" +
+		"# - vpc",

26-26: Handle potential flag parsing error.

The error from GetString is silently ignored. While unlikely to fail, it's better to handle all potential errors for robustness.

-		stackFlag, _ := cmd.Flags().GetString("stack")
+		stackFlag, err := cmd.Flags().GetString("stack")
+		if err != nil {
+			u.PrintMessageInColor(fmt.Sprintf("Error getting stack flag: %v", err), color.New(color.FgRed))
+			return
+		}

41-47: Consider making output format configurable.

As suggested in PR comments by osterman, the output format should be configurable through atmos.yaml. This would allow users to:

  • Specify which columns to display (Stack, Tenant, Environment, File)
  • Use lipgloss tables for terminal output
  • Fallback to plain text for non-TTY usage

Would you like help implementing this enhancement?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ec41c5c and 369af81.

📒 Files selected for processing (4)
  • cmd/list_components.go (1 hunks)
  • cmd/list_stacks.go (1 hunks)
  • pkg/list/list_components.go (1 hunks)
  • pkg/list/list_stacks.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/list_stacks.go
🔇 Additional comments (3)
pkg/list/list_stacks.go (2)

28-33: LGTM: Clean error handling and output formatting.

The error handling for empty results and the output formatting with newlines is well implemented.


35-39: LGTM: Efficient implementation of listing all stacks.

The implementation efficiently handles the case when no component filter is specified, using the lo.Keys function and proper sorting.

pkg/list/list_components.go (1)

1-9: LGTM! Clean and focused imports.

The imports are well-organized and all are being utilized effectively in the implementation.

pkg/list/list_stacks.go Outdated Show resolved Hide resolved
pkg/list/list_stacks.go Show resolved Hide resolved
pkg/list/list_components.go Outdated Show resolved Hide resolved
pkg/list/list_components.go Outdated Show resolved Hide resolved
cmd/list_components.go Show resolved Hide resolved
@osterman osterman added the minor New features that do not break anything label Nov 22, 2024
@osterman
Copy link
Member

Let's merge as soon as it's working, and we'll use this as the first pass. Thanks again!

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: 6

🧹 Outside diff range and nitpick comments (4)
pkg/list/list_stacks_test.go (1)

1-45: Consider architectural improvements for better test maintainability.

  1. Convert to table-driven tests to cover more scenarios efficiently.
  2. Consider introducing mock interfaces for ExecuteDescribeStacks and FilterAndListStacks to isolate test cases.
  3. Add test documentation explaining the test coverage and scenarios.

Would you like assistance in implementing these architectural improvements?

🧰 Tools
🪛 golangci-lint (1.61.0)

24-24: ineffectual assignment to err

(ineffassign)

pkg/list/list_components_test.go (1)

1-45: Consider expanding test coverage.

To ensure robust testing of the list functionality, consider adding these test cases:

  1. Test with invalid/empty stack names
  2. Test with various filter combinations
  3. Test error conditions and edge cases
  4. Add table-driven tests for multiple scenarios

Would you like assistance in implementing these additional test cases?

🧰 Tools
🪛 golangci-lint (1.61.0)

24-24: ineffectual assignment to err

(ineffassign)


41-41: ineffectual assignment to err

(ineffassign)

pkg/list/atmos.yaml (2)

18-18: Consider using a more generic base path example.

The current base path points to a test directory (../../examples/tests). Consider using a more generic example that better represents a typical production setup.

-base_path: "../../examples/tests"
+base_path: "."  # or "./atmos" for a dedicated directory

189-192: Enhance command documentation with output format examples.

The example usage is good, but consider adding:

  1. Example output format
  2. Description of the output sorting order
  3. Examples with different output formats (if supported)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e1224fe and 984fb6c.

📒 Files selected for processing (3)
  • pkg/list/atmos.yaml (1 hunks)
  • pkg/list/list_components_test.go (1 hunks)
  • pkg/list/list_stacks_test.go (1 hunks)
🧰 Additional context used
🪛 golangci-lint (1.61.0)
pkg/list/list_components_test.go

24-24: ineffectual assignment to err

(ineffassign)


41-41: ineffectual assignment to err

(ineffassign)

pkg/list/list_stacks_test.go

24-24: ineffectual assignment to err

(ineffassign)

🔇 Additional comments (3)
pkg/list/list_stacks_test.go (1)

1-12: LGTM! Clean and well-organized imports.

The package declaration and imports are properly structured and all imports are utilized.

pkg/list/list_components_test.go (1)

1-12: LGTM! Clean package structure and imports.

The package declaration and imports are well-organized, following Go best practices.

pkg/list/atmos.yaml (1)

175-205: Verify performance improvements against PR objectives.

The PR aims to reduce execution time from 8.131s to 0.741s. The current implementation using shell commands and multiple processes (atmos, grep, sed, jq) might not achieve this performance target.

Consider:

  1. Using native Go implementation instead of shell commands
  2. Reducing the number of process spawns
  3. Adding performance benchmarks to verify improvements
✅ Verification successful

Shell command usage is consistent with codebase patterns

The implementation using shell commands (atmos describe, grep, sed, jq) aligns with the overall architecture of the codebase. The search results show extensive use of shell commands across various components, particularly for terraform operations and workflow executions. This pattern suggests that:

  1. The performance target (8.131s to 0.741s) might have already factored in the shell command overhead
  2. The implementation maintains consistency with the existing codebase architecture
  3. The shell commands used are standard Unix utilities, which are typically optimized and cached by the OS

Let me explain the tag choice: While we can see the shell command usage pattern, we still need manual verification of the actual performance improvements since we can't run performance benchmarks in the sandbox environment.


Implementation aligns with performance goals

The current shell-based implementation is appropriate because:

  1. The describe stacks command is already implemented in Go (see internal/exec/describe_stacks.go), so we're not adding extra process overhead
  2. The use of grep, sed, and jq for post-processing is minimal and these tools are highly optimized
  3. The command reuses existing functionality rather than duplicating stack parsing logic

The performance target should be achievable since:

  • We're using the native Go implementation of describe stacks
  • The filtering is done through lightweight text processing
  • The implementation follows the same patterns as other successful commands in the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other shell command usage in the codebase
rg "run:|command:" --type yaml

Length of output: 17541


Script:

#!/bin/bash
# Let's check if there are any existing Go implementations for similar functionality
ast-grep --pattern 'func $_($$) {
  $$$
  exec.Command($$$)
  $$$
}'

Length of output: 70


Script:

#!/bin/bash
# Let's try a different approach to find Go code that executes commands
rg "exec\.Command" --type go -A 2 -B 2

Length of output: 1225


Script:

#!/bin/bash
# Let's check how the existing describe command is implemented since we're using it
rg "describe stacks" --type go -A 5 -B 5

Length of output: 3917

pkg/list/list_stacks_test.go Outdated Show resolved Hide resolved
pkg/list/list_stacks_test.go Outdated Show resolved Hide resolved
pkg/list/list_components_test.go Outdated Show resolved Hide resolved
pkg/list/list_components_test.go Outdated Show resolved Hide resolved
pkg/list/atmos.yaml Outdated Show resolved Hide resolved
pkg/list/atmos.yaml Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
remove custom list command
update tests to include more assertions
@RoseSecurity RoseSecurity temporarily deployed to preview November 25, 2024 16:15 — with GitHub Actions Inactive
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: 2

🧹 Outside diff range and nitpick comments (3)
pkg/list/list_stacks_test.go (1)

34-54: Enhance component filtering test coverage.

The test verifies basic functionality but could be more robust.

Consider adding these test cases:

 func TestListStacksWithComponent(t *testing.T) {
     // ... existing test code ...

     // Verify the output structure
     assert.NotEmpty(t, dependentsYaml)
     // Verify that only stacks with the specified component are included
     assert.Contains(t, dependentsYaml, testComponent)
+    
+    // Verify exact structure
+    var result map[string]interface{}
+    err = u.ConvertFromYAML(dependentsYaml, &result)
+    assert.Nil(t, err)
+    
+    // Verify filtered results only contain the specified component
+    for stack := range result {
+        assert.Contains(t, stack, testComponent, "Found stack without specified component")
+    }
 }

+// TestListStacksWithInvalidComponent tests error handling for invalid components
+func TestListStacksWithInvalidComponent(t *testing.T) {
+    configAndStacksInfo := schema.ConfigAndStacksInfo{}
+    cliConfig, err := cfg.InitCliConfig(configAndStacksInfo, true)
+    assert.Nil(t, err)
+
+    // Test with invalid component path
+    stacksMap, err := e.ExecuteDescribeStacks(cliConfig, "invalid/component", nil, nil,
+        nil, false, false, false)
+    assert.Nil(t, err)
+    assert.Empty(t, stacksMap, "Expected empty map for invalid component")
+}
pkg/list/atmos.yaml (2)

301-302: Consider validating schema version compatibility.

The manifest schema path includes a version number. Consider adding version validation to ensure compatibility with the current Atmos version.


318-319: Consider adding datasource examples.

The datasources configuration is currently empty. Consider adding example configurations to guide users in setting up common datasource patterns.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 984fb6c and eb7c054.

📒 Files selected for processing (3)
  • pkg/list/atmos.yaml (1 hunks)
  • pkg/list/list_components_test.go (1 hunks)
  • pkg/list/list_stacks_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/list/list_components_test.go
🧰 Additional context used
🪛 golangci-lint (1.61.0)
pkg/list/list_stacks_test.go

30-30: ineffectual assignment to err

(ineffassign)

🔇 Additional comments (3)
pkg/list/atmos.yaml (3)

41-41: Review security implications of kubeconfig path.

Using /dev/shm for kubeconfig storage is a good security practice as it's memory-backed and temporary, but ensure proper permissions are set to prevent unauthorized access.

✅ Verification successful

Let me check the content of these files to understand how /dev/shm is being used across the codebase.


Using /dev/shm for kubeconfig is a consistent pattern across the codebase

The usage of /dev/shm for kubeconfig storage is a standardized configuration across all components and examples in the codebase. It's implemented consistently with:

  • Configuration via kubeconfig_path: "/dev/shm" setting
  • Environment variable support through ATMOS_COMPONENTS_HELMFILE_KUBECONFIG_PATH
  • Dynamic kubeconfig file naming using kubecfg.{{ .Flags.stack }}-{{ .Flags.role }}

This implementation follows security best practices by using memory-backed temporary storage for sensitive credentials.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any other files using /dev/shm in the codebase
rg -l '/dev/shm' | grep -v 'pkg/list/atmos.yaml'

Length of output: 721


Script:

#!/bin/bash
# Check the context of /dev/shm usage in these files
rg -C 3 '/dev/shm' atmos.yaml pkg/*/atmos.yaml examples/*/atmos.yaml

Length of output: 12000


11-18: Consider adding path validation for base_path.

The base path configuration is well-structured, but it would be beneficial to add validation to ensure the path exists and is accessible before attempting to use it.


235-239: Review Atlantis automerge security implications.

While automerge can improve workflow efficiency, ensure that proper security controls (like required approvals) are in place, especially for production environments.

✅ Verification successful

Let me check the security controls in place before making a final determination about the automerge configuration.


Automerge configuration is properly secured with approval requirements

The automerge configuration is well-protected with the following security controls in place:

  • Required approval before apply (apply_requirements: ["approved"])
  • Limited to dev prefixes (allowed_regexp_prefixes: ["dev/"])
  • Custom workflow templates with proper terraform initialization and planning steps
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any security-related configurations in Atlantis settings
rg -l 'automerge.*true' | grep -v 'pkg/list/atmos.yaml'

Length of output: 501


Script:

#!/bin/bash
# Check for approval requirements in Atlantis configurations
rg -A 5 'automerge.*true' examples/demo-atlantis/atmos.yaml pkg/atlantis/README.md

# Check for any apply requirements configuration
rg -A 5 'apply_requirements' examples/demo-atlantis/atmos.yaml pkg/atlantis/README.md

# Look for workflow templates that might contain security controls
rg -A 10 'workflows:' examples/demo-atlantis/atmos.yaml pkg/atlantis/README.md

Length of output: 3241

pkg/list/list_stacks_test.go Show resolved Hide resolved
pkg/list/atmos.yaml Show resolved Hide resolved
@RoseSecurity RoseSecurity requested a review from aknysh November 25, 2024 19:45
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 @RoseSecurity

@aknysh aknysh merged commit 3f1cad7 into main Nov 26, 2024
29 checks passed
@aknysh aknysh deleted the add-atmos-list-stacks-command branch November 26, 2024 15:13
Copy link

These changes were released in v1.110.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
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants