diff --git a/pkg/controller/operators/catalog/operator.go b/pkg/controller/operators/catalog/operator.go index 47075e354f2..31de3dda1b2 100644 --- a/pkg/controller/operators/catalog/operator.go +++ b/pkg/controller/operators/catalog/operator.go @@ -19,10 +19,12 @@ import ( extinf "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime/schema" utilclock "k8s.io/apimachinery/pkg/util/clock" utilruntime "k8s.io/apimachinery/pkg/util/runtime" + utilerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/client-go/dynamic" "k8s.io/client-go/informers" "k8s.io/client-go/tools/cache" @@ -388,6 +390,65 @@ func (o *Operator) syncObject(obj interface{}) (syncError error) { o.requeueOwners(metaObj) + return o.syncInstallPlanRetry(obj) +} + +func (o *Operator) syncInstallPlanRetry(obj interface{}) (syncError error) { + metaObj, ok := obj.(metav1.Object) + if !ok { + syncError = errors.New("casting to metav1 object failed") + o.logger.Warn(syncError.Error()) + return + } + + object, ok := obj.(runtime.Object) + if !ok { + syncError = errors.New("casting to runtime.Object object failed") + o.logger.Warn(syncError.Error()) + return + } + + if err := ownerutil.InferGroupVersionKind(object); err != nil { + syncError = err + return + } + + + kind := object.GetObjectKind().GroupVersionKind().Kind + switch kind { + case roleKind: + fallthrough + case roleBindingKind: + fallthrough + case serviceAccountKind: + o.logger.Infof("syncInstallPlanRetry: kind=%s", kind) + + ips, err := o.lister.OperatorsV1alpha1().InstallPlanLister().InstallPlans(metaObj.GetNamespace()).List(labels.Everything()) + if err != nil { + syncError = err + return + } + + var errs []error + for _, ip := range ips { + if ip.Status.Phase == v1alpha1.InstallPlanPhaseFailed { + out := ip.DeepCopy() + out.Status.Phase = v1alpha1.InstallPlanPhaseInstalling + _, updateErr := o.client.OperatorsV1alpha1().InstallPlans(ip.GetNamespace()).UpdateStatus(out) + + if updateErr != nil { + errs = append(errs, updateErr) + o.logger.Warnf("failed to kick off InstallPlan retry - %v", updateErr) + continue + } + + o.logger.Debugf("InstallPlan status set to Installing for retry - %s/%s", ip.GetNamespace(), ip.GetName()) + } + } + + syncError = utilerrors.NewAggregate(errs) + } + return }