Skip to content

Conversation

@johanbcn
Copy link

@johanbcn johanbcn commented Nov 3, 2025

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.

…nerators

Added tests that validate support of env files and regular files aliased with
keys when using kustomize during the render stage, and when running
skaffold in dev mode.
@johanbcn johanbcn requested a review from a team as a code owner November 3, 2025 15:14
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @johanbcn, I'm Gemini Code Assist1! 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 configMapGenerator and secretGenerator to correctly handle EnvSources and FileSources that use the [{key}=]{path} syntax.
  • Fixes File Omission During Render: Resolved an issue where files defined in env sections 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 in files sections of generators are properly recognized and watched for changes in skaffold dev mode.
  • 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 👍 and 👎 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.

Footnotes

  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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue where skaffold would fail to mirror or watch files from kustomize's configMapGenerator and secretGenerator when using env sources or the key=path syntax for files sources. The changes correctly parse these sources to identify the file paths. The accompanying test cases are well-written and cover the fixed scenarios.

My review focuses on improving code maintainability by addressing code duplication. I've suggested refactoring the duplicated logic for handling generator sources into helper functions in pkg/skaffold/render/renderer/kustomize/kustomize.go. This will make the code cleaner and easier to maintain.

Comment on lines 550 to 592
for _, generator := range content.ConfigMapGenerator {
deps = append(deps, sUtil.AbsolutePaths(dir, generator.FileSources)...)
envs := generator.EnvSources
var sources []string

if generator.FileSources != nil {
for _, f := range generator.FileSources {
// Entries from FileSources can take the form: [{key}=]{path}
i := strings.IndexRune(f, '=')
if i > -1 {
f = f[i+1:]
}
sources = append(sources, f)
}
}

sources = append(sources, generator.EnvSources...)
if generator.EnvSource != "" {
envs = append(envs, generator.EnvSource)
sources = append(sources, generator.EnvSource)
}
deps = append(deps, sUtil.AbsolutePaths(dir, envs)...)

deps = append(deps, sUtil.AbsolutePaths(dir, sources)...)
}

for _, generator := range content.SecretGenerator {
deps = append(deps, sUtil.AbsolutePaths(dir, generator.FileSources)...)
envs := generator.EnvSources
var sources []string

if generator.FileSources != nil {
for _, f := range generator.FileSources {
// Entries from FileSources can take the form: [{key}=]{path}
i := strings.IndexRune(f, '=')
if i > -1 {
f = f[i+1:]
}
sources = append(sources, f)
}
}

sources = append(sources, generator.EnvSources...)
if generator.EnvSource != "" {
envs = append(envs, generator.EnvSource)
sources = append(sources, generator.EnvSource)
}
deps = append(deps, sUtil.AbsolutePaths(dir, envs)...)

deps = append(deps, sUtil.AbsolutePaths(dir, sources)...)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic to collect dependency sources from ConfigMapGenerator (lines 550-570) is identical to the logic for SecretGenerator (lines 572-592). To avoid this duplication and improve maintainability, you can extract this logic into a helper function.

Here's an example of what that helper function could look like:

func getGeneratorSources(fileSources, envSources []string, envSource string) []string {
	var sources []string
	for _, f := range fileSources {
		// Entries from FileSources can take the form: [{key}=]{path}
		if _, path, found := strings.Cut(f, "="); found {
			f = path
		}
		sources = append(sources, f)
	}

	sources = append(sources, envSources...)
	if envSource != "" {
		sources = append(sources, envSource)
	}
	return sources
}

Using this helper function would simplify both loops in DependenciesForKustomization:

for _, generator := range content.ConfigMapGenerator {
	sources := getGeneratorSources(generator.FileSources, generator.EnvSources, generator.EnvSource)
	deps = append(deps, sUtil.AbsolutePaths(dir, sources)...)
}

for _, generator := range content.SecretGenerator {
	sources := getGeneratorSources(generator.FileSources, generator.EnvSources, generator.EnvSource)
	deps = append(deps, sUtil.AbsolutePaths(dir, sources)...)
}

I also suggest using strings.Cut (available since Go 1.18) to make the path extraction from FileSources slightly cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant