@@ -25,14 +25,10 @@ import (
2525 . "github.com/onsi/gomega"
2626 admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
2727 corev1 "k8s.io/api/core/v1"
28- networkingv1 "k8s.io/api/networking/v1"
2928 k8sErrors "k8s.io/apimachinery/pkg/api/errors"
30- "k8s.io/apimachinery/pkg/api/resource"
3129 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3230 "k8s.io/apimachinery/pkg/types"
3331
34- placementv1beta1 "go.goms.io/fleet/apis/placement/v1beta1"
35-
3632 testutils "go.goms.io/fleet/test/e2e/v1alpha1/utils"
3733)
3834
@@ -63,62 +59,6 @@ func createUnmanagedNamespace(name string) *corev1.Namespace {
6359 }
6460}
6561
66- func createManagedResourceQuota (name , namespace string ) * corev1.ResourceQuota {
67- return & corev1.ResourceQuota {
68- ObjectMeta : metav1.ObjectMeta {
69- Name : name ,
70- Namespace : namespace ,
71- Labels : map [string ]string {
72- managedByLabel : managedByLabelValue ,
73- },
74- },
75- Spec : corev1.ResourceQuotaSpec {
76- Hard : corev1.ResourceList {
77- corev1 .ResourcePods : resource .MustParse ("10" ),
78- },
79- },
80- }
81- }
82-
83- func createManagedNetworkPolicy (name , namespace string ) * networkingv1.NetworkPolicy {
84- return & networkingv1.NetworkPolicy {
85- ObjectMeta : metav1.ObjectMeta {
86- Name : name ,
87- Namespace : namespace ,
88- Labels : map [string ]string {
89- managedByLabel : managedByLabelValue ,
90- },
91- },
92- Spec : networkingv1.NetworkPolicySpec {
93- PodSelector : metav1.LabelSelector {},
94- PolicyTypes : []networkingv1.PolicyType {
95- networkingv1 .PolicyTypeIngress ,
96- },
97- },
98- }
99- }
100-
101- func createManagedCRP (name string ) * placementv1beta1.ClusterResourcePlacement {
102- return & placementv1beta1.ClusterResourcePlacement {
103- ObjectMeta : metav1.ObjectMeta {
104- Name : name ,
105- Labels : map [string ]string {
106- managedByLabel : managedByLabelValue ,
107- },
108- },
109- Spec : placementv1beta1.PlacementSpec {
110- ResourceSelectors : []placementv1beta1.ClusterResourceSelector {
111- {
112- Group : "" ,
113- Version : "v1" ,
114- Kind : "Namespace" ,
115- Name : "test-ns" ,
116- },
117- },
118- },
119- }
120- }
121-
12262func expectDeniedByVAP (err error ) {
12363 var statusErr * k8sErrors.StatusError
12464 Expect (errors .As (err , & statusErr )).To (BeTrue (), fmt .Sprintf ("Expected StatusError, got error %s of type %s" , err , reflect .TypeOf (err )))
@@ -132,16 +72,12 @@ func expectDeniedByVAP(err error) {
13272}
13373
13474var _ = Describe ("ValidatingAdmissionPolicy for Managed Resources" , Label ("managedresource" ), Ordered , func () {
135- BeforeEach (func () {
136- Eventually (func () error {
137- var vap admissionregistrationv1.ValidatingAdmissionPolicy
138- return hubClient .Get (ctx , types.NamespacedName {Name : vapName }, & vap )
139- }, testutils .PollTimeout , testutils .PollInterval ).Should (Succeed (), "ValidatingAdmissionPolicy should be installed" )
140-
141- Eventually (func () error {
142- var vapBinding admissionregistrationv1.ValidatingAdmissionPolicyBinding
143- return hubClient .Get (ctx , types.NamespacedName {Name : vapBindingName }, & vapBinding )
144- }, testutils .PollTimeout , testutils .PollInterval ).Should (Succeed (), "ValidatingAdmissionPolicyBinding should be installed" )
75+ BeforeAll (func () {
76+ var vap admissionregistrationv1.ValidatingAdmissionPolicy
77+ Expect (hubClient .Get (ctx , types.NamespacedName {Name : vapName }, & vap )).Should (Succeed (), "ValidatingAdmissionPolicy should be installed" )
78+
79+ var vapBinding admissionregistrationv1.ValidatingAdmissionPolicyBinding
80+ Expect (hubClient .Get (ctx , types.NamespacedName {Name : vapBindingName }, & vapBinding )).Should (Succeed (), "ValidatingAdmissionPolicyBinding should be installed" )
14581 })
14682
14783 Context ("Namespace operations on managed-by label" , func () {
@@ -157,6 +93,7 @@ var _ = Describe("ValidatingAdmissionPolicy for Managed Resources", Label("manag
15793 By ("creating managed namespace with system:masters user" )
15894 Expect (hubClient .Create (ctx , managedNS )).To (Succeed ())
15995
96+ var updateErr error
16097 Eventually (func () error {
16198 var ns corev1.Namespace
16299 if err := hubClient .Get (ctx , types.NamespacedName {Name : managedNS .Name }, & ns ); err != nil {
@@ -168,10 +105,11 @@ var _ = Describe("ValidatingAdmissionPolicy for Managed Resources", Label("manag
168105 if k8sErrors .IsConflict (err ) {
169106 return err
170107 }
171- expectDeniedByVAP ( err )
108+ updateErr = err
172109 return nil
173110 }, testutils .PollTimeout , testutils .PollInterval ).Should (Succeed ())
174111
112+ expectDeniedByVAP (updateErr )
175113 Expect (hubClient .Delete (ctx , managedNS )).To (Succeed ())
176114 })
177115
0 commit comments