Skip to content

Commit

Permalink
Change default operations
Browse files Browse the repository at this point in the history
Signed-off-by: anushkamittal2001 <[email protected]>
  • Loading branch information
anushkamittal2001 committed Oct 3, 2023
1 parent 841b1d9 commit 32cf58f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/controllers/webhook/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,10 +796,9 @@ func computeOperationsForValidatingWebhookConf(rules []kyvernov1.Rule, operation
if !opFound {
operationStatusMap[webhookCreate] = true
operationStatusMap[webhookUpdate] = true
operationStatusMap[webhookConnect] = true
operationStatusMap[webhookDelete] = true

Check failure on line 801 in pkg/controllers/webhook/controller.go

View workflow job for this annotation

GitHub Actions / tests

unnecessary trailing newline (whitespace)

Check failure on line 801 in pkg/controllers/webhook/controller.go

View workflow job for this annotation

GitHub Actions / tests

unnecessary trailing newline (whitespace)
if r.HasGenerate() {
operationStatusMap[webhookDelete] = true
}
}
}
return operationStatusMap
Expand Down Expand Up @@ -836,6 +835,7 @@ func computeOperationsForMutatingWebhookConf(rules []kyvernov1.Rule, operationSt
operationStatusMap[webhookCreate] = true
operationStatusMap[webhookUpdate] = true
}
operationStatusMap[webhookDelete] = true
}
return operationStatusMap
}
Expand Down
16 changes: 14 additions & 2 deletions pkg/controllers/webhook/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package webhook

import (
"reflect"
"sort"
"testing"

kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
Expand Down Expand Up @@ -39,6 +40,13 @@ func TestGetMinimumOperations(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
result := getMinimumOperations(testCase.inputMap)
sort.Slice(result, func(i, j int) bool {
return result[i] < result[j]
})
sort.Slice(testCase.expectedResult, func(i, j int) bool {
return testCase.expectedResult[i] < testCase.expectedResult[j]
})

if !reflect.DeepEqual(result, testCase.expectedResult) {
t.Errorf("Expected %v, but got %v", testCase.expectedResult, result)
}
Expand All @@ -65,6 +73,7 @@ func TestComputeOperationsForMutatingWebhookConf(t *testing.T) {
},
expectedResult: map[string]bool{
"CREATE": true,
"DELETE": true,
},
},
{
Expand All @@ -82,6 +91,7 @@ func TestComputeOperationsForMutatingWebhookConf(t *testing.T) {
expectedResult: map[string]bool{
webhookCreate: true,
webhookUpdate: true,
webhookDelete: true,
},
},
}
Expand Down Expand Up @@ -138,8 +148,10 @@ func TestComputeOperationsForValidatingWebhookConf(t *testing.T) {
},
},
expectedResult: map[string]bool{
webhookCreate: true,
webhookUpdate: true,
webhookCreate: true,
webhookUpdate: true,
webhookConnect: true,
webhookDelete: true,
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions test/conformance/kuttl/webhooks/all-scale/webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ webhooks:
operations:
- CREATE
- UPDATE
- CONNECT
- DELETE
resources:
- '*/scale'
scope: '*'
2 changes: 2 additions & 0 deletions test/conformance/kuttl/webhooks/double-wildcard/webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ webhooks:
operations:
- CREATE
- UPDATE
- CONNECT
- DELETE
resources:
- '*/*'
scope: '*'
2 changes: 2 additions & 0 deletions test/conformance/kuttl/webhooks/only-pod/webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ webhooks:
operations:
- CREATE
- UPDATE
- CONNECT
- DELETE
resources:
- pods
- pods/ephemeralcontainers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ webhooks:
operations:
- CREATE
- UPDATE
- CONNECT
- DELETE
resources:
- pods/attach
- pods/binding
Expand Down
2 changes: 2 additions & 0 deletions test/conformance/kuttl/webhooks/wildcard/webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ webhooks:
operations:
- CREATE
- UPDATE
- CONNECT
- DELETE
resources:
- '*'
- pods/ephemeralcontainers
Expand Down

0 comments on commit 32cf58f

Please sign in to comment.