Skip to content

Commit

Permalink
[v1.3.x] Bug 1921458: run bundle-upgrade should handle error gracef…
Browse files Browse the repository at this point in the history
…ully when a previous operator version doesn't exist (#4451)

* `run bundle-upgrade` command will handle error gracefully if the previous operator version doesn't exist in the cluster

Signed-off-by: rashmigottipati <chowdary.grashmi@gmail.com>
  • Loading branch information
openshift-cherrypick-robot committed Jan 29, 2021
1 parent 4bee54f commit 96970e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog/fragments/bugfix-run-bundle-upgrade.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
entries:
- description: >
`run bundle-upgrade` handles error gracefully when a previous operator version doesn't exist
kind: bugfix
6 changes: 6 additions & 0 deletions internal/olm/operator/registry/operator_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package registry

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 96970e9

Please sign in to comment.