From 4dbfa6bd17821b6f022a30d18bbf0c9cac3cd1b8 Mon Sep 17 00:00:00 2001 From: rashmigottipati Date: Thu, 28 Jan 2021 16:12:54 -0500 Subject: [PATCH 1/2] Gracefully handle `run bundle-upgrade` if the previous version operator doesn't exist in the cluster Signed-off-by: rashmigottipati --- internal/olm/operator/registry/operator_installer.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/olm/operator/registry/operator_installer.go b/internal/olm/operator/registry/operator_installer.go index 14c5c32fce..20081de18a 100644 --- a/internal/olm/operator/registry/operator_installer.go +++ b/internal/olm/operator/registry/operator_installer.go @@ -16,6 +16,7 @@ package registry import ( "context" + "errors" "fmt" "time" @@ -108,6 +109,11 @@ func (o OperatorInstaller) UpgradeOperator(ctx context.Context) (*v1alpha1.Clust return nil, fmt.Errorf("error getting list of subscriptions: %v", err) } + // If there are no subscriptions found, then the previous operator version doesn't exist, so return error + if len(subList.Items) == 0 { + return nil, errors.New("no existing operator found in the cluster to upgrade") + } + var subscription *v1alpha1.Subscription for i := range subList.Items { s := subList.Items[i] From b4a47782b74e0854615f2370fb50614e7aad953a Mon Sep 17 00:00:00 2001 From: rashmigottipati Date: Thu, 28 Jan 2021 17:14:26 -0500 Subject: [PATCH 2/2] Add changelog fragment Signed-off-by: rashmigottipati --- changelog/fragments/bugfix-run-bundle-upgrade.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/fragments/bugfix-run-bundle-upgrade.yaml diff --git a/changelog/fragments/bugfix-run-bundle-upgrade.yaml b/changelog/fragments/bugfix-run-bundle-upgrade.yaml new file mode 100644 index 0000000000..af0a6ccf6e --- /dev/null +++ b/changelog/fragments/bugfix-run-bundle-upgrade.yaml @@ -0,0 +1,4 @@ +entries: + - description: > + `run bundle-upgrade` handles error gracefully when a previous operator version doesn't exist + kind: bugfix