Skip to content

Commit

Permalink
test: Pass container to ExecPodCmdBackground()
Browse files Browse the repository at this point in the history
Add container option to kubectl exec to avoid test failures due to unexpected output like this:

            s: "could not parse \"Defaulted container \\\"cilium-agent\\\" out of: cilium-agent, clean-cilium-state (init)\" as JSON (line 0 of \"kubectl exec -n kube-system cilium-fsfdb -- hubble observe --follow --output=json --last 1 --type l7 --from-pod 202106040737k8shubbletesthubbleobservetestl7flow/app2-58757b7dd5-4fvh7 --to-namespace 202106040737k8shubbletesthubbleobservetestl7flow --to-label id=app1,zgroup=testapp --protocol http\")",

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
  • Loading branch information
jrajahalme authored and nebril committed Jul 15, 2021
1 parent 1da68d8 commit c95f6fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions test/helpers/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,10 @@ func (kub *Kubectl) ExecPodCmdContext(ctx context.Context, namespace string, pod
// To receive the output of this function, the caller must invoke either
// kub.WaitUntilFinish() or kub.WaitUntilMatch() then subsequently fetch the
// output out of the result.
func (kub *Kubectl) ExecPodCmdBackground(ctx context.Context, namespace string, pod string, cmd string, options ...ExecOptions) *CmdRes {
func (kub *Kubectl) ExecPodCmdBackground(ctx context.Context, namespace string, pod, container string, cmd string, options ...ExecOptions) *CmdRes {
if container != "" {
pod += " -c " + container
}
command := fmt.Sprintf("%s exec -n %s %s -- %s", KubectlCmd, namespace, pod, cmd)
return kub.ExecInBackground(ctx, command, options...)
}
Expand Down Expand Up @@ -3156,7 +3159,7 @@ func (kub *Kubectl) CiliumReport(commands ...string) {
ginkgoext.GinkgoPrint("Fetching command output from pods %s", pods)
for _, pod := range pods {
for _, cmd := range commands {
res = kub.ExecPodCmdBackground(ctx, CiliumNamespace, pod, cmd, ExecOptions{SkipLog: true})
res = kub.ExecPodCmdBackground(ctx, CiliumNamespace, pod, "cilium-agent", cmd, ExecOptions{SkipLog: true})
results = append(results, res)
}
}
Expand Down Expand Up @@ -3476,7 +3479,7 @@ func (kub *Kubectl) DumpCiliumCommandOutput(ctx context.Context, namespace strin
continue
}
//Remove bugtool artifact, so it'll be not used if any other fail test
_ = kub.ExecPodCmdBackground(ctx, namespace, pod, fmt.Sprintf("rm /tmp/%s", line))
_ = kub.ExecPodCmdBackground(ctx, namespace, pod, "cilium-agent", fmt.Sprintf("rm /tmp/%s", line))
}

}
Expand Down Expand Up @@ -4115,9 +4118,9 @@ func (kub *Kubectl) HubbleObserve(pod string, args string) *CmdRes {
}

// HubbleObserveFollow runs `hubble observe --follow --output=json <args>` on
// 'ns/pod' in the background. The process is stopped when ctx is cancelled.
// the Cilium pod 'ns/pod' in the background. The process is stopped when ctx is cancelled.
func (kub *Kubectl) HubbleObserveFollow(ctx context.Context, pod string, args string) *CmdRes {
return kub.ExecPodCmdBackground(ctx, CiliumNamespace, pod, fmt.Sprintf("hubble observe --follow --output=json %s", args))
return kub.ExecPodCmdBackground(ctx, CiliumNamespace, pod, "cilium-agent", fmt.Sprintf("hubble observe --follow --output=json %s", args))
}

// WaitForIPCacheEntry waits until the given ipAddr appears in "cilium bpf ipcache list"
Expand Down
4 changes: 2 additions & 2 deletions test/k8sT/Chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ var _ = SkipDescribeIf(helpers.RunsOn54Kernel, "K8sChaosTest", func() {
res := kubectl.ExecPodCmdBackground(
ctx,
helpers.DefaultNamespace,
netperfClient,
netperfClient, "",
fmt.Sprintf("netperf -l 60 -t TCP_STREAM -H %s", podsIps[netperfServer]))

restartCilium()
Expand All @@ -250,7 +250,7 @@ var _ = SkipDescribeIf(helpers.RunsOn54Kernel, "K8sChaosTest", func() {
res := kubectl.ExecPodCmdBackground(
ctx,
helpers.DefaultNamespace,
netperfClient,
netperfClient, "",
fmt.Sprintf("netperf -l 60 -t TCP_STREAM -H %s", podsIps[netperfServer]))

By("Installing the L3-L4 Policy")
Expand Down

0 comments on commit c95f6fd

Please sign in to comment.