Skip to content

Commit 51a2d90

Browse files
authored
K8SPG-999: Fix dropping multiple custom extensions (#1539)
* Fix error handling in disableCustomExtensionsInDB function * Rename array to removedExtensions for clarity * refactor: change to a more precise error
1 parent d3f779b commit 51a2d90

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

percona/controller/pgcluster/controller.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ func (r *PGClusterReconciler) reconcileCustomExtensions(ctx context.Context, cr
698698
}
699699

700700
if cr.CompareVersion("2.6.0") >= 0 {
701-
var removedExtension []string
701+
var removedExtensions []string
702702
installedExtensions := cr.Status.InstalledCustomExtensions
703703
crExtensions := make(map[string]struct{})
704704
for _, ext := range extensionNames {
@@ -709,13 +709,13 @@ func (r *PGClusterReconciler) reconcileCustomExtensions(ctx context.Context, cr
709709
for _, ext := range installedExtensions {
710710
// If an object exists in installedExtensions but not in crExtensions, the extension should be deleted.
711711
if _, ok := crExtensions[ext]; !ok {
712-
removedExtension = append(removedExtension, ext)
712+
removedExtensions = append(removedExtensions, ext)
713713
}
714714
}
715715

716-
if len(removedExtension) > 0 {
716+
if len(removedExtensions) > 0 {
717717
disable := func(ctx context.Context, exec postgres.Executor) error {
718-
return errors.WithStack(disableCustomExtensionsInDB(ctx, exec, removedExtension))
718+
return errors.WithStack(disableCustomExtensionsInDB(ctx, exec, removedExtensions))
719719
}
720720

721721
primary, err := perconaPG.GetPrimaryPod(ctx, r.Client, cr)
@@ -765,9 +765,11 @@ func disableCustomExtensionsInDB(ctx context.Context, exec postgres.Executor, cu
765765
},
766766
)
767767

768-
log.V(1).Info("extension was disabled ", "extensionName", extensionName)
768+
if err != nil {
769+
return errors.Wrap(err, "drop custom extension")
770+
}
769771

770-
return errors.Wrap(err, "custom extension deletion")
772+
log.V(1).Info("extension was disabled ", "extensionName", extensionName)
771773
}
772774

773775
return nil

0 commit comments

Comments
 (0)