Skip to content

Commit 09fadeb

Browse files
committed
test/k8s: replace L7 visibility Pod annotations by L7 visibility policy
[ upstream commit 7793a07 ] L7 visibility using Pod annotations is deprecated and the feature will be removed in a successive commit. Switch K8sAgentHubbleTest still using it to use L7 visibility policy instead. Signed-off-by: Tobias Klauser <[email protected]>
1 parent 916bab2 commit 09fadeb

File tree

2 files changed

+30
-36
lines changed

2 files changed

+30
-36
lines changed

test/k8s/hubble.go

+14-36
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import (
88
"fmt"
99
"net"
1010
"strconv"
11-
"strings"
1211

1312
. "github.com/onsi/gomega"
1413
"google.golang.org/protobuf/encoding/protojson"
1514

1615
observerpb "github.com/cilium/cilium/api/v1/observer"
17-
"github.com/cilium/cilium/pkg/annotation"
1816
"github.com/cilium/cilium/pkg/hubble/defaults"
1917
"github.com/cilium/cilium/pkg/identity"
2018
. "github.com/cilium/cilium/test/ginkgo-ext"
@@ -38,7 +36,8 @@ var _ = Describe("K8sAgentHubbleTest", func() {
3836
hubbleRelayService = "hubble-relay"
3937
hubbleRelayAddress string
4038

41-
demoPath string
39+
demoPath string
40+
visibilityPolicyPath string
4241

4342
app1Service = "app1-service"
4443
app1Labels = "id=app1,zgroup=testapp"
@@ -51,37 +50,15 @@ var _ = Describe("K8sAgentHubbleTest", func() {
5150
app1Port int
5251
)
5352

54-
addVisibilityAnnotation := func(ns, podLabels, direction, port, l4proto, l7proto string) {
55-
visibilityAnnotation := fmt.Sprintf("<%s/%s/%s/%s>", direction, port, l4proto, l7proto)
56-
By("Adding visibility annotation %s on pod with labels %s", visibilityAnnotation, podLabels)
57-
58-
// Prints <node>=<ns>/<podname> for each pod the annotation was applied to
59-
res := kubectl.Exec(fmt.Sprintf("%s annotate pod -n %s -l %s %s=%q"+
60-
" -o 'jsonpath={.spec.nodeName}={.metadata.namespace}/{.metadata.name}{\"\\n\"}'",
61-
helpers.KubectlCmd,
62-
ns, app1Labels,
63-
annotation.ProxyVisibility, visibilityAnnotation))
64-
res.ExpectSuccess("adding proxy visibility annotation failed")
65-
66-
// For each pod, check that the Cilium proxy-statistics contain the new annotation
67-
expectedProxyState := strings.ToLower(visibilityAnnotation)
68-
for node, podName := range res.KVOutput() {
69-
ciliumPod, err := kubectl.GetCiliumPodOnNodeByName(node)
70-
Expect(err).To(BeNil())
71-
72-
// Extract annotation from endpoint model of pod. It does not have the l4proto, so we insert it manually.
73-
cmd := fmt.Sprintf("cilium-dbg endpoint get pod-name:%s"+
74-
" -o jsonpath='{range [*].status.policy.proxy-statistics[*]}<{.location}/{.port}/%s/{.protocol}>{\"\\n\"}{end}'",
75-
podName, strings.ToLower(l4proto))
76-
err = kubectl.CiliumExecUntilMatch(ciliumPod, cmd, expectedProxyState)
77-
Expect(err).To(BeNil(), "timed out waiting for endpoint to regenerate for visibility annotation")
78-
}
53+
addVisibilityPolicy := func(ns string) {
54+
By("Applying L7 visibility policy")
55+
res := kubectl.Apply(helpers.ApplyOptions{FilePath: visibilityPolicyPath, Namespace: ns})
56+
res.ExpectSuccess("could not create L7 visibility policy")
7957
}
8058

81-
removeVisibilityAnnotation := func(ns, podLabels string) {
82-
By("Removing visibility annotation on pod with labels %s", app1Labels)
83-
res := kubectl.Exec(fmt.Sprintf("%s annotate pod -n %s -l %s %s-", helpers.KubectlCmd, ns, podLabels, annotation.ProxyVisibility))
84-
res.ExpectSuccess("removing proxy visibility annotation failed")
59+
removeVisibilityPolicy := func(ns string) {
60+
By("Removing L7 visibility policy")
61+
kubectl.DeleteInNamespace(ns, visibilityPolicyPath)
8562
}
8663

8764
getFlowsFromRelay := func(args string) []*observerpb.GetFlowsResponse {
@@ -123,6 +100,7 @@ var _ = Describe("K8sAgentHubbleTest", func() {
123100
k8s1NodeName, _ = kubectl.GetNodeInfo(helpers.K8s1)
124101

125102
demoPath = helpers.ManifestGet(kubectl.BasePath(), "demo.yaml")
103+
visibilityPolicyPath = helpers.ManifestGet(kubectl.BasePath(), "l7-policy-visibility.yaml")
126104

127105
ciliumFilename = helpers.TimestampFilename("cilium.yaml")
128106
DeployCiliumOptionsAndDNS(kubectl, ciliumFilename, map[string]string{
@@ -225,8 +203,8 @@ var _ = Describe("K8sAgentHubbleTest", func() {
225203
})
226204

227205
It("Test L7 Flow", func() {
228-
defer removeVisibilityAnnotation(namespaceForTest, app1Labels)
229-
addVisibilityAnnotation(namespaceForTest, app1Labels, "Ingress", "80", "TCP", "HTTP")
206+
defer removeVisibilityPolicy(namespaceForTest)
207+
addVisibilityPolicy(namespaceForTest)
230208

231209
ctx, cancel := context.WithTimeout(context.Background(), helpers.MidCommandTimeout)
232210
defer cancel()
@@ -251,8 +229,8 @@ var _ = Describe("K8sAgentHubbleTest", func() {
251229
})
252230

253231
It("Test L7 Flow with hubble-relay", func() {
254-
defer removeVisibilityAnnotation(namespaceForTest, app1Labels)
255-
addVisibilityAnnotation(namespaceForTest, app1Labels, "Ingress", "80", "TCP", "HTTP")
232+
defer removeVisibilityPolicy(namespaceForTest)
233+
addVisibilityPolicy(namespaceForTest)
256234

257235
res := kubectl.ExecPodCmd(namespaceForTest, appPods[helpers.App2],
258236
helpers.CurlFail(fmt.Sprintf("http://%s/public", app1ClusterIP)))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: "cilium.io/v2"
2+
kind: CiliumNetworkPolicy
3+
metadata:
4+
name: "l7-visibility"
5+
spec:
6+
endpointSelector:
7+
matchLabels:
8+
id: app1
9+
zgroup: testapp
10+
ingress:
11+
- toPorts:
12+
- ports:
13+
- port: "80"
14+
protocol: TCP
15+
rules:
16+
http: [{}]

0 commit comments

Comments
 (0)