Skip to content

Commit f8b564e

Browse files
dinhxuanvuopenshift-cherrypick-robot
authored andcommitted
Using subscription reconciliation to clean installplan status instead
Signed-off-by: Vu Dinh <[email protected]>
1 parent af8de51 commit f8b564e

File tree

4 files changed

+82
-50
lines changed

4 files changed

+82
-50
lines changed

pkg/controller/operators/catalog/operator.go

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -831,12 +831,6 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
831831
return err
832832
}
833833

834-
ips, err := o.listInstallPlansMap(namespace)
835-
if err != nil {
836-
logger.WithError(err).Debug("couldn't list installplan")
837-
return err
838-
}
839-
840834
// TODO: parallel
841835
maxGeneration := 0
842836
subscriptionUpdated := false
@@ -853,7 +847,7 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
853847
}
854848

855849
// ensure the installplan reference is correct
856-
sub, changedIP, err := o.ensureSubscriptionInstallPlanState(logger, sub, ips)
850+
sub, changedIP, err := o.ensureSubscriptionInstallPlanState(logger, sub)
857851
if err != nil {
858852
logger.Debugf("error ensuring installplan state: %v", err)
859853
return err
@@ -958,29 +952,9 @@ func (o *Operator) nothingToUpdate(logger *logrus.Entry, sub *v1alpha1.Subscript
958952
return false
959953
}
960954

961-
// checkMissingInstallPlan checks if the installplan is missing or not when
962-
// the subscription is in pending upgrade state
963-
func (o *Operator) checkMissingInstallPlan(sub *v1alpha1.Subscription, ips map[string]struct{}) (*v1alpha1.Subscription, bool, error) {
964-
_, ok := ips[sub.Status.InstallPlanRef.Name]
965-
if !ok && sub.Status.State == v1alpha1.SubscriptionStateUpgradePending {
966-
out := sub.DeepCopy()
967-
out.Status.InstallPlanRef = nil
968-
out.Status.Install = nil
969-
out.Status.CurrentCSV = ""
970-
out.Status.State = v1alpha1.SubscriptionStateNone
971-
out.Status.LastUpdated = o.now()
972-
updated, err := o.client.OperatorsV1alpha1().Subscriptions(sub.GetNamespace()).UpdateStatus(context.TODO(), out, metav1.UpdateOptions{})
973-
if err != nil {
974-
return out, false, nil
975-
}
976-
return updated, true, nil
977-
}
978-
return sub, false, nil
979-
}
980-
981-
func (o *Operator) ensureSubscriptionInstallPlanState(logger *logrus.Entry, sub *v1alpha1.Subscription, ips map[string]struct{}) (*v1alpha1.Subscription, bool, error) {
955+
func (o *Operator) ensureSubscriptionInstallPlanState(logger *logrus.Entry, sub *v1alpha1.Subscription) (*v1alpha1.Subscription, bool, error) {
982956
if sub.Status.InstallPlanRef != nil || sub.Status.Install != nil {
983-
return o.checkMissingInstallPlan(sub, ips)
957+
return sub, false, nil
984958
}
985959

986960
logger.Debug("checking for existing installplan")
@@ -2046,20 +2020,6 @@ func (o *Operator) listInstallPlans(namespace string) (ips []*v1alpha1.InstallPl
20462020
return
20472021
}
20482022

2049-
func (o *Operator) listInstallPlansMap(namespace string) (ips map[string]struct{}, err error) {
2050-
list, err := o.client.OperatorsV1alpha1().InstallPlans(namespace).List(context.TODO(), metav1.ListOptions{})
2051-
if err != nil {
2052-
return
2053-
}
2054-
2055-
ips = make(map[string]struct{})
2056-
for i := range list.Items {
2057-
ips[list.Items[i].GetName()] = struct{}{}
2058-
}
2059-
2060-
return
2061-
}
2062-
20632023
// competingCRDOwnersExist returns true if there exists a CSV that owns at least one of the given CSVs owned CRDs (that's not the given CSV)
20642024
func competingCRDOwnersExist(namespace string, csv *v1alpha1.ClusterServiceVersion, existingOwners map[string][]string) (bool, error) {
20652025
// Attempt to find a pre-existing owner in the namespace for any owned crd

pkg/controller/operators/catalog/subscription/reconciler_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,63 @@ func TestInstallPlanReconcile(t *testing.T) {
11711171
}),
11721172
},
11731173
},
1174+
{
1175+
description: "SubscriptionExistsToInstallPlanNotFound/SubscriptionStateUpgradePending/Changes",
1176+
fields: fields{
1177+
config: &fakeReconcilerConfig{
1178+
now: nowFunc,
1179+
existingObjs: existingObjs{
1180+
clientObjs: []runtime.Object{
1181+
&v1alpha1.Subscription{
1182+
ObjectMeta: metav1.ObjectMeta{
1183+
Name: "sub",
1184+
Namespace: "ns",
1185+
},
1186+
Status: v1alpha1.SubscriptionStatus{
1187+
InstallPlanRef: &corev1.ObjectReference{
1188+
Namespace: "ns",
1189+
Name: "ip",
1190+
},
1191+
LastUpdated: earlier,
1192+
State: v1alpha1.SubscriptionStateUpgradePending,
1193+
},
1194+
},
1195+
},
1196+
},
1197+
},
1198+
},
1199+
args: args{
1200+
in: newSubscriptionExistsState(&v1alpha1.Subscription{
1201+
ObjectMeta: metav1.ObjectMeta{
1202+
Name: "sub",
1203+
Namespace: "ns",
1204+
},
1205+
Status: v1alpha1.SubscriptionStatus{
1206+
InstallPlanRef: &corev1.ObjectReference{
1207+
Namespace: "ns",
1208+
Name: "ip",
1209+
},
1210+
LastUpdated: earlier,
1211+
Conditions: []v1alpha1.SubscriptionCondition{
1212+
planPendingCondition(corev1.ConditionTrue, string(v1alpha1.InstallPlanPhaseInstalling), "", &earlier),
1213+
},
1214+
State: v1alpha1.SubscriptionStateUpgradePending,
1215+
},
1216+
}),
1217+
},
1218+
want: want{
1219+
out: newInstallPlanMissingState(&v1alpha1.Subscription{
1220+
ObjectMeta: metav1.ObjectMeta{
1221+
Name: "sub",
1222+
Namespace: "ns",
1223+
},
1224+
Status: v1alpha1.SubscriptionStatus{
1225+
LastUpdated: now,
1226+
State: v1alpha1.SubscriptionStateNone,
1227+
},
1228+
}),
1229+
},
1230+
},
11741231
{
11751232
description: "SubscriptionExistsToInstallPlanPending/Installing/Conditions/NoChanges",
11761233
fields: fields{

pkg/controller/operators/catalog/subscription/state.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,22 @@ func (i *installPlanReferencedState) InstallPlanNotFound(now *metav1.Time, clien
385385
// Remove pending and failed conditions
386386
out.Status.RemoveConditions(v1alpha1.SubscriptionInstallPlanPending, v1alpha1.SubscriptionInstallPlanFailed)
387387

388-
// Set missing condition to true
389-
missingCond := out.Status.GetCondition(v1alpha1.SubscriptionInstallPlanMissing)
390-
missingCond.Status = corev1.ConditionTrue
391-
missingCond.Reason = v1alpha1.ReferencedInstallPlanNotFound
392-
missingCond.LastTransitionTime = now
393-
out.Status.SetCondition(missingCond)
388+
// If the installplan is missing when subscription is in pending upgrade,
389+
// clear the installplan ref so the resolution can happen again
390+
if in.Status.State == v1alpha1.SubscriptionStateUpgradePending {
391+
out.Status.InstallPlanRef = nil
392+
out.Status.Install = nil
393+
out.Status.CurrentCSV = ""
394+
out.Status.State = v1alpha1.SubscriptionStateNone
395+
out.Status.LastUpdated = *now
396+
} else {
397+
// Set missing condition to true
398+
cond := out.Status.GetCondition(v1alpha1.SubscriptionInstallPlanMissing)
399+
cond.Status = corev1.ConditionTrue
400+
cond.Reason = v1alpha1.ReferencedInstallPlanNotFound
401+
cond.LastTransitionTime = now
402+
out.Status.SetCondition(cond)
403+
}
394404

395405
// Build missing state
396406
missingState := &installPlanMissingState{

test/e2e/subscription_e2e_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,12 @@ var _ = Describe("Subscription", func() {
243243
require.Equal(GinkgoT(), v1alpha1.ApprovalManual, newInstallPlan.Spec.Approval)
244244
require.Equal(GinkgoT(), v1alpha1.InstallPlanPhaseRequiresApproval, newInstallPlan.Status.Phase)
245245

246-
newInstallPlan.Spec.Approved = true
246+
// Set the InstallPlan's approved to True
247+
Eventually(Apply(newInstallPlan, func(p *v1alpha1.InstallPlan) error {
248+
p.Spec.Approved = true
249+
return nil
250+
})).Should(Succeed())
251+
247252
_, err = crc.OperatorsV1alpha1().InstallPlans(testNamespace).Update(context.Background(), newInstallPlan, metav1.UpdateOptions{})
248253
require.NoError(GinkgoT(), err)
249254

0 commit comments

Comments
 (0)