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
10 changes: 5 additions & 5 deletions src/go/pt-k8s-debug-collector/dumper/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ type Dumper struct {

// individualFile struct is used to dump the necessary files from the containers
type individualFile struct {
resourceName string
containerName string
filepaths []string
dirpaths map[string][]string // map[tarFolder][]dirPaths
resourceName string
containerNames []string
filepaths []string
dirpaths map[string][]string // map[tarFolder][]dirPaths
}

// resourceMap struct is used to dump the resources from namespace scope or cluster scope
Expand All @@ -91,7 +91,7 @@ func New(location, namespace, kubeconfig, clusterName, forwardport, resource str
log.AddHook(&ErrorArchiveHook{safeLogger: safeLog})

if clusterName == "" {
_, clusterName = parseResourceSpec(resource)
_, clusterName = parseResourceSpec(resource)
}

config, err := buildRestConfig(kubeconfig, clusterName)
Expand Down
25 changes: 21 additions & 4 deletions src/go/pt-k8s-debug-collector/dumper/individual_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ func replaceEnvVars(input string, envMap map[string]string) string {
return result
}

func selectContainer(pod corev1.Pod, candidates []string) (string, bool) {
for _, candidate := range candidates {
for _, c := range pod.Spec.Containers {
if c.Name == candidate {
return candidate, true
}
}
}
return "", false
}

func (d *Dumper) getIndividualFiles(ctx context.Context, job exportJob, crType string) {
normalizedCRType := resourceType(crType)

Expand All @@ -44,17 +55,23 @@ func (d *Dumper) getIndividualFiles(ctx context.Context, job exportJob, crType s
continue
}

container, ok := selectContainer(job.Pod, indf.containerNames)
if !ok {
log.Warnf("None of the containers %v were found in pod %s/%s, skipping", indf.containerNames, job.Pod.Namespace, job.Pod.Name)
continue
}

// Parse environment variables once for this container
envMap, err := d.getContainerEnvMap(job.Pod, indf.containerName)
envMap, err := d.getContainerEnvMap(job.Pod, container)
if err != nil {
log.Warnf("Failed to get env for container %q: %v", indf.containerName, err)
log.Warnf("Failed to get env for container %q: %v", container, err)
continue
}

// Process individual files
for _, indPath := range indf.filepaths {
resolvedPath := replaceEnvVars(indPath, envMap)
if err := d.processSingleFile(ctx, job, indf.containerName, "", resolvedPath); err != nil {
if err := d.processSingleFile(ctx, job, container, "", resolvedPath); err != nil {
log.Warnf("Failed to process file %q: %v", resolvedPath, err)
}
}
Expand All @@ -63,7 +80,7 @@ func (d *Dumper) getIndividualFiles(ctx context.Context, job exportJob, crType s
for tarFolder, dirPaths := range indf.dirpaths {
for _, dirPath := range dirPaths {
resolvedPath := replaceEnvVars(dirPath, envMap)
if err := d.processDir(ctx, job, indf.containerName, tarFolder, resolvedPath); err != nil {
if err := d.processDir(ctx, job, container, tarFolder, resolvedPath); err != nil {
log.Warnf("Skipping directory %q: %v", resolvedPath, err)
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/go/pt-k8s-debug-collector/dumper/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func (d *Dumper) addPg1() error {
}

d.individualFiles = append(d.individualFiles, individualFile{
resourceName: "pgo",
containerName: "database",
dirpaths: dirpaths,
resourceName: "pgo",
containerNames: []string{"database"},
dirpaths: dirpaths,
})
return nil
}
Expand All @@ -30,9 +30,9 @@ func (d *Dumper) addPg2() error {
}

d.individualFiles = append(d.individualFiles, individualFile{
resourceName: "pgv2",
containerName: "database",
dirpaths: dirpaths,
resourceName: "pgv2",
containerNames: []string{"database"},
dirpaths: dirpaths,
})
return nil
}
Expand All @@ -50,9 +50,9 @@ func (d *Dumper) addPxc() error {
}

d.individualFiles = append(d.individualFiles, individualFile{
resourceName: "pxc",
containerName: "logs",
filepaths: filepaths,
resourceName: "pxc",
containerNames: []string{"logs", "pxc"},
filepaths: filepaths,
})
return nil
}
Expand Down
Loading