@@ -128,6 +128,8 @@ func (c *Cluster) syncPublication(dbName string, databaseSlotsList map[string]za
128
128
createPublications [slotName ] = tableList
129
129
} else if currentTables != tableList {
130
130
alterPublications [slotName ] = tableList
131
+ } else {
132
+ (* slotsToSync )[slotName ] = slotAndPublication .Slot
131
133
}
132
134
}
133
135
@@ -142,30 +144,34 @@ func (c *Cluster) syncPublication(dbName string, databaseSlotsList map[string]za
142
144
return nil
143
145
}
144
146
145
- var errorMessage error = nil
147
+ errors := make ([] string , 0 )
146
148
for publicationName , tables := range createPublications {
147
149
if err = c .executeCreatePublication (publicationName , tables ); err != nil {
148
- errorMessage = fmt .Errorf ("creation of publication %q failed: %v" , publicationName , err )
150
+ errors = append ( errors , fmt .Sprintf ("creation of publication %q failed: %v" , publicationName , err ) )
149
151
continue
150
152
}
151
153
(* slotsToSync )[publicationName ] = databaseSlotsList [publicationName ].Slot
152
154
}
153
155
for publicationName , tables := range alterPublications {
154
156
if err = c .executeAlterPublication (publicationName , tables ); err != nil {
155
- errorMessage = fmt .Errorf ("update of publication %q failed: %v" , publicationName , err )
157
+ errors = append ( errors , fmt .Sprintf ("update of publication %q failed: %v" , publicationName , err ) )
156
158
continue
157
159
}
158
160
(* slotsToSync )[publicationName ] = databaseSlotsList [publicationName ].Slot
159
161
}
160
162
for _ , publicationName := range deletePublications {
161
163
if err = c .executeDropPublication (publicationName ); err != nil {
162
- errorMessage = fmt .Errorf ("deletion of publication %q failed: %v" , publicationName , err )
164
+ errors = append ( errors , fmt .Sprintf ("deletion of publication %q failed: %v" , publicationName , err ) )
163
165
continue
164
166
}
165
167
(* slotsToSync )[publicationName ] = nil
166
168
}
167
169
168
- return errorMessage
170
+ if len (errors ) > 0 {
171
+ return fmt .Errorf ("%v" , strings .Join (errors , `', '` ))
172
+ }
173
+
174
+ return nil
169
175
}
170
176
171
177
func (c * Cluster ) generateFabricEventStream (appId string ) * zalandov1.FabricEventStream {
@@ -370,7 +376,7 @@ func (c *Cluster) syncStreams() error {
370
376
for dbName , databaseSlotsList := range databaseSlots {
371
377
err := c .syncPublication (dbName , databaseSlotsList , & slotsToSync )
372
378
if err != nil {
373
- c .logger .Warningf ("could not sync publications in database %q: %v" , dbName , err )
379
+ c .logger .Warningf ("could not sync all publications in database %q: %v" , dbName , err )
374
380
continue
375
381
}
376
382
}
@@ -398,7 +404,7 @@ func (c *Cluster) syncStreams() error {
398
404
c .logger .Warningf ("could not sync event streams with applicationId %s: %v" , appId , err )
399
405
}
400
406
} else {
401
- c .logger .Warningf ("database replication slots for streams with applicationId %s not in sync, skipping event stream sync" , appId )
407
+ c .logger .Warningf ("database replication slots %#v for streams with applicationId %s not in sync, skipping event stream sync" , slotsToSync , appId )
402
408
}
403
409
}
404
410
@@ -415,8 +421,9 @@ func hasSlotsInSync(appId string, databaseSlots map[string]map[string]zalandov1.
415
421
for dbName , slots := range databaseSlots {
416
422
for slotName := range slots {
417
423
if slotName == getSlotName (dbName , appId ) {
418
- if _ , exists := slotsToSync [slotName ]; ! exists {
424
+ if slot , exists := slotsToSync [slotName ]; ! exists || slot == nil {
419
425
allSlotsInSync = false
426
+ continue
420
427
}
421
428
}
422
429
}
@@ -432,7 +439,17 @@ func (c *Cluster) syncStream(appId string) error {
432
439
if appId == stream .Spec .ApplicationId {
433
440
streamExists = true
434
441
desiredStreams := c .generateFabricEventStream (appId )
435
- if match , reason := sameStreams (stream .Spec .EventStreams , desiredStreams .Spec .EventStreams ); ! match {
442
+ if ! reflect .DeepEqual (stream .ObjectMeta .OwnerReferences , desiredStreams .ObjectMeta .OwnerReferences ) {
443
+ c .logger .Infof ("owner references of event streams with applicationId %s do not match the current ones" , appId )
444
+ stream .ObjectMeta .OwnerReferences = desiredStreams .ObjectMeta .OwnerReferences
445
+ c .setProcessName ("updating event streams with applicationId %s" , appId )
446
+ stream , err := c .KubeClient .FabricEventStreams (stream .Namespace ).Update (context .TODO (), stream , metav1.UpdateOptions {})
447
+ if err != nil {
448
+ return fmt .Errorf ("could not update event streams with applicationId %s: %v" , appId , err )
449
+ }
450
+ c .Streams [appId ] = stream
451
+ }
452
+ if match , reason := c .compareStreams (stream , desiredStreams ); ! match {
436
453
c .logger .Debugf ("updating event streams with applicationId %s: %s" , appId , reason )
437
454
desiredStreams .ObjectMeta = stream .ObjectMeta
438
455
updatedStream , err := c .updateStreams (desiredStreams )
@@ -459,7 +476,26 @@ func (c *Cluster) syncStream(appId string) error {
459
476
return nil
460
477
}
461
478
462
- func sameStreams (curEventStreams , newEventStreams []zalandov1.EventStream ) (match bool , reason string ) {
479
+ func (c * Cluster ) compareStreams (curEventStreams , newEventStreams * zalandov1.FabricEventStream ) (match bool , reason string ) {
480
+ reasons := make ([]string , 0 )
481
+ match = true
482
+
483
+ // stream operator can add extra annotations so incl. current annotations in desired annotations
484
+ desiredAnnotations := c .annotationsSet (curEventStreams .Annotations )
485
+ if changed , reason := c .compareAnnotations (curEventStreams .ObjectMeta .Annotations , desiredAnnotations ); changed {
486
+ match = false
487
+ reasons = append (reasons , fmt .Sprintf ("new streams annotations do not match: %s" , reason ))
488
+ }
489
+
490
+ if changed , reason := sameEventStreams (curEventStreams .Spec .EventStreams , newEventStreams .Spec .EventStreams ); ! changed {
491
+ match = false
492
+ reasons = append (reasons , fmt .Sprintf ("new streams EventStreams array does not match : %s" , reason ))
493
+ }
494
+
495
+ return match , strings .Join (reasons , ", " )
496
+ }
497
+
498
+ func sameEventStreams (curEventStreams , newEventStreams []zalandov1.EventStream ) (match bool , reason string ) {
463
499
if len (newEventStreams ) != len (curEventStreams ) {
464
500
return false , "number of defined streams is different"
465
501
}
0 commit comments