Skip to content

K8SPG-737: expose /pgdata mountpoint for node_exporter #1113

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 7 commits into from
Apr 8, 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
20 changes: 20 additions & 0 deletions e2e-tests/tests/monitoring-pmm3/08-check-mountpoint-expose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |-
set -o errexit
set -o xtrace

source ../../functions

series_fetched=$(curl --insecure -G "https://admin:admin@$(get_service_ip monitoring-service)/prometheus/api/v1/query_range" \
--data-urlencode "query=node_filesystem_free_bytes{mountpoint=\"/pgdata\"}" \
--data-urlencode "start=$(($(date +%s) - 300))" \
--data-urlencode "end=$(date +%s)" \
--data-urlencode "step=5s" | jq -r '.stats.seriesFetched')

if [[ $series_fetched == 0 ]]; then
echo "seriesFetched is 0"
exit 1
fi
timeout: 360
20 changes: 20 additions & 0 deletions e2e-tests/tests/monitoring/08-check-mountpoint-expose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |-
set -o errexit
set -o xtrace

source ../../functions

series_fetched=$(curl --insecure -G "https://admin:admin@$(get_service_ip monitoring-service)/prometheus/api/v1/query_range" \
--data-urlencode "query=node_filesystem_free_bytes{mountpoint=\"/pgdata\"}" \
--data-urlencode "start=$(($(date +%s) - 300))" \
--data-urlencode "end=$(date +%s)" \
--data-urlencode "step=5s" | jq -r '.stats.seriesFetched')

if [[ $series_fetched == 0 ]]; then
echo "seriesFetched is 0"
exit 1
fi
timeout: 360
3 changes: 3 additions & 0 deletions internal/controller/postgrescluster/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,9 @@ func generateInstanceStatefulSetIntent(_ context.Context,
// containers see each other's processes.
// - https://docs.k8s.io/tasks/configure-pod-container/share-process-namespace/
sts.Spec.Template.Spec.ShareProcessNamespace = initialize.Bool(true)
if cluster.CompareVersion("2.7.0") >= 0 {
sts.Spec.Template.Spec.ShareProcessNamespace = initialize.Bool(false) // K8SPG-737: should be false
}

// Patroni calls the Kubernetes API and pgBackRest may interact with a cloud
// storage provider. Use the instance ServiceAccount and automatically mount
Expand Down
30 changes: 23 additions & 7 deletions percona/pmm/pmm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/percona/percona-postgresql-operator/internal/postgres"
v2 "github.com/percona/percona-postgresql-operator/pkg/apis/pgv2.percona.com/v2"
)

Expand Down Expand Up @@ -42,6 +43,21 @@ func sidecarContainerV2(pgc *v2.PerconaPGCluster) corev1.Container {

pmmSpec := pgc.Spec.PMM

volumeMounts := []corev1.VolumeMount{
{
Name: "cert-volume",
MountPath: "/pgconf/tls",
ReadOnly: true,
},
}
if pgc.CompareVersion("2.7.0") >= 0 {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: postgres.DataVolumeMount().Name,
MountPath: postgres.DataVolumeMount().MountPath,
ReadOnly: true,
})
}

container := corev1.Container{
Name: "pmm-client",
Image: pmmSpec.Image,
Expand Down Expand Up @@ -74,13 +90,7 @@ func sidecarContainerV2(pgc *v2.PerconaPGCluster) corev1.Container {
},
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "cert-volume",
MountPath: "/pgconf/tls",
ReadOnly: true,
},
},
VolumeMounts: volumeMounts,
Env: []corev1.EnvVar{
{
Name: "POD_NAME",
Expand Down Expand Up @@ -306,7 +316,13 @@ func sidecarContainerV3(pgc *v2.PerconaPGCluster) corev1.Container {
MountPath: "/pgconf/tls",
ReadOnly: true,
},
{
Name: postgres.DataVolumeMount().Name,
MountPath: postgres.DataVolumeMount().MountPath,
ReadOnly: true,
},
},

Env: []corev1.EnvVar{
{
Name: "POD_NAME",
Expand Down
6 changes: 2 additions & 4 deletions percona/pmm/pmm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -136,7 +135,6 @@ func TestContainer(t *testing.T) {
assert.Contains(t, container.Env, tt.verificationEnvVar())
})
}

}

func TestSidecarContainerV2(t *testing.T) {
Expand Down Expand Up @@ -248,7 +246,7 @@ func TestSidecarContainerV2(t *testing.T) {
}
}

assert.Len(t, container.VolumeMounts, 1)
assert.Len(t, container.VolumeMounts, 2)
assert.Equal(t, "/pgconf/tls", container.VolumeMounts[0].MountPath)
assert.True(t, container.VolumeMounts[0].ReadOnly)
}
Expand Down Expand Up @@ -357,7 +355,7 @@ func TestSidecarContainerV3(t *testing.T) {
}
}

assert.Len(t, container.VolumeMounts, 1)
assert.Len(t, container.VolumeMounts, 2)
assert.Equal(t, "/pgconf/tls", container.VolumeMounts[0].MountPath)
assert.True(t, container.VolumeMounts[0].ReadOnly)
}
Loading