Skip to content

Commit

Permalink
adding strictCost const
Browse files Browse the repository at this point in the history
Signed-off-by: Jaydip Gabani <[email protected]>
  • Loading branch information
JaydipGabani committed Aug 2, 2024
1 parent e35a7e5 commit e736423
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion constraint/pkg/client/drivers/k8scel/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (d *Driver) AddTemplate(_ context.Context, ct *templates.ConstraintTemplate
}
vapVars = append(vapVars, vapVarsSuffix...)
// Defaulting to true in MustBaseEnvSet to enforce strict cost calculation for CEL, following k8s.
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), true))
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), transform.StrictCost))
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const (
`
)

const StrictCost = true

func MatchExcludedNamespacesGlobV1Beta1() admissionregistrationv1beta1.MatchCondition {
return admissionregistrationv1beta1.MatchCondition{
Name: "gatekeeper_internal_match_excluded_namespaces",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func TestMatchKinds(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), true))
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), StrictCost))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -458,7 +458,7 @@ func TestMatchNameGlob(t *testing.T) {

for _, subTest := range expandedTests {
t.Run(subTest.name, func(t *testing.T) {
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), true))
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), StrictCost))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -628,7 +628,7 @@ func TestMatchNamespacesGlob(t *testing.T) {

for _, subTest := range expandedTests {
t.Run(subTest.name, func(t *testing.T) {
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), true))
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), StrictCost))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -802,7 +802,7 @@ func TestMatchExcludedNamespacesGlob(t *testing.T) {

for _, subTest := range expandedTests {
t.Run(subTest.name, func(t *testing.T) {
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), true))
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), StrictCost))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -866,7 +866,7 @@ func TestParamsBinding(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), true))
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), StrictCost))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -947,7 +947,7 @@ func TestObjectBinding(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), true))
filterCompiler, err := cel.NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), StrictCost))
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit e736423

Please sign in to comment.