@@ -91,22 +91,22 @@ func parsePackageManifestsFromConfigMap(cm *corev1.ConfigMap, catsrc *operatorsv
91
91
logger .Debug ("ConfigMap contains CSVs" )
92
92
csvListJSON , err := yaml .YAMLToJSON ([]byte (csvListYaml ))
93
93
if err != nil {
94
- logrus .Debugf ("Load ConfigMap -- ERROR %s : error=%s" , cmName , err )
94
+ logger .Debugf ("Load ConfigMap -- ERROR %s : error=%s" , cmName , err )
95
95
return nil , fmt .Errorf ("error loading CSV list yaml from ConfigMap %s: %s" , cmName , err )
96
96
}
97
97
98
98
var parsedCSVList []operatorsv1alpha1.ClusterServiceVersion
99
99
err = json .Unmarshal ([]byte (csvListJSON ), & parsedCSVList )
100
100
if err != nil {
101
- logrus .Debugf ("Load ConfigMap -- ERROR %s : error=%s" , cmName , err )
101
+ logger .Debugf ("Load ConfigMap -- ERROR %s : error=%s" , cmName , err )
102
102
return nil , fmt .Errorf ("error parsing CSV list (json) from ConfigMap %s: %s" , cmName , err )
103
103
}
104
104
105
105
for _ , csv := range parsedCSVList {
106
106
found = true
107
107
108
108
// TODO: add check for invalid CSV definitions
109
- logrus .Debugf ("found csv %s" , csv .GetName ())
109
+ logger .Debugf ("found csv %s" , csv .GetName ())
110
110
csvs [csv .GetName ()] = csv
111
111
}
112
112
}
@@ -175,7 +175,7 @@ func parsePackageManifestsFromConfigMap(cm *corev1.ConfigMap, catsrc *operatorsv
175
175
manifest .ObjectMeta .Labels [k ] = v
176
176
}
177
177
178
- logrus .Debugf ("retrieved packagemanifest %s" , manifest .GetName ())
178
+ logger .Debugf ("retrieved packagemanifest %s" , manifest .GetName ())
179
179
manifests = append (manifests , manifest )
180
180
}
181
181
}
@@ -196,6 +196,12 @@ func (m *InMemoryProvider) syncCatalogSource(obj interface{}) error {
196
196
return fmt .Errorf ("casting catalog source failed" )
197
197
}
198
198
199
+ logger := logrus .WithFields (logrus.Fields {
200
+ "Action" : "Sync CatalogSource" ,
201
+ "name" : catsrc .GetName (),
202
+ "namespace" : catsrc .GetNamespace (),
203
+ })
204
+
199
205
var manifests []packagev1alpha1.PackageManifest
200
206
201
207
// handle by sourceType
@@ -217,7 +223,7 @@ func (m *InMemoryProvider) syncCatalogSource(obj interface{}) error {
217
223
return fmt .Errorf ("catalog source %s in namespace %s source type %s not recognized" , catsrc .GetName (), catsrc .GetNamespace (), catsrc .Spec .SourceType )
218
224
}
219
225
220
- // update manifests
226
+ logger . Debug ( "updating in-memory PackageManifests" )
221
227
m .mu .Lock ()
222
228
defer m .mu .Unlock ()
223
229
for _ , manifest := range manifests {
@@ -228,18 +234,18 @@ func (m *InMemoryProvider) syncCatalogSource(obj interface{}) error {
228
234
}
229
235
230
236
if pm , ok := m .manifests [key ]; ok {
231
- // use existing CreationTimestamp
237
+ logger . Debugf ( "package %s already exists" , key . packageName )
232
238
manifest .CreationTimestamp = pm .ObjectMeta .CreationTimestamp
233
239
} else {
234
- // set CreationTimestamp if first time seeing the PackageManifest
240
+ logger . Debugf ( "new package %s found" , key . packageName )
235
241
manifest .CreationTimestamp = metav1 .NewTime (time .Now ())
236
242
for _ , add := range m .add {
237
243
if add .namespace == manifest .Status .CatalogSourceNamespace || add .namespace == metav1 .NamespaceAll || manifest .Status .CatalogSourceNamespace == m .globalNamespace {
244
+ logger .Debugf ("sending new package %s to watcher for namespace %s" , key .packageName , add .namespace )
238
245
add .ch <- manifest
239
246
}
240
247
}
241
248
}
242
-
243
249
m .manifests [key ] = manifest
244
250
}
245
251
@@ -276,45 +282,48 @@ func (m *InMemoryProvider) List(namespace string) (*packagev1alpha1.PackageManif
276
282
matching = append (matching , pm )
277
283
}
278
284
}
279
-
280
285
manifestList .Items = matching
281
286
}
282
-
283
287
return manifestList , nil
284
288
}
285
289
286
290
func (m * InMemoryProvider ) Subscribe (namespace string , stopCh <- chan struct {}) (PackageChan , PackageChan , PackageChan , error ) {
291
+ logger := logrus .WithFields (logrus.Fields {
292
+ "Action" : "PackageManifest Subscribe" ,
293
+ "namespace" : namespace ,
294
+ })
295
+
287
296
m .mu .Lock ()
288
297
defer m .mu .Unlock ()
289
298
290
- add := eventChan {namespace , make (chan packagev1alpha1.PackageManifest )}
291
- modify := eventChan {namespace , make (chan packagev1alpha1.PackageManifest )}
292
- delete := eventChan {namespace , make (chan packagev1alpha1.PackageManifest )}
293
- addIndex := len (m .add )
294
- modifyIndex := len (m .modify )
295
- deleteIndex := len (m .delete )
296
- m .add = append (m .add , add )
297
- m .modify = append (m .modify , modify )
298
- m .delete = append (m .delete , delete )
299
+ addEvent := eventChan {namespace , make (chan packagev1alpha1.PackageManifest )}
300
+ modifyEvent := eventChan {namespace , make (chan packagev1alpha1.PackageManifest )}
301
+ deleteEvent := eventChan {namespace , make (chan packagev1alpha1.PackageManifest )}
302
+ m .add = append (m .add , addEvent )
303
+ m .modify = append (m .modify , modifyEvent )
304
+ m .delete = append (m .delete , deleteEvent )
305
+
306
+ removeChan := func (target chan packagev1alpha1.PackageManifest , all []eventChan ) []eventChan {
307
+ for i , event := range all {
308
+ if event .ch == target {
309
+ logger .Debugf ("closing channel" )
310
+ close (event .ch )
311
+ return append (all [:i ], all [i + 1 :]... )
312
+ }
313
+ }
314
+ return all
315
+ }
299
316
300
317
go func () {
301
318
<- stopCh
302
319
m .mu .Lock ()
303
320
defer m .mu .Unlock ()
304
- for _ , add := range m .add {
305
- m .add = append (m .add [:addIndex ], m .add [:addIndex + 1 ]... )
306
- close (add .ch )
307
- }
308
- for _ , modify := range m .modify {
309
- m .modify = append (m .modify [:modifyIndex ], m .modify [:modifyIndex + 1 ]... )
310
- close (modify .ch )
311
- }
312
- for _ , delete := range m .delete {
313
- m .delete = append (m .delete [:deleteIndex ], m .delete [:deleteIndex + 1 ]... )
314
- close (delete .ch )
315
- }
321
+
322
+ m .add = removeChan (addEvent .ch , m .add )
323
+ m .modify = removeChan (modifyEvent .ch , m .modify )
324
+ m .delete = removeChan (deleteEvent .ch , m .delete )
316
325
return
317
326
}()
318
327
319
- return add .ch , modify .ch , delete .ch , nil
328
+ return addEvent .ch , modifyEvent .ch , deleteEvent .ch , nil
320
329
}
0 commit comments