mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Add e2e tests for node log viewer
Adding e2e tests for the feature: add node log viewer
This commit is contained in:
parent
d046a58de4
commit
ff92963551
@ -19,6 +19,7 @@ package node
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
@ -30,6 +31,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
e2ekubectl "k8s.io/kubernetes/test/e2e/framework/kubectl"
|
||||
e2ekubelet "k8s.io/kubernetes/test/e2e/framework/kubelet"
|
||||
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
||||
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||
@ -455,4 +457,82 @@ var _ = SIGDescribe("kubelet", func() {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
//Test kubectl alpha node-logs <node-name> commands
|
||||
ginkgo.Describe("kubectl node-logs <node-name> [Feature:add node log viewer]", func() {
|
||||
var (
|
||||
numNodes int
|
||||
nodeNames sets.String
|
||||
)
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
nodes, err := e2enode.GetBoundedReadySchedulableNodes(c, maxNodesToCheck)
|
||||
numNodes = len(nodes.Items)
|
||||
framework.ExpectNoError(err)
|
||||
nodeNames = sets.NewString()
|
||||
for i := 0; i < numNodes; i++ {
|
||||
nodeNames.Insert(nodes.Items[i].Name)
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
Test if kubectl node-logs <node-name>
|
||||
returns something or not!
|
||||
*/
|
||||
|
||||
ginkgo.It("should return the logs ", func() {
|
||||
ginkgo.By("Starting the command")
|
||||
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
||||
|
||||
for nodeName := range nodeNames {
|
||||
cmd := tk.KubectlCmd("alpha", "node-logs", nodeName)
|
||||
runKubectlCommand(cmd, "")
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
Test if kubectl node-logs <node-name> --service kubelet
|
||||
returns something or not!
|
||||
*/
|
||||
|
||||
ginkgo.It("should return the logs for the requested service", func() {
|
||||
ginkgo.By("Starting the command")
|
||||
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
||||
|
||||
for nodeName := range nodeNames {
|
||||
cmd := tk.KubectlCmd("alpha", "node-logs", nodeName, "--service", "kubelet")
|
||||
runKubectlCommand(cmd, "--service")
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
Test if kubectl node-logs <node-name> --path pods
|
||||
returns something or not!
|
||||
*/
|
||||
|
||||
ginkgo.It("should return the logs for the provided path", func() {
|
||||
ginkgo.By("Starting the command")
|
||||
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
||||
|
||||
for nodeName := range nodeNames {
|
||||
cmd := tk.KubectlCmd("alpha", "node-logs", nodeName, "--path", "pods")
|
||||
runKubectlCommand(cmd, "--path")
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
func runKubectlCommand(cmd *exec.Cmd, arg string) {
|
||||
stdout, stderr, err := framework.StartCmdAndStreamOutput(cmd)
|
||||
if err != nil {
|
||||
framework.Failf("Failed to start kubectl command: %v", err)
|
||||
}
|
||||
defer stdout.Close()
|
||||
defer stderr.Close()
|
||||
defer framework.TryKill(cmd)
|
||||
buf := make([]byte, 128)
|
||||
if _, err = stdout.Read(buf); err != nil {
|
||||
framework.Failf("Expected output from kubectl alpha node-logs %s: %v", arg, err)
|
||||
}
|
||||
framework.Logf("output: %s", buf)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user