Skip to content

Commit e769fbf

Browse files
author
Nont
committed
Fix review comments
Signed-off-by: Nont <[email protected]>
1 parent 264971a commit e769fbf

File tree

4 files changed

+18
-80
lines changed

4 files changed

+18
-80
lines changed

pkg/webhook/managedresource/validatingadmissionpolicy.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ import (
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111
)
1212

13+
const resourceName = "aks-fleet-managed-by-arm"
14+
1315
func GetValidatingAdmissionPolicy(isHub bool) *admv1.ValidatingAdmissionPolicy {
1416
vap := &admv1.ValidatingAdmissionPolicy{
1517
TypeMeta: metav1.TypeMeta{
1618
APIVersion: "admissionregistration.k8s.io/v1",
1719
Kind: "ValidatingAdmissionPolicy",
1820
},
1921
ObjectMeta: metav1.ObjectMeta{
20-
Name: "aks-fleet-managed-by-arm",
22+
Name: resourceName,
2123
},
2224
Spec: admv1.ValidatingAdmissionPolicySpec{
2325
MatchConstraints: &admv1.MatchResources{
@@ -92,7 +94,7 @@ func GetValidatingAdmissionPolicyBinding() *admv1.ValidatingAdmissionPolicyBindi
9294
Kind: "ValidatingAdmissionPolicyBinding",
9395
},
9496
ObjectMeta: metav1.ObjectMeta{
95-
Name: "aks-fleet-managed-by-arm",
97+
Name: resourceName,
9698
},
9799
Spec: admv1.ValidatingAdmissionPolicyBindingSpec{
98100
PolicyName: "aks-fleet-managed-by-arm",

pkg/webhook/managedresource/validatingadmissionpolicy_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
Copyright (c) Microsoft Corporation.
3+
Licensed under the MIT license.
4+
*/
5+
16
package managedresource
27

38
import (

test/e2e/managed_resource_vap_test.go

Lines changed: 9 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
12262
func 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

13474
var _ = 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

test/e2e/resources/managed-namespace.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)