@@ -313,7 +313,7 @@ var _ = Describe("Catalog", func() {
313313
314314 stableChannel := "stable"
315315
316- dependentCRD := newCRD ( genName ("ins-" ))
316+ dependentCRD := newCRD (genName ("ins-" ))
317317 mainCSV := newCSV (mainPackageStable , testNamespace , "" , semver .MustParse ("0.1.0" ), nil , []apiextensions.CustomResourceDefinition {dependentCRD }, nil )
318318 dependentCSV := newCSV (dependentPackageStable , testNamespace , "" , semver .MustParse ("0.1.0" ), []apiextensions.CustomResourceDefinition {dependentCRD }, nil , nil )
319319
@@ -556,7 +556,7 @@ var _ = Describe("Catalog", func() {
556556
557557 // Wait for a new registry pod to be created
558558 notUID := func (pods * corev1.PodList ) bool {
559- uids := make ([]string ,0 )
559+ uids := make ([]string , 0 )
560560 for _ , pod := range pods .Items {
561561 uids = append (uids , string (pod .GetUID ()))
562562 if pod .GetUID () == uid {
@@ -620,7 +620,7 @@ var _ = Describe("Catalog", func() {
620620
621621 // Wait for a new registry pod to be created
622622 notUID := func (pods * corev1.PodList ) bool {
623- uids := make ([]string ,0 )
623+ uids := make ([]string , 0 )
624624 for _ , pod := range pods .Items {
625625 uids = append (uids , string (pod .GetUID ()))
626626 if pod .GetUID () == uid {
@@ -984,6 +984,77 @@ var _ = Describe("Catalog", func() {
984984 require .NoError (GinkgoT (), err )
985985 require .Equal (GinkgoT (), "busybox-dependency.v1.0.0" , csv .Spec .Replaces )
986986 })
987+ It ("registry polls on the correct interval" , func () {
988+ // Create a catalog source with polling enabled
989+ // Confirm the following
990+ // a) the new update pod is spun up roughly in line with the registry polling interval
991+ // b) the update pod is removed quickly when the image is found to not have changed
992+ // This is more of a behavioral test that ensures the feature is working as designed.
993+
994+ c := newKubeClient ()
995+ crc := newCRClient ()
996+
997+ sourceName := genName ("catalog-" )
998+ source := & v1alpha1.CatalogSource {
999+ TypeMeta : metav1.TypeMeta {
1000+ Kind : v1alpha1 .CatalogSourceKind ,
1001+ APIVersion : v1alpha1 .CatalogSourceCRDAPIVersion ,
1002+ },
1003+ ObjectMeta : metav1.ObjectMeta {
1004+ Name : sourceName ,
1005+ Namespace : testNamespace ,
1006+ Labels : map [string ]string {"olm.catalogSource" : sourceName },
1007+ },
1008+ Spec : v1alpha1.CatalogSourceSpec {
1009+ SourceType : v1alpha1 .SourceTypeGrpc ,
1010+ Image : "quay.io/olmtest/catsrc-update-test:new" ,
1011+ UpdateStrategy : & v1alpha1.UpdateStrategy {
1012+ RegistryPoll : & v1alpha1.RegistryPoll {
1013+ Interval : & metav1.Duration {Duration : 45 * time .Second },
1014+ },
1015+ },
1016+ },
1017+ }
1018+
1019+ source , err := crc .OperatorsV1alpha1 ().CatalogSources (source .GetNamespace ()).Create (context .TODO (), source , metav1.CreateOptions {})
1020+ Expect (err ).ToNot (HaveOccurred ())
1021+
1022+ // wait for new catalog source pod to be created and report ready
1023+ selector := labels .SelectorFromSet (map [string ]string {"olm.catalogSource" : source .GetName ()})
1024+ singlePod := podCount (1 )
1025+ catalogPods , err := awaitPods (GinkgoT (), c , source .GetNamespace (), selector .String (), singlePod )
1026+ Expect (err ).ToNot (HaveOccurred ())
1027+ Expect (catalogPods ).ToNot (BeNil ())
1028+
1029+ Eventually (func () (bool , error ) {
1030+ podList , err := c .KubernetesInterface ().CoreV1 ().Pods (source .GetNamespace ()).List (context .TODO (), metav1.ListOptions {LabelSelector : selector .String ()})
1031+ if err != nil {
1032+ return false , err
1033+ }
1034+
1035+ for _ , p := range podList .Items {
1036+ if podReady (& p ) {
1037+ return true , nil
1038+ }
1039+ return false , nil
1040+ }
1041+
1042+ return false , nil
1043+ }).Should (BeTrue ())
1044+
1045+ // Wait roughly the polling interval for update pod to show up
1046+ updateSelector := labels .SelectorFromSet (map [string ]string {"catalogsource.operators.coreos.com/update" : source .GetName ()})
1047+ updatePods , err := awaitPodsWithInterval (GinkgoT (), c , source .GetNamespace (), updateSelector .String (), 5 * time .Second , 2 * time .Minute , singlePod )
1048+ Expect (err ).ToNot (HaveOccurred ())
1049+ Expect (updatePods ).ToNot (BeNil ())
1050+ Expect (updatePods .Items ).To (HaveLen (1 ))
1051+
1052+ // No update to image: update pod should be deleted quickly
1053+ noPod := podCount (0 )
1054+ updatePods , err = awaitPodsWithInterval (GinkgoT (), c , source .GetNamespace (), updateSelector .String (), 1 * time .Second , 30 * time .Second , noPod )
1055+ Expect (err ).ToNot (HaveOccurred ())
1056+ Expect (updatePods .Items ).To (HaveLen (0 ))
1057+ })
9871058})
9881059
9891060const (
0 commit comments