k8s: ProcessEnvs appends env var before checking createEnvVarSource error

Open
#3,798 1 comment 0 reactions 1 assignee View on GitHub

@Elvand-Lie is already working on this.

Since Jun 2, 2026.

Assessment

This issue has not been assessed yet.

Description

kind/bug

In pkg/k8s/deployer.go, ProcessEnvs (around line 635-639) calls createEnvVarSource, then immediately appends the returned valueFrom to envVars BEFORE checking the error:

valueFrom, err := createEnvVarSource(slices, referencedSecrets, referencedConfigMaps)
envVars = append(envVars, corev1.EnvVar{Name: *env.Name, ValueFrom: valueFrom})
if err != nil {
    return nil, nil, err
}

While the function does return nil on error (so the caller discards the slice), this violates the standard Go error-handling pattern of checking errors before using return values. If any future refactoring changes the return to a continue, the partially-initialized entry stays in the list.

Additionally, createEnvFromSource and createEnvVarSource (lines 718-738 and 753-785) both validate that sourceName is non-empty only AFTER using it to construct resource references and inserting it into the referenced sets. The empty-string checks should be moved before the switch statement that uses sourceName.

Fix: reorder the append to happen after the error check, and move the empty-name validation earlier in both helper functions.

Dominant language
Go
Stars
365
Forks
223
Avg merge
2d 3h
Merged PRs (30d)
25

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from knative/func

All issues in knative/func

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.