Skip to content

Commit

Permalink
updated error message when trying to upgrade operator to a lower version
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoover103 committed Jul 26, 2024
1 parent 06b2455 commit 6962c0c
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions internal/resolve/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1alpha1.ClusterEx
var (
resolvedBundle *declcfg.Bundle
resolvedDeprecation *declcfg.Deprecation
oldBundle *declcfg.Bundle
)

if err := r.WalkCatalogsFunc(ctx, packageName, func(ctx context.Context, cat *catalogd.ClusterCatalog, packageFBC *declcfg.DeclarativeConfig, err error) error {
Expand Down Expand Up @@ -101,6 +102,7 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1alpha1.ClusterEx
return nil
}
if compare.ByVersion(*resolvedBundle, thisBundle) < 0 {
oldBundle = &thisBundle
return nil
}
}
Expand All @@ -116,15 +118,26 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1alpha1.ClusterEx
if installedBundle != nil {
errPrefix = fmt.Sprintf("error upgrading from currently installed version %q: ", installedBundle.Version)
}
switch {
case versionRange != "" && channelName != "":
return nil, nil, nil, fmt.Errorf("%sno package %q matching version %q in channel %q found", errPrefix, packageName, versionRange, channelName)
case versionRange != "":
return nil, nil, nil, fmt.Errorf("%sno package %q matching version %q found", errPrefix, packageName, versionRange)
case channelName != "":
return nil, nil, nil, fmt.Errorf("%sno package %q in channel %q found", errPrefix, packageName, channelName)
default:
return nil, nil, nil, fmt.Errorf("%sno package %q found", errPrefix, packageName)
if oldBundle == nil {
switch {
case versionRange != "" && channelName != "":
return nil, nil, nil, fmt.Errorf("%sno package %q matching version %q in channel %q found", errPrefix, packageName, versionRange, channelName)
case versionRange != "":
return nil, nil, nil, fmt.Errorf("%sno package %q matching version %q found", errPrefix, packageName, versionRange)
case channelName != "":
return nil, nil, nil, fmt.Errorf("%sno package %q in channel %q found", errPrefix, packageName, channelName)
default:
return nil, nil, nil, fmt.Errorf("%sno package %q found", errPrefix, packageName)
}
} else {
switch {
case versionRange != "" && channelName != "":
return nil, nil, nil, fmt.Errorf("%sdesired package %q with version %q in channel %q does not match any successor of %q", errPrefix, packageName, versionRange, channelName, installedBundle.Version)
case versionRange != "":
return nil, nil, nil, fmt.Errorf("%sdesired package %q with version %q does not match any successors of %q", errPrefix, packageName, versionRange, installedBundle.Version)
default:
return nil, nil, nil, fmt.Errorf("%sno package %q found", errPrefix, packageName)
}
}
}

Expand Down

0 comments on commit 6962c0c

Please sign in to comment.