feat(support-bundle): add runHostCollectorsInPod in spec (#1608)

This commit is contained in:
Dexter Yan
2024-09-20 11:57:58 -05:00
committed by GitHub
parent 8823f7d99e
commit e97b9613a5
48 changed files with 447 additions and 57 deletions

View File

@@ -0,0 +1,67 @@
package e2e
import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
"testing"
"golang.org/x/exp/slices"
"sigs.k8s.io/e2e-framework/pkg/envconf"
"sigs.k8s.io/e2e-framework/pkg/features"
)
func TestHostOSRemoteCollector(t *testing.T) {
tests := []struct {
paths []string
expectType string
}{
{
paths: []string{
"hostos_info.json",
},
expectType: "file",
},
}
feature := features.New("Host OS Remote Collector Test").
Assess("check support bundle catch host os remote collector", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
var out bytes.Buffer
supportbundleName := "host-os-remote-collector"
tarPath := fmt.Sprintf("%s.tar.gz", supportbundleName)
targetFolder := fmt.Sprintf("%s/host-collectors/system/", supportbundleName)
cmd := exec.CommandContext(ctx, sbBinary(), "spec/hostOSRemoteCollector.yaml", "--interactive=false", fmt.Sprintf("-o=%s", supportbundleName))
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
t.Fatal(err)
}
defer func() {
err := os.Remove(fmt.Sprintf("%s.tar.gz", supportbundleName))
if err != nil {
t.Fatal("Error remove file:", err)
}
}()
files, _, err := readFilesAndFoldersFromTar(tarPath, targetFolder)
if err != nil {
t.Fatal(err)
}
for _, test := range tests {
if test.expectType == "file" {
for _, path := range test.paths {
if !slices.Contains(files, path) {
t.Fatalf("Expected file %s not found", path)
}
}
}
}
return ctx
}).Feature()
testenv.Test(t, feature)
}

View File

@@ -0,0 +1,8 @@
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
name: sb
runHostCollectorsInPod: true # default is false
spec:
hostCollectors:
- hostOS: {}