Skip to content

[release-4.6] Bug 1899747: Recreate pending installplan if deleted before approval #1874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ func (o *Operator) nothingToUpdate(logger *logrus.Entry, sub *v1alpha1.Subscript
}

func (o *Operator) ensureSubscriptionInstallPlanState(logger *logrus.Entry, sub *v1alpha1.Subscription) (*v1alpha1.Subscription, bool, error) {
if sub.Status.InstallPlanRef != nil {
if sub.Status.InstallPlanRef != nil || sub.Status.Install != nil {
return sub, false, nil
}

Expand Down
57 changes: 57 additions & 0 deletions pkg/controller/operators/catalog/subscription/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,63 @@ func TestInstallPlanReconcile(t *testing.T) {
}),
},
},
{
description: "SubscriptionExistsToInstallPlanNotFound/SubscriptionStateUpgradePending/Changes",
fields: fields{
config: &fakeReconcilerConfig{
now: nowFunc,
existingObjs: existingObjs{
clientObjs: []runtime.Object{
&v1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: "sub",
Namespace: "ns",
},
Status: v1alpha1.SubscriptionStatus{
InstallPlanRef: &corev1.ObjectReference{
Namespace: "ns",
Name: "ip",
},
LastUpdated: earlier,
State: v1alpha1.SubscriptionStateUpgradePending,
},
},
},
},
},
},
args: args{
in: newSubscriptionExistsState(&v1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: "sub",
Namespace: "ns",
},
Status: v1alpha1.SubscriptionStatus{
InstallPlanRef: &corev1.ObjectReference{
Namespace: "ns",
Name: "ip",
},
LastUpdated: earlier,
Conditions: []v1alpha1.SubscriptionCondition{
planPendingCondition(corev1.ConditionTrue, string(v1alpha1.InstallPlanPhaseInstalling), "", &earlier),
},
State: v1alpha1.SubscriptionStateUpgradePending,
},
}),
},
want: want{
out: newInstallPlanMissingState(&v1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: "sub",
Namespace: "ns",
},
Status: v1alpha1.SubscriptionStatus{
LastUpdated: now,
State: v1alpha1.SubscriptionStateNone,
},
}),
},
},
{
description: "SubscriptionExistsToInstallPlanPending/Installing/Conditions/NoChanges",
fields: fields{
Expand Down
22 changes: 16 additions & 6 deletions pkg/controller/operators/catalog/subscription/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,22 @@ func (i *installPlanReferencedState) InstallPlanNotFound(now *metav1.Time, clien
// Remove pending and failed conditions
out.Status.RemoveConditions(v1alpha1.SubscriptionInstallPlanPending, v1alpha1.SubscriptionInstallPlanFailed)

// Set missing condition to true
missingCond := out.Status.GetCondition(v1alpha1.SubscriptionInstallPlanMissing)
missingCond.Status = corev1.ConditionTrue
missingCond.Reason = v1alpha1.ReferencedInstallPlanNotFound
missingCond.LastTransitionTime = now
out.Status.SetCondition(missingCond)
// If the installplan is missing when subscription is in pending upgrade,
// clear the installplan ref so the resolution can happen again
if in.Status.State == v1alpha1.SubscriptionStateUpgradePending {
out.Status.InstallPlanRef = nil
out.Status.Install = nil
out.Status.CurrentCSV = ""
out.Status.State = v1alpha1.SubscriptionStateNone
out.Status.LastUpdated = *now
} else {
// Set missing condition to true
cond := out.Status.GetCondition(v1alpha1.SubscriptionInstallPlanMissing)
cond.Status = corev1.ConditionTrue
cond.Reason = v1alpha1.ReferencedInstallPlanNotFound
cond.LastTransitionTime = now
out.Status.SetCondition(cond)
}

// Build missing state
missingState := &installPlanMissingState{
Expand Down
35 changes: 33 additions & 2 deletions test/e2e/subscription_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,39 @@ var _ = Describe("Subscription", func() {
require.Equal(GinkgoT(), v1alpha1.ApprovalManual, installPlan.Spec.Approval)
require.Equal(GinkgoT(), v1alpha1.InstallPlanPhaseRequiresApproval, installPlan.Status.Phase)

installPlan.Spec.Approved = true
_, err = crc.OperatorsV1alpha1().InstallPlans(testNamespace).Update(context.Background(), installPlan, metav1.UpdateOptions{})
// Delete the current installplan
err = crc.OperatorsV1alpha1().InstallPlans(testNamespace).Delete(context.Background(), installPlan.Name, metav1.DeleteOptions{})
require.NoError(GinkgoT(), err)

var ipName string
Eventually(func() bool {
fetched, err := crc.OperatorsV1alpha1().Subscriptions(testNamespace).Get(context.TODO(), "manual-subscription", metav1.GetOptions{})
if err != nil {
return false
}
if fetched.Status.Install != nil {
ipName = fetched.Status.Install.Name
return fetched.Status.Install.Name != installPlan.Name
}
return false
}, 5*time.Minute, 10*time.Second).Should(BeTrue())

// Fetch new installplan
newInstallPlan, err := fetchInstallPlan(GinkgoT(), crc, ipName, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseRequiresApproval))
require.NoError(GinkgoT(), err)
require.NotNil(GinkgoT(), newInstallPlan)

require.NotEqual(GinkgoT(), installPlan.Name, newInstallPlan.Name, "expected new installplan recreated")
require.Equal(GinkgoT(), v1alpha1.ApprovalManual, newInstallPlan.Spec.Approval)
require.Equal(GinkgoT(), v1alpha1.InstallPlanPhaseRequiresApproval, newInstallPlan.Status.Phase)

// Set the InstallPlan's approved to True
Eventually(Apply(newInstallPlan, func(p *v1alpha1.InstallPlan) error {
p.Spec.Approved = true
return nil
})).Should(Succeed())

_, err = crc.OperatorsV1alpha1().InstallPlans(testNamespace).Update(context.Background(), newInstallPlan, metav1.UpdateOptions{})
require.NoError(GinkgoT(), err)

subscription, err = fetchSubscription(crc, testNamespace, "manual-subscription", subscriptionStateAtLatestChecker)
Expand Down