Skip to content

Commit 8a842df

Browse files
committed
Using subscription reconciliation to clean installplan status instead
Signed-off-by: Vu Dinh <[email protected]>
1 parent 0d812b3 commit 8a842df

File tree

2 files changed

+23
-53
lines changed

2 files changed

+23
-53
lines changed

pkg/controller/operators/catalog/operator.go

+3-43
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/state.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -385,23 +385,33 @@ 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
396-
missingState := &installPlanMissingState{
406+
state := &installPlanMissingState{
397407
InstallPlanKnownState: &installPlanKnownState{
398408
InstallPlanReferencedState: i,
399409
},
400410
}
401411

402412
// Bail out if the conditions haven't changed (using select fields included in a hash)
403413
if hashEqual(out.Status.Conditions, in.Status.Conditions) {
404-
return missingState, nil
414+
return state, nil
405415
}
406416

407417
// Update the Subscription
@@ -412,9 +422,9 @@ func (i *installPlanReferencedState) InstallPlanNotFound(now *metav1.Time, clien
412422
}
413423

414424
// Stuff updated Subscription into state
415-
missingState.setSubscription(updated)
425+
state.setSubscription(updated)
416426

417-
return missingState, nil
427+
return state, nil
418428
}
419429

420430
func (i *installPlanReferencedState) CheckInstallPlanStatus(now *metav1.Time, client clientv1alpha1.SubscriptionInterface, status *v1alpha1.InstallPlanStatus) (InstallPlanReferencedState, error) {

0 commit comments

Comments
 (0)