Skip to content

feat: adds http patch support to cel expressions#54

Open
gaganhr94 wants to merge 2 commits into
kyverno:mainfrom
gaganhr94:feat/http-patch-support
Open

feat: adds http patch support to cel expressions#54
gaganhr94 wants to merge 2 commits into
kyverno:mainfrom
gaganhr94:feat/http-patch-support

Conversation

@gaganhr94

@gaganhr94 gaganhr94 commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Explanation

This PR adds HTTP PATCH method support to the Kyverno SDK CEL HTTP library. Currently, the library only supports GET and POST operations. The PATCH method is a fundamental part of RESTful API interactions. This enhancement allows users to make PATCH requests with custom headers and request bodies from within CEL expressions, enabling full resource update capabilities in policy expressions.

Related issue

Fixes kyverno/kyverno#15471
Dependent on the merge of PR #53 since this PR is built on top of that. Will rebase this branch with main once #53 is merged

Proposed Changes

The PATCH implementation mirrors the existing PATCH method pattern to maintain consistency across the codebase. These changes will add support to the patch method (say, for example http.Patch() being used in the CEL expressions)

Checklist

  • I have read the contributing guidelines.
  • I have read the PR documentation guide and followed the process including adding proof manifests to this PR.
  • This is a bug fix and I have added unit tests that prove my fix is effective.

Further Comments

@codecov-commenter

codecov-commenter commented Mar 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.08333% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.59%. Comparing base (376d911) to head (2329184).

Files with missing lines Patch % Lines
extensions/cel/libs/http/http.go 50.00% 6 Missing and 6 partials ⚠️
extensions/cel/libs/http/impl.go 75.00% 4 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #54      +/-   ##
==========================================
+ Coverage   70.35%   70.59%   +0.24%     
==========================================
  Files          80       80              
  Lines        2540     2636      +96     
==========================================
+ Hits         1787     1861      +74     
- Misses        602      612      +10     
- Partials      151      163      +12     

☔ 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.

@gaganhr94 gaganhr94 changed the title Feat/http patch support feat: adds http patch support to cel expressions Mar 8, 2026
Signed-off-by: Gagan H R <hrgagan4@gmail.com>
Signed-off-by: Gagan H R <hrgagan4@gmail.com>
Copilot AI review requested due to automatic review settings April 25, 2026 11:08
@gaganhr94 gaganhr94 force-pushed the feat/http-patch-support branch from 083edda to 2329184 Compare April 25, 2026 11:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds HTTP PUT and PATCH support to the Kyverno SDK CEL HTTP library so CEL expressions can perform full update operations (beyond existing GET/POST) with optional headers and request bodies.

Changes:

  • Extend the CEL environment with Put/put and Patch/patch member functions (overloads with/without headers).
  • Implement PUT/PATCH request handling in the CEL binding layer and the underlying HTTP context implementation.
  • Add unit tests covering successful PUT/PATCH calls and argument validation errors.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
extensions/cel/libs/http/types.go Extends the exported HTTP context interface to include Put and Patch.
extensions/cel/libs/http/lib.go Registers CEL function overloads for Put/put and Patch/patch.
extensions/cel/libs/http/impl.go Adds CEL function bindings that validate/convert args and invoke ContextInterface.Put/Patch.
extensions/cel/libs/http/http.go Implements Put and Patch request creation/dispatch in contextImpl.
extensions/cel/libs/http/impl_test.go Adds tests validating PUT/PATCH behavior and error handling.

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

Comment on lines 9 to 14
type ContextInterface interface {
Get(url string, headers map[string]string) (any, error)
Post(url string, data any, headers map[string]string) (any, error)
Put(url string, data any, headers map[string]string) (any, error)
Patch(url string, data any, headers map[string]string) (any, error)
Client(caBundle string) (ContextInterface, error)

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

Adding new methods to the exported ContextInterface is a breaking Go API change for any downstream users that may implement this interface. If backwards-compatibility is required, consider introducing a new interface (e.g. ContextInterfaceV2), embedding the old interface, or exposing PUT/PATCH via concrete types while keeping the original interface unchanged.

Copilot uses AI. Check for mistakes.
Comment on lines +322 to +326
body, err := buildRequestData(data)
if err != nil {
return nil, fmt.Errorf("failed to encode request data: %w", err)
}
req, err := http.NewRequestWithContext(context.TODO(), "PUT", url, body)

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

buildRequestData returns an error message that hard-codes "HTTP POST data", but this code path is now used by PUT (and PATCH below). Consider making the error message method-agnostic (or passing the HTTP method into the helper) so failures during PUT/PATCH encoding don't misleadingly mention POST.

Copilot uses AI. Check for mistakes.
assert.NoError(t, err)
assert.NotNil(t, env)
ast, issues := env.Compile(`http.Put("http://localhost:8080", { "key": dyn("value"), "foo": dyn(2) })`)
fmt.Println(issues.String())

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

This fmt.Println(issues.String()) writes to stdout during go test runs and makes CI output noisy. Consider removing it, or switching to t.Log/Logf only when issues != nil and issues.Err() != nil (or equivalent) to log failures only.

Suggested change
fmt.Println(issues.String())
if issues != nil {
t.Log(issues.String())
}

Copilot uses AI. Check for mistakes.
Comment on lines +801 to +803
ast, issues := env.Compile(`http.Put("http://localhost:8080", {"key": "value"}, {"Authorization": "Bearer token"})`)
fmt.Println(issues.String())
assert.Nil(t, issues)

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

This fmt.Println(issues.String()) writes to stdout during go test runs and makes CI output noisy. Consider removing it, or switching to t.Log/Logf only when issues != nil and issues.Err() != nil (or equivalent) to log failures only.

Copilot uses AI. Check for mistakes.
Comment on lines +882 to +885
ast, issues := env.Compile(`http.Patch("http://localhost:8080", {"key": "value"})`)
fmt.Println(issues.String())
assert.Nil(t, issues)
assert.NotNil(t, ast)

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

This fmt.Println(issues.String()) writes to stdout during go test runs and makes CI output noisy. Consider removing it, or switching to t.Log/Logf only when issues != nil and issues.Err() != nil (or equivalent) to log failures only.

Copilot uses AI. Check for mistakes.
Comment on lines +925 to +928
ast, issues := env.Compile(`http.Patch("http://localhost:8080", {"key": "value"}, {"Authorization": "Bearer token", "Content-Type": "application/json"})`)
fmt.Println(issues.String())
assert.Nil(t, issues)
assert.NotNil(t, ast)

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

This fmt.Println(issues.String()) writes to stdout during go test runs and makes CI output noisy. Consider removing it, or switching to t.Log/Logf only when issues != nil and issues.Err() != nil (or equivalent) to log failures only.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add HTTP PATCH method support to CEL HTTP library

4 participants