Skip to content

Commit 28e88e3

Browse files
authored
Merge pull request kubernetes#79659 from liggitt/test-webhook-watch-cache
Test webhooks with and without watch cache enabled
2 parents 1e96207 + 38ec458 commit 28e88e3

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

test/integration/apiserver/admissionwebhook/admission_test.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,18 @@ func (h *holder) verifyOptions(options runtime.Object) error {
386386
return nil
387387
}
388388

389-
// TestWebhookAdmission tests communication between API server and webhook process.
390-
func TestWebhookAdmission(t *testing.T) {
389+
// TestWebhookAdmissionWithWatchCache tests communication between API server and webhook process.
390+
func TestWebhookAdmissionWithWatchCache(t *testing.T) {
391+
testWebhookAdmission(t, true)
392+
}
393+
394+
// TestWebhookAdmissionWithoutWatchCache tests communication between API server and webhook process.
395+
func TestWebhookAdmissionWithoutWatchCache(t *testing.T) {
396+
testWebhookAdmission(t, false)
397+
}
398+
399+
// testWebhookAdmission tests communication between API server and webhook process.
400+
func testWebhookAdmission(t *testing.T, watchCache bool) {
391401
// holder communicates expectations to webhooks, and results from webhooks
392402
holder := &holder{
393403
t: t,
@@ -428,6 +438,7 @@ func TestWebhookAdmission(t *testing.T) {
428438
// start API server
429439
etcdConfig := framework.SharedEtcd()
430440
server := kubeapiservertesting.StartTestServerOrDie(t, nil, []string{
441+
fmt.Sprintf("--watch-cache=%v", watchCache),
431442
// turn off admission plugins that add finalizers
432443
"--disable-admission-plugins=ServiceAccount,StorageObjectInUseProtection",
433444
// force enable all resources so we can check storage.

test/integration/apiserver/admissionwebhook/reinvocation_test.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,18 @@ const (
4949
testReinvocationClientUsername = "webhook-reinvocation-integration-client"
5050
)
5151

52-
// TestWebhookReinvocationPolicy ensures that the admission webhook reinvocation policy is applied correctly.
53-
func TestWebhookReinvocationPolicy(t *testing.T) {
52+
// TestWebhookReinvocationPolicyWithWatchCache ensures that the admission webhook reinvocation policy is applied correctly with the watch cache enabled.
53+
func TestWebhookReinvocationPolicyWithWatchCache(t *testing.T) {
54+
testWebhookReinvocationPolicy(t, true)
55+
}
56+
57+
// TestWebhookReinvocationPolicyWithoutWatchCache ensures that the admission webhook reinvocation policy is applied correctly without the watch cache enabled.
58+
func TestWebhookReinvocationPolicyWithoutWatchCache(t *testing.T) {
59+
testWebhookReinvocationPolicy(t, false)
60+
}
61+
62+
// testWebhookReinvocationPolicy ensures that the admission webhook reinvocation policy is applied correctly.
63+
func testWebhookReinvocationPolicy(t *testing.T, watchCache bool) {
5464
reinvokeNever := registrationv1beta1.NeverReinvocationPolicy
5565
reinvokeIfNeeded := registrationv1beta1.IfNeededReinvocationPolicy
5666

@@ -175,6 +185,7 @@ func TestWebhookReinvocationPolicy(t *testing.T) {
175185

176186
s := kubeapiservertesting.StartTestServerOrDie(t, kubeapiservertesting.NewDefaultTestServerOptions(), []string{
177187
"--disable-admission-plugins=ServiceAccount",
188+
fmt.Sprintf("--watch-cache=%v", watchCache),
178189
}, framework.SharedEtcd())
179190
defer s.TearDownFn()
180191

0 commit comments

Comments
 (0)