@@ -15,6 +15,7 @@ import (
15
15
"github.com/stretchr/testify/assert"
16
16
"github.com/stretchr/testify/require"
17
17
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
18
+ corev1 "k8s.io/api/core/v1"
18
19
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19
20
"sigs.k8s.io/controller-runtime/pkg/client"
20
21
"sigs.k8s.io/controller-runtime/pkg/client/fake"
@@ -57,7 +58,7 @@ func TestPatchTopologyWebhook(t *testing.T) {
57
58
cases := []struct {
58
59
caseName string
59
60
webhook * admissionregistrationv1.MutatingWebhookConfiguration
60
- caBundle [] byte
61
+ secret * corev1. Secret
61
62
wantErr error
62
63
wantPatch bool
63
64
}{
@@ -69,7 +70,10 @@ func TestPatchTopologyWebhook(t *testing.T) {
69
70
},
70
71
Webhooks : []admissionregistrationv1.MutatingWebhook {{ClientConfig : admissionregistrationv1.WebhookClientConfig {}}},
71
72
},
72
- caBundle : []byte ("foo" ),
73
+ secret : & corev1.Secret {
74
+ ObjectMeta : metav1.ObjectMeta {Name : "envoy-gateway" , Namespace : cfg .ControllerNamespace },
75
+ Data : map [string ][]byte {"ca.crt" : []byte ("foo" )},
76
+ },
73
77
wantErr : nil ,
74
78
wantPatch : true ,
75
79
},
@@ -81,25 +85,28 @@ func TestPatchTopologyWebhook(t *testing.T) {
81
85
},
82
86
Webhooks : []admissionregistrationv1.MutatingWebhook {{ClientConfig : admissionregistrationv1.WebhookClientConfig {CABundle : []byte ("foo" )}}},
83
87
},
84
- caBundle : []byte ("foo" ),
88
+ secret : & corev1.Secret {
89
+ ObjectMeta : metav1.ObjectMeta {Name : "envoy-gateway" , Namespace : cfg .ControllerNamespace },
90
+ Data : map [string ][]byte {"ca.crt" : []byte ("foo" )},
91
+ },
85
92
wantPatch : false ,
86
93
},
87
94
}
88
95
for _ , tc := range cases {
89
96
t .Run (tc .caseName , func (t * testing.T ) {
90
97
fakeClient := fake .NewClientBuilder ().
91
- WithRuntimeObjects (tc .webhook ).
98
+ WithRuntimeObjects (tc .webhook , tc . secret ).
92
99
Build ()
93
100
beforeWebhook := & admissionregistrationv1.MutatingWebhookConfiguration {}
94
101
require .NoError (t , fakeClient .Get (context .Background (), client.ObjectKey {Name : tc .webhook .Name }, beforeWebhook ))
95
- err = patchTopologyInjectorWebhook (context .Background (), fakeClient , cfg )
96
102
103
+ err = patchTopologyInjectorWebhook (context .Background (), fakeClient , cfg )
97
104
require .NoError (t , err )
98
105
99
106
afterWebhook := & admissionregistrationv1.MutatingWebhookConfiguration {}
100
107
require .NoError (t , fakeClient .Get (context .Background (), client.ObjectKey {Name : tc .webhook .Name }, afterWebhook ))
101
108
102
- require .Equal (t , afterWebhook .Webhooks [0 ].ClientConfig .CABundle , tc .caBundle )
109
+ require .Equal (t , afterWebhook .Webhooks [0 ].ClientConfig .CABundle , tc .secret . Data [ "ca.crt" ] )
103
110
assert .Equal (t , tc .wantPatch , beforeWebhook .GetResourceVersion () != afterWebhook .GetResourceVersion ())
104
111
})
105
112
}
0 commit comments