fix(kustomize): Updated generator support for both EnvSources and FileSources using [{key}=]{path} syntax
Fixes: #9338 Related: n/a Merge before/after: n/a
Description
When using kustomize during the render stage, if files must be mirrored before rendering because they require modifications (when using --set flags, for example), files defined in the env section of configMapGenerator and secretGenerator are omitted, and thus the render ends up failing because it cannot find all the required filed.
The error message in that case is similar to this:
running [kustomize build /var/folders/dy/qslwfy7n0jz3wp1gjxs3m32h0000gp/T/4251885249/Users/foobar/src/test/skaffold-set-issue/src/foobar/kustomize/overlays/issue1]
- stdout: ""
- stderr: "Error: loading KV pairs: env source files: [local.env]: evalsymlink failure on '/private/var/folders/dy/qslwfy7n0jz3wp1gjxs3m32h0000gp/T/4251885249/Users/foobar/src/test/skaffold-set-issue/src/foobar/kustomize/overlays/issue1/local.env' : lstat /private/var/folders/dy/qslwfy7n0jz3wp1gjxs3m32h0000gp/T/4251885249/Users/foobar/src/test/skaffold-set-issue/src/foobar/kustomize/overlays/issue1/local.env: no such file or directory\n"
- cause: exit status 1
Moreover, both on the previous situation and when using skaffold in dev mode (using the skaffold dev command), files defined in the files section of the configMapGenerator and secretGenerator that make use of the [{key}=]{path} syntax aren't properly recognized and the files neither won't be copied when mirroring or watched upon for changes in dev mode.
The error message visible during the render stage is similar to this:
open /Users/foobar/src/test/skaffold-set-issue/src/foobar/kustomize/overlays/issue2/application.yaml=application-foobar.yaml: no such file or directory
An example of the [{key}=]{path} syntax can be seen in the second example from kustomize's reference documentation).
This PR adds additional test cases for the situations described above and the required fixes.
Summary of Changes
Hello @johanbcn, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses critical issues within Skaffold's Kustomize integration, specifically concerning how configMapGenerator and secretGenerator process file sources. It ensures that all referenced files, including environment sources and those using the [{key}=]{path} syntax, are correctly mirrored during the rendering process and properly tracked for changes in development mode. This prevents build failures and improves the reliability of Kustomize-based deployments within Skaffold.
Highlights
- Kustomize Generator Support: Enhanced Kustomize
configMapGeneratorandsecretGeneratorto correctly handleEnvSourcesandFileSourcesthat use the[{key}=]{path}syntax. - Fixes File Omission During Render: Resolved an issue where files defined in
envsections of generators were omitted during the render stage, leading to 'no such file or directory' errors. - Improved Dev Mode File Watching: Ensured that files specified with the
[{key}=]{path}syntax infilessections of generators are properly recognized and watched for changes inskaffold devmode. - Comprehensive Test Coverage: Added new test cases to validate the correct mirroring and dependency detection for various generator configurations, including those using alternative keys and environment sources.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.
The added tests brought up to light another issue when mirroring files in Windows systems, which didn't handle filesystem paths correctly.
I have updated the PR to fix that too.
I rebased the changes over the latest commits from main. Let me know if there is anything else that must be done.