diff --git a/percona/controller/pgcluster/controller.go b/percona/controller/pgcluster/controller.go index b8acecaee6..a24c1d487b 100644 --- a/percona/controller/pgcluster/controller.go +++ b/percona/controller/pgcluster/controller.go @@ -201,7 +201,7 @@ func (r *PGClusterReconciler) Reconcile(ctx context.Context, request reconcile.R users = append(users, user) } - if cr.Spec.PMM.Enabled { + if cr.PMMEnabled() { users = append(cr.Spec.Users, v1beta1.PostgresUserSpec{ Name: pmm.MonitoringUser, Options: "SUPERUSER", @@ -253,7 +253,7 @@ func (r *PGClusterReconciler) Reconcile(ctx context.Context, request reconcile.R } func (r *PGClusterReconciler) addPMMSidecar(ctx context.Context, cr *v2.PerconaPGCluster) error { - if cr.Spec.PMM == nil || !cr.Spec.PMM.Enabled { + if !cr.PMMEnabled() { return nil } @@ -319,7 +319,7 @@ func (r *PGClusterReconciler) addPMMSidecar(ctx context.Context, cr *v2.PerconaP } func (r *PGClusterReconciler) handleMonitorUserPassChange(ctx context.Context, cr *v2.PerconaPGCluster) error { - if cr.Spec.PMM == nil || !cr.Spec.PMM.Enabled { + if !cr.PMMEnabled() { return nil } diff --git a/percona/controller/pgcluster/version.go b/percona/controller/pgcluster/version.go index 8d585a7d0a..3175ebf67c 100644 --- a/percona/controller/pgcluster/version.go +++ b/percona/controller/pgcluster/version.go @@ -46,7 +46,7 @@ func (r *PGClusterReconciler) getVersionMeta(cr *v2.PerconaPGCluster, operatorDe PGVersion: strconv.Itoa(cr.Spec.PostgresVersion), BackupVersion: "", PMMVersion: "", - PMMEnabled: cr.Spec.PMM != nil && cr.Spec.PMM.Enabled, + PMMEnabled: cr.PMMEnabled(), } if _, ok := cr.Labels["helm.sh/chart"]; ok { diff --git a/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go b/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go index de068c91b2..326987e5af 100644 --- a/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go +++ b/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go @@ -267,6 +267,10 @@ type PMMSpec struct { RuntimeClassName *string `json:"runtimeClassName,omitempty"` } +func (cr *PerconaPGCluster) PMMEnabled() bool { + return cr.Spec.PMM != nil && cr.Spec.PMM.Enabled +} + type SecretsSpec struct { // The secret containing the Certificates and Keys to encrypt PostgreSQL // traffic will need to contain the server TLS certificate, TLS key and the