Skip to content

Commit

Permalink
rebase and update e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce Palmer <bpalmer@redhat.com>
  • Loading branch information
everettraven committed Jun 6, 2023
1 parent 6034b41 commit 44d2c15
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 176 deletions.
299 changes: 156 additions & 143 deletions test/e2e/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,167 +29,33 @@ var _ = Describe("Operator Install", func() {
ctx context.Context
pkgName string
operatorName string
catalogName string
operator *operatorv1alpha1.Operator
operatorCatalog *catalogd.Catalog
)
When("An operator is installed from an operator catalog", func() {
BeforeEach(func() {
ctx = context.Background()
catalogName = fmt.Sprintf("catalog-%s", rand.String(8))
operatorCatalog = &catalogd.Catalog{
ObjectMeta: metav1.ObjectMeta{
Name: catalogName,
},
Spec: catalogd.CatalogSpec{
Source: catalogd.CatalogSource{
Type: catalogd.SourceTypeImage,
Image: &catalogd.ImageSource{
Ref: testCatalogRef,
},
},
},
}
})
It("resolves the specified package with correct bundle path", func() {
err := c.Create(ctx, operatorCatalog)
Expect(err).ToNot(HaveOccurred())
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: testCatalogName}, operatorCatalog)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(len(operatorCatalog.Status.Conditions)).To(Equal(1))
cond := apimeta.FindStatusCondition(operatorCatalog.Status.Conditions, catalogd.TypeUnpacked)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
g.Expect(cond.Reason).To(Equal(catalogd.ReasonUnpackSuccessful))
g.Expect(cond.Message).To(ContainSubstring("successfully unpacked the catalog image"))
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())

By("creating the Operator resource")
err = c.Create(ctx, operator)
var err error
operatorCatalog, err = createTestCatalog(ctx, testCatalogName, testCatalogRef)
Expect(err).ToNot(HaveOccurred())

By("eventually reporting a successful resolution and bundle path")
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
g.Expect(err).ToNot(HaveOccurred())

cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
g.Expect(cond.Message).To(ContainSubstring("successfully unpacked the catalog image"))

// For some reason the above condition check is returning true and the
// Operators end up being created before the packages exist. Adding this check
// to ensure that there are some packages that exist before actually returning from this
// check.
pkgList := &catalogd.PackageList{}
err = c.List(ctx, pkgList)
g.Expect(err).ToNot(HaveOccurred())
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeInstalled)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
g.Expect(cond.Reason).To(Equal(operatorv1alpha1.ReasonSuccess))
g.Expect(cond.Message).To(ContainSubstring("installed from"))
g.Expect(operator.Status.InstalledBundleResource).ToNot(BeEmpty())
bd := rukpakv1alpha1.BundleDeployment{}
err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &bd)
g.Expect(err).ToNot(HaveOccurred())

cond = apimeta.FindStatusCondition(bd.Status.Conditions, rukpakv1alpha1.TypeHasValidBundle)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
g.Expect(cond.Reason).To(Equal(rukpakv1alpha1.ReasonUnpackSuccessful))

cond = apimeta.FindStatusCondition(bd.Status.Conditions, rukpakv1alpha1.TypeInstalled)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
g.Expect(cond.Reason).To(Equal(rukpakv1alpha1.ReasonInstallationSucceeded))
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
})
It("resolves again when a new catalog is available", func() {
Eventually(func(g Gomega) {
// target package should not be present on cluster
err := c.Get(ctx, types.NamespacedName{Name: pkgName}, &catalogd.Package{})
Expect(errors.IsNotFound(err)).To(BeTrue())
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())

By("creating the Operator resource")
err := c.Create(ctx, operator)
Expect(err).ToNot(HaveOccurred())

By("failing to find Operator during resolution")
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
g.Expect(err).ToNot(HaveOccurred())
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionFalse))
g.Expect(cond.Reason).To(Equal(operatorv1alpha1.ReasonResolutionFailed))
g.Expect(cond.Message).To(Equal(fmt.Sprintf("package '%s' not found", pkgName)))
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())

By("creating an Operator catalog with the desired package")
err = c.Create(ctx, operatorCatalog)
Expect(err).ToNot(HaveOccurred())
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, operatorCatalog)
err := c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, operatorCatalog)
g.Expect(err).ToNot(HaveOccurred())
cond := apimeta.FindStatusCondition(operatorCatalog.Status.Conditions, catalogd.TypeUnpacked)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
g.Expect(cond.Reason).To(Equal(catalogd.ReasonUnpackSuccessful))
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
// g.Expect(cond.Message).To(ContainSubstring("resolved to"))

By("eventually resolving the package successfully")
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
// Ensure some packages exist before continuing so the
// operators don't get stuck in a bad state
pList := &catalogd.PackageList{}
err = c.List(ctx, pList)
g.Expect(err).ToNot(HaveOccurred())
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
g.Expect(cond.Reason).To(Equal(operatorv1alpha1.ReasonSuccess))
g.Expect(pList.Items).To(HaveLen(2))
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
})

AfterEach(func() {
err := c.Delete(ctx, operator)
Expect(err).ToNot(HaveOccurred())
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &operatorv1alpha1.Operator{})
Expect(errors.IsNotFound(err)).To(BeTrue())
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())

err = c.Delete(ctx, operatorCatalog)
Expect(err).ToNot(HaveOccurred())
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, &catalogd.Catalog{})
Expect(errors.IsNotFound(err)).To(BeTrue())
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())

// speed up delete without waiting for gc
err = c.DeleteAllOf(ctx, &catalogd.BundleMetadata{})
Expect(err).ToNot(HaveOccurred())
err = c.DeleteAllOf(ctx, &catalogd.Package{})
Expect(err).ToNot(HaveOccurred())

Eventually(func(g Gomega) {
// ensure resource cleanup
packages := &catalogd.PackageList{}
err = c.List(ctx, packages)
Expect(err).To(BeNil())
Expect(packages.Items).To(BeEmpty())

bmd := &catalogd.BundleMetadataList{}
err = c.List(ctx, bmd)
Expect(err).To(BeNil())
Expect(bmd.Items).To(BeEmpty())

err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &rukpakv1alpha1.BundleDeployment{})
Expect(errors.IsNotFound(err)).To(BeTrue())
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
})

When("the operator bundle format is registry+v1", func() {
BeforeEach(func() {
pkgName = "prometheus"
Expand Down Expand Up @@ -238,7 +104,54 @@ var _ = Describe("Operator Install", func() {
g.Expect(bd.Status.Conditions[0].Reason).To(Equal("UnpackSuccessful"))
g.Expect(bd.Status.Conditions[1].Reason).To(Equal("InstallationSucceeded"))
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
})
It("resolves again when a new catalog is available", func() {
// Delete the catalog first
err := c.Delete(ctx, operatorCatalog)
Expect(err).ToNot(HaveOccurred())

Eventually(func(g Gomega) {
// target package should not be present on cluster
err := c.Get(ctx, types.NamespacedName{Name: pkgName}, &catalogd.Package{})
g.Expect(errors.IsNotFound(err)).To(BeTrue())
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())

By("creating the Operator resource")
err = c.Create(ctx, operator)
Expect(err).ToNot(HaveOccurred())

By("failing to find Operator during resolution")
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
g.Expect(err).ToNot(HaveOccurred())
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionFalse))
g.Expect(cond.Reason).To(Equal(operatorv1alpha1.ReasonResolutionFailed))
g.Expect(cond.Message).To(Equal(fmt.Sprintf("package '%s' not found", pkgName)))
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())

By("creating an Operator catalog with the desired package")
operatorCatalog, err = createTestCatalog(ctx, testCatalogName, testCatalogRef)
Expect(err).ToNot(HaveOccurred())
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, operatorCatalog)
g.Expect(err).ToNot(HaveOccurred())
cond := apimeta.FindStatusCondition(operatorCatalog.Status.Conditions, catalogd.TypeUnpacked)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
g.Expect(cond.Reason).To(Equal(catalogd.ReasonUnpackSuccessful))
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())

By("eventually resolving the package successfully")
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
g.Expect(err).ToNot(HaveOccurred())
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
g.Expect(cond.Reason).To(Equal(operatorv1alpha1.ReasonSuccess))
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
})
AfterEach(func() {
err := c.Delete(ctx, operator)
Expand Down Expand Up @@ -294,13 +207,113 @@ var _ = Describe("Operator Install", func() {
g.Expect(bd.Status.Conditions[0].Reason).To(Equal("UnpackSuccessful"))
g.Expect(bd.Status.Conditions[1].Reason).To(Equal("InstallationSucceeded"))
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
})
It("resolves again when a new catalog is available", func() {
// Delete the catalog first
err := c.Delete(ctx, operatorCatalog)
Expect(err).ToNot(HaveOccurred())

Eventually(func(g Gomega) {
// target package should not be present on cluster
err := c.Get(ctx, types.NamespacedName{Name: pkgName}, &catalogd.Package{})
g.Expect(errors.IsNotFound(err)).To(BeTrue())
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())

By("creating the Operator resource")
err = c.Create(ctx, operator)
Expect(err).ToNot(HaveOccurred())

By("failing to find Operator during resolution")
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
g.Expect(err).ToNot(HaveOccurred())
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionFalse))
g.Expect(cond.Reason).To(Equal(operatorv1alpha1.ReasonResolutionFailed))
g.Expect(cond.Message).To(Equal(fmt.Sprintf("package '%s' not found", pkgName)))
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())

By("creating an Operator catalog with the desired package")
operatorCatalog, err = createTestCatalog(ctx, testCatalogName, testCatalogRef)
Expect(err).ToNot(HaveOccurred())
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, operatorCatalog)
g.Expect(err).ToNot(HaveOccurred())
cond := apimeta.FindStatusCondition(operatorCatalog.Status.Conditions, catalogd.TypeUnpacked)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
g.Expect(cond.Reason).To(Equal(catalogd.ReasonUnpackSuccessful))
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())

By("eventually resolving the package successfully")
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
g.Expect(err).ToNot(HaveOccurred())
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
g.Expect(cond).ToNot(BeNil())
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
g.Expect(cond.Reason).To(Equal(operatorv1alpha1.ReasonSuccess))
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
})
AfterEach(func() {
err := c.Delete(ctx, operator)
Expect(err).ToNot(HaveOccurred())
})
})

AfterEach(func() {
err := c.Delete(ctx, operatorCatalog)
Expect(err).ToNot(HaveOccurred())
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, &catalogd.Catalog{})
Expect(errors.IsNotFound(err)).To(BeTrue())
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())

// speed up delete without waiting for gc
err = c.DeleteAllOf(ctx, &catalogd.BundleMetadata{})
Expect(err).ToNot(HaveOccurred())
err = c.DeleteAllOf(ctx, &catalogd.Package{})
Expect(err).ToNot(HaveOccurred())

Eventually(func(g Gomega) {
// ensure resource cleanup
packages := &catalogd.PackageList{}
err = c.List(ctx, packages)
Expect(err).To(BeNil())
Expect(packages.Items).To(BeEmpty())

bmd := &catalogd.BundleMetadataList{}
err = c.List(ctx, bmd)
Expect(err).To(BeNil())
Expect(bmd.Items).To(BeEmpty())

err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &rukpakv1alpha1.BundleDeployment{})
Expect(errors.IsNotFound(err)).To(BeTrue())
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
})

})
})

// createTestCatalog will create a new catalog on the test cluster, provided
// the context, catalog name, and the image reference. It returns the created catalog
// or an error if any errors occurred while creating the catalog.
func createTestCatalog(ctx context.Context, name string, imageRef string) (*catalogd.Catalog, error) {
catalog := &catalogd.Catalog{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: catalogd.CatalogSpec{
Source: catalogd.CatalogSource{
Type: catalogd.SourceTypeImage,
Image: &catalogd.ImageSource{
Ref: imageRef,
},
},
},
}

err := c.Create(ctx, catalog)
return catalog, err
}
33 changes: 0 additions & 33 deletions testdata/catalogs/test-catalog/catalog.json

This file was deleted.

0 comments on commit 44d2c15

Please sign in to comment.