Skip to content

Commit 9ee9d16

Browse files
committed
fix: Fix with linter returns
1 parent 85db6c5 commit 9ee9d16

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

internal/controller/postgresql/postgres/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (c *pg) IsDatabaseExist(ctx context.Context, dbname string) (bool, error) {
126126
o, err := c.GetDatabaseOwner(ctx, dbname)
127127
// Check error
128128
if err != nil {
129-
return false, nil
129+
return false, err
130130
}
131131

132132
return o != "", nil

internal/controller/postgresql/postgres/publication.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (c *pg) GetPublicationTablesDetails(ctx context.Context, db, publicationNam
6464

6565
for rows.Next() {
6666
var it PublicationTableDetail
67+
6768
var pqSA pq.StringArray
6869
// Scan
6970
err = rows.Scan(&it.SchemaName, &it.TableName, &pqSA, &it.AdditionalWhere)

internal/controller/postgresql/postgresqlpublication_controller.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,21 @@ func (r *PostgresqlPublicationReconciler) mainReconcile(
261261
}
262262
} else {
263263
// Check if reconcile from PG state is necessary because spec haven't been changed
264-
need, err := r.isReconcileOnPGNecessary(ctx, instance, pg, pgDB, pubRes, nameToSearch)
264+
need, err2 := r.isReconcileOnPGNecessary(ctx, instance, pg, pgDB, pubRes, nameToSearch)
265265
// Check error
266-
if err != nil {
267-
return r.manageError(ctx, reqLogger, instance, originalPatch, err)
266+
if err2 != nil {
267+
return r.manageError(ctx, reqLogger, instance, originalPatch, err2)
268268
}
269269

270270
// Check if it is needed
271271
if need {
272272
reqLogger.Info("PG state have been changed but not via operator, update need to be done")
273273

274-
err = r.manageUpdate(ctx, instance, pg, pgDB, pubRes, nameToSearch)
274+
err2 = r.manageUpdate(ctx, instance, pg, pgDB, pubRes, nameToSearch)
275+
// Check error
276+
if err2 != nil {
277+
return r.manageError(ctx, reqLogger, instance, originalPatch, err2)
278+
}
275279
}
276280
}
277281

@@ -385,7 +389,7 @@ func (*PostgresqlPublicationReconciler) isReconcileOnPGNecessary(
385389
}
386390

387391
// Check if we are in the all tables in schema case
388-
if len(instanceSpec.TablesInSchema) != 0 {
392+
if len(instanceSpec.TablesInSchema) != 0 { //nolint:wsl
389393
// Compute list of schema coming from publication tables and compare list length.
390394
// The computed list must be <= with the desired list
391395
// Why <= ? Because we can list a schema without any tables in
@@ -401,6 +405,7 @@ func (*PostgresqlPublicationReconciler) isReconcileOnPGNecessary(
401405
if !lo.Contains(computedSchemaList, it.SchemaName) {
402406
computedSchemaList = append(computedSchemaList, it.SchemaName)
403407
}
408+
404409
if !lo.Contains(currentTableNames, it.TableName) {
405410
currentTableNames = append(currentTableNames, it.TableName)
406411
}
@@ -419,9 +424,9 @@ func (*PostgresqlPublicationReconciler) isReconcileOnPGNecessary(
419424
// Loop over all schema listed
420425
for _, sch := range instanceSpec.TablesInSchema {
421426
// Get all tables in this schema
422-
tableDetails, err := pg.GetTablesInSchema(ctx, pgDB.Status.Database, sch)
423-
if err != nil {
424-
return false, err
427+
tableDetails, err2 := pg.GetTablesInSchema(ctx, pgDB.Status.Database, sch)
428+
if err2 != nil {
429+
return false, err2
425430
}
426431

427432
// Transform in string slice
@@ -455,13 +460,14 @@ func (*PostgresqlPublicationReconciler) isReconcileOnPGNecessary(
455460

456461
// Now need to check columns
457462

458-
columnNamesToCheck := []string{}
463+
var columnNamesToCheck []string
459464

460465
// Check if columns aren't set in spec
461466
if st.Columns == nil {
462467
// If so, get real columns from table and check if list aren't identical
463468
// Split spec table name
464469
spl := strings.Split(st.TableName, ".")
470+
465471
var schemaName, tableName string
466472

467473
// Check split size
@@ -527,12 +533,10 @@ func (*PostgresqlPublicationReconciler) manageUpdate(
527533
if instance.Spec.WithParameters != nil {
528534
// Change with
529535
builder = builder.SetWith(instance.Spec.WithParameters.Publish, instance.Spec.WithParameters.PublishViaPartitionRoot)
530-
} else {
536+
} else if pubRes.PublicationViaRoot || !pubRes.Delete || !pubRes.Insert || !pubRes.Truncate || !pubRes.Update {
531537
// Potential reconcile case to manage
532-
if pubRes.PublicationViaRoot || !pubRes.Delete || !pubRes.Insert || !pubRes.Truncate || !pubRes.Update {
533-
// Set default
534-
builder = builder.SetDefaultWith()
535-
}
538+
// Set default
539+
builder = builder.SetDefaultWith()
536540
}
537541

538542
// Perform update

0 commit comments

Comments
 (0)