@@ -63,7 +63,52 @@ func TestSnapshotValidationWebhook() {
6363 })
6464 gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
6565
66- introduceDelayForAdmission (ctx )
66+ validClassName := "e2e-valid-" + uuid .New ().String ()[:8 ]
67+ validClass := & unstructured.Unstructured {}
68+ validClass .SetAPIVersion ("snapshot.storage.k8s.io/v1" )
69+ validClass .SetKind ("VolumeSnapshotClass" )
70+ validClass .SetName (validClassName )
71+ validClass .SetLabels (map [string ]string {csiTestLabel : mock .RunID })
72+ _ = unstructured .SetNestedField (validClass .Object , "storage.csi.upcloud.com" , "driver" )
73+ _ = unstructured .SetNestedField (validClass .Object , "Delete" , "deletionPolicy" )
74+
75+ _ , err = client .Dynamic ().Resource (snapshotClassGVR ).Create (ctx , validClass , metav1.CreateOptions {})
76+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
77+
78+ invalidClassName := "e2e-invalid-" + uuid .New ().String ()[:8 ]
79+ invalidClass := & unstructured.Unstructured {}
80+ invalidClass .SetAPIVersion ("snapshot.storage.k8s.io/v1" )
81+ invalidClass .SetKind ("VolumeSnapshotClass" )
82+ invalidClass .SetName (invalidClassName )
83+ invalidClass .SetLabels (map [string ]string {csiTestLabel : mock .RunID })
84+ _ = unstructured .SetNestedField (invalidClass .Object , "storage.csi.upcloud.com" , "driver" )
85+ _ = unstructured .SetNestedField (invalidClass .Object , "Invalid" , "deletionPolicy" )
86+
87+ _ , err = client .Dynamic ().Resource (snapshotClassGVR ).Create (ctx , invalidClass , metav1.CreateOptions {})
88+ gomega .Expect (err ).To (gomega .HaveOccurred ())
89+
90+ _ = client .Dynamic ().Resource (snapshotClassGVR ).Delete (ctx , validClassName , metav1.DeleteOptions {})
91+
92+ disableWebhook ()
93+ }
94+
95+ func TestSnapshotValidationWebhookCertManager () {
96+ ctx := context .Background ()
97+ client , err := mock .NewClient (Namespace )
98+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
99+
100+ enableWebhookCertManager ("e2e-selfsigned" , "ClusterIssuer" )
101+
102+ waitForCertManagerCertificate (ctx , client )
103+
104+ err = wait .PollUntilContextTimeout (ctx , 2 * time .Second , 3 * time .Minute , true , func (ctx context.Context ) (bool , error ) {
105+ deploy , err := client .K8s ().AppsV1 ().Deployments ("kube-system" ).Get (ctx , "upcloud-csi-snapshot-validation-deployment" , metav1.GetOptions {})
106+ if err != nil {
107+ return false , err
108+ }
109+ return deploy .Status .ReadyReplicas >= 1 , nil
110+ })
111+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
67112
68113 validClassName := "e2e-valid-" + uuid .New ().String ()[:8 ]
69114 validClass := & unstructured.Unstructured {}
@@ -154,71 +199,12 @@ func disableWebhook() {
154199 )
155200}
156201
157- func introduceDelayForAdmission (ctx context.Context ) {
158- for range 10 {
159- select {
160- case <- ctx .Done ():
161- return
162- case <- time .After (3 * time .Second ):
163- }
164- }
165- }
166-
167202var certGVR = schema.GroupVersionResource { //nolint:gochecknoglobals // immutable schema constant
168203 Group : "cert-manager.io" ,
169204 Version : "v1" ,
170205 Resource : "certificates" ,
171206}
172207
173- func TestSnapshotValidationWebhookCertManager () {
174- ctx := context .Background ()
175- client , err := mock .NewClient (Namespace )
176- gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
177-
178- enableWebhookCertManager ("e2e-selfsigned" , "ClusterIssuer" )
179-
180- waitForCertManagerCertificate (ctx , client )
181-
182- err = wait .PollUntilContextTimeout (ctx , 2 * time .Second , 3 * time .Minute , true , func (ctx context.Context ) (bool , error ) {
183- deploy , err := client .K8s ().AppsV1 ().Deployments ("kube-system" ).Get (ctx , "upcloud-csi-snapshot-validation-deployment" , metav1.GetOptions {})
184- if err != nil {
185- return false , err
186- }
187- return deploy .Status .ReadyReplicas >= 1 , nil
188- })
189- gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
190-
191- introduceDelayForAdmission (ctx )
192-
193- validClassName := "e2e-valid-" + uuid .New ().String ()[:8 ]
194- validClass := & unstructured.Unstructured {}
195- validClass .SetAPIVersion ("snapshot.storage.k8s.io/v1" )
196- validClass .SetKind ("VolumeSnapshotClass" )
197- validClass .SetName (validClassName )
198- validClass .SetLabels (map [string ]string {csiTestLabel : mock .RunID })
199- _ = unstructured .SetNestedField (validClass .Object , "storage.csi.upcloud.com" , "driver" )
200- _ = unstructured .SetNestedField (validClass .Object , "Delete" , "deletionPolicy" )
201-
202- _ , err = client .Dynamic ().Resource (snapshotClassGVR ).Create (ctx , validClass , metav1.CreateOptions {})
203- gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
204-
205- invalidClassName := "e2e-invalid-" + uuid .New ().String ()[:8 ]
206- invalidClass := & unstructured.Unstructured {}
207- invalidClass .SetAPIVersion ("snapshot.storage.k8s.io/v1" )
208- invalidClass .SetKind ("VolumeSnapshotClass" )
209- invalidClass .SetName (invalidClassName )
210- invalidClass .SetLabels (map [string ]string {csiTestLabel : mock .RunID })
211- _ = unstructured .SetNestedField (invalidClass .Object , "storage.csi.upcloud.com" , "driver" )
212- _ = unstructured .SetNestedField (invalidClass .Object , "Invalid" , "deletionPolicy" )
213-
214- _ , err = client .Dynamic ().Resource (snapshotClassGVR ).Create (ctx , invalidClass , metav1.CreateOptions {})
215- gomega .Expect (err ).To (gomega .HaveOccurred ())
216-
217- _ = client .Dynamic ().Resource (snapshotClassGVR ).Delete (ctx , validClassName , metav1.DeleteOptions {})
218-
219- disableWebhook ()
220- }
221-
222208func enableWebhookCertManager (issuerName , issuerKind string ) {
223209 err := runHelmUpgrade (
224210 "--namespace" , "kube-system" ,
0 commit comments