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 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]