diff --git a/e2e-tests/tests/monitoring/09-deleted-from-server-inventory.yaml b/e2e-tests/tests/monitoring/10-deleted-from-server-inventory.yaml similarity index 100% rename from e2e-tests/tests/monitoring/09-deleted-from-server-inventory.yaml rename to e2e-tests/tests/monitoring/10-deleted-from-server-inventory.yaml diff --git a/percona/pmm/pmm.go b/percona/pmm/pmm.go index c4e6b9f4b5..5151479a72 100644 --- a/percona/pmm/pmm.go +++ b/percona/pmm/pmm.go @@ -34,6 +34,20 @@ func Container(secret *corev1.Secret, pgc *v2.PerconaPGCluster) (corev1.Containe } // sidecarContainerV2 refers to the construction of the PMM2 container. +// pmmConfigFile returns the path for the stateless pmm-agent.yaml. From v3.1.0 +// it is placed directly in the writable "/tmp" emptyDir (pmm-agent does not +// create the config's parent dir, so a subdirectory cannot be used) so PMM +// works with readOnlyRootFilesystem. +func pmmConfigFile(pgc *v2.PerconaPGCluster, isPMM3 bool) string { + if pgc.CompareVersion("3.1.0") >= 0 { + return "/tmp/pmm-agent.yaml" + } + if isPMM3 { + return "/usr/local/percona/pmm/config/pmm-agent.yaml" + } + return "/usr/local/percona/pmm2/config/pmm-agent.yaml" +} + func sidecarContainerV2(pgc *v2.PerconaPGCluster) corev1.Container { ports := []corev1.ContainerPort{{ContainerPort: 7777}} @@ -131,7 +145,7 @@ func sidecarContainerV2(pgc *v2.PerconaPGCluster) corev1.Container { }, { Name: "PMM_AGENT_CONFIG_FILE", - Value: "/usr/local/percona/pmm2/config/pmm-agent.yaml", + Value: pmmConfigFile(pgc, false), }, { Name: "PMM_AGENT_LOG_LEVEL", @@ -332,7 +346,7 @@ func sidecarContainerV3(pgc *v2.PerconaPGCluster) corev1.Container { }, { Name: "PMM_AGENT_CONFIG_FILE", - Value: "/usr/local/percona/pmm/config/pmm-agent.yaml", + Value: pmmConfigFile(pgc, true), }, { Name: "PMM_AGENT_LOG_LEVEL", diff --git a/percona/pmm/pmm_test.go b/percona/pmm/pmm_test.go index b0459f832a..5fbf6781a0 100644 --- a/percona/pmm/pmm_test.go +++ b/percona/pmm/pmm_test.go @@ -141,6 +141,30 @@ func TestContainer(t *testing.T) { } +func TestPMMConfigFile(t *testing.T) { + newPGC := func(crVersion string) *v2.PerconaPGCluster { + return &v2.PerconaPGCluster{ + Spec: v2.PerconaPGClusterSpec{CRVersion: crVersion}, + } + } + + t.Run("v3.1.0 PMM2", func(t *testing.T) { + assert.Equal(t, "/tmp/pmm-agent.yaml", pmmConfigFile(newPGC("3.1.0"), false)) + }) + t.Run("v3.1.0 PMM3", func(t *testing.T) { + assert.Equal(t, "/tmp/pmm-agent.yaml", pmmConfigFile(newPGC("3.1.0"), true)) + }) + t.Run("newer than 3.1.0", func(t *testing.T) { + assert.Equal(t, "/tmp/pmm-agent.yaml", pmmConfigFile(newPGC("3.2.0"), true)) + }) + t.Run("older than 3.1.0 PMM2", func(t *testing.T) { + assert.Equal(t, "/usr/local/percona/pmm2/config/pmm-agent.yaml", pmmConfigFile(newPGC("3.0.0"), false)) + }) + t.Run("older than 3.1.0 PMM3", func(t *testing.T) { + assert.Equal(t, "/usr/local/percona/pmm/config/pmm-agent.yaml", pmmConfigFile(newPGC("3.0.0"), true)) + }) +} + func TestSidecarContainerV2(t *testing.T) { pmmSpec := &v2.PMMSpec{ Image: "percona/pmm-client:pmm2-enabled", @@ -200,7 +224,7 @@ func TestSidecarContainerV2(t *testing.T) { "PMM_AGENT_LISTEN_PORT": "7777", "PMM_AGENT_PORTS_MIN": "30100", "PMM_AGENT_PORTS_MAX": "30105", - "PMM_AGENT_CONFIG_FILE": "/usr/local/percona/pmm2/config/pmm-agent.yaml", + "PMM_AGENT_CONFIG_FILE": "/tmp/pmm-agent.yaml", "PMM_AGENT_LOG_LEVEL": "info", "PMM_AGENT_DEBUG": "false", "PMM_AGENT_TRACE": "false", @@ -309,7 +333,7 @@ func TestSidecarContainerV3(t *testing.T) { "PMM_AGENT_LISTEN_PORT": "7777", "PMM_AGENT_PORTS_MIN": "30100", "PMM_AGENT_PORTS_MAX": "30105", - "PMM_AGENT_CONFIG_FILE": "/usr/local/percona/pmm/config/pmm-agent.yaml", + "PMM_AGENT_CONFIG_FILE": "/tmp/pmm-agent.yaml", "PMM_AGENT_LOG_LEVEL": "info", "PMM_AGENT_DEBUG": "false", "PMM_AGENT_TRACE": "false",