Skip to content

Commit fbe03d3

Browse files
committed
use status instead of annotations
1 parent a4c54f2 commit fbe03d3

File tree

10 files changed

+59
-39
lines changed

10 files changed

+59
-39
lines changed

build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17384,6 +17384,10 @@ spec:
1738417384
properties:
1738517385
host:
1738617386
type: string
17387+
installedCustomExtensions:
17388+
items:
17389+
type: string
17390+
type: array
1738717391
pgbouncer:
1738817392
properties:
1738917393
ready:

config/crd/bases/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17790,6 +17790,10 @@ spec:
1779017790
properties:
1779117791
host:
1779217792
type: string
17793+
installedCustomExtensions:
17794+
items:
17795+
type: string
17796+
type: array
1779317797
pgbouncer:
1779417798
properties:
1779517799
ready:

deploy/bundle.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18083,6 +18083,10 @@ spec:
1808318083
properties:
1808418084
host:
1808518085
type: string
18086+
installedCustomExtensions:
18087+
items:
18088+
type: string
18089+
type: array
1808618090
pgbouncer:
1808718091
properties:
1808818092
ready:

deploy/crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18083,6 +18083,10 @@ spec:
1808318083
properties:
1808418084
host:
1808518085
type: string
18086+
installedCustomExtensions:
18087+
items:
18088+
type: string
18089+
type: array
1808618090
pgbouncer:
1808718091
properties:
1808818092
ready:

deploy/cw-bundle.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18083,6 +18083,10 @@ spec:
1808318083
properties:
1808418084
host:
1808518085
type: string
18086+
installedCustomExtensions:
18087+
items:
18088+
type: string
18089+
type: array
1808618090
pgbouncer:
1808718091
properties:
1808818092
ready:

percona/controller/pgcluster/controller.go

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -529,61 +529,49 @@ 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)
533532
if cr.Spec.Extensions.Storage.Secret == nil {
534533
return nil
535534
}
536535

537536
extensionKeys := make([]string, 0)
537+
extensionNames := make([]string, 0)
538+
538539
for _, extension := range cr.Spec.Extensions.Custom {
539540
key := extensions.GetExtensionKey(cr.Spec.PostgresVersion, extension.Name, extension.Version)
540541
extensionKeys = append(extensionKeys, key)
542+
extensionNames = append(extensionNames, extension.Name)
541543
}
542-
log.Info("List of extension keys", "extensionKeys", extensionKeys)
544+
543545
if cr.CompareVersion("2.6.0") >= 0 {
544546
// custom extensions to be removed
545547
var removedExtension []string
546548
// list of installed custom extensions
547549
var installedExtensions []string
548-
if cr.Spec.Metadata != nil && cr.Spec.Metadata.Annotations != nil {
549-
if val, ok := cr.Spec.Metadata.Annotations[pNaming.AnnotationClusterCustomExtensions]; ok && val != "" {
550-
installedExtensions = strings.Split(val, ",")
551-
}
552-
crExtensions := make(map[string]struct{})
553-
for _, ext := range extensionKeys {
554-
crExtensions[ext] = struct{}{}
550+
installedExtensions = cr.Status.InstalledCustomExtensions
551+
crExtensions := make(map[string]struct{})
552+
for _, ext := range extensionNames {
553+
crExtensions[ext] = struct{}{}
554+
}
555+
// Check for missing entries in crExtensions
556+
for _, ext := range installedExtensions {
557+
// If an object exists in installedExtensions but not in crExtensions, the extension should be deleted.
558+
if _, exists := crExtensions[ext]; !exists {
559+
removedExtension = append(removedExtension, ext)
555560
}
561+
}
556562

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-
}
563+
if len(removedExtension) > 0 {
564+
var exec postgres.Executor
565+
if exec == nil {
566+
return errors.New("executor is nil")
564567
}
565-
log.Info("Test extensions installedExt", "removedExtension", removedExtension)
566-
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-
}
568+
err := DisableCustomExtensionsInPostgreSQL(ctx, removedExtension, exec)
569+
if err != nil {
570+
return errors.Wrap(err, "custom extension deletion")
576571
}
577572
}
578-
if cr.Spec.Metadata == nil {
579-
cr.Spec.Metadata = new(v1beta1.Metadata)
580-
}
581-
582-
if cr.Spec.Metadata.Annotations == nil {
583-
cr.Spec.Metadata.Annotations = make(map[string]string)
584-
}
585-
cr.Spec.Metadata.Annotations[pNaming.AnnotationClusterCustomExtensions] = strings.Join(extensionKeys, ",")
586573
}
574+
587575
for i := 0; i < len(cr.Spec.InstanceSets); i++ {
588576
set := &cr.Spec.InstanceSets[i]
589577
set.InitContainers = append(set.InitContainers, extensions.ExtensionRelocatorContainer(

percona/controller/pgcluster/status.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package pgcluster
22

33
import (
44
"context"
5-
65
"github.com/pkg/errors"
76
corev1 "k8s.io/api/core/v1"
87
"k8s.io/apimachinery/pkg/types"
@@ -78,6 +77,11 @@ func (r *PGClusterReconciler) updateStatus(ctx context.Context, cr *v2.PerconaPG
7877
return errors.Wrap(err, "get app host")
7978
}
8079

80+
installedCustomExtensions := make([]string, 0)
81+
for _, extension := range cr.Spec.Extensions.Custom {
82+
installedCustomExtensions = append(installedCustomExtensions, extension.Name)
83+
}
84+
8185
var size, ready int32
8286
ss := make([]v2.PostgresInstanceSetStatus, 0, len(status.InstanceSets))
8387
for _, is := range status.InstanceSets {
@@ -111,6 +115,8 @@ func (r *PGClusterReconciler) updateStatus(ctx context.Context, cr *v2.PerconaPG
111115
Ready: status.Proxy.PGBouncer.ReadyReplicas,
112116
},
113117
Host: host,
118+
119+
InstalledCustomExtensions: installedCustomExtensions,
114120
}
115121

116122
cluster.Status.State = r.getState(cr, &cluster.Status, status)

percona/naming/annotations.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ const (
4646
// AnnotationClusterBootstrapRestore is the annotation that is added to PerconaPGRestore to
4747
// indicate that it is a cluster bootstrap restore.
4848
AnnotationClusterBootstrapRestore = AnnotationPrefix + "cluster-bootstrap-restore"
49-
50-
//AnnotationClusterCustomExtension is annotation that added to pg cluster to handle the list of custom extensions.
51-
AnnotationClusterCustomExtensions = AnnotationPrefix + "custom_extensions"
5249
)
5350

5451
func ToCrunchyAnnotation(annotation string) string {

pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ type PerconaPGClusterStatus struct {
393393
// +optional
394394
// +operator-sdk:csv:customresourcedefinitions:type=status
395395
Host string `json:"host"`
396+
397+
// +optional
398+
// +operator-sdk:csv:customresourcedefinitions:type=status
399+
InstalledCustomExtensions []string `json:"installedCustomExtensions"`
396400
}
397401

398402
type Backups struct {

pkg/apis/pgv2.percona.com/v2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)