Skip to content

Commit

Permalink
Improve InstallPlan error handling (#3404)
Browse files Browse the repository at this point in the history
With this change we no set condition on subscriptions
about errors during InstallPlan creation.

Previously we were only logging these errors.

Signed-off-by: Mikalai Radchuk <[email protected]>
  • Loading branch information
m1kola authored Sep 29, 2024
1 parent 3030064 commit 75d70e6
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,20 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {

installPlanReference, err := o.ensureInstallPlan(logger, namespace, maxGeneration+1, subs, installPlanApproval, steps, bundleLookups)
if err != nil {
logger.WithError(err).Debug("error ensuring installplan")
err := fmt.Errorf("error ensuring InstallPlan: %s", err)
logger.Infof("%v", err)

_, updateErr := o.updateSubscriptionStatuses(
o.setSubsCond(subs, v1alpha1.SubscriptionCondition{
Type: v1alpha1.SubscriptionBundleUnpackFailed,
Reason: "EnsureInstallPlanFailed",
Message: err.Error(),
Status: corev1.ConditionTrue,
}))
if updateErr != nil {
logger.WithError(updateErr).Debug("failed to update subs conditions")
return updateErr
}
return err
}
updatedSubs = o.setIPReference(updatedSubs, maxGeneration+1, installPlanReference)
Expand Down
112 changes: 112 additions & 0 deletions pkg/controller/operators/catalog/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
clitesting "k8s.io/client-go/testing"
utilclocktesting "k8s.io/utils/clock/testing"

operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
Expand Down Expand Up @@ -570,6 +571,117 @@ func TestSyncSubscriptions(t *testing.T) {
},
},
},
{
name: "NoStatus/NoCurrentCSV/EnsureInstallPlanFailed",
fields: fields{
clientOptions: []clientfake.Option{
clientfake.WithSelfLinks(t),
func(c clientfake.ClientsetDecorator) {
c.PrependReactor("create", "installplans", func(a clitesting.Action) (bool, runtime.Object, error) {
return true, nil, errors.New("fake install plan create error")
})
},
},
existingOLMObjs: []runtime.Object{
&v1alpha1.Subscription{
TypeMeta: metav1.TypeMeta{
Kind: v1alpha1.SubscriptionKind,
APIVersion: v1alpha1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "sub",
Namespace: testNamespace,
},
Spec: &v1alpha1.SubscriptionSpec{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
},
Status: v1alpha1.SubscriptionStatus{
CurrentCSV: "",
State: "",
},
},
},
resolveSteps: []*v1alpha1.Step{
{
Resolving: "csv.v.2",
Resource: v1alpha1.StepResource{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.2",
Manifest: "{}",
},
},
},
resolveSubs: []*v1alpha1.Subscription{
{
TypeMeta: metav1.TypeMeta{
Kind: v1alpha1.SubscriptionKind,
APIVersion: v1alpha1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "sub",
Namespace: testNamespace,
},
Spec: &v1alpha1.SubscriptionSpec{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
},
},
},
},
args: args{
obj: &v1alpha1.Subscription{
TypeMeta: metav1.TypeMeta{
Kind: v1alpha1.SubscriptionKind,
APIVersion: v1alpha1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "sub",
Namespace: testNamespace,
},
Spec: &v1alpha1.SubscriptionSpec{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
},
Status: v1alpha1.SubscriptionStatus{
CurrentCSV: "",
State: "",
},
},
},
wantSubscriptions: []*v1alpha1.Subscription{
{
TypeMeta: metav1.TypeMeta{
Kind: v1alpha1.SubscriptionKind,
APIVersion: v1alpha1.SubscriptionCRDAPIVersion,
},
ObjectMeta: metav1.ObjectMeta{
Name: "sub",
Namespace: testNamespace,
},
Spec: &v1alpha1.SubscriptionSpec{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
},
Status: v1alpha1.SubscriptionStatus{
LastUpdated: now,
Conditions: []v1alpha1.SubscriptionCondition{
{
Type: v1alpha1.SubscriptionBundleUnpackFailed,
Reason: "EnsureInstallPlanFailed",
Message: "error ensuring InstallPlan: fake install plan create error",
Status: corev1.ConditionTrue,
},
},
},
},
},
wantErr: errors.New("error ensuring InstallPlan: fake install plan create error"),
},
{
name: "NoStatus/NoCurrentCSV/BundleLookupError",
fields: fields{
Expand Down

0 comments on commit 75d70e6

Please sign in to comment.