@@ -114,10 +114,10 @@ func (c *Cluster) syncPublication(dbName string, databaseSlotsList map[string]za
114
114
}
115
115
116
116
for slotName , slotAndPublication := range databaseSlotsList {
117
- tables := slotAndPublication .Publication
118
- tableNames := make ([]string , len (tables ))
117
+ newTables := slotAndPublication .Publication
118
+ tableNames := make ([]string , len (newTables ))
119
119
i := 0
120
- for t := range tables {
120
+ for t := range newTables {
121
121
tableName , schemaName := getTableSchema (t )
122
122
tableNames [i ] = fmt .Sprintf ("%s.%s" , schemaName , tableName )
123
123
i ++
@@ -126,6 +126,12 @@ func (c *Cluster) syncPublication(dbName string, databaseSlotsList map[string]za
126
126
tableList := strings .Join (tableNames , ", " )
127
127
128
128
currentTables , exists := currentPublications [slotName ]
129
+ // if newTables is empty it means that it's definition was removed from streams section
130
+ // but when slot is defined in manifest we should sync publications, too
131
+ // by reusing current tables we make sure it is not
132
+ if len (newTables ) == 0 {
133
+ tableList = currentTables
134
+ }
129
135
if ! exists {
130
136
createPublications [slotName ] = tableList
131
137
} else if currentTables != tableList {
@@ -351,15 +357,6 @@ func (c *Cluster) syncStreams() error {
351
357
}
352
358
353
359
databaseSlots := make (map [string ]map [string ]zalandov1.Slot )
354
- slotsToSync := make (map [string ]map [string ]string )
355
- requiredPatroniConfig := c .Spec .Patroni
356
-
357
- if len (requiredPatroniConfig .Slots ) > 0 {
358
- for slotName , slotConfig := range requiredPatroniConfig .Slots {
359
- slotsToSync [slotName ] = slotConfig
360
- }
361
- }
362
-
363
360
if err := c .initDbConn (); err != nil {
364
361
return fmt .Errorf ("could not init database connection" )
365
362
}
@@ -379,6 +376,18 @@ func (c *Cluster) syncStreams() error {
379
376
}
380
377
}
381
378
379
+ // need to take explicitly defined slots into account whey syncing Patroni config
380
+ slotsToSync := make (map [string ]map [string ]string )
381
+ requiredPatroniConfig := c .Spec .Patroni
382
+ if len (requiredPatroniConfig .Slots ) > 0 {
383
+ for slotName , slotConfig := range requiredPatroniConfig .Slots {
384
+ slotsToSync [slotName ] = slotConfig
385
+ if _ , exists := databaseSlots [slotConfig ["database" ]]; exists {
386
+ databaseSlots [slotConfig ["database" ]][slotName ] = zalandov1.Slot {Slot : slotConfig }
387
+ }
388
+ }
389
+ }
390
+
382
391
// get list of required slots and publications, group by database
383
392
for _ , stream := range c .Spec .Streams {
384
393
if _ , exists := databaseSlots [stream .Database ]; ! exists {
0 commit comments