@@ -20,7 +20,6 @@ import (
20
20
"context"
21
21
"crypto/tls"
22
22
"crypto/x509"
23
- "encoding/json"
24
23
"fmt"
25
24
"io"
26
25
"net/http"
@@ -49,6 +48,7 @@ import (
49
48
"k8s.io/apimachinery/pkg/runtime"
50
49
"k8s.io/apimachinery/pkg/runtime/schema"
51
50
"k8s.io/apimachinery/pkg/types"
51
+ "k8s.io/apimachinery/pkg/util/json"
52
52
"k8s.io/apimachinery/pkg/util/sets"
53
53
"k8s.io/apimachinery/pkg/util/wait"
54
54
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
@@ -446,16 +446,25 @@ func (w *warningHandler) HandleWarningHeader(code int, agent string, message str
446
446
447
447
// TestWebhookAdmissionWithWatchCache tests communication between API server and webhook process.
448
448
func TestWebhookAdmissionWithWatchCache (t * testing.T ) {
449
- testWebhookAdmission (t , true )
449
+ testWebhookAdmission (t , true , func (testing. TB , * rest. Config ) {} )
450
450
}
451
451
452
452
// TestWebhookAdmissionWithoutWatchCache tests communication between API server and webhook process.
453
453
func TestWebhookAdmissionWithoutWatchCache (t * testing.T ) {
454
- testWebhookAdmission (t , false )
454
+ testWebhookAdmission (t , false , func (testing.TB , * rest.Config ) {})
455
+ }
456
+
457
+ func TestWebhookAdmissionWithCBOR (t * testing.T ) {
458
+ framework .EnableCBORServingAndStorageForTest (t )
459
+ framework .SetTestOnlyCBORClientFeatureGatesForTest (t , true , true )
460
+ testWebhookAdmission (t , false , func (t testing.TB , config * rest.Config ) {
461
+ config .Wrap (framework .AssertRequestResponseAsCBOR (t ))
462
+ })
455
463
}
456
464
457
465
// testWebhookAdmission tests communication between API server and webhook process.
458
- func testWebhookAdmission (t * testing.T , watchCache bool ) {
466
+ func testWebhookAdmission (t * testing.T , watchCache bool , reconfigureClient func (testing.TB , * rest.Config )) {
467
+
459
468
// holder communicates expectations to webhooks, and results from webhooks
460
469
holder := & holder {
461
470
t : t ,
@@ -528,10 +537,6 @@ func testWebhookAdmission(t *testing.T, watchCache bool) {
528
537
}
529
538
530
539
// gather resources to test
531
- dynamicClient , err := dynamic .NewForConfig (clientConfig )
532
- if err != nil {
533
- t .Fatal (err )
534
- }
535
540
_ , resources , err := client .Discovery ().ServerGroupsAndResources ()
536
541
if err != nil {
537
542
t .Fatalf ("Failed to get ServerGroupsAndResources with error: %+v" , err )
@@ -640,6 +645,13 @@ func testWebhookAdmission(t *testing.T, watchCache bool) {
640
645
for _ , verb := range []string {"create" , "update" , "patch" , "connect" , "delete" , "deletecollection" } {
641
646
if shouldTestResourceVerb (gvr , resource , verb ) {
642
647
t .Run (verb , func (t * testing.T ) {
648
+ clientConfig := rest .CopyConfig (clientConfig )
649
+ reconfigureClient (t , clientConfig )
650
+ dynamicClient , err := dynamic .NewForConfig (clientConfig )
651
+ if err != nil {
652
+ t .Fatal (err )
653
+ }
654
+
643
655
count ++
644
656
holder .reset (t )
645
657
testFunc := getTestFunc (gvr , verb )
0 commit comments