Skip to content
Open
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
18 changes: 16 additions & 2 deletions percona/pmm/pmm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
28 changes: 26 additions & 2 deletions percona/pmm/pmm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading