Skip to content

fix: apply resource validation to first-deploy path in k8s and keda deployers#3671

Open
Ankitsinghsisodya wants to merge 2 commits intoknative:mainfrom
Ankitsinghsisodya:fix/k8s-keda-resource-validation
Open

fix: apply resource validation to first-deploy path in k8s and keda deployers#3671
Ankitsinghsisodya wants to merge 2 commits intoknative:mainfrom
Ankitsinghsisodya:fix/k8s-keda-resource-validation

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

@Ankitsinghsisodya Ankitsinghsisodya commented May 7, 2026

Problem

generateDeployment in pkg/k8s/deployer.go allocated its own local
referencedSecrets, referencedConfigMaps, and referencedPVCs sets
internally. Those sets were never visible to the caller, so
CheckResourcesArePresent was never called on the k8s deploy path —
silently passing validation regardless of whether referenced Secrets,
ConfigMaps, or PVCs actually existed on the cluster.

The keda deployer is a thin wrapper around the k8s deployer and inherited
the same gap.

This is the same class of bug fixed for the knative deployer in #3579.

Pass the three sets as parameters into generateDeployment instead of
allocating them locally. Deploy() now:

  1. Allocates the sets before calling generateDeployment
  2. Calls CheckResourcesArePresent after generateDeployment on both the
    create path (first deploy) and the update path (redeployment), before
    touching the API

The keda deployer gets the fix for free since it delegates to the k8s
deployer.

Tests

  • TestInt_ResourceValidationOnFirstDeploy wired in pkg/k8s/deployer_int_test.go
    and pkg/keda/deployer_int_test.go — exercises the same shared scenario
    from pkg/deployer/testing/integration_test_helper.go used by the
    knative deployer since fix: pass referenced resource sets to generateNewService for proper validation #3579
  • Existing unit tests in pkg/k8s/deployer_test.go updated to match the
    new generateDeployment signature

…generation logic

- Introduced TestInt_ResourceValidationOnFirstDeploy to ensure that deploying a function referencing a non-existent Secret fails, while subsequent deploys succeed after the Secret is created.
- Updated the generateDeployment function to accept referenced resource sets (secrets, config maps, PVCs) for proper validation during deployment.
- Adjusted related tests to utilize the new validation logic, ensuring comprehensive coverage for resource checks on first deployments.

Ref knative#3514
Copilot AI review requested due to automatic review settings May 7, 2026 13:08
@knative-prow knative-prow Bot requested review from dsimansk and jrangelramos May 7, 2026 13:08
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 7, 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 matejvasek 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 added the size/M 🤖 PR changes 30-99 lines, ignoring generated files. label May 7, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 7, 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.

@knative-prow knative-prow Bot added the needs-ok-to-test 🤖 Needs an org member to approve testing label May 7, 2026
@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor Author

cc @matejvasek

Copy link
Copy Markdown
Contributor

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

Fixes a gap in the Kubernetes and KEDA deployers where referenced Secrets/ConfigMaps/PVCs were not validated on the first-deploy path due to referenced-resource sets being allocated inside generateDeployment and never surfaced to the caller.

Changes:

  • Pass caller-owned referenced-resource sets into k8s.Deployer.generateDeployment so env/volume processing populates them.
  • Invoke CheckResourcesArePresent on both create (first deploy) and update (redeploy) paths before hitting the Kubernetes API.
  • Add integration coverage for first-deploy resource validation for both k8s and keda deployers; update unit tests for the new signature.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
pkg/k8s/deployer.go Plumbs referenced-resource sets through deployment generation and enforces resource validation on create/update paths.
pkg/k8s/deployer_test.go Updates unit tests to match the new generateDeployment signature.
pkg/k8s/deployer_int_test.go Adds integration test to ensure first-deploy validation rejects missing referenced resources.
pkg/keda/deployer_int_test.go Adds the same integration coverage for the KEDA deployer (delegates to k8s deployer).

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

Comment thread pkg/k8s/deployer.go Outdated
Comment thread pkg/k8s/deployer.go Outdated
Comment thread pkg/k8s/deployer.go
Comment on lines +150 to 155
referencedSecrets := sets.New[string]()
referencedConfigMaps := sets.New[string]()
referencedPVCs := sets.New[string]()

deployment, err := d.generateDeployment(f, namespace, daprInstalled, &referencedSecrets, &referencedConfigMaps, &referencedPVCs)
if err != nil {
Updated error messages in the Deploy function to clarify that failures are due to validation of referenced resources rather than deployment creation or updates. This change enhances the clarity of error reporting when resources are missing or invalid.

Ref knative#3514
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 68.42105% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.65%. Comparing base (33a9d85) to head (696653d).

Files with missing lines Patch % Lines
pkg/k8s/deployer.go 68.42% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3671      +/-   ##
==========================================
+ Coverage   56.61%   56.65%   +0.04%     
==========================================
  Files         181      181              
  Lines       20853    20862       +9     
==========================================
+ Hits        11806    11820      +14     
+ Misses       7833     7830       -3     
+ Partials     1214     1212       -2     
Flag Coverage Δ
e2e 36.26% <57.89%> (-0.01%) ⬇️
e2e go 32.89% <0.00%> (-0.02%) ⬇️
e2e node 28.60% <0.00%> (-0.02%) ⬇️
e2e python 33.26% <0.00%> (-0.02%) ⬇️
e2e quarkus 28.75% <0.00%> (-0.02%) ⬇️
e2e rust 28.15% <0.00%> (-0.02%) ⬇️
e2e springboot 26.64% <0.00%> (+<0.01%) ⬆️
e2e typescript 28.73% <0.00%> (+<0.01%) ⬆️
e2e-config-ci 17.97% <0.00%> (-0.01%) ⬇️
integration 17.51% <86.66%> (+0.19%) ⬆️
unit macos-14 44.62% <20.00%> (-0.04%) ⬇️
unit macos-latest 44.62% <20.00%> (-0.04%) ⬇️
unit ubuntu-24.04-arm 44.86% <15.78%> (-0.05%) ⬇️
unit ubuntu-latest 45.47% <20.00%> (-0.04%) ⬇️
unit windows-latest 44.60% <20.00%> (-0.04%) ⬇️

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.

@matejvasek matejvasek requested review from creydr, gauron99 and lkingland and removed request for dsimansk and jrangelramos May 7, 2026 19:25
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/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants