Skip to content

fix: pass referenced resource sets to generateNewService for proper validation#3579

Open
Ankitsinghsisodya wants to merge 4 commits intoknative:mainfrom
Ankitsinghsisodya:fix/deploy-env-vars-not-applied
Open

fix: pass referenced resource sets to generateNewService for proper validation#3579
Ankitsinghsisodya wants to merge 4 commits intoknative:mainfrom
Ankitsinghsisodya:fix/deploy-env-vars-not-applied

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

@Ankitsinghsisodya Ankitsinghsisodya commented Apr 3, 2026

Changes

generateNewService in pkg/knative/deployer.go was allocating its own local
referencedSecrets, referencedConfigMaps, and referencedPVCs sets
internally. Those sets were never visible to the caller, so
CheckResourcesArePresent on the first-deploy path was always invoked with
empty sets, silently passing validation regardless of whether referenced
Secrets, ConfigMaps, or PVCs actually existed on the cluster.

The fix adds the three sets as parameters to generateNewService and removes
the internal allocations. ProcessEnvs and ProcessVolumes now populate the
caller-owned sets, so CheckResourcesArePresent receives the correct data and
can reject a deployment that references missing resources.

On the test side, Two new tests are added:
TestUpdateService_EnvsPropagated calls the updateService closure directly
against a service with a stale env var and asserts that the container env list
is replaced, not merged; TestGenerateNewService_ResourceSetsPopulated is a
regression test for the create path that asserts the caller-supplied
referencedSecrets and referencedConfigMaps sets are populated after
generateNewService returns — a future regression that reintroduces internal
allocation would cause this test to fail.

relates #3514

…alidation

The generateNewService function was creating its own local
referencedSecrets, referencedConfigMaps, and referencedPVCs sets
internally, but these were never returned to the caller. This meant
CheckResourcesArePresent was always called with empty sets, silently
skipping resource validation for new service deployments.

Fix by passing the caller's sets into generateNewService so they get
properly populated by ProcessEnvs and ProcessVolumes.

Also adds regression tests verifying:
- env vars from -e flag are passed through to the deployer
- env vars appear in the generated Knative Service container spec

Ref knative#3514
Copilot AI review requested due to automatic review settings April 3, 2026 09:34
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented Apr 3, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ankitsinghsisodya
Once this PR has been reviewed and has the lgtm label, please assign jrangelramos for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 knative-prow bot requested review from dsimansk and jrangelramos April 3, 2026 09:34
@knative-prow knative-prow bot added size/L 🤖 PR changes 100-499 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels Apr 3, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented Apr 3, 2026

Hi @Ankitsinghsisodya. 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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a deploy regression where env vars passed via func deploy -e KEY=VALUE were not reliably propagated all the way into the generated Knative Service container spec (particularly on first deploy where referenced resource tracking could be lost).

Changes:

  • Pass caller-owned referenced Secret/ConfigMap/PVC sets into the new-service generation path so resource references are tracked consistently.
  • Ensure deploy-time envs (f.Run.Envs) are preserved through Knative Service generation (container env/envFrom).
  • Add regression tests covering both CLI-to-deployer env propagation and Knative Service env generation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/knative/deployer.go Threads referenced resource sets into generateNewService so first-deploy validation and env/volume processing use the caller-owned sets.
pkg/knative/deployer_test.go Adds a regression test asserting function envs appear in the generated Knative Service container env list.
cmd/deploy_test.go Adds a regression test asserting --env flags are present in the fn.Function passed to the deployer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// function are correctly included in the generated Knative Service container spec.
// This is a regression test for issue #3514.
func TestGenerateNewService_Envs(t *testing.T) {
ptr := func(s string) *string { return &s }
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

In this test, the local helper variable ptr shadows the imported knative.dev/pkg/ptr package used elsewhere in this file (e.g., ptr.Bool(...)). This makes the test harder to read and can lead to accidental mistakes when editing. Consider renaming the helper (e.g., strPtr) or using ptr.String(...) consistently instead.

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.36%. Comparing base (3e493ac) to head (e1f72ce).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3579      +/-   ##
==========================================
+ Coverage   56.24%   56.36%   +0.11%     
==========================================
  Files         180      180              
  Lines       20465    20461       -4     
==========================================
+ Hits        11511    11533      +22     
+ Misses       7755     7727      -28     
- Partials     1199     1201       +2     
Flag Coverage Δ
e2e 36.12% <100.00%> (+0.01%) ⬆️
e2e go 32.53% <100.00%> (-0.02%) ⬇️
e2e node 28.35% <100.00%> (-0.01%) ⬇️
e2e python 32.91% <100.00%> (-0.01%) ⬇️
e2e quarkus 28.49% <100.00%> (-0.02%) ⬇️
e2e rust 27.91% <100.00%> (-0.02%) ⬇️
e2e springboot 26.36% <100.00%> (-0.02%) ⬇️
e2e typescript 28.45% <100.00%> (-0.02%) ⬇️
e2e-config-ci 18.15% <0.00%> (+<0.01%) ⬆️
integration 17.38% <100.00%> (-0.05%) ⬇️
unit macos-14 43.86% <75.00%> (+0.49%) ⬆️
unit macos-latest 43.86% <75.00%> (+0.49%) ⬆️
unit ubuntu-24.04-arm 44.14% <75.00%> (+0.57%) ⬆️
unit ubuntu-latest 44.74% <75.00%> (+0.48%) ⬆️
unit windows-latest 43.88% <75.00%> (+0.49%) ⬆️

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

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

Remove TestGenerateNewService_Envs which tested pre-existing behaviour
and was mislabelled as a regression test for knative#3514.

Add TestUpdateService_EnvsPropagated which directly exercises the
update path through deployer.go: it calls the updateService closure
with a pre-existing service (simulating previousService != nil) and
asserts that cp.Env = newEnv at deployer.go:553 correctly replaces the
container's env list. This is the path that runs on every redeployment
of an existing function.

Also correct the doc-comment on TestDeploy_EnvsPassedToDeployer: it is
a valid characterisation test, not a regression test for knative#3514.
@Ankitsinghsisodya Ankitsinghsisodya changed the title fix: ensure func deploy -e env vars reach the Knative Service spec fix: pass referenced resource sets into generateNewService to enable first-deploy validation Apr 3, 2026
@Ankitsinghsisodya Ankitsinghsisodya force-pushed the fix/deploy-env-vars-not-applied branch from 14971c1 to 31f05f4 Compare April 3, 2026 10:37
Add TestGenerateNewService_ResourceSetsPopulated to pin the first-deploy
path: verifies that generateNewService populates the caller-supplied
referencedSecrets and referencedConfigMaps sets so CheckResourcesArePresent
actually validates them. A regression reintroducing internal sets would
cause this test to fail.

Tone down the comment on TestUpdateService_EnvsPropagated to accurately
reflect that it only exercises the updateService closure directly, not
Deploy, ProcessEnvs, or UpdateServiceWithRetry.

Ref knative#3514
@Ankitsinghsisodya Ankitsinghsisodya changed the title fix: pass referenced resource sets into generateNewService to enable first-deploy validation fix: pass referenced resource sets to generateNewService for proper validation Apr 3, 2026
TestDeploy_Envs already covers env var parsing and persistence through
the deploy command. The removed test added no coverage beyond what was
already there.
@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor Author

cc @gauron99

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

Labels

needs-ok-to-test 🤖 Needs an org member to approve testing size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants