Skip to content

feat: replace mockEnvVars bool with RenderEnvVarsMode in GetContentFromFiles#444

Merged
mheap merged 1 commit intomainfrom
no-env-expansion-mode
Apr 8, 2026
Merged

feat: replace mockEnvVars bool with RenderEnvVarsMode in GetContentFromFiles#444
mheap merged 1 commit intomainfrom
no-env-expansion-mode

Conversation

@mheap
Copy link
Copy Markdown
Member

@mheap mheap commented Apr 7, 2026

Summary

Adds newGetContentFromFilesWithEnvVars method with a typed RenderEnvVarsMode, adding a new EnvVarsSkip mode that skips template rendering entirely.

Changes

  • Added RenderEnvVarsMode type with three constants to pkg/file/template.go:
    • EnvVarsExpand — expands env vars (replaces false)
    • EnvVarsMock — returns var names as values (replaces true)
    • EnvVarsSkip — skips template rendering entirely (new)
  • Updated GetContentFromFilesWithEnvVars, getContent, readContent, and renderTemplate to use the new type
  • Updated all callers in tests and integration tests

Usage

// Skip env var expansion entirely
content, err := file.GetContentFromFilesWithEnvVars(filenames, file.EnvVarsSkip)

@mheap mheap requested a review from shivaygupta-dotcom April 7, 2026 10:30
mheap added a commit to Kong/deck that referenced this pull request Apr 7, 2026
Replace the manual getContentWithoutEnvExpansion helper and the bool
mockEnvVars parameter with the new file.RenderEnvVarsMode enum
(EnvVarsExpand, EnvVarsMock, EnvVarsSkip) introduced in
Kong/go-database-reconciler#444.

- convert.Convert now takes file.RenderEnvVarsMode instead of bool
- --no-expand-env-vars passes file.EnvVarsSkip (template skipped entirely)
- file render passes file.EnvVarsMock or file.EnvVarsExpand as before
- All other GetContentFromFiles call sites updated to file.EnvVarsExpand

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 28.90%. Comparing base (484667e) to head (9c97094).

Files with missing lines Patch % Lines
tests/integration/test_utils.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #444      +/-   ##
==========================================
+ Coverage   28.81%   28.90%   +0.09%     
==========================================
  Files         121      121              
  Lines       16517    16524       +7     
==========================================
+ Hits         4760     4777      +17     
+ Misses      11138    11129       -9     
+ Partials      619      618       -1     

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

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

@mheap mheap force-pushed the no-env-expansion-mode branch from 5aaf038 to cd74a1c Compare April 7, 2026 11:15
@Prashansa-K
Copy link
Copy Markdown
Collaborator

Prashansa-K commented Apr 8, 2026

Note: This is a breaking API change — callers must update from bool to RenderEnvVarsMode

We will have to push for major version release in that case, which would require a lot of changes. Is this really worth the effort?
What is the exact usecase for this? Found this: https://kongstrong.slack.com/archives/C04349E4KRC/p1775115564350019

@Prashansa-K Prashansa-K self-requested a review April 8, 2026 05:45
@mheap
Copy link
Copy Markdown
Member Author

mheap commented Apr 8, 2026

@Prashansa-K I don't think we need the major version bump here. There is only one consumer (deck) which we also own.

If you feel strongly, I can add a new method which has the new signature and make the old one an alias

@Prashansa-K
Copy link
Copy Markdown
Collaborator

Prashansa-K commented Apr 8, 2026

What if we make a new config struct for this or utilise the existing RenderConfig struct to add the new modes? deck can set the config and the GetContent* interfaces can use them without breaking contracts?

We use a similar model for dumpConfig too.

This would make the implementation future-proof as well.

@Prashansa-K
Copy link
Copy Markdown
Collaborator

I can add a new method which has the new signature and make the old one an alias

This works too. Whatever is easy and not confusing can be done.

Add EnvVarsExpand, EnvVarsMock, and EnvVarsSkip modes to allow callers
to skip template rendering entirely when env variable expansion is not
desired.
@mheap mheap force-pushed the no-env-expansion-mode branch from cd74a1c to 9c97094 Compare April 8, 2026 16:05
@mheap mheap merged commit afd6c37 into main Apr 8, 2026
18 checks passed
@mheap mheap deleted the no-env-expansion-mode branch April 8, 2026 16:34
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.

4 participants