Skip to content

Commit

Permalink
add test to verify error clears on correct update
Browse files Browse the repository at this point in the history
Signed-off-by: Anik Bhattacharjee <anikbhattacharya93@gmail.com>
  • Loading branch information
anik120 committed Apr 7, 2022
1 parent eb24011 commit 07ef80d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
4 changes: 0 additions & 4 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,6 @@ func (o *Operator) syncRegistryServer(logger *logrus.Entry, in *v1alpha1.Catalog
if out.Spec.UpdateStrategy.RegistryPoll != nil {
if out.Spec.UpdateStrategy.RegistryPoll.ParsingError != "" && out.Status.Reason != v1alpha1.CatalogSourceIntervalInvalidError {
out.SetError(v1alpha1.CatalogSourceIntervalInvalidError, fmt.Errorf(out.Spec.UpdateStrategy.RegistryPoll.ParsingError))
if _, err := o.client.OperatorsV1alpha1().CatalogSources(out.GetNamespace()).UpdateStatus(context.TODO(), out, metav1.UpdateOptions{}); err != nil {
logger.Errorf("error while updating catalogsource status for an invalid interval - %v", err)
return
}
}
logger.Debugf("requeuing registry server sync based on polling interval %s", out.Spec.UpdateStrategy.Interval.Duration.String())
resyncPeriod := reconciler.SyncRegistryUpdateInterval(out, time.Now())
Expand Down
48 changes: 41 additions & 7 deletions test/e2e/catalog_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
Expect(err).ShouldNot(HaveOccurred())
Expect(csv.Spec.Replaces).To(Equal("busybox-dependency.v1.0.0"))
})
When("A catalogSource is created with correct interval", func() {
When("A catalogSource is created with correct polling interval", func() {

var source *v1alpha1.CatalogSource
singlePod := podCount(1)
Expand Down Expand Up @@ -1146,12 +1146,18 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {

})

When("A catalogSource is created with incorrect interval", func() {

var source *v1alpha1.CatalogSource
When("A catalogSource is created with incorrect polling interval", func() {

var (
source *v1alpha1.CatalogSource
sourceName string
)
const (
incorrectInterval = "45mError.code"
correctInterval = "45m"
)
BeforeEach(func() {
sourceName := genName("catalog-")
sourceName = genName("catalog-")
source = &v1alpha1.CatalogSource{
TypeMeta: metav1.TypeMeta{
Kind: v1alpha1.CatalogSourceKind,
Expand All @@ -1167,7 +1173,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
Image: "quay.io/olmtest/catsrc-update-test:new",
UpdateStrategy: &v1alpha1.UpdateStrategy{
RegistryPoll: &v1alpha1.RegistryPoll{
RawInterval: "45mError.code",
RawInterval: incorrectInterval,
},
},
},
Expand All @@ -1177,7 +1183,10 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
Expect(err).ToNot(HaveOccurred())

})

AfterEach(func() {
err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Delete(context.TODO(), source.GetName(), metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
})
It("the catalogsource status communicates that a default interval time is being used instead", func() {
Eventually(func() bool {
catsrc, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.TODO(), source.GetName(), metav1.GetOptions{})
Expand All @@ -1190,6 +1199,31 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
return false
}).Should(BeTrue())
})
When("the catalogsource is updated with a valid polling interval", func() {
BeforeEach(func() {
catsrc, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.TODO(), source.GetName(), metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
catsrc.Spec.UpdateStrategy.RegistryPoll.RawInterval = correctInterval
_, err = crc.OperatorsV1alpha1().CatalogSources(catsrc.GetNamespace()).Update(context.TODO(), catsrc, metav1.UpdateOptions{})
Expect(err).ToNot(HaveOccurred())
})
It("the catalogsource spec shows the updated polling interval, and the error message in the status is cleared", func() {
Eventually(func() error {
catsrc, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.TODO(), source.GetName(), metav1.GetOptions{})
if err != nil {
return err
}
expectedTime, err := time.ParseDuration(correctInterval)
if err != nil {
return err
}
if catsrc.Status.Reason != "" || (catsrc.Spec.UpdateStrategy.Interval != &metav1.Duration{expectedTime}) {
return err
}
return nil
}).Should(Succeed())
})
})
})

It("adding catalog template adjusts image used", func() {
Expand Down

0 comments on commit 07ef80d

Please sign in to comment.