@@ -529,6 +529,7 @@ func (r *PGClusterReconciler) handleMonitorUserPassChange(ctx context.Context, c
529
529
}
530
530
531
531
func (r * PGClusterReconciler ) reconcileCustomExtensions (ctx context.Context , cr * v2.PerconaPGCluster ) error {
532
+ log := logging .FromContext (ctx ).WithValues ("cluster" , cr .Name , "namespace" , cr .Namespace )
532
533
if cr .Spec .Extensions .Storage .Secret == nil {
533
534
return nil
534
535
}
@@ -538,7 +539,7 @@ func (r *PGClusterReconciler) reconcileCustomExtensions(ctx context.Context, cr
538
539
key := extensions .GetExtensionKey (cr .Spec .PostgresVersion , extension .Name , extension .Version )
539
540
extensionKeys = append (extensionKeys , key )
540
541
}
541
-
542
+ log . Info ( "List of extension keys" , "extensionKeys" , extensionKeys )
542
543
if cr .CompareVersion ("2.6.0" ) >= 0 {
543
544
// custom extensions to be removed
544
545
var removedExtension []string
@@ -548,37 +549,41 @@ func (r *PGClusterReconciler) reconcileCustomExtensions(ctx context.Context, cr
548
549
if val , ok := cr .Spec .Metadata .Annotations [pNaming .AnnotationClusterCustomExtensions ]; ok && val != "" {
549
550
installedExtensions = strings .Split (val , "," )
550
551
}
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
+ }
554
556
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 )
559
566
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
+ }
565
576
}
566
577
}
578
+ if cr .Spec .Metadata == nil {
579
+ cr .Spec .Metadata = new (v1beta1.Metadata )
580
+ }
567
581
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 )
577
584
}
578
585
cr .Spec .Metadata .Annotations [pNaming .AnnotationClusterCustomExtensions ] = strings .Join (extensionKeys , "," )
579
-
580
586
}
581
-
582
587
for i := 0 ; i < len (cr .Spec .InstanceSets ); i ++ {
583
588
set := & cr .Spec .InstanceSets [i ]
584
589
set .InitContainers = append (set .InitContainers , extensions .ExtensionRelocatorContainer (
0 commit comments