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

revert "refactor loading and checking of atmos config" #885

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

mcalhoun
Copy link
Member

@mcalhoun mcalhoun commented Dec 23, 2024

what

Reverts #869

why

Because this PR introduced some regressions with help commands.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a preliminary configuration check for Atmos in various command executions to enhance robustness.
  • Bug Fixes

    • Improved error handling during Atmos configuration initialization across multiple commands.
  • Refactor

    • Streamlined the retrieval and handling of Atmos configuration in several commands, removing unnecessary context management.
  • Documentation

    • Updated command execution logic descriptions to reflect the new configuration validation steps.

@mergify mergify bot added the triage Needs triage label Dec 23, 2024
@mcalhoun mcalhoun self-assigned this Dec 23, 2024
@mcalhoun mcalhoun added no-release Do not create a new release (wait for additional code changes) and removed triage Needs triage labels Dec 23, 2024
@mcalhoun mcalhoun marked this pull request as ready for review December 23, 2024 16:34
@mcalhoun mcalhoun requested a review from a team as a code owner December 23, 2024 16:34
Copy link
Contributor

coderabbitai bot commented Dec 23, 2024

📝 Walkthrough

Walkthrough

The pull request introduces a systematic enhancement to the Atmos CLI configuration validation process across multiple command files. The changes primarily involve adding a checkAtmosConfig() function call at the beginning of various command Run methods, ensuring that configuration validation occurs before command execution. This modification standardizes configuration checks, improves error handling, and provides a consistent approach to verifying Atmos configurations before running commands.

Changes

File Change Summary
cmd/cmd_utils.go Updated checkAtmosConfig() and CheckForAtmosUpdateAndPrintMessage() function signatures, removing pointer references and modifying configuration initialization
cmd/root.go Added global atmosConfig variable, modified configuration initialization in Execute() function
Multiple command files Added checkAtmosConfig() function call before command execution (e.g., terraform.go, list_components.go, describe_stacks.go)

Possibly related PRs

Suggested Reviewers

  • Gowiem
  • aknysh
  • osterman

The changes represent a robust approach to standardizing configuration validation across the Atmos CLI, ensuring consistent error handling and configuration checks.

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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. (Beta)
  • @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: 0

🧹 Nitpick comments (2)
cmd/helmfile.go (1)

40-41: Great Addition

Calling checkAtmosConfig() ensures configuration validity before proceeding with Helmfile logic.

Could you consider adding a short inline comment indicating why configuration verification is mandatory at this phase?

cmd/root.go (1)

21-21: Consider scoping the global variable more narrowly.

While adding a global variable for storing configuration simplifies the code, it might make concurrency or reusability more difficult in the future.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 262affa and eb46fca.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (23)
  • cmd/atlantis_generate_repo_config.go (1 hunks)
  • cmd/cmd_utils.go (6 hunks)
  • cmd/describe_affected.go (1 hunks)
  • cmd/describe_component.go (1 hunks)
  • cmd/describe_dependents.go (1 hunks)
  • cmd/describe_stacks.go (1 hunks)
  • cmd/helmfile.go (1 hunks)
  • cmd/helmfile_generate_varfile.go (1 hunks)
  • cmd/list_components.go (2 hunks)
  • cmd/list_stacks.go (2 hunks)
  • cmd/pro_lock.go (1 hunks)
  • cmd/pro_unlock.go (1 hunks)
  • cmd/root.go (3 hunks)
  • cmd/terraform.go (2 hunks)
  • cmd/terraform_generate_backend.go (1 hunks)
  • cmd/terraform_generate_backends.go (1 hunks)
  • cmd/terraform_generate_varfile.go (1 hunks)
  • cmd/terraform_generate_varfiles.go (1 hunks)
  • cmd/validate_component.go (1 hunks)
  • cmd/validate_stacks.go (1 hunks)
  • cmd/vendor_diff.go (1 hunks)
  • cmd/vendor_pull.go (1 hunks)
  • cmd/version.go (1 hunks)
🧰 Additional context used
📓 Learnings (2)
cmd/version.go (1)
Learnt from: Listener430
PR: cloudposse/atmos#844
File: cmd/version.go:34-44
Timestamp: 2024-12-13T15:28:13.630Z
Learning: In `cmd/version.go`, when handling the `--check` flag in the `versionCmd`, avoid using `CheckForAtmosUpdateAndPrintMessage(cliConfig)` as it updates the cache timestamp, which may not be desired in this context.
cmd/cmd_utils.go (2)
Learnt from: Listener430
PR: cloudposse/atmos#844
File: cmd/version.go:34-44
Timestamp: 2024-12-13T15:28:13.630Z
Learning: In `cmd/version.go`, when handling the `--check` flag in the `versionCmd`, avoid using `CheckForAtmosUpdateAndPrintMessage(cliConfig)` as it updates the cache timestamp, which may not be desired in this context.
Learnt from: osterman
PR: cloudposse/atmos#740
File: cmd/cmd_utils.go:340-359
Timestamp: 2024-11-12T05:52:05.088Z
Learning: In the Go codebase for Atmos, when reviewing functions like `checkAtmosConfig` in `cmd/cmd_utils.go`, avoid suggesting refactoring to return errors instead of calling `os.Exit` if such changes would significantly increase the scope due to the need to update multiple call sites.
🔇 Additional comments (38)
cmd/list_components.go (3)

7-7: Import usage looks fine

The newly added import for config aligns with your existing usage.


23-25: Configuration check is well-placed

Calling checkAtmosConfig() before other operations is good for ensuring a valid state.


28-33: Initialization logic looks tidy

Assigning configAndStacksInfo and handling the error quickly keeps things straightforward.

cmd/list_stacks.go (3)

7-7: Import usage matches pattern

The config import here is consistent with other commands.


24-26: Proactive validation

Placing checkAtmosConfig() near the start helps prevent deeper command failures.


29-34: Error handling is effective

Exiting early on a config error prevents further issues down the line.

cmd/pro_unlock.go (1)

18-20: Clear config check

Adding checkAtmosConfig() improves consistency with other commands.

cmd/validate_stacks.go (1)

20-22: Validation happens early

Short-circuiting on bad config avoids wasted effort in validating stacks.

cmd/pro_lock.go (1)

18-20: Configuration validation is consistent

This check is in line with the approach used across other commands.

cmd/terraform_generate_backend.go (1)

18-19: Looks good

This reinstatement of configuration checking is aligned with the rest of the code. No issues found.

cmd/vendor_diff.go (1)

18-19: Smooth integration

Calling checkAtmosConfig() up front is consistent. No concerns noted.

cmd/helmfile_generate_varfile.go (1)

18-19: All set

The addition of checkAtmosConfig() maintains consistency with other commands.

cmd/terraform_generate_varfile.go (1)

18-19: No concerns

Pre-flight config checks are useful. This is straightforward and compliant with existing patterns.

cmd/helmfile.go (1)

37-37: Seems Good

The updated function call uses the local variable directly, simplifying the code.

cmd/describe_dependents.go (1)

19-20: Wise Check

Invoking checkAtmosConfig() early helps avoid misconfiguration issues. The approach is consistent with other commands.

cmd/terraform.go (3)

39-39: Slight Improvement

Switching away from taking a pointer reduces confusion about config mutability. Nicely done.


42-43: Essential Configuration Validation

Ensures config correctness before executing terraform commands. This keeps behavior consistent.


20-21: Check Intent

It looks like this segment is commented out. Could you clarify if this is intentional or if you meant for the check to remain active?

✅ Verification successful

Let me investigate this by checking the codebase for more context about this commented function.

This will help us understand:

  1. If the function exists elsewhere in the codebase
  2. How Atmos configuration is handled in general
  3. The full context of the terraform.go file where this comment appears

Let me check the content of the terraform.go file specifically to understand the context of this commented line.


Let me check if this check is performed elsewhere in the same file, as it might have been moved to a different location.


The commented line is intentional and safe to ignore

The check is actually performed later in the same function. The commented line at the beginning was likely moved down to be executed after the help check, as we can see the active checkAtmosConfig() call is present after the help check but before executing terraform. This is a better logical flow as it prevents unnecessary configuration checks when only help is requested.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for checkAtmosConfig function definition and usage
rg "checkAtmosConfig" -A 5

# Look for any Atmos configuration related code
rg "Atmos.*config" -i

# Check the specific file content
cat cmd/terraform.go

Length of output: 67538


Script:

#!/bin/bash
# Get the specific content around the commented line
rg -A 10 -B 10 "//checkAtmosConfig\(\)" cmd/terraform.go

Length of output: 873


Script:

#!/bin/bash
# Get the full content of terraform.go to see where the check might be performed
cat cmd/terraform.go | grep -A 50 "Run: func"

Length of output: 1178

cmd/vendor_pull.go (1)

20-20: Thoughtful Enhancement

Including WithStackValidation(...) is a good step toward ensuring a proper config check when the --stack flag is used.

cmd/describe_component.go (1)

18-19: Validate configuration before command execution

Performing the Atmos configuration check here ensures errors are caught early. Keep up the consistency across commands.

cmd/version.go (1)

56-56: Avoid caching updates if it’s not desired

Consider the learning about not updating the timestamp when using the --check flag. Confirm whether caching updates are actually needed in this context.

✅ Verification successful

Let me gather more information about the update checking functionality to verify this concern.


Let me check how the --check flag is handled in the version command.


Let me check the version command implementation specifically.


Cache update behavior is correct and intentional

The code is properly handling caching updates. When the --check flag is used, it performs a direct version check without caching (lines 39-53). The CheckForAtmosUpdateAndPrintMessage is only called when --check flag is not used (line 56), which is the intended behavior for normal version checks that should respect the caching configuration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Let's first look at the CheckForAtmosUpdateAndPrintMessage function implementation
ast-grep --pattern 'func CheckForAtmosUpdateAndPrintMessage($_) {
  $$$
}'

# Also search for any check flag related logic
rg -A 5 "check.*flag" 

# Look for update caching related code
rg -i "cache.*update"

Length of output: 5493


Script:

#!/bin/bash
# Look at the version command implementation to see how the --check flag is handled
ast-grep --pattern 'func newVersionCmd($_) {
  $$$
}'

# Also check for any version check configuration handling
rg -A 5 "Version.*Check"

Length of output: 1713


Script:

#!/bin/bash
# Look at the content of the version.go file
cat cmd/version.go

Length of output: 1825

cmd/validate_component.go (1)

24-25: Configuration check for consistent validation

Including the config check is a good addition. It helps maintain uniform validation flow across the application.

cmd/describe_stacks.go (1)

18-19: Ensuring Atmos config correctness

Validating configuration at the start helps avoid downstream errors. Good practice to keep it consistent with other commands.

cmd/terraform_generate_varfiles.go (1)

18-19: Good addition of early config check
Verifying the atmos configuration at the beginning helps ensure correctness before proceeding with command execution.

cmd/terraform_generate_backends.go (1)

18-19: Checking config upfront is a solid approach
Validating configuration at the outset safeguards against unexpected issues during backend generation.

cmd/describe_affected.go (1)

18-20: Early configuration validation boosts reliability
Ensuring the atmos configuration is in order first helps prevent errors further along in the workflow.

cmd/atlantis_generate_repo_config.go (1)

18-19: Ensuring config correctness is beneficial
Performing the config check at the outset supports consistent behavior and lowers the chance of run-time errors.

cmd/root.go (2)

48-49: Clear separation of concerns.

Invoking checkAtmosConfig() here ensures the configuration is validated before proceeding with the main command logic.


89-90: Re-initializing the global config.

The approach reinitializes 'atmosConfig' in Execute(). Ensure threading is not a concern since this is a CLI. Otherwise, a more local scoping might be preferable.

cmd/cmd_utils.go (9)

367-367: Flexible validation options.

Allowing optional validation checks via AtmosValidateOption is a neat extension point for future expansions.


385-385: Graceful exit.

Printing a helpful message and exiting is user-friendly. No suggestions.


444-444: Helpful warning.

Logging a warning rather than silently failing is beneficial for troubleshooting.


457-457: Consistent logging.

Maintaining consistent log levels for errors ensures users can easily filter or parse logs.


462-462: Fallback messaging.

Providing a fallback message (like "No release information available") is a good practice to keep the user informed in case of unavailable data.


478-478: Cache update failure is now logged.

This is helpful for diagnosing any issues with writing to the cache.


377-381: Global variable overshadowing possibility.

Be mindful that 'atmosConfig, err := ...' might overshadow the global variable if declared in a different scope. Confirm that both references indeed refer to the same variable.


435-435: Non-pointer signature.

Changing the parameter type to a value instead of a pointer can simplify usage. Verify that large structures aren’t inadvertently copied if performance is critical.

✅ Verification successful

Let me gather information about the structure size and its usage to verify this concern.


Based on the inspection of AtmosConfiguration, I can now make a definitive assessment. The struct contains numerous fields but most are pointers or small value types (strings, bools). The largest embedded structs are well-defined configurations that are meant to be passed around. The struct is used extensively throughout the codebase as a value type, suggesting it was designed to be copied efficiently.

Using value semantics is appropriate here.

  • The struct is primarily composed of configuration data that needs to be read but rarely modified
  • Most fields are small value types or pointers
  • The codebase consistently uses value semantics for this type across numerous function calls
  • No performance issues are apparent from the widespread value passing of this configuration struct
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Check the definition of AtmosConfiguration to understand its size
ast-grep --pattern 'type AtmosConfiguration struct {
  $$$
}'

# Look for other usages of AtmosConfiguration to see how it's typically passed
rg "AtmosConfiguration" -A 2 -B 2

Length of output: 66327


485-485: Potential cache update on help command.

By calling CheckForAtmosUpdateAndPrintMessage() here, the cache timestamp may be updated even when displaying help. Evaluate whether this behavior is desired or should be conditional.

✅ Verification successful

Let me gather information about the cache update behavior and the help command implementation.


Let me check how this update check is integrated with the help command.


Cache update behavior on help command is intentional and properly implemented.

The cache update behavior during help command execution is an intentional design choice, implemented through customHelpMessageToUpgradeToAtmosLatestRelease. The function has built-in safeguards:

  • Version checking can be disabled via config (atmosConfig.Version.Check.Enabled)
  • Cache updates only occur based on frequency checks (ShouldCheckForUpdates)
  • The behavior is consistent with the tool's update notification strategy across commands
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# First, let's find the implementation of CheckForAtmosUpdateAndPrintMessage
ast-grep --pattern 'func CheckForAtmosUpdateAndPrintMessage($$$)'

# Let's also look for help command related code
rg -A 5 "help command" 

# Search for cache update related code
rg -i "cache.*update" 

Length of output: 3403


Script:

#!/bin/bash
# Let's look at the context where CheckForAtmosUpdateAndPrintMessage is called
rg -B 5 -A 5 "CheckForAtmosUpdateAndPrintMessage"

# Also check the root command implementation
ast-grep --pattern 'func Execute($$$)'

Length of output: 7258

@mcalhoun mcalhoun merged commit e72fad0 into main Dec 23, 2024
42 of 48 checks passed
@mcalhoun mcalhoun deleted the revert-869-chore/load-atmos-config-in-root-command branch December 23, 2024 16:43
Copy link

These changes were released in v1.131.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-release Do not create a new release (wait for additional code changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants