@@ -437,13 +437,10 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() {
437
437
})
438
438
439
439
ginkgo .By ("Updating a validating webhook configuration's rules to not include the create operation" )
440
- err = retry .RetryOnConflict (retry .DefaultRetry , func () error {
441
- h , err := admissionClient .ValidatingWebhookConfigurations ().Get (ctx , f .UniqueName , metav1.GetOptions {})
442
- framework .ExpectNoError (err , "Getting validating webhook configuration" )
443
- h .Webhooks [0 ].Rules [0 ].Operations = []admissionregistrationv1.OperationType {admissionregistrationv1 .Update }
444
- _ , err = admissionClient .ValidatingWebhookConfigurations ().Update (ctx , h , metav1.UpdateOptions {})
445
- return err
446
- })
440
+ notIncludeCreateOperationFn := func (c * admissionregistrationv1.ValidatingWebhookConfiguration ) {
441
+ c .Webhooks [0 ].Rules [0 ].Operations = []admissionregistrationv1.OperationType {admissionregistrationv1 .Update }
442
+ }
443
+ _ , err = updateValidatingWebhookConfigurations (ctx , client , f .UniqueName , notIncludeCreateOperationFn )
447
444
framework .ExpectNoError (err , "Updating validating webhook configuration" )
448
445
449
446
ginkgo .By ("Creating a configMap that does not comply to the validation webhook rules" )
@@ -743,9 +740,12 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() {
743
740
Expression : "object.metadata.namespace == 'staging'" ,
744
741
},
745
742
}
746
- validatingWebhookConfiguration .Webhooks [0 ].MatchConditions = updatedMatchConditions
747
- _ , err = client .AdmissionregistrationV1 ().ValidatingWebhookConfigurations ().Update (ctx , validatingWebhookConfiguration , metav1.UpdateOptions {})
748
- framework .ExpectNoError (err )
743
+
744
+ updateMatchConditionsFn := func (c * admissionregistrationv1.ValidatingWebhookConfiguration ) {
745
+ c .Webhooks [0 ].MatchConditions = updatedMatchConditions
746
+ }
747
+ _ , err = updateValidatingWebhookConfigurations (ctx , client , f .UniqueName , updateMatchConditionsFn )
748
+ framework .ExpectNoError (err , "Updating validating webhook configuration" )
749
749
750
750
ginkgo .By ("verifying the validating webhook match conditions" )
751
751
validatingWebhookConfiguration , err = client .AdmissionregistrationV1 ().ValidatingWebhookConfigurations ().Get (ctx , f .UniqueName , metav1.GetOptions {})
@@ -794,8 +794,11 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() {
794
794
Expression : "object.metadata.namespace == 'staging'" ,
795
795
},
796
796
}
797
- mutatingWebhookConfiguration .Webhooks [0 ].MatchConditions = updatedMatchConditions
798
- _ , err = client .AdmissionregistrationV1 ().MutatingWebhookConfigurations ().Update (ctx , mutatingWebhookConfiguration , metav1.UpdateOptions {})
797
+
798
+ updateMatchConditionsFn := func (c * admissionregistrationv1.MutatingWebhookConfiguration ) {
799
+ c .Webhooks [0 ].MatchConditions = updatedMatchConditions
800
+ }
801
+ _ , err = updateMutatingWebhookConfigurations (ctx , client , f .UniqueName , updateMatchConditionsFn )
799
802
framework .ExpectNoError (err )
800
803
801
804
ginkgo .By ("verifying the mutating webhook match conditions" )
@@ -1914,6 +1917,38 @@ func updateConfigMap(ctx context.Context, c clientset.Interface, ns, name string
1914
1917
return cm , pollErr
1915
1918
}
1916
1919
1920
+ type updateValidatingWebhookConfigurationsFn func (c * admissionregistrationv1.ValidatingWebhookConfiguration )
1921
+
1922
+ func updateValidatingWebhookConfigurations (ctx context.Context , client clientset.Interface , name string ,
1923
+ update updateValidatingWebhookConfigurationsFn ) (* admissionregistrationv1.ValidatingWebhookConfiguration , error ) {
1924
+ var config * admissionregistrationv1.ValidatingWebhookConfiguration
1925
+ err := retry .RetryOnConflict (retry .DefaultRetry , func () error {
1926
+ var err error
1927
+ config , err = client .AdmissionregistrationV1 ().ValidatingWebhookConfigurations ().Get (ctx , name , metav1.GetOptions {})
1928
+ framework .ExpectNoError (err , "Getting validating webhook configuration" )
1929
+ update (config )
1930
+ config , err = client .AdmissionregistrationV1 ().ValidatingWebhookConfigurations ().Update (ctx , config , metav1.UpdateOptions {})
1931
+ return err
1932
+ })
1933
+ return config , err
1934
+ }
1935
+
1936
+ type updateMutatingWebhookConfigurationsFn func (c * admissionregistrationv1.MutatingWebhookConfiguration )
1937
+
1938
+ func updateMutatingWebhookConfigurations (ctx context.Context , client clientset.Interface , name string ,
1939
+ update updateMutatingWebhookConfigurationsFn ) (* admissionregistrationv1.MutatingWebhookConfiguration , error ) {
1940
+ var config * admissionregistrationv1.MutatingWebhookConfiguration
1941
+ err := retry .RetryOnConflict (retry .DefaultRetry , func () error {
1942
+ var err error
1943
+ config , err = client .AdmissionregistrationV1 ().MutatingWebhookConfigurations ().Get (ctx , name , metav1.GetOptions {})
1944
+ framework .ExpectNoError (err , "Getting mutating webhook configuration" )
1945
+ update (config )
1946
+ config , err = client .AdmissionregistrationV1 ().MutatingWebhookConfigurations ().Update (ctx , config , metav1.UpdateOptions {})
1947
+ return err
1948
+ })
1949
+ return config , err
1950
+ }
1951
+
1917
1952
type updateCustomResourceFn func (cm * unstructured.Unstructured )
1918
1953
1919
1954
func updateCustomResource (ctx context.Context , c dynamic.ResourceInterface , ns , name string , update updateCustomResourceFn ) (* unstructured.Unstructured , error ) {
0 commit comments