Skip to content

Commit

Permalink
improve e2e test format, add comments
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 605fa39 commit a7ee2fa
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 119 deletions.
4 changes: 4 additions & 0 deletions internal/controllers/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ func mapBundleMediaTypeToBundleProvisioner(mediaType string) (string, error) {
switch mediaType {
case entity.MediaTypePlain:
return "core-rukpak-io-plain", nil
// To ensure compatibility with bundles created with OLMv0 where the
// olm.bundle.mediatype property doesn't exist, we assume that if the
// property is empty (i.e doesn't exist) that the bundle is one created
// with OLMv0 and therefore should use the registry provisioner
case entity.MediaTypeRegistry, "":
return "core-rukpak-io-registry", nil
default:
Expand Down
2 changes: 2 additions & 0 deletions internal/resolution/entitysources/catalogdsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func getEntities(ctx context.Context, client client.Client) (input.EntityList, e
for _, bundle := range bundleMetadatas.Items {
props := map[string]string{}

// TODO: We should make sure all properties are forwarded
// through and avoid a lossy translation from FBC --> entity
for _, prop := range bundle.Spec.Properties {
switch prop.Type {
case property.TypePackage:
Expand Down
5 changes: 5 additions & 0 deletions internal/resolution/variable_sources/entity/bundle_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
)

const PropertyBundlePath = "olm.bundle.path"

// TODO: Is this the right place for these?
// ----
const PropertyBundleMediaType = "olm.bundle.mediatype"

type MediaType string
Expand All @@ -20,6 +23,8 @@ const (
MediaTypeRegistry = "registry+v1"
)

// ----

type ChannelProperties struct {
property.Channel
Replaces string `json:"replaces,omitempty"`
Expand Down
186 changes: 67 additions & 119 deletions test/e2e/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const (
var _ = Describe("Operator Install", func() {
var (
ctx context.Context
pkgName string
operatorName string
operator *operatorv1alpha1.Operator
operatorCatalog *catalogd.Catalog
Expand Down Expand Up @@ -55,18 +54,18 @@ var _ = Describe("Operator Install", func() {
g.Expect(err).ToNot(HaveOccurred())
g.Expect(pList.Items).To(HaveLen(2))
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())

operatorName = fmt.Sprintf("operator-%s", rand.String(8))
operator = &operatorv1alpha1.Operator{
ObjectMeta: metav1.ObjectMeta{
Name: operatorName,
},
}
})
When("the operator bundle format is registry+v1", func() {
BeforeEach(func() {
pkgName = "prometheus"
operatorName = fmt.Sprintf("operator-%s", rand.String(8))
operator = &operatorv1alpha1.Operator{
ObjectMeta: metav1.ObjectMeta{
Name: operatorName,
},
Spec: operatorv1alpha1.OperatorSpec{
PackageName: pkgName,
},
operator.Spec = operatorv1alpha1.OperatorSpec{
PackageName: "prometheus",
}
})
It("resolves the specified package with correct bundle path", func() {
Expand Down Expand Up @@ -105,71 +104,12 @@ var _ = Describe("Operator Install", func() {
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())
})
})

When("the operator bundle format is plain+v0", func() {
BeforeEach(func() {
pkgName = "plain"
operatorName = fmt.Sprintf("operator-%s", rand.String(8))
operator = &operatorv1alpha1.Operator{
ObjectMeta: metav1.ObjectMeta{
Name: operatorName,
},
Spec: operatorv1alpha1.OperatorSpec{
PackageName: pkgName,
},
operator.Spec = operatorv1alpha1.OperatorSpec{
PackageName: "plain",
}
})
It("resolves the specified package with correct bundle path", func() {
Expand Down Expand Up @@ -208,62 +148,70 @@ var _ = Describe("Operator Install", func() {
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())
It("resolves again when a new catalog is available", func() {
pkgName := "prometheus"
operator.Spec = operatorv1alpha1.OperatorSpec{
PackageName: pkgName,
}

By("creating the Operator resource")
err = c.Create(ctx, operator)
Expect(err).ToNot(HaveOccurred())
// Delete the catalog first
err := c.Delete(ctx, operatorCatalog)
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())
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 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("creating the Operator resource")
err = c.Create(ctx, operator)
Expect(err).ToNot(HaveOccurred())

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())
})
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, operatorCatalog)
err := c.Delete(ctx, operator)
Eventually(func(g Gomega) {
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, &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{})
Expand Down

0 comments on commit a7ee2fa

Please sign in to comment.