@@ -99,11 +99,8 @@ func (r *OperatorStepResolver) ResolveSteps(namespace string, _ SourceQuerier) (
99
99
updatedSubs := []* v1alpha1.Subscription {}
100
100
bundleLookups := []v1alpha1.BundleLookup {}
101
101
for name , op := range operators {
102
- // Find an existing subscription that resolves to this operator.
103
- var (
104
- existingSubscription * v1alpha1.Subscription
105
- alreadyExists bool
106
- )
102
+ // Find any existing subscriptions that resolve to this operator.
103
+ existingSubscriptions := make (map [* v1alpha1.Subscription ]bool )
107
104
sourceInfo := * op .SourceInfo ()
108
105
for _ , sub := range subs {
109
106
if sub .Spec .Package != sourceInfo .Package {
@@ -119,17 +116,24 @@ func (r *OperatorStepResolver) ResolveSteps(namespace string, _ SourceQuerier) (
119
116
if ! subCatalogKey .Empty () && ! subCatalogKey .Equal (sourceInfo .Catalog ) {
120
117
continue
121
118
}
122
- alreadyExists , err = r .hasExistingCurrentCSV (sub )
119
+ alreadyExists , err : = r .hasExistingCurrentCSV (sub )
123
120
if err != nil {
124
- return nil , nil , nil , fmt .Errorf ("unable to determine whether subscription has a preexisting CSV" )
121
+ return nil , nil , nil , fmt .Errorf ("unable to determine whether subscription %s has a preexisting CSV" , sub . GetName () )
125
122
}
126
- existingSubscription = sub
127
- break
123
+ existingSubscriptions [sub ] = alreadyExists
128
124
}
129
125
130
- // subscription exists and is up to date
131
- if existingSubscription != nil && existingSubscription .Status .CurrentCSV == op .Identifier () && alreadyExists {
132
- continue
126
+ if len (existingSubscriptions ) > 0 {
127
+ upToDate := true
128
+ for sub , exists := range existingSubscriptions {
129
+ if ! exists || sub .Status .CurrentCSV != op .Identifier () {
130
+ upToDate = false
131
+ }
132
+ }
133
+ // all matching subscriptions are up to date
134
+ if upToDate {
135
+ continue
136
+ }
133
137
}
134
138
135
139
// add steps for any new bundle
@@ -172,7 +176,7 @@ func (r *OperatorStepResolver) ResolveSteps(namespace string, _ SourceQuerier) (
172
176
bundleLookups = append (bundleLookups , lookup )
173
177
}
174
178
175
- if existingSubscription == nil {
179
+ if len ( existingSubscriptions ) == 0 {
176
180
// explicitly track the resolved CSV as the starting CSV on the resolved subscriptions
177
181
op .SourceInfo ().StartingCSV = op .Identifier ()
178
182
subStep , err := NewSubscriptionStepResource (namespace , * op .SourceInfo ())
@@ -188,10 +192,13 @@ func (r *OperatorStepResolver) ResolveSteps(namespace string, _ SourceQuerier) (
188
192
}
189
193
190
194
// add steps for subscriptions for bundles that were added through resolution
191
- if existingSubscription != nil && existingSubscription .Status .CurrentCSV != op .Identifier () {
195
+ for sub := range existingSubscriptions {
196
+ if sub .Status .CurrentCSV == op .Identifier () {
197
+ continue
198
+ }
192
199
// update existing subscription status
193
- existingSubscription .Status .CurrentCSV = op .Identifier ()
194
- updatedSubs = append (updatedSubs , existingSubscription )
200
+ sub .Status .CurrentCSV = op .Identifier ()
201
+ updatedSubs = append (updatedSubs , sub )
195
202
}
196
203
}
197
204
0 commit comments