@@ -831,6 +831,12 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
831
831
return err
832
832
}
833
833
834
+ ips , err := o .listInstallPlansMap (namespace )
835
+ if err != nil {
836
+ logger .WithError (err ).Debug ("couldn't list installplan" )
837
+ return err
838
+ }
839
+
834
840
// TODO: parallel
835
841
maxGeneration := 0
836
842
subscriptionUpdated := false
@@ -847,7 +853,7 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
847
853
}
848
854
849
855
// ensure the installplan reference is correct
850
- sub , changedIP , err := o .ensureSubscriptionInstallPlanState (logger , sub )
856
+ sub , changedIP , err := o .ensureSubscriptionInstallPlanState (logger , sub , ips )
851
857
if err != nil {
852
858
logger .Debugf ("error ensuring installplan state: %v" , err )
853
859
return err
@@ -952,9 +958,29 @@ func (o *Operator) nothingToUpdate(logger *logrus.Entry, sub *v1alpha1.Subscript
952
958
return false
953
959
}
954
960
955
- func (o * Operator ) ensureSubscriptionInstallPlanState (logger * logrus.Entry , sub * v1alpha1.Subscription ) (* v1alpha1.Subscription , bool , error ) {
956
- if sub .Status .InstallPlanRef != nil {
957
- return sub , false , nil
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 ) {
982
+ if sub .Status .InstallPlanRef != nil || sub .Status .Install != nil {
983
+ return o .checkMissingInstallPlan (sub , ips )
958
984
}
959
985
960
986
logger .Debug ("checking for existing installplan" )
@@ -2020,6 +2046,20 @@ func (o *Operator) listInstallPlans(namespace string) (ips []*v1alpha1.InstallPl
2020
2046
return
2021
2047
}
2022
2048
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
+
2023
2063
// 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)
2024
2064
func competingCRDOwnersExist (namespace string , csv * v1alpha1.ClusterServiceVersion , existingOwners map [string ][]string ) (bool , error ) {
2025
2065
// Attempt to find a pre-existing owner in the namespace for any owned crd
0 commit comments