Skip to content

Commit 928e1ba

Browse files
committed
fixup! Update error handling in reconciler
Signed-off-by: Todd Short <[email protected]>
1 parent 9f32ace commit 928e1ba

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

internal/controllers/clusterextension_controller.go

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,6 @@ import (
7878
"github.com/operator-framework/operator-controller/internal/labels"
7979
)
8080

81-
// ResolutionError type
82-
// If a more specific error type needs to be distinguished,
83-
// add another type here
84-
type ResolutionError struct {
85-
message string
86-
}
87-
88-
func (e ResolutionError) Error() string {
89-
return e.message
90-
}
91-
9281
// ClusterExtensionReconciler reconciles a ClusterExtension object
9382
type ClusterExtensionReconciler struct {
9483
client.Client
@@ -207,15 +196,11 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
207196
// run resolution
208197
bundle, err := r.resolve(ctx, *ext)
209198
if err != nil {
199+
// Note: We don't distinguish between resolution-specific errors and generic errors
210200
ext.Status.ResolvedBundle = nil
211201
ext.Status.InstalledBundle = nil
212202
setResolvedStatusConditionFailed(&ext.Status.Conditions, err.Error(), ext.GetGeneration())
213-
// TODO: indicate Progressing state based on whether error is ResolutionError or not
214-
if errors.As(err, &ResolutionError{}) {
215-
ensureAllConditionsWithReason(ext, ocv1alpha1.ReasonResolutionFailed, err.Error())
216-
} else {
217-
ensureAllConditionsWithReason(ext, ocv1alpha1.ReasonInstallationStatusUnknown, err.Error())
218-
}
203+
ensureAllConditionsWithReason(ext, ocv1alpha1.ReasonResolutionFailed, err.Error())
219204
return ctrl.Result{}, err
220205
}
221206

@@ -405,7 +390,7 @@ func (r *ClusterExtensionReconciler) resolve(ctx context.Context, ext ocv1alpha1
405390
if versionRange != "" {
406391
vr, err := mmsemver.NewConstraint(versionRange)
407392
if err != nil {
408-
return nil, ResolutionError{fmt.Sprintf("invalid version range %q: %v", versionRange, err)}
393+
return nil, fmt.Errorf("invalid version range %q: %w", versionRange, err)
409394
}
410395
predicates = append(predicates, catalogfilter.InMastermindsSemverRange(vr))
411396
}
@@ -432,13 +417,13 @@ func (r *ClusterExtensionReconciler) resolve(ctx context.Context, ext ocv1alpha1
432417
if len(resultSet) == 0 {
433418
switch {
434419
case versionRange != "" && channelName != "":
435-
return nil, ResolutionError{fmt.Sprintf("%sno package %q matching version %q in channel %q found", upgradeErrorPrefix, packageName, versionRange, channelName)}
420+
return nil, fmt.Errorf("%sno package %q matching version %q in channel %q found", upgradeErrorPrefix, packageName, versionRange, channelName)
436421
case versionRange != "":
437-
return nil, ResolutionError{fmt.Sprintf("%sno package %q matching version %q found", upgradeErrorPrefix, packageName, versionRange)}
422+
return nil, fmt.Errorf("%sno package %q matching version %q found", upgradeErrorPrefix, packageName, versionRange)
438423
case channelName != "":
439-
return nil, ResolutionError{fmt.Sprintf("%sno package %q in channel %q found", upgradeErrorPrefix, packageName, channelName)}
424+
return nil, fmt.Errorf("%sno package %q in channel %q found", upgradeErrorPrefix, packageName, channelName)
440425
default:
441-
return nil, ResolutionError{fmt.Sprintf("%sno package %q found", upgradeErrorPrefix, packageName)}
426+
return nil, fmt.Errorf("%sno package %q found", upgradeErrorPrefix, packageName)
442427
}
443428
}
444429

0 commit comments

Comments
 (0)