@@ -8,13 +8,11 @@ import (
8
8
"fmt"
9
9
"net"
10
10
"strconv"
11
- "strings"
12
11
13
12
. "github.com/onsi/gomega"
14
13
"google.golang.org/protobuf/encoding/protojson"
15
14
16
15
observerpb "github.com/cilium/cilium/api/v1/observer"
17
- "github.com/cilium/cilium/pkg/annotation"
18
16
"github.com/cilium/cilium/pkg/hubble/defaults"
19
17
"github.com/cilium/cilium/pkg/identity"
20
18
. "github.com/cilium/cilium/test/ginkgo-ext"
@@ -38,7 +36,8 @@ var _ = Describe("K8sAgentHubbleTest", func() {
38
36
hubbleRelayService = "hubble-relay"
39
37
hubbleRelayAddress string
40
38
41
- demoPath string
39
+ demoPath string
40
+ visibilityPolicyPath string
42
41
43
42
app1Service = "app1-service"
44
43
app1Labels = "id=app1,zgroup=testapp"
@@ -51,37 +50,15 @@ var _ = Describe("K8sAgentHubbleTest", func() {
51
50
app1Port int
52
51
)
53
52
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" )
79
57
}
80
58
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 )
85
62
}
86
63
87
64
getFlowsFromRelay := func (args string ) []* observerpb.GetFlowsResponse {
@@ -123,6 +100,7 @@ var _ = Describe("K8sAgentHubbleTest", func() {
123
100
k8s1NodeName , _ = kubectl .GetNodeInfo (helpers .K8s1 )
124
101
125
102
demoPath = helpers .ManifestGet (kubectl .BasePath (), "demo.yaml" )
103
+ visibilityPolicyPath = helpers .ManifestGet (kubectl .BasePath (), "l7-policy-visibility.yaml" )
126
104
127
105
ciliumFilename = helpers .TimestampFilename ("cilium.yaml" )
128
106
DeployCiliumOptionsAndDNS (kubectl , ciliumFilename , map [string ]string {
@@ -225,8 +203,8 @@ var _ = Describe("K8sAgentHubbleTest", func() {
225
203
})
226
204
227
205
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 )
230
208
231
209
ctx , cancel := context .WithTimeout (context .Background (), helpers .MidCommandTimeout )
232
210
defer cancel ()
@@ -251,8 +229,8 @@ var _ = Describe("K8sAgentHubbleTest", func() {
251
229
})
252
230
253
231
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 )
256
234
257
235
res := kubectl .ExecPodCmd (namespaceForTest , appPods [helpers .App2 ],
258
236
helpers .CurlFail (fmt .Sprintf ("http://%s/public" , app1ClusterIP )))
0 commit comments