Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: flaky fleet guard rail E2E where namespace is terminating #586

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion test/e2e/fleet_guard_rail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ var _ = Describe("fleet guard rail tests for deny MC CREATE operations", func()

var _ = Describe("fleet guard rail tests for allow/deny MC UPDATE, DELETE operations", Serial, Ordered, func() {
mcName := fmt.Sprintf(mcNameTemplate, GinkgoParallelProcess())
imcNamespace := fmt.Sprintf(utils.NamespaceNameFormat, mcName)

BeforeAll(func() {
createMemberClusterResource(mcName, testUser)
})

AfterAll(func() {
deleteMemberClusterResource(mcName)
checkMemberClusterNamespaceIsDeleted(imcNamespace)
})

It("should deny UPDATE operation on member cluster CR for user not in MC identity", func() {
Expand Down Expand Up @@ -180,6 +182,7 @@ var _ = Describe("fleet guard rail tests for deny IMC CREATE operations", func()
},
}
Expect(hubClient.Delete(ctx, &ns)).Should(Succeed())
checkMemberClusterNamespaceIsDeleted(imcNamespace)
})

It("should deny CREATE operation on internal member cluster CR for user not in MC identity in fleet member namespace", func() {
Expand Down Expand Up @@ -213,6 +216,7 @@ var _ = Describe("fleet guard rail tests for IMC UPDATE operation, in fleet-memb

AfterAll(func() {
deleteMemberClusterResource(mcName)
checkMemberClusterNamespaceIsDeleted(imcNamespace)
})

It("should deny UPDATE operation on internal member cluster CR for user not in MC identity in fleet member namespace", func() {
Expand All @@ -237,7 +241,7 @@ var _ = Describe("fleet guard rail tests for IMC UPDATE operation, in fleet-memb
var imc clusterv1beta1.InternalMemberCluster
Expect(hubClient.Get(ctx, types.NamespacedName{Name: mcName, Namespace: imcNamespace}, &imc)).Should(Succeed())

By("expecting denial of operation UPDATE of Internal Member Cluster")
By("expecting denial of operation DELETE of Internal Member Cluster")
err := impersonateHubClient.Delete(ctx, &imc)
var statusErr *k8sErrors.StatusError
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Delete internal member cluster call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
Expand Down Expand Up @@ -282,6 +286,7 @@ var _ = Describe("fleet guard rail tests for IMC UPDATE operation, in fleet-memb

AfterAll(func() {
deleteMemberClusterResource(mcName)
checkMemberClusterNamespaceIsDeleted(imcNamespace)
})

It("should allow UPDATE operation on internal member cluster CR status for user in MC identity", func() {
Expand Down Expand Up @@ -346,6 +351,7 @@ var _ = Describe("fleet guard rail tests for deny Work CREATE operations", func(
},
}
Expect(hubClient.Delete(ctx, &ns)).Should(Succeed())
checkMemberClusterNamespaceIsDeleted(imcNamespace)
})

It("should deny CREATE operation on internal member cluster CR for user not in MC identity in fleet member namespace", func() {
Expand Down Expand Up @@ -408,6 +414,7 @@ var _ = Describe("fleet guard rail for UPDATE work operations, in fleet prefixed
AfterAll(func() {
deleteWorkResource(workName, imcNamespace)
deleteMemberClusterResource(mcName)
checkMemberClusterNamespaceIsDeleted(imcNamespace)
})

It("should deny UPDATE operation on work CR status for user not in MC identity", func() {
Expand Down Expand Up @@ -462,6 +469,7 @@ var _ = Describe("fleet guard rail for UPDATE work operations, in fleet prefixed
AfterAll(func() {
deleteWorkResource(workName, imcNamespace)
deleteMemberClusterResource(mcName)
checkMemberClusterNamespaceIsDeleted(imcNamespace)
})

It("should allow UPDATE operation on work CR for user in MC identity", func() {
Expand Down
16 changes: 15 additions & 1 deletion test/e2e/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -280,7 +281,10 @@ func deleteMemberClusterResource(name string) {
}
g.Expect(err).Should(Succeed(), "Failed to get MC %s", name)
controllerutil.RemoveFinalizer(&mc, placementv1beta1.MemberClusterFinalizer)
g.Expect(hubClient.Update(ctx, &mc)).Should(Succeed())
err = hubClient.Update(ctx, &mc)
if errors.IsConflict(err) {
return err
}
g.Expect(hubClient.Delete(ctx, &mc)).Should(Succeed())
return nil
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
Expand All @@ -306,6 +310,16 @@ func checkInternalMemberClusterExists(name, namespace string) {
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
}

func checkMemberClusterNamespaceIsDeleted(name string) {
Eventually(func(g Gomega) error {
var ns corev1.Namespace
if err := hubClient.Get(ctx, types.NamespacedName{Name: name}, &ns); !errors.IsNotFound(err) {
return fmt.Errorf("member cluster namespace %s still exists or an unexpected error occurred: %w", name, err)
}
return nil
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
}

func createWorkResource(name, namespace string) {
testDeployment := appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Expand Down
Loading