Skip to content

fix(k8s): fix error ordering in ProcessEnvs and late validation - #3807

Open
Elvand-Lie wants to merge 1 commit into
knative:mainfrom
Elvand-Lie:fix/processenvs-error-ordering
Open

Elvand-Lie wants to merge 1 commit into
knative:mainfrom
Elvand-Lie:fix/processenvs-error-ordering

Conversation

@Elvand-Lie

Copy link
Copy Markdown
Contributor

Problem

ProcessEnvs error ordering:
ProcessEnvs appends the result of createEnvVarSource to the envVars slice before checking the returned error. This violates standard Go error-handling pattern.

createEnvFromSource/createEnvVarSource late validation:
Both functions validate that sourceName is non-empty only after using it to construct resource references and inserting it into the referenced sets.

Fix

Reordered ProcessEnvs so the error check comes first. Moved the empty-name validation before the switch statements in createEnvFromSource and createEnvVarSource so the sets are not polluted with empty strings.

Tests added

  • Test_ProcessEnvs_ErrorCheckBeforeAppend: error returns nil slice
  • Test_createEnvFromSource_EmptyName: empty name errors without polluting set
  • Test_createEnvVarSource_EmptyName: empty name errors without polluting set
  • Test_createEnvVarSource_EmptyKey: empty key errors

Fixes #3798

@knative-prow
knative-prow Bot requested review from dsimansk and jrangelramos May 20, 2026 19:53
@knative-prow knative-prow Bot added size/M 🤖 PR changes 30-99 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels May 20, 2026
@knative-prow

knative-prow Bot commented May 20, 2026

Copy link
Copy Markdown

Hi @Elvand-Lie. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@codecov

codecov Bot commented May 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.06%. Comparing base (d7b93f6) to head (a3ae155).
⚠️ Report is 93 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3807      +/-   ##
==========================================
+ Coverage   54.00%   54.06%   +0.05%     
==========================================
  Files         200      200              
  Lines       23687    23679       -8     
==========================================
+ Hits        12792    12801       +9     
+ Misses       9660     9647      -13     
+ Partials     1235     1231       -4     
Flag Coverage Δ
e2e 34.03% <10.00%> (-0.02%) ⬇️
e2e go 29.40% <0.00%> (+0.01%) ⬆️
e2e node 25.73% <0.00%> (+<0.01%) ⬆️
e2e python 29.73% <0.00%> (+0.01%) ⬆️
e2e quarkus 25.85% <0.00%> (+0.02%) ⬆️
e2e rust 25.32% <0.00%> (-0.01%) ⬇️
e2e springboot 24.01% <0.00%> (+<0.01%) ⬆️
e2e typescript 25.84% <0.00%> (+<0.01%) ⬆️
e2e-config-ci 26.91% <0.00%> (+<0.01%) ⬆️
integration 15.66% <14.28%> (-0.02%) ⬇️
unit macos-14 43.19% <85.71%> (+0.13%) ⬆️
unit macos-latest 43.19% <85.71%> (+0.13%) ⬆️
unit ubuntu-24.04-arm 43.50% <90.00%> (+0.13%) ⬆️
unit ubuntu-latest 44.05% <85.71%> (+0.13%) ⬆️
unit windows-latest 43.26% <85.71%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Elvand-Lie
Elvand-Lie force-pushed the fix/processenvs-error-ordering branch from 66defd6 to 015a7da Compare May 21, 2026 06:29
@lkingland lkingland added ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test 🤖 Needs an org member to approve testing labels May 21, 2026
@matejvasek

Copy link
Copy Markdown
Contributor

/approve
/lgtm
/ok-to-test

@knative-prow knative-prow Bot added lgtm 🤖 PR is ready to be merged. approved 🤖 PR has been approved by an approver from all required OWNERS files. labels Jun 11, 2026
@matejvasek

Copy link
Copy Markdown
Contributor

there is conflict @Elvand-Lie

@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label Jun 12, 2026
@Elvand-Lie
Elvand-Lie force-pushed the fix/processenvs-error-ordering branch from 015a7da to f523d59 Compare June 13, 2026 04:29
@knative-prow

knative-prow Bot commented Jun 13, 2026

Copy link
Copy Markdown

New changes are detected. LGTM label has been removed.

@knative-prow knative-prow Bot removed the lgtm 🤖 PR is ready to be merged. label Jun 13, 2026
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Jun 13, 2026
@Elvand-Lie

Copy link
Copy Markdown
Contributor Author

Rebased onto main. The conflict was from the ProcessVolumes nil-path tests that were merged in the meantime. Kept both test sets in. @matejvasek

@Elvand-Lie
Elvand-Lie force-pushed the fix/processenvs-error-ordering branch from f523d59 to a3ae155 Compare June 26, 2026 13:36
@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label Aug 31, 2026
ProcessEnvs appends the result of createEnvVarSource to the envVars
slice before checking the error. Reordered so the error check happens
first, following standard Go error handling.

createEnvFromSource and createEnvVarSource both validate that sourceName
is non-empty only after using it to construct resource references and
inserting it into the referenced sets. Moved the empty-name validation
before the switch statements.

Fixes knative#3798

Signed-off-by: Elvand Lie Nababan <elvandlie@gmail.com>
@Elvand-Lie
Elvand-Lie force-pushed the fix/processenvs-error-ordering branch from a3ae155 to 13e66f6 Compare October 28, 2026 15:46
@knative-prow

knative-prow Bot commented Oct 28, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Elvand-Lie, matejvasek

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Oct 28, 2026
@Elvand-Lie

Copy link
Copy Markdown
Contributor Author

Rebased onto main. The only conflict was tests appended at the end of pkg/k8s/deployer_test.go; both sets are kept and the fix itself is unchanged. @matejvasek could you re-/lgtm when you have a moment?

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

Labels

approved 🤖 PR has been approved by an approver from all required OWNERS files. ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

k8s: ProcessEnvs appends env var before checking createEnvVarSource error

4 participants