Skip to content

Deferred YAML Function Evaluation in Merge - #1821

Merged
Andriy Knysh (aknysh) merged 36 commits into
mainfrom
fixes-4
Dec 1, 2025
Merged

Andriy Knysh (aknysh) merged 36 commits into
mainfrom
fixes-4

Conversation

@aknysh

@aknysh Andriy Knysh (aknysh) commented Nov 29, 2025 •

Copy link
Copy Markdown
Member

what

  • Implemented deferred merge infrastructure to solve type conflicts when YAML functions are present in hierarchical stack configurations
  • Added comprehensive test coverage (76 tests, 89.9% code coverage) for deferred merge functionality
  • Created blog post documenting the new deferred merge feature
  • Cleaned up leftover test fixtures from abandoned implementations

why

  • YAML functions (!template, !terraform.output, !store.get, etc.) were being merged before evaluation, creating type mismatches that broke merge operations
  • When base configurations had string values and overrides had template functions, the merge would fail due to type conflicts
  • This affected real-world scenarios: multi-environment deployments, team-specific configurations, gradual migrations, and mixed configuration sources
  • The deferred merge approach (defer → merge → apply) eliminates type conflicts while preserving all YAML function capabilities

references

Summary by CodeRabbit

  • New Features

    • Deferred YAML function evaluation during merges to avoid type conflicts.
    • Enhanced !template decoding: JSON strings auto-decode into native YAML structures.
    • Component-aware YAML function processing and configurable list merge strategies (replace, append, merge).
  • Updates

    • Large dependency upgrades across SDKs, Kubernetes, container tooling, and utilities.
    • Example Dockerfile Atmos version bumped.
  • Tests

    • Extensive new unit, integration, and benchmark tests and fixtures covering YAML functions and deferred-merge scenarios.
  • Documentation

    • New design doc and blog post explaining deferred merge workflow and usage.

✏️ Tip: You can customize this high-level summary in your review settings.

@aknysh Andriy Knysh (aknysh) added the minor New features that do not break anything label Nov 29, 2025
@aknysh Andriy Knysh (aknysh) added the minor New features that do not break anything label Nov 29, 2025
@github-actions github-actions Bot added the size/xl Extra large size PR label Nov 29, 2025
@aknysh Andriy Knysh (aknysh) self-assigned this Nov 29, 2025
@mergify

mergify Bot commented Nov 29, 2025

Copy link
Copy Markdown
Contributor

Warning

This PR exceeds the recommended limit of 1,000 lines.

Large PRs are difficult to review and may be rejected due to their size.

Please verify that this PR does not address multiple issues.
Consider refactoring it into smaller, more focused PRs to facilitate a smoother review process.

@mergify

mergify Bot commented Nov 29, 2025

Copy link
Copy Markdown
Contributor

Important

Cloud Posse Engineering Team Review Required

This pull request modifies files that require Cloud Posse's review. Please be patient, and a core maintainer will review your changes.

To expedite this process, reach out to us on Slack in the #pr-reviews channel.

@mergify mergify Bot added the needs-cloudposse Needs Cloud Posse assistance label Nov 29, 2025
@github-actions

github-actions Bot commented Nov 29, 2025 •

Copy link
Copy Markdown

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 4 package(s) with unknown licenses.
See the Details below.

License Issues

go.mod

PackageVersionLicenseIssue Type
golang.org/x/crypto0.45.0NullUnknown License
golang.org/x/mod0.30.0NullUnknown License
golang.org/x/tools0.39.0NullUnknown License
github.com/klauspost/compress1.18.1NullUnknown License
Allowed Licenses: MIT, MIT-0, Apache-2.0, BSD-2-Clause, BSD-2-Clause-Views, BSD-3-Clause, ISC, MPL-2.0, 0BSD, Unlicense, CC0-1.0, CC-BY-3.0, CC-BY-4.0, CC-BY-SA-3.0, Python-2.0, OFL-1.1, LicenseRef-scancode-generic-cla, LicenseRef-scancode-unknown-license-reference, LicenseRef-scancode-unicode

Scanned Files

  • go.mod

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
pkg/merge/merge_yaml_functions.go (1)

40-76: Slices containing YAML functions are still not deferred.

This was previously flagged. The current implementation only defers YAML functions that are direct map values (lines 57-63) or recurses into nested maps (lines 66-69). Slices—even those containing YAML function strings—pass through unchanged at line 72.

🧹 Nitpick comments (1)
pkg/merge/merge_yaml_functions.go (1)

128-150: Add performance tracking to public function.

GetValueAtPath is missing defer perf.Track(nil, "merge.GetValueAtPath")(). Per coding guidelines, performance tracking is enforced on all public functions including utility functions.

 func GetValueAtPath(data map[string]interface{}, path []string) (interface{}, bool) {
+	defer perf.Track(nil, "merge.GetValueAtPath")()
+
 	if len(path) == 0 || data == nil {
 		return nil, false
 	}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4e22ed2 and 8149d0d.

📒 Files selected for processing (2)
  • pkg/merge/merge_deferred_test.go (1 hunks)
  • pkg/merge/merge_yaml_functions.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/merge/merge_deferred_test.go
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.go: Use functional options pattern to avoid functions with many parameters. Define Option functions that modify a Config struct and pass variadic options to New functions.
Use context.Context for cancellation signals, deadlines/timeouts, and request-scoped values (trace IDs). Context should be first parameter in functions that accept it. DO NOT use context for configuration, dependencies, or avoiding proper function parameters.
All comments must end with periods. This is enforced by the godot linter.
NEVER delete existing comments without a very strong reason. Preserve helpful comments, update them to match code changes, refactor for clarity, and add context when modifying code. Only remove factually incorrect, duplicated, or outdated comments.
Organize imports in three groups separated by blank lines (Go stdlib, 3rd-party excluding cloudposse/atmos, Atmos packages), sorted alphabetically. Maintain aliases: cfg, log, u, errUtils.
Add defer perf.Track(atmosConfig, "pkg.FuncName")() + blank line to all public functions. Use nil if no atmosConfig parameter.
All errors MUST be wrapped using static errors defined in errors/errors.go. Use errors.Join for combining multiple errors, fmt.Errorf with %w for adding string context, error builder for complex errors, and errors.Is() for error checking. NEVER use dynamic errors directly.
Use go.uber.org/mock/mockgen with //go:generate directives for mock generation. Never create manual mocks.
Use viper.BindEnv with ATMOS_ prefix for environment variables.
Use colors from pkg/ui/theme/colors.go for theme consistency.
Ensure Linux/macOS/Windows compatibility. Use SDKs over binaries. Use filepath.Join(), not hardcoded path separators.
Small focused files (<600 lines). One cmd/impl per file. Co-locate tests. Never use //revive:disable:file-length-limit.

**/*.go: Use Viper for managing configuration, environment variables, and flags in CLI commands
Use interfaces for external dependencies to facilitate mocking and consider us...

Files:

  • pkg/merge/merge_yaml_functions.go
🧠 Learnings (18)
📓 Common learnings
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.
Learnt from: aknysh
Repo: cloudposse/atmos PR: 944
File: go.mod:206-206
Timestamp: 2025-01-17T00:18:57.769Z
Learning: For indirect dependencies with license compliance issues in the cloudposse/atmos repository, the team prefers to handle them in follow-up PRs rather than blocking the current changes, as these issues often require deeper investigation of the dependency tree.
📚 Learning: 2025-11-24T17:35:20.297Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:20.297Z
Learning: Applies to **/*.go : Add defer perf.Track(atmosConfig, "pkg.FuncName")() + blank line to all public functions. Use nil if no atmosConfig parameter.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-11-24T17:35:20.297Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:20.297Z
Learning: Applies to internal/exec/template_funcs.go : New configs support Go templating with FuncMap() from internal/exec/template_funcs.go. Implement template functions in internal/exec/template_funcs.go, register them, add tests, and update documentation.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-10-16T05:26:31.892Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1639
File: pkg/merge/merge.go:392-430
Timestamp: 2025-10-16T05:26:31.892Z
Learning: In Atmos merge operations (pkg/merge/merge.go), context.Positions is a PositionMap (map[string]*schema.Position) keyed by JSONPath strings, not a slice indexed by input array position. Position lookups are path-based, making them independent of input array reorganization or filtering. This design allows filtering empty inputs without affecting provenance tracking correctness.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-09-30T19:03:50.738Z
Learnt from: Cerebrovinny
Repo: cloudposse/atmos PR: 1560
File: pkg/utils/string_utils.go:43-64
Timestamp: 2025-09-30T19:03:50.738Z
Learning: In the Atmos codebase, YAML tags like !terraform.output rely on positional arguments, so the SplitStringByDelimiter function in pkg/utils/string_utils.go must preserve empty strings (even after trimming quotes) to maintain the correct number of positional arguments. Filtering out empty values after trimming would collapse the array and break these function calls.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2024-11-19T23:00:45.899Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 795
File: internal/exec/stack_processor_utils.go:378-386
Timestamp: 2024-11-19T23:00:45.899Z
Learning: In the `ProcessYAMLConfigFile` function within `internal/exec/stack_processor_utils.go`, directory traversal in stack imports is acceptable and should not be restricted.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-11-30T04:16:01.879Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1821
File: pkg/merge/deferred.go:50-59
Timestamp: 2025-11-30T04:16:01.879Z
Learning: In the cloudposse/atmos repository, performance tracking with `defer perf.Track()` should NOT be added to trivial O(1) getter methods that only return field references or check map lengths (e.g., `GetDeferredValues()`, `HasDeferredValues()`). The guideline to add perf tracking to "all public functions" applies to functions that do meaningful work (I/O, computation, external calls), not to trivial accessors where the tracking overhead would exceed the operation time and pollute performance reports.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-11-30T04:16:24.023Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1821
File: pkg/merge/deferred.go:34-48
Timestamp: 2025-11-30T04:16:24.023Z
Learning: In the cloudposse/atmos repository, the `defer perf.Track()` guideline applies to functions that perform meaningful work (I/O, computation, external calls), but explicitly excludes trivial accessors/mutators (e.g., simple getters, setters with single integer increments, string joins, or map appends) where the tracking overhead would exceed the actual method cost and provide no actionable performance data. Hot-path methods called in tight loops should especially avoid perf.Track() if they perform only trivial operations.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-11-09T19:06:58.470Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1752
File: pkg/profile/list/formatter_table.go:27-29
Timestamp: 2025-11-09T19:06:58.470Z
Learning: In the cloudposse/atmos repository, performance tracking with `defer perf.Track()` is enforced on all functions via linting, including high-frequency utility functions, formatters, and renderers. This is a repository-wide policy to maintain consistency and avoid making case-by-case judgment calls about which functions should have profiling.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-10-13T18:13:54.020Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1622
File: pkg/perf/perf.go:140-184
Timestamp: 2025-10-13T18:13:54.020Z
Learning: In pkg/perf/perf.go, the `trackWithSimpleStack` function intentionally skips ownership checks at call stack depth > 1 to avoid expensive `getGoroutineID()` calls on every nested function. This is a performance optimization for the common single-goroutine execution case (most Atmos commands), accepting the rare edge case of potential metric corruption if multi-goroutine execution occurs at depth > 1. The ~19× performance improvement justifies this trade-off.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2024-10-23T21:36:40.262Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 740
File: cmd/cmd_utils.go:340-359
Timestamp: 2024-10-23T21:36:40.262Z
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.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2024-12-02T21:26:32.337Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 808
File: pkg/config/config.go:478-483
Timestamp: 2024-12-02T21:26:32.337Z
Learning: In the 'atmos' project, when reviewing Go code like `pkg/config/config.go`, avoid suggesting file size checks after downloading remote configs if such checks aren't implemented elsewhere in the codebase.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-11-08T19:56:18.660Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1697
File: internal/exec/oci_utils.go:0-0
Timestamp: 2025-11-08T19:56:18.660Z
Learning: In the Atmos codebase, when a function receives an `*schema.AtmosConfiguration` parameter, it should read configuration values from `atmosConfig.Settings` fields rather than using direct `os.Getenv()` or `viper.GetString()` calls. The Atmos pattern is: viper.BindEnv in cmd/root.go binds environment variables → Viper unmarshals into atmosConfig.Settings via mapstructure → business logic reads from the Settings struct. This provides centralized config management, respects precedence, and enables testability. Example: `atmosConfig.Settings.AtmosGithubToken` instead of `os.Getenv("ATMOS_GITHUB_TOKEN")` in functions like `getGHCRAuth` in internal/exec/oci_utils.go.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-01-19T22:30:27.600Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 0
File: :0-0
Timestamp: 2025-01-19T22:30:27.600Z
Learning: The Atmos YAML function `!include` allows downloading local or remote files from different sources and assigning their contents to sections in stack manifests. It supports various protocols (file, http, git, s3, etc.) and can filter content using YQ expressions.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-04-04T02:03:23.676Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1185
File: internal/exec/yaml_func_store.go:26-26
Timestamp: 2025-04-04T02:03:23.676Z
Learning: The Atmos codebase currently uses `log.Fatal` for error handling in multiple places. The maintainers are aware this isn't an ideal pattern (should only be used in main() or init() functions) and plan to address it comprehensively in a separate PR. CodeRabbit should not flag these issues or push for immediate changes until that refactoring is complete.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to **/*.go : Follow Go's error handling idioms: use meaningful error messages, wrap errors with context using `fmt.Errorf("context: %w", err)`, and consider using custom error types for domain-specific errors

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-01-25T04:01:58.095Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: internal/exec/docs_generate.go:98-101
Timestamp: 2025-01-25T04:01:58.095Z
Learning: In the `generateSingleReadme` function of the docs generation feature (internal/exec/docs_generate.go), errors from `fetchAndParseYAML` should be logged and skipped rather than causing early returns. This is by design to process all inputs and collect all errors, instead of failing fast on the first error.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
📚 Learning: 2025-11-24T17:35:20.297Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:20.297Z
Learning: Applies to **/*.go : All errors MUST be wrapped using static errors defined in errors/errors.go. Use errors.Join for combining multiple errors, fmt.Errorf with %w for adding string context, error builder for complex errors, and errors.Is() for error checking. NEVER use dynamic errors directly.

Applied to files:

  • pkg/merge/merge_yaml_functions.go
🧬 Code graph analysis (1)
pkg/merge/merge_yaml_functions.go (6)
pkg/merge/deferred.go (3)
  • DeferredMergeContext (19-22)
  • DeferredValue (11-16)
  • NewDeferredMergeContext (25-32)
pkg/perf/perf.go (1)
  • Track (121-138)
errors/errors.go (4)
  • ErrEmptyPath (152-152)
  • ErrCannotNavigatePath (153-153)
  • ErrMerge (228-228)
  • ErrUnknownListMergeStrategy (154-154)
pkg/merge/merge.go (4)
  • Merge (389-427)
  • ListMergeStrategyReplace (17-17)
  • ListMergeStrategyAppend (18-18)
  • ListMergeStrategyMerge (19-19)
pkg/schema/schema.go (1)
  • AtmosConfiguration (53-94)
pkg/merge/yaml_processor.go (1)
  • YAMLFunctionProcessor (5-10)
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Acceptance Tests (windows)
  • GitHub Check: Summary
🔇 Additional comments (2)
pkg/merge/merge_yaml_functions.go (2)

152-297: Merge strategy implementations look solid.

The merge logic correctly handles the three strategies (replace, append, merge) with appropriate type checking and error handling. Error wrapping with errUtils.ErrMerge is properly applied at lines 178 and 264.


398-473: Orchestration logic correctly preserves concrete overrides.

The addition of addExistingConcreteValue (lines 398-413) and its integration in processDeferredField (line 418) ensures that concrete override values participate in the merge with highest precedence. This addresses the critical concern from previous reviews about losing concrete map overrides when base configs contain YAML functions.

The flow is now: retrieve existing concrete value → add as highest-precedence entry → sort → process YAML functions → merge → apply. This preserves override semantics for simple types while enabling deep-merge for maps.

@aknysh
Andriy Knysh (aknysh) merged commit f3f594e into main Dec 1, 2025
@aknysh
Andriy Knysh (aknysh) deleted the fixes-4 branch December 1, 2025 16:15
@mergify mergify Bot removed the needs-cloudposse Needs Cloud Posse assistance label Dec 1, 2025
@github-actions

github-actions Bot commented Dec 1, 2025

Copy link
Copy Markdown

Warning

Changelog Entry Required

This PR is labeled minor or major but doesn't include a changelog entry.

Action needed: Add a new blog post in website/blog/ to announce this change.

Example filename: website/blog/2025-12-01-feature-name.mdx

Alternatively: If this change doesn't require a changelog entry, remove the minor or major label.

Erik Osterman (Cloud Posse) (osterman) added a commit that referenced this pull request Dec 1, 2025
Brings in recent changes from main including:
- Deferred YAML function evaluation in merge (#1821)
- Website changelog redesign with vertical timeline (#1818)
- Version management documentation improvements (#1817)
- PR size labeler workflow (#1816)
- golangci-lint pinning for Git v2.52+ compatibility (#1815)

No conflicts detected - clean merge.

Note: Pre-existing linting issues in init/scaffold experimental code
remain and will be addressed separately before merging to main.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

This branch was successfully deployed

No deployments
preview — 8149d0d5 Deployed Dec 1, 2025 by github-actions[bot]
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 size/xl Extra large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants