From 273e90fd2e2406a29e0417c469f12f37daf10a7e Mon Sep 17 00:00:00 2001 From: Daniel Sover Date: Mon, 21 Sep 2020 16:00:33 -0400 Subject: [PATCH] fix: update check from previous polling implementation --- pkg/controller/operators/catalog/operator.go | 4 +- test/e2e/catalog_e2e_test.go | 77 +++++++++++++++++++- 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/pkg/controller/operators/catalog/operator.go b/pkg/controller/operators/catalog/operator.go index 78123aa469..2eefd8a822 100644 --- a/pkg/controller/operators/catalog/operator.go +++ b/pkg/controller/operators/catalog/operator.go @@ -613,8 +613,8 @@ func (o *Operator) syncRegistryServer(logger *logrus.Entry, in *v1alpha1.Catalog if healthy && in.Status.RegistryServiceStatus != nil { logger.Debug("registry state good") continueSync = true - // Check if registryService is ready for polling update - if !out.Update() { + // return here if catalog does not have polling enabled + if !out.Poll() { return } } diff --git a/test/e2e/catalog_e2e_test.go b/test/e2e/catalog_e2e_test.go index cfaa152376..ccf93e8348 100644 --- a/test/e2e/catalog_e2e_test.go +++ b/test/e2e/catalog_e2e_test.go @@ -313,7 +313,7 @@ var _ = Describe("Catalog", func() { stableChannel := "stable" - dependentCRD := newCRD( genName("ins-")) + dependentCRD := newCRD(genName("ins-")) mainCSV := newCSV(mainPackageStable, testNamespace, "", semver.MustParse("0.1.0"), nil, []apiextensions.CustomResourceDefinition{dependentCRD}, nil) dependentCSV := newCSV(dependentPackageStable, testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{dependentCRD}, nil, nil) @@ -556,7 +556,7 @@ var _ = Describe("Catalog", func() { // Wait for a new registry pod to be created notUID := func(pods *corev1.PodList) bool { - uids := make([]string,0) + uids := make([]string, 0) for _, pod := range pods.Items { uids = append(uids, string(pod.GetUID())) if pod.GetUID() == uid { @@ -620,7 +620,7 @@ var _ = Describe("Catalog", func() { // Wait for a new registry pod to be created notUID := func(pods *corev1.PodList) bool { - uids := make([]string,0) + uids := make([]string, 0) for _, pod := range pods.Items { uids = append(uids, string(pod.GetUID())) if pod.GetUID() == uid { @@ -984,6 +984,77 @@ var _ = Describe("Catalog", func() { require.NoError(GinkgoT(), err) require.Equal(GinkgoT(), "busybox-dependency.v1.0.0", csv.Spec.Replaces) }) + It("registry polls on the correct interval", func() { + // Create a catalog source with polling enabled + // Confirm the following + // a) the new update pod is spun up roughly in line with the registry polling interval + // b) the update pod is removed quickly when the image is found to not have changed + // This is more of a behavioral test that ensures the feature is working as designed. + + c := newKubeClient() + crc := newCRClient() + + sourceName := genName("catalog-") + source := &v1alpha1.CatalogSource{ + TypeMeta: metav1.TypeMeta{ + Kind: v1alpha1.CatalogSourceKind, + APIVersion: v1alpha1.CatalogSourceCRDAPIVersion, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: sourceName, + Namespace: testNamespace, + Labels: map[string]string{"olm.catalogSource": sourceName}, + }, + Spec: v1alpha1.CatalogSourceSpec{ + SourceType: v1alpha1.SourceTypeGrpc, + Image: "quay.io/olmtest/catsrc-update-test:new", + UpdateStrategy: &v1alpha1.UpdateStrategy{ + RegistryPoll: &v1alpha1.RegistryPoll{ + Interval: &metav1.Duration{Duration: 45 * time.Second}, + }, + }, + }, + } + + source, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{}) + Expect(err).ToNot(HaveOccurred()) + + // wait for new catalog source pod to be created and report ready + selector := labels.SelectorFromSet(map[string]string{"olm.catalogSource": source.GetName()}) + singlePod := podCount(1) + catalogPods, err := awaitPods(GinkgoT(), c, source.GetNamespace(), selector.String(), singlePod) + Expect(err).ToNot(HaveOccurred()) + Expect(catalogPods).ToNot(BeNil()) + + Eventually(func() (bool, error) { + podList, err := c.KubernetesInterface().CoreV1().Pods(source.GetNamespace()).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.String()}) + if err != nil { + return false, err + } + + for _, p := range podList.Items { + if podReady(&p) { + return true, nil + } + return false, nil + } + + return false, nil + }).Should(BeTrue()) + + // Wait roughly the polling interval for update pod to show up + updateSelector := labels.SelectorFromSet(map[string]string{"catalogsource.operators.coreos.com/update": source.GetName()}) + updatePods, err := awaitPodsWithInterval(GinkgoT(), c, source.GetNamespace(), updateSelector.String(), 5*time.Second, 2*time.Minute, singlePod) + Expect(err).ToNot(HaveOccurred()) + Expect(updatePods).ToNot(BeNil()) + Expect(updatePods.Items).To(HaveLen(1)) + + // No update to image: update pod should be deleted quickly + noPod := podCount(0) + updatePods, err = awaitPodsWithInterval(GinkgoT(), c, source.GetNamespace(), updateSelector.String(), 1*time.Second, 30*time.Second, noPod) + Expect(err).ToNot(HaveOccurred()) + Expect(updatePods.Items).To(HaveLen(0)) + }) }) const (