Skip to content

Commit 24f7e0c

Browse files
committed
chore: remove CEL XValidation, keep Enum marker for Scope field
1 parent a653ef9 commit 24f7e0c

3 files changed

Lines changed: 0 additions & 46 deletions

File tree

api/v2/apisixroute_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ type ApisixRouteAuthenticationLDAPAuth struct {
412412
}
413413

414414
// ApisixRouteHTTPMatchExprSubject describes the subject of a route matching expression.
415-
// +kubebuilder:validation:XValidation:rule="self.scope == 'Path' || self.name != ”",message="name is required when scope is not Path"
416415
type ApisixRouteHTTPMatchExprSubject struct {
417416
// Scope specifies the subject scope.
418417
// Supported values: `Header`, `Query`, `Path`, `Cookie`, `Variable`, `Body`.

api/v2/apisixroute_types_test.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,52 +20,10 @@ package v2
2020
import (
2121
"testing"
2222

23-
"github.com/google/cel-go/cel"
2423
"github.com/stretchr/testify/assert"
2524
"github.com/stretchr/testify/require"
2625
)
2726

28-
// celSubjectRule is the CEL expression embedded via +kubebuilder:validation:XValidation
29-
// on ApisixRouteHTTPMatchExprSubject. This test validates its correctness.
30-
const celSubjectRule = "self.scope == 'Path' || self.name != ''"
31-
32-
// evalCELSubjectRule evaluates celSubjectRule against a fake subject object.
33-
func evalCELSubjectRule(t *testing.T, scope, name string) bool {
34-
t.Helper()
35-
env, err := cel.NewEnv(
36-
cel.Variable("self", cel.MapType(cel.StringType, cel.StringType)),
37-
)
38-
require.NoError(t, err)
39-
40-
ast, issues := env.Compile(celSubjectRule)
41-
require.NoError(t, issues.Err())
42-
43-
prg, err := env.Program(ast)
44-
require.NoError(t, err)
45-
46-
out, _, err := prg.Eval(map[string]any{
47-
"self": map[string]any{"scope": scope, "name": name},
48-
})
49-
require.NoError(t, err)
50-
return out.Value().(bool)
51-
}
52-
53-
func TestCEL_SubjectRule_ValidScopes(t *testing.T) {
54-
// All non-Path scopes with a non-empty name must pass.
55-
for _, scope := range []string{ScopeHeader, ScopeQuery, ScopeCookie, ScopeVariable, ScopeBody} {
56-
assert.True(t, evalCELSubjectRule(t, scope, "field"), "scope=%s with name should pass", scope)
57-
}
58-
// Path scope with empty name must pass (name is ignored for Path).
59-
assert.True(t, evalCELSubjectRule(t, ScopePath, ""), "Path with empty name should pass")
60-
}
61-
62-
func TestCEL_SubjectRule_InvalidEmptyName(t *testing.T) {
63-
// Non-Path scopes with empty name must fail.
64-
for _, scope := range []string{ScopeHeader, ScopeQuery, ScopeCookie, ScopeVariable, ScopeBody} {
65-
assert.False(t, evalCELSubjectRule(t, scope, ""), "scope=%s with empty name should fail", scope)
66-
}
67-
}
68-
6927
func strPtr(s string) *string { return &s }
7028

7129
func TestToVars_ScopeBody_SimpleField(t *testing.T) {

config/crd/bases/apisix.apache.org_apisixroutes.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,6 @@ spec:
230230
- name
231231
- scope
232232
type: object
233-
x-kubernetes-validations:
234-
- message: name is required when scope is not Path
235-
rule: self.scope == 'Path' || self.name != ”
236233
value:
237234
description: |-
238235
Value defines a single value to compare against the subject.

0 commit comments

Comments
 (0)