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

Add unit test for deletion of numaflow controller rollout #90

Merged
merged 1 commit into from
Jun 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -38,13 +39,13 @@ var _ = Describe("NumaflowControllerRollout Controller", Ordered, func() {
ctx := context.Background()

resourceLookupKey := types.NamespacedName{
Name: "numaflow-controller",
Name: NumaflowControllerDeploymentName,
Namespace: namespace,
}

numaflowControllerResource := apiv1.NumaflowControllerRollout{
ObjectMeta: metav1.ObjectMeta{
Name: "numaflow-controller",
Name: NumaflowControllerDeploymentName,
Namespace: namespace,
},
Spec: apiv1.NumaflowControllerRolloutSpec{
Expand Down Expand Up @@ -85,7 +86,7 @@ var _ = Describe("NumaflowControllerRollout Controller", Ordered, func() {
By("Verifying the numaflow controller deployment")
Eventually(func() bool {
numaflowDeployment := &appsv1.Deployment{}
err := k8sClient.Get(ctx, types.NamespacedName{Name: "numaflow-controller", Namespace: namespace}, numaflowDeployment)
err := k8sClient.Get(ctx, types.NamespacedName{Name: NumaflowControllerDeploymentName, Namespace: namespace}, numaflowDeployment)
return err == nil
}, duration, interval).Should(BeTrue())
})
Expand All @@ -101,7 +102,7 @@ var _ = Describe("NumaflowControllerRollout Controller", Ordered, func() {
By("Verifying the numaflow controller deployment image version")
Eventually(func() bool {
numaflowDeployment := &appsv1.Deployment{}
err := k8sClient.Get(ctx, types.NamespacedName{Name: "numaflow-controller", Namespace: namespace}, numaflowDeployment)
err := k8sClient.Get(ctx, types.NamespacedName{Name: NumaflowControllerDeploymentName, Namespace: namespace}, numaflowDeployment)
if err == nil {
return numaflowDeployment.Spec.Template.Spec.Containers[0].Image == "quay.io/numaproj/numaflow:v1.2.1"
}
Expand All @@ -120,10 +121,26 @@ var _ = Describe("NumaflowControllerRollout Controller", Ordered, func() {
})

AfterAll(func() {
// Cleanup the resource after each test and ignore the error if it doesn't exist
resource := &apiv1.NumaflowControllerRollout{}
_ = k8sClient.Get(ctx, resourceLookupKey, resource)
_ = k8sClient.Delete(ctx, resource)
// Cleanup the resource after the tests
Expect(k8sClient.Delete(ctx, &apiv1.NumaflowControllerRollout{
ObjectMeta: numaflowControllerResource.ObjectMeta,
})).Should(Succeed())

deletedResource := &apiv1.NumaflowControllerRollout{}
Eventually(func() bool {
err := k8sClient.Get(ctx, resourceLookupKey, deletedResource)
return errors.IsNotFound(err)
}, timeout, interval).Should(BeTrue())

deletingChildResource := &appsv1.Deployment{}
Eventually(func() bool {
err := k8sClient.Get(ctx, resourceLookupKey, deletingChildResource)
return err == nil
}, timeout, interval).Should(BeTrue())

Expect(deletingChildResource.OwnerReferences).Should(HaveLen(1))
Expect(deletedResource.UID).Should(Equal(deletingChildResource.OwnerReferences[0].UID))

})
})
})
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import (
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.

const (
timeout = 10 * time.Second
timeout = 15 * time.Second
duration = 10 * time.Second
interval = 250 * time.Millisecond
)
Expand Down
Loading