Skip to content

K8SPG-654 add possibility of adding custom postgres params for PMM #1111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13633,6 +13633,8 @@ spec:
- Never
- IfNotPresent
type: string
postgresParams:
type: string
querySource:
default: pgstatmonitor
enum:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/pgv2.percona.com_perconapgclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14038,6 +14038,8 @@ spec:
- Never
- IfNotPresent
type: string
postgresParams:
type: string
querySource:
default: pgstatmonitor
enum:
Expand Down
2 changes: 2 additions & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14331,6 +14331,8 @@ spec:
- Never
- IfNotPresent
type: string
postgresParams:
type: string
querySource:
default: pgstatmonitor
enum:
Expand Down
3 changes: 2 additions & 1 deletion deploy/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ spec:
# imagePullPolicy: IfNotPresent
secret: cluster1-pmm-secret
serverHost: monitoring-service
# customClusterName: "<string>"
# customClusterName: "<string>"
# postgresParams: "<string>"
# querySource: pgstatmonitor
# patroni:
# # Some values of the Liveness/Readiness probes of the patroni container are calculated using syncPeriodSeconds by the following formulas:
Expand Down
2 changes: 2 additions & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14331,6 +14331,8 @@ spec:
- Never
- IfNotPresent
type: string
postgresParams:
type: string
querySource:
default: pgstatmonitor
enum:
Expand Down
2 changes: 2 additions & 0 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14331,6 +14331,8 @@ spec:
- Never
- IfNotPresent
type: string
postgresParams:
type: string
querySource:
default: pgstatmonitor
enum:
Expand Down
5 changes: 3 additions & 2 deletions e2e-tests/functions
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ get_cr() {
.spec.proxy.pgBouncer.image = "'$IMAGE_PGBOUNCER'" |
.spec.pmm.image = "'$IMAGE_PMM_CLIENT'" |
.spec.pmm.secret = "'${cr_name}'-pmm-secret" |
.spec.pmm.customClusterName = "'${cr_name}'-pmm-custom-name"
.spec.pmm.customClusterName = "'${cr_name}'-pmm-custom-name" |
.spec.pmm.postgresParams = "--environment=dev-postgres"
' $DEPLOY_DIR/cr.yaml >$TEMP_DIR/cr.yaml

if [[ $OPENSHIFT ]]; then
Expand Down Expand Up @@ -381,7 +382,7 @@ deploy_pmm3_server() {
oc create rolebinding pmm-pg-operator-namespace-only --role percona-postgresql-operator --serviceaccount=$NAMESPACE:pmm-server -n "${NAMESPACE}"
oc patch role/percona-postgresql-operator --type json -p='[{"op":"add","path": "/rules/-","value":{"apiGroups":["security.openshift.io"],"resources":["securitycontextconstraints"],"verbs":["use"],"resourceNames":["privileged"]}}]' -n "$NAMESPACE"
fi
helm install monitoring --set imageTag=${IMAGE_PMM3_SERVER#*:} --set imageRepo=${IMAGE_PMM3_SERVER%:*} --set platform=$platform --set sa=pmm-server --set supresshttp2=false https://percona-charts.storage.googleapis.com/pmm-server-${PMM3_SERVER_VERSION}.tgz -n "$NAMESPACE"
helm install monitoring --set imageTag=${IMAGE_PMM3_SERVER#*:} --set imageRepo=${IMAGE_PMM3_SERVER%:*} --set platform=$platform --set sa=pmm-server --set supresshttp2=false https://percona-charts.storage.googleapis.com/pmm-server-${PMM_SERVER_VERSION}.tgz -n "$NAMESPACE"
else
platform=kubernetes

Expand Down
1 change: 1 addition & 0 deletions e2e-tests/tests/monitoring-pmm3/03-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ spec:
secret: monitoring-pmm3-pmm-secret
serverHost: monitoring-service
customClusterName: monitoring-pmm3-pmm-custom-name
postgresParams: "--environment=dev-postgres"
port: 5432
proxy:
pgBouncer:
Expand Down
1 change: 1 addition & 0 deletions e2e-tests/tests/monitoring/03-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ spec:
secret: monitoring-pmm-secret
serverHost: monitoring-service
customClusterName: monitoring-pmm-custom-name
postgresParams: "--environment=dev-postgres"
port: 5432
proxy:
pgBouncer:
Expand Down
20 changes: 15 additions & 5 deletions percona/pmm/pmm.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,16 @@ func sidecarContainerV2(pgc *v2.PerconaPGCluster) corev1.Container {
if pgc.Spec.PMM.CustomClusterName != "" {
clusterName = pgc.Spec.PMM.CustomClusterName
}
container.Env = append(container.Env, corev1.EnvVar{
Name: "CLUSTER_NAME",
Value: clusterName,
})
container.Env = append(container.Env,
corev1.EnvVar{
Name: "CLUSTER_NAME",
Value: clusterName,
},
corev1.EnvVar{
Name: "PMM_POSTGRES_PARAMS",
Value: pmmSpec.PostgresParams,
},
)
}

return container
Expand Down Expand Up @@ -434,6 +440,10 @@ func sidecarContainerV3(pgc *v2.PerconaPGCluster) corev1.Container {
Name: "CLUSTER_NAME",
Value: clusterName,
},
{
Name: "PMM_POSTGRES_PARAMS",
Value: pmmSpec.PostgresParams,
},
},
}

Expand Down Expand Up @@ -461,7 +471,7 @@ func agentPrerunScript(querySource v2.PMMQuerySource, pgc *v2.PerconaPGCluster)

if pgc.CompareVersion("2.7.0") >= 0 {
addServiceArgs = append(addServiceArgs,
"--cluster=$(CLUSTER_NAME)",
"--cluster=$(CLUSTER_NAME)", "$PMM_POSTGRES_PARAMS",
)
}
addService := fmt.Sprintf("pmm-admin add postgresql %s", strings.Join(addServiceArgs, " "))
Expand Down
13 changes: 9 additions & 4 deletions percona/pmm/pmm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestContainer(t *testing.T) {
ImagePullPolicy: corev1.PullIfNotPresent,
ServerHost: "pmm.server.local",
Secret: "pmm-secret",
PostgresParams: "--environment=dev-postgres",
Resources: corev1.ResourceRequirements{},
ContainerSecurityContext: &corev1.SecurityContext{},
}
Expand Down Expand Up @@ -144,6 +145,7 @@ func TestSidecarContainerV2(t *testing.T) {
ImagePullPolicy: corev1.PullIfNotPresent,
ServerHost: "pmm.server.local",
Secret: "pmm-secret",
PostgresParams: "--environment=dev-postgres",
Resources: corev1.ResourceRequirements{},
ContainerSecurityContext: &corev1.SecurityContext{},
}
Expand Down Expand Up @@ -179,7 +181,7 @@ func TestSidecarContainerV2(t *testing.T) {
assert.NotNil(t, container.Lifecycle.PreStop)
assert.Equal(t, []string{"bash", "-c", "pmm-admin unregister --force"}, container.Lifecycle.PreStop.Exec.Command)

assert.Len(t, container.Env, 32)
assert.Len(t, container.Env, 33)

expectedEnvVars := map[string]string{
"POD_NAME": "", // field reference is asserted separately
Expand Down Expand Up @@ -211,9 +213,10 @@ func TestSidecarContainerV2(t *testing.T) {
"DB_TYPE": "postgresql",
"DB_USER": v2.UserMonitoring,
"DB_PASS": "", // secret reference is asserted separately
"PMM_AGENT_PRERUN_SCRIPT": "pmm-admin status --wait=10s; pmm-admin add postgresql --username=$(DB_USER) --password='$(DB_PASS)' --host=127.0.0.1 --port=5432 --tls-cert-file=/pgconf/tls/tls.crt --tls-key-file=/pgconf/tls/tls.key --tls-ca-file=/pgconf/tls/ca.crt --tls-skip-verify --skip-connection-check --metrics-mode=push --service-name=$(PMM_AGENT_SETUP_NODE_NAME) --query-source= --cluster=$(CLUSTER_NAME); pmm-admin annotate --service-name=$(PMM_AGENT_SETUP_NODE_NAME) 'Service restarted'",
"PMM_AGENT_PRERUN_SCRIPT": "pmm-admin status --wait=10s; pmm-admin add postgresql --username=$(DB_USER) --password='$(DB_PASS)' --host=127.0.0.1 --port=5432 --tls-cert-file=/pgconf/tls/tls.crt --tls-key-file=/pgconf/tls/tls.key --tls-ca-file=/pgconf/tls/ca.crt --tls-skip-verify --skip-connection-check --metrics-mode=push --service-name=$(PMM_AGENT_SETUP_NODE_NAME) --query-source= --cluster=$(CLUSTER_NAME) $PMM_POSTGRES_PARAMS; pmm-admin annotate --service-name=$(PMM_AGENT_SETUP_NODE_NAME) 'Service restarted'",
"PMM_AGENT_PATHS_TEMPDIR": "/tmp",
"CLUSTER_NAME": "test-cluster",
"PMM_POSTGRES_PARAMS": "--environment=dev-postgres",
}

for _, envVar := range container.Env {
Expand Down Expand Up @@ -256,6 +259,7 @@ func TestSidecarContainerV3(t *testing.T) {
ImagePullPolicy: corev1.PullIfNotPresent,
ServerHost: "pmm.server.local",
Secret: "pmm-secret",
PostgresParams: "--environment=dev-postgres",
Resources: corev1.ResourceRequirements{},
ContainerSecurityContext: &corev1.SecurityContext{},
}
Expand Down Expand Up @@ -291,7 +295,7 @@ func TestSidecarContainerV3(t *testing.T) {
assert.NotNil(t, container.Lifecycle.PreStop)
assert.Equal(t, []string{"bash", "-c", "pmm-admin unregister --force"}, container.Lifecycle.PreStop.Exec.Command)

assert.Len(t, container.Env, 27)
assert.Len(t, container.Env, 28)

expectedEnvVars := map[string]string{
"POD_NAME": "", // field reference is asserted separately
Expand All @@ -318,9 +322,10 @@ func TestSidecarContainerV3(t *testing.T) {
"DB_TYPE": "postgresql",
"DB_USER": v2.UserMonitoring,
"DB_PASS": "", // secret reference is asserted separately
"PMM_AGENT_PRERUN_SCRIPT": "pmm-admin status --wait=10s; pmm-admin add postgresql --username=$(DB_USER) --password='$(DB_PASS)' --host=127.0.0.1 --port=5432 --tls-cert-file=/pgconf/tls/tls.crt --tls-key-file=/pgconf/tls/tls.key --tls-ca-file=/pgconf/tls/ca.crt --tls-skip-verify --skip-connection-check --metrics-mode=push --service-name=$(PMM_AGENT_SETUP_NODE_NAME) --query-source= --cluster=$(CLUSTER_NAME); pmm-admin annotate --service-name=$(PMM_AGENT_SETUP_NODE_NAME) 'Service restarted'",
"PMM_AGENT_PRERUN_SCRIPT": "pmm-admin status --wait=10s; pmm-admin add postgresql --username=$(DB_USER) --password='$(DB_PASS)' --host=127.0.0.1 --port=5432 --tls-cert-file=/pgconf/tls/tls.crt --tls-key-file=/pgconf/tls/tls.key --tls-ca-file=/pgconf/tls/ca.crt --tls-skip-verify --skip-connection-check --metrics-mode=push --service-name=$(PMM_AGENT_SETUP_NODE_NAME) --query-source= --cluster=$(CLUSTER_NAME) $PMM_POSTGRES_PARAMS; pmm-admin annotate --service-name=$(PMM_AGENT_SETUP_NODE_NAME) 'Service restarted'",
"PMM_AGENT_PATHS_TEMPDIR": "/tmp",
"CLUSTER_NAME": "test-cluster",
"PMM_POSTGRES_PARAMS": "--environment=dev-postgres",
}

for _, envVar := range container.Env {
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@ type PMMSpec struct {
// +optional
CustomClusterName string `json:"customClusterName,omitempty"`

// +optional
PostgresParams string `json:"postgresParams,omitempty"`

// +kubebuilder:validation:Required
Secret string `json:"secret,omitempty"`

Expand Down
Loading