From f6c5509b4fcf9504456be9cbf4e088e710fe99ba Mon Sep 17 00:00:00 2001 From: Evan Cordell Date: Tue, 18 Dec 2018 15:13:43 -0500 Subject: [PATCH] requeue dependent subscriptions when a catalog syncs --- pkg/controller/operators/catalog/operator.go | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/controller/operators/catalog/operator.go b/pkg/controller/operators/catalog/operator.go index 2d1178cb9f6..00f746b4cfe 100644 --- a/pkg/controller/operators/catalog/operator.go +++ b/pkg/controller/operators/catalog/operator.go @@ -13,6 +13,7 @@ import ( v1beta1ext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/informers" @@ -295,11 +296,11 @@ func (o *Operator) syncConfigMapSource(logger *logrus.Entry, catsrc *v1alpha1.Ca return fmt.Errorf("failed to get catalog config map %s: %s", catsrc.Spec.ConfigMap, err) } + out := catsrc.DeepCopy() sourceKey := registry.ResourceKey{Name: catsrc.GetName(), Namespace: catsrc.GetNamespace()} if _, ok := o.sources[sourceKey]; !ok || catsrc.Status.ConfigMapResource == nil || catsrc.Status.ConfigMapResource.UID != configMap.GetUID() || catsrc.Status.ConfigMapResource.ResourceVersion != configMap.GetResourceVersion() { // configmap ref nonexistant or updated, write out the new configmap ref to status and exit - out := catsrc.DeepCopy() out.Status.ConfigMapResource = &v1alpha1.ConfigMapResourceReference{ Name: configMap.GetName(), Namespace: configMap.GetNamespace(), @@ -346,6 +347,28 @@ func (o *Operator) syncConfigMapSource(logger *logrus.Entry, catsrc *v1alpha1.Ca return nil } + logger = logger.WithFields(logrus.Fields{"catalogSource": out.GetName(), "catalogNamespace": out.GetNamespace()}) + + // Sync any dependent Subscriptions + subs, err := o.lister.OperatorsV1alpha1().SubscriptionLister().List(labels.Everything()) + if err != nil { + logger.Warnf("could not list Subscriptions") + return nil + } + + for _, sub := range subs { + subLogger := logger.WithFields(logrus.Fields{"subscriptionCatalogSource": sub.Spec.CatalogSource, "subscriptionCatalogNamespace": sub.Spec.CatalogSourceNamespace}) + catalogNamespace := sub.Spec.CatalogSourceNamespace + if catalogNamespace == "" { + catalogNamespace = o.namespace + } + subLogger.Debug("checking subscription") + if sub.Spec.CatalogSource == out.GetName() && catalogNamespace == out.GetNamespace() { + logger.Debug("requeueing subscription") + o.requeueSubscription(sub.GetName(), sub.GetNamespace()) + } + } + return nil }