mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
Merge pull request #717 from percona/PT-2281_provide_container_name_for_copying_files_in_the_dump
PT-2281 - provide container name for copying files in the dump
This commit is contained in:
@@ -20,16 +20,17 @@ import (
|
|||||||
|
|
||||||
// Dumper struct is for dumping cluster
|
// Dumper struct is for dumping cluster
|
||||||
type Dumper struct {
|
type Dumper struct {
|
||||||
cmd string
|
cmd string
|
||||||
kubeconfig string
|
kubeconfig string
|
||||||
resources []string
|
resources []string
|
||||||
filePaths []string
|
filePaths []string
|
||||||
namespace string
|
fileContainer string
|
||||||
location string
|
namespace string
|
||||||
errors string
|
location string
|
||||||
mode int64
|
errors string
|
||||||
crType string
|
mode int64
|
||||||
forwardport string
|
crType string
|
||||||
|
forwardport string
|
||||||
}
|
}
|
||||||
|
|
||||||
var resourcesRe = regexp.MustCompile(`(\w+)\.(\w+).percona\.com`)
|
var resourcesRe = regexp.MustCompile(`(\w+)\.(\w+).percona\.com`)
|
||||||
@@ -124,6 +125,7 @@ func New(location, namespace, resource string, kubeconfig string, forwardport st
|
|||||||
"var/lib/mysql/mysqld.post.processing.log",
|
"var/lib/mysql/mysqld.post.processing.log",
|
||||||
"var/lib/mysql/auto.cnf",
|
"var/lib/mysql/auto.cnf",
|
||||||
)
|
)
|
||||||
|
d.fileContainer = "logs"
|
||||||
}
|
}
|
||||||
d.resources = resources
|
d.resources = resources
|
||||||
d.crType = resource
|
d.crType = resource
|
||||||
@@ -272,7 +274,7 @@ func (d *Dumper) DumpCluster() error {
|
|||||||
// get individual Logs
|
// get individual Logs
|
||||||
location = filepath.Join(d.location, ns.Name, pod.Name)
|
location = filepath.Join(d.location, ns.Name, pod.Name)
|
||||||
for _, path := range d.filePaths {
|
for _, path := range d.filePaths {
|
||||||
err = d.getIndividualFiles(resourceType(d.crType), ns.Name, pod.Name, path, location, tw)
|
err = d.getIndividualFiles(ns.Name, pod.Name, path, location, tw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logError(err.Error(), "get file "+path+" for pod "+pod.Name)
|
d.logError(err.Error(), "get file "+path+" for pod "+pod.Name)
|
||||||
log.Printf("Error: get %s file: %v", path, err)
|
log.Printf("Error: get %s file: %v", path, err)
|
||||||
@@ -370,13 +372,15 @@ type crSecrets struct {
|
|||||||
} `json:"spec"`
|
} `json:"spec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check if resource parameter is really needed
|
func (d *Dumper) getIndividualFiles(namespace string, podName, path, location string, tw *tar.Writer) error {
|
||||||
func (d *Dumper) getIndividualFiles(resource, namespace string, podName, path, location string, tw *tar.Writer) error {
|
if len(d.fileContainer) == 0 {
|
||||||
args := []string{"-n", namespace, "cp", podName + ":" + path, "/dev/stdout"}
|
return errors.Errorf("Logs container name is not specified for resource %s in namespace %s", resourceType(d.crType), d.namespace)
|
||||||
|
}
|
||||||
|
args := []string{"-n", namespace, "-c", d.fileContainer, "cp", podName + ":" + path, "/dev/stdout"}
|
||||||
output, err := d.runCmd(args...)
|
output, err := d.runCmd(args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logError(err.Error(), args...)
|
d.logError(err.Error(), args...)
|
||||||
log.Printf("Error: get path %s for resource %s in namespace %s: %v", path, resource, d.namespace, err)
|
log.Printf("Error: get path %s for resource %s in namespace %s: %v", path, resourceType(d.crType), d.namespace, err)
|
||||||
return addToArchive(location, d.mode, []byte(err.Error()), tw)
|
return addToArchive(location, d.mode, []byte(err.Error()), tw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
src/go/pt-k8s-debug-collector/dumper/dumper_test.go
Normal file
20
src/go/pt-k8s-debug-collector/dumper/dumper_test.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package dumper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Unit test for non-existing logs container name error handling
|
||||||
|
*/
|
||||||
|
|
||||||
|
func TestGetIndividualFilesError(t *testing.T) {
|
||||||
|
d := New("", "", "psmdb", "", "")
|
||||||
|
|
||||||
|
err := d.getIndividualFiles("", "", "", "", nil)
|
||||||
|
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.ErrorContains(t, err, "Logs container name is not specified")
|
||||||
|
}
|
Reference in New Issue
Block a user