|
1 | | -suite: tenant monitoring ingest (logs and metrics) crosses the tenant boundary |
2 | | -# A sub-tenant (and the guest clusters inside it) that resolves its monitoring |
3 | | -# to an ancestor must be able to write both metrics (vminsert) and logs |
4 | | -# (vlinsert) to that ancestor's ingest endpoints. The egress opens the write |
5 | | -# hop; the ancestor's ingress must accept it. |
| 1 | +suite: tenant monitoring ingest egress reaches the monitoring owner at any depth |
| 2 | +# A tenant (and the guest clusters inside it) that resolves its monitoring to an |
| 3 | +# ancestor must be able to write both metrics (vminsert) and logs (vlinsert) to |
| 4 | +# that owner's ingest endpoints. The owner is inherited through |
| 5 | +# _namespace.monitoring, so the egress targets the real owner directly rather |
| 6 | +# than walking the namespace prefix (which never reaches tenant-root from below |
| 7 | +# the first level). The ancestor already accepts the ingress via its |
| 8 | +# allow-external-communication policy (fromEntities: cluster), so no extra |
| 9 | +# ingress policy is rendered here. |
6 | 10 | templates: |
7 | 11 | - templates/networkpolicy.yaml |
8 | 12 | release: |
|
12 | 16 | _cluster: |
13 | 17 | bundle-name: paas-full |
14 | 18 | tests: |
15 | | - - it: lets a sub-tenant egress to the ancestor's vlinsert as well as vminsert |
| 19 | + - it: egresses to the parent owner's vminsert and vlinsert in one rule |
16 | 20 | release: |
17 | 21 | name: tenant-sub |
18 | 22 | namespace: tenant-ktj |
19 | 23 | set: |
20 | 24 | _cluster: |
21 | 25 | bundle-name: paas-full |
| 26 | + _namespace: |
| 27 | + monitoring: tenant-ktj |
22 | 28 | documentSelector: |
23 | 29 | path: metadata.name |
24 | 30 | value: tenant-ktj-sub-egress |
25 | 31 | asserts: |
26 | 32 | - isKind: |
27 | 33 | of: CiliumClusterwideNetworkPolicy |
28 | 34 | - contains: |
29 | | - path: spec.egress[1].toEndpoints |
| 35 | + path: spec.egress |
30 | 36 | content: |
31 | | - matchLabels: |
32 | | - "k8s:app.kubernetes.io/name": "vminsert" |
33 | | - "k8s:io.kubernetes.pod.namespace": tenant-ktj |
| 37 | + toEndpoints: |
| 38 | + - matchLabels: |
| 39 | + "k8s:io.kubernetes.pod.namespace": tenant-ktj |
| 40 | + matchExpressions: |
| 41 | + - key: "k8s:app.kubernetes.io/name" |
| 42 | + operator: In |
| 43 | + values: |
| 44 | + - vminsert |
| 45 | + - vlinsert |
| 46 | + |
| 47 | + - it: targets the owning tenant-root even when the owner is not the parent |
| 48 | + # Common layout: monitoring lives only in tenant-root and every descendant |
| 49 | + # inherits it. A namespace-prefix walk from tenant-ktj-a would emit |
| 50 | + # tenant-ktj and tenant-ktj-a and never tenant-root, dropping the traffic. |
| 51 | + release: |
| 52 | + name: tenant-b |
| 53 | + namespace: tenant-ktj-a |
| 54 | + set: |
| 55 | + _cluster: |
| 56 | + bundle-name: paas-full |
| 57 | + _namespace: |
| 58 | + monitoring: tenant-root |
| 59 | + documentSelector: |
| 60 | + path: metadata.name |
| 61 | + value: tenant-ktj-a-b-egress |
| 62 | + asserts: |
| 63 | + - isKind: |
| 64 | + of: CiliumClusterwideNetworkPolicy |
34 | 65 | - contains: |
35 | | - path: spec.egress[1].toEndpoints |
| 66 | + path: spec.egress |
36 | 67 | content: |
37 | | - matchLabels: |
38 | | - "k8s:app.kubernetes.io/name": "vlinsert" |
39 | | - "k8s:io.kubernetes.pod.namespace": tenant-ktj |
| 68 | + toEndpoints: |
| 69 | + - matchLabels: |
| 70 | + "k8s:io.kubernetes.pod.namespace": tenant-root |
| 71 | + matchExpressions: |
| 72 | + - key: "k8s:app.kubernetes.io/name" |
| 73 | + operator: In |
| 74 | + values: |
| 75 | + - vminsert |
| 76 | + - vlinsert |
40 | 77 |
|
41 | | - - it: opens the ancestor's ingress on vlinsert and vminsert for its sub-tenants |
| 78 | + - it: renders no monitoring egress rule when the tenant owns its monitoring |
| 79 | + # Owner resolves to the tenant itself, so writes stay in-namespace (covered |
| 80 | + # by allow-internal-communication) and no cross-namespace rule is added. |
42 | 81 | set: |
43 | 82 | monitoring: true |
44 | 83 | _cluster: |
45 | 84 | bundle-name: paas-full |
46 | 85 | documentSelector: |
47 | 86 | path: metadata.name |
48 | | - value: tenant-ktj-ingress-monitoring |
| 87 | + value: tenant-ktj-egress |
49 | 88 | asserts: |
50 | 89 | - isKind: |
51 | 90 | of: CiliumClusterwideNetworkPolicy |
52 | 91 | - equal: |
53 | | - path: spec.endpointSelector.matchExpressions[0].values |
| 92 | + path: spec.egress |
54 | 93 | value: |
55 | | - - vlinsert |
56 | | - - vminsert |
57 | | - - equal: |
58 | | - path: spec.ingress[0].fromEndpoints[0].matchLabels["k8s:io.cilium.k8s.namespace.labels.namespace.cozystack.io/monitoring"] |
59 | | - value: tenant-ktj |
| 94 | + - toEndpoints: |
| 95 | + - matchLabels: |
| 96 | + "k8s:io.cilium.k8s.namespace.labels.tenant.cozystack.io/tenant-ktj": "" |
| 97 | + - toEndpoints: |
| 98 | + - matchLabels: |
| 99 | + "k8s:app.kubernetes.io/instance": "etcd" |
| 100 | + "k8s:io.kubernetes.pod.namespace": tenant-root |
| 101 | + - toEndpoints: |
| 102 | + - matchLabels: |
| 103 | + cozystack.io/service: ingress |
| 104 | + "k8s:io.kubernetes.pod.namespace": tenant-root |
60 | 105 |
|
61 | | - - it: does not open the ingest ingress when the tenant has no monitoring |
| 106 | + - it: does not render the removed ingress-monitoring policy |
62 | 107 | set: |
63 | | - monitoring: false |
| 108 | + monitoring: true |
64 | 109 | _cluster: |
65 | 110 | bundle-name: paas-full |
66 | 111 | asserts: |
|
0 commit comments