Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci/K8sHubble: Retry failed requests on hubble-relay #11708

Merged
merged 1 commit into from
May 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 47 additions & 16 deletions test/k8sT/hubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net"
"strconv"
"strings"
"time"

"github.com/asaskevich/govalidator"
"github.com/cilium/cilium/pkg/annotation"
Expand Down Expand Up @@ -82,6 +83,28 @@ var _ = Describe("K8sHubbleTest", func() {
res.ExpectSuccess("removing proxy visibility annotation failed")
}

hubbleObserveUntilMatch := func(hubbleNamespace, hubblePod, args, filter, expected string, timeout *helpers.TimeoutConfig) {
hubbleObserve := func() bool {
res := kubectl.HubbleObserve(hubbleNamespace, hubblePod, args)
res.ExpectSuccess("hubble observe invocation failed: %q", res.OutputPrettyPrint())

lines, err := res.FilterLines(filter)
Expect(err).Should(BeNil(), "hubble observe: invalid filter: %q", filter)

for _, line := range lines {
if line.String() == expected {
return true
}
}

return false
}

err := helpers.RepeatUntilTrue(hubbleObserve, timeout)
Expect(err).Should(BeNil(),
"hubble observe: filter %q never matched expected string %q", filter, expected)
}

BeforeAll(func() {
kubectl = helpers.CreateKubectl(helpers.K8s1VMName(), logger)
ciliumFilename = helpers.TimestampFilename("cilium.yaml")
Expand Down Expand Up @@ -177,18 +200,22 @@ var _ = Describe("K8sHubbleTest", func() {
})

It("Test L3/L4 Flow with hubble-relay", func() {
ctx, cancel := context.WithTimeout(context.Background(), helpers.MidCommandTimeout)
defer cancel()
follow := kubectl.HubbleObserveFollow(ctx, hubbleNamespace, hubblePodK8s1, fmt.Sprintf(
"--server %s --last 1 --type trace --from-pod %s/%s --to-namespace %s --to-label %s --to-port %d",
hubbleRelayAddress, namespaceForTest, appPods[helpers.App2], namespaceForTest, app1Labels, app1Port))

res := kubectl.ExecPodCmd(namespaceForTest, appPods[helpers.App2],
helpers.CurlFail(fmt.Sprintf("http://%s/public", app1ClusterIP)))
res.ExpectSuccess("%q cannot curl clusterIP %q", appPods[helpers.App2], app1ClusterIP)

err := follow.WaitUntilMatchFilterLineTimeout(`{$.Type}`, "L3_L4", helpers.ShortCommandTimeout)
Expect(err).To(BeNil(), fmt.Sprintf("hubble observe query timed out on %q", follow.OutputPrettyPrint()))
// In case a node was temporarily unavailable, hubble-relay will
// reconnect once it receives a new request. Therefore we retry
// in a 5 second interval.
hubbleObserveUntilMatch(hubbleNamespace, hubblePodK8s1, fmt.Sprintf(
"--server %s --last 1 --type trace --from-pod %s/%s --to-namespace %s --to-label %s --to-port %d",
hubbleRelayAddress, namespaceForTest, appPods[helpers.App2], namespaceForTest, app1Labels, app1Port),
`{$.Type}`, "L3_L4",
&helpers.TimeoutConfig{
Ticker: 5 * time.Second,
Timeout: helpers.MidCommandTimeout,
},
)
})

It("Test L7 Flow", func() {
Expand Down Expand Up @@ -220,18 +247,22 @@ var _ = Describe("K8sHubbleTest", func() {
addVisibilityAnnotation(namespaceForTest, app1Labels, "Ingress", "80", "TCP", "HTTP")
defer removeVisbilityAnnotation(namespaceForTest, app1Labels)

ctx, cancel := context.WithTimeout(context.Background(), helpers.MidCommandTimeout)
defer cancel()
follow := kubectl.HubbleObserveFollow(ctx, hubbleNamespace, hubblePodK8s1, fmt.Sprintf(
"--server %s --last 1 --type l7 --from-pod %s/%s --to-namespace %s --to-label %s --protocol http",
hubbleRelayAddress, namespaceForTest, appPods[helpers.App2], namespaceForTest, app1Labels))

res := kubectl.ExecPodCmd(namespaceForTest, appPods[helpers.App2],
helpers.CurlFail(fmt.Sprintf("http://%s/public", app1ClusterIP)))
res.ExpectSuccess("%q cannot curl clusterIP %q", appPods[helpers.App2], app1ClusterIP)

err := follow.WaitUntilMatchFilterLineTimeout(`{$.Type}`, "L7", helpers.ShortCommandTimeout)
Expect(err).To(BeNil(), fmt.Sprintf("hubble observe query timed out on %q", follow.OutputPrettyPrint()))
// In case a node was temporarily unavailable, hubble-relay will
// reconnect once it receives a new request. Therefore we retry
// in a 5 second interval.
hubbleObserveUntilMatch(hubbleNamespace, hubblePodK8s1, fmt.Sprintf(
"--server %s --last 1 --type l7 --from-pod %s/%s --to-namespace %s --to-label %s --protocol http",
hubbleRelayAddress, namespaceForTest, appPods[helpers.App2], namespaceForTest, app1Labels),
`{$.Type}`, "L7",
&helpers.TimeoutConfig{
Ticker: 5 * time.Second,
Timeout: helpers.MidCommandTimeout,
},
)
})
})
})