Skip to content

test: add E2E matrix test for deploy -e flag (fixes #3514) - #3806

Merged
knative-prow[bot] merged 2 commits into
knative:mainfrom
Itx-Psycho0:fix/3514-deploy-env-flag-e2e-test-clean
Oct 30, 2026
Merged

knative-prow[bot] merged 2 commits into
knative:mainfrom
Itx-Psycho0:fix/3514-deploy-env-flag-e2e-test-clean

Conversation

@Itx-Psycho0

Copy link
Copy Markdown
Contributor

What This PR Does

This PR adds an end-to-end matrix test that verifies environment variables passed via the -e flag during deployment actually work across all supported runtimes and builders.

Background

Issue #3514 reported that environment variables passed with func deploy -e KEY=VALUE weren't showing up in the deployed service. The user could see them working with func run -e, but when deploying to the cluster, the variables were missing from the container.

After looking through the codebase, I noticed we have tests for func config envs add, but there's no E2E test that actually verifies the -e flag works during deployment. We're testing the config management commands but not the actual deployment behavior with environment variables.

@lkingland suggested adding an E2E matrix test that creates a function which reports back whether it received the environment variables, deploys it with -e flags, invokes it, and checks if the variables made it through. This would run across all our supported combinations to catch any builder or runtime-specific issues.

Implementation

I created e2e/e2e_matrix_deploy_envs_test.go with a new test function TestMatrix_Deploy_Envs() that does the following for each runtime/builder/template combination:

  1. Initializes a function with the specific runtime and template
  2. Replaces the generated code with a simple implementation that reads TEST_VAR and ANOTHER_VAR from the environment and returns their values in the response
  3. Deploys using func deploy -e TEST_VAR=test_value -e ANOTHER_VAR=another_value --builder <builder>
  4. Waits for the function to become ready
  5. Makes an HTTP request to the deployed function
  6. Verifies the response contains both variables with correct values

The test includes language-specific implementations for reading environment variables since each runtime does it differently:

  • Go: os.Getenv()
  • Node/TypeScript: process.env
  • Python: os.getenv()
  • Rust: env::var()
  • Quarkus: @ConfigProperty injection
  • SpringBoot: Environment.getProperty()

Each implementation returns HTTP 500 if either variable is missing, and HTTP 200 with the values if both are present. This makes failures easy to detect.

Why This Approach

The test follows the same pattern as existing matrix tests like TestMatrix_Deploy, using the forEachPermutation helper to run across all valid combinations. It respects the same matrix exceptions and timeout configurations.

By testing all combinations, we ensure the -e flag works consistently whether you're using host builder with Go, pack builder with Python, or s2i builder with Node. If there's a bug in how a specific builder handles environment variables, this test will catch it.

Expected Results

When this runs in CI:

The test runs with FUNC_E2E_MATRIX=true go test -v ./e2e -run TestMatrix_Deploy_Envs and will automatically run in CI when the matrix test environment variable is set.

Testing

I've verified:

  • Code compiles without errors
  • Test structure follows existing matrix test patterns
  • Each language implementation is syntactically correct
  • Test properly cleans up resources

I haven't run the full matrix locally since it requires a Kubernetes cluster with all builders and runtime images, but the test follows the established patterns from other working matrix tests.

Fixes #3514

@knative-prow
knative-prow Bot requested review from dsimansk and jrangelramos May 20, 2026 19:48
@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 May 20, 2026
@knative-prow

knative-prow Bot commented May 20, 2026

Copy link
Copy Markdown

Hi @Itx-Psycho0. 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.

@Itx-Psycho0

Copy link
Copy Markdown
Contributor Author

Hi @lkingland sir,

I've implemented the E2E matrix test you suggested for issue #3514. The test creates a function that echoes back environment variables, deploys it with func deploy -e TEST_VAR=test_value -e ANOTHER_VAR=another_value, and verifies the variables are present in the deployed container.

The test covers all 7 runtimes (go, python, node, typescript, rust, quarkus, springboot), all 3 builders (host, pack, s2i), and both templates (http, cloudevents). Each language has its own implementation for reading and returning the environment variables.

This should help us verify whether the -e flag works correctly across all combinations, or if there's a specific builder/runtime pair that has the issue reported in #3514.

Would appreciate your review when you get a chance. Thanks!

@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 45.41%. Comparing base (2bbf9fe) to head (ff84bf8).
⚠️ Report is 163 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (2bbf9fe) and HEAD (ff84bf8). Click for more details.

HEAD has 10 uploads less than BASE
Flag BASE (2bbf9fe) HEAD (ff84bf8)
e2e 3 2
e2e-config-ci 1 0
e2e springboot 1 0
e2e node 1 0
e2e typescript 1 0
e2e go 1 0
e2e rust 1 0
e2e python 1 0
e2e quarkus 1 0
integration 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3806       +/-   ##
===========================================
- Coverage   57.06%   45.41%   -11.65%     
===========================================
  Files         181      200       +19     
  Lines       21145    23426     +2281     
===========================================
- Hits        12067    10640     -1427     
- Misses       7855    11843     +3988     
+ Partials     1223      943      -280     
Flag Coverage Δ
e2e 21.63% <ø> (-14.29%) ⬇️
e2e go ?
e2e node ?
e2e python ?
e2e quarkus ?
e2e rust ?
e2e springboot ?
e2e typescript ?
e2e-config-ci ?
integration ?
unit macos-14 42.20% <ø> (-2.86%) ⬇️
unit macos-latest 42.20% <ø> (-2.86%) ⬇️
unit ubuntu-24.04-arm 42.50% <ø> (-2.82%) ⬇️
unit ubuntu-latest 43.06% <ø> (-2.95%) ⬇️
unit windows-latest 42.24% <ø> (-2.87%) ⬇️

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.

@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

Some check if failing.

@github-actions

Copy link
Copy Markdown
Contributor

This Pull Request is stale because it has been open for 90 days with
no activity. It will automatically close after 30 more days of
inactivity. Reopen with /reopen. Mark as fresh by adding the
comment /remove-lifecycle stale.

@github-actions github-actions Bot added the lifecycle/stale 🤖 No recent activity. label Aug 24, 2026
@github-actions github-actions Bot closed this Sep 24, 2026
@Itx-Psycho0

Copy link
Copy Markdown
Contributor Author

/reopen

@knative-prow knative-prow Bot reopened this Oct 13, 2026
@knative-prow

knative-prow Bot commented Oct 13, 2026

Copy link
Copy Markdown

@Itx-Psycho0: Reopened this PR.

Details

In response to this:

/reopen

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.

@github-actions github-actions Bot removed the lifecycle/stale 🤖 No recent activity. label Oct 14, 2026
Itx-Psycho0 and others added 2 commits October 29, 2026 21:27
Add comprehensive E2E matrix test to verify that environment variables
passed via `func deploy -e KEY=VALUE` are correctly applied to deployed
functions across all supported builders and runtimes.

The test:
- Creates a function that echoes back environment variables
- Deploys it with `func deploy -e TEST_VAR=test_value -e ANOTHER_VAR=another_value`
- Invokes the function and verifies env vars are present
- Runs for all builder ?? runtime ?? template combinations

This addresses the lack of test coverage for the -e flag on deploy,
which was identified as the root cause of issue knative#3514.

Implementation:
- Added TestMatrix_Deploy_Envs() function in e2e/e2e_matrix_deploy_envs_test.go
- Added createEnvEchoFunction() helper for language-specific implementations
- Supports all 7 runtimes: go, python, node, typescript, rust, quarkus, springboot
- Supports all 3 builders: host, pack, s2i
- Supports both templates: http, cloudevents

The test will run in CI when FUNC_E2E_MATRIX=true is set, verifying that
the -e flag works correctly across all supported combinations and preventing
future regressions.

Fixes knative#3514
The first revision wrote each language's echo to a path the template
does not build, and used handler shapes the current templates no
longer have. The deployed container therefore kept answering "OK",
and waitFor treated that as ready.

Overwrite the http template's real handler, and the template tests
that assert the stock body, so the image serves ENV_ECHO. Skip
cloudevents: those handlers are a different contract, and http is
enough to prove deploy -e reached the process.

waitFor matches ENV_ECHO, then the test still requires
TEST_VAR=test_value and ANOTHER_VAR=another_value. A marker without
those values is knative#3514. Leave that assertion in place.

Issue knative#3514
@lkingland
lkingland force-pushed the fix/3514-deploy-env-flag-e2e-test-clean branch from ff84bf8 to 3664c14 Compare October 30, 2026 09:55
@knative-prow knative-prow Bot added size/XL 🤖 PR changes 500-999 lines, ignoring generated files. and removed size/L 🤖 PR changes 100-499 lines, ignoring generated files. labels Oct 30, 2026
@lkingland

Copy link
Copy Markdown
Member

Thanks @Itx-Psycho0! Rebased onto main and added a commit on top so the env-echo handler actually replaces each template's handler (the deployed function was still answering the stock "OK"). It's http-only, and it now passes across all runtimes, confirming deploy -e reaches the container.

/lgtm
/approve

@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label Oct 30, 2026
@knative-prow

knative-prow Bot commented Oct 30, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Itx-Psycho0, lkingland

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 knative-prow Bot added the approved 🤖 PR has been approved by an approver from all required OWNERS files. label Oct 30, 2026
@knative-prow
knative-prow Bot merged commit 16c5d74 into knative:main Oct 30, 2026
45 checks passed
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. lgtm 🤖 PR is ready to be merged. ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/XL 🤖 PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Environment variables passed via -e flag not applied on deploy

3 participants