Skip to content

Commit a4c54f2

Browse files
committed
update annotations adding
1 parent 08e178d commit a4c54f2

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

percona/controller/pgcluster/controller.go

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ func (r *PGClusterReconciler) handleMonitorUserPassChange(ctx context.Context, c
529529
}
530530

531531
func (r *PGClusterReconciler) reconcileCustomExtensions(ctx context.Context, cr *v2.PerconaPGCluster) error {
532+
log := logging.FromContext(ctx).WithValues("cluster", cr.Name, "namespace", cr.Namespace)
532533
if cr.Spec.Extensions.Storage.Secret == nil {
533534
return nil
534535
}
@@ -538,7 +539,7 @@ func (r *PGClusterReconciler) reconcileCustomExtensions(ctx context.Context, cr
538539
key := extensions.GetExtensionKey(cr.Spec.PostgresVersion, extension.Name, extension.Version)
539540
extensionKeys = append(extensionKeys, key)
540541
}
541-
542+
log.Info("List of extension keys", "extensionKeys", extensionKeys)
542543
if cr.CompareVersion("2.6.0") >= 0 {
543544
// custom extensions to be removed
544545
var removedExtension []string
@@ -548,37 +549,41 @@ func (r *PGClusterReconciler) reconcileCustomExtensions(ctx context.Context, cr
548549
if val, ok := cr.Spec.Metadata.Annotations[pNaming.AnnotationClusterCustomExtensions]; ok && val != "" {
549550
installedExtensions = strings.Split(val, ",")
550551
}
551-
} else {
552-
return errors.Wrap(nil, "custom extension don't use")
553-
}
552+
crExtensions := make(map[string]struct{})
553+
for _, ext := range extensionKeys {
554+
crExtensions[ext] = struct{}{}
555+
}
554556

555-
crExtensions := make(map[string]struct{})
556-
for _, ext := range extensionKeys {
557-
crExtensions[ext] = struct{}{}
558-
}
557+
// Check for missing entries in crExtensions
558+
for _, ext := range installedExtensions {
559+
log.Info("Test extensions installedExt")
560+
// If an object exists in installedExtensions but not in crExtensions, the extension should be deleted.
561+
if _, exists := crExtensions[ext]; !exists {
562+
removedExtension = append(removedExtension, strings.Split(ext, "-")[0])
563+
}
564+
}
565+
log.Info("Test extensions installedExt", "removedExtension", removedExtension)
559566

560-
// Check for missing entries in crExtensions
561-
for _, ext := range installedExtensions {
562-
// If an object exists in installedExtensions but not in crExtensions, the extension should be deleted.
563-
if _, exists := crExtensions[ext]; !exists {
564-
removedExtension = append(removedExtension, ext)
567+
if len(removedExtension) > 0 {
568+
var exec postgres.Executor
569+
if exec == nil {
570+
return errors.New("executor is nil")
571+
}
572+
err := DisableCustomExtensionsInPostgreSQL(ctx, removedExtension, exec)
573+
if err != nil {
574+
return errors.Wrap(err, "custom extension deletion")
575+
}
565576
}
566577
}
578+
if cr.Spec.Metadata == nil {
579+
cr.Spec.Metadata = new(v1beta1.Metadata)
580+
}
567581

568-
if len(removedExtension) > 0 {
569-
var exec postgres.Executor
570-
if exec == nil {
571-
return errors.New("executor is nil")
572-
}
573-
err := DisableCustomExtensionsInPostgreSQL(ctx, removedExtension, exec)
574-
if err != nil {
575-
return errors.Wrap(err, "custom extension deletion")
576-
}
582+
if cr.Spec.Metadata.Annotations == nil {
583+
cr.Spec.Metadata.Annotations = make(map[string]string)
577584
}
578585
cr.Spec.Metadata.Annotations[pNaming.AnnotationClusterCustomExtensions] = strings.Join(extensionKeys, ",")
579-
580586
}
581-
582587
for i := 0; i < len(cr.Spec.InstanceSets); i++ {
583588
set := &cr.Spec.InstanceSets[i]
584589
set.InitContainers = append(set.InitContainers, extensions.ExtensionRelocatorContainer(

0 commit comments

Comments
 (0)