|
| 1 | +# ┌───────────┐ ┌───────────┐ ┌───────────┐ |
| 2 | +# │namespace-a│ │namespace-b│ │namespace-c│ |
| 3 | +# │ │ │ │ │ │ |
| 4 | +# │ ┌───────┐ │ │ ┌───────┐ │ │ ┌───────┐ │ |
| 5 | +# │ │ pod-1 │◀─────│ pod-1 │ │ │ │ pod-1 │ │ |
| 6 | +# │ └───────┘────┐│ └───────┘ │ │ └───────┘ │ |
| 7 | +# │ ┌───────┐ │ ││ ┌───────┐ │ │ ┌───────┐ │ |
| 8 | +# │ │ pod-2 │ │ └─▶ pod-2 │ │ │ │ pod-2 │ │ |
| 9 | +# │ └───────┘ │ │ └───────┘ │ │ └───────┘ │ |
| 10 | +# └───────────┘ └───────────┘ └───────────┘ |
| 11 | +--- |
| 12 | +apiVersion: v1 |
| 13 | +kind: Namespace |
| 14 | +metadata: |
| 15 | + name: test-namespace-a |
| 16 | + labels: |
| 17 | + name: test-namespace-a |
| 18 | +--- |
| 19 | +apiVersion: v1 |
| 20 | +kind: Namespace |
| 21 | +metadata: |
| 22 | + name: test-namespace-b |
| 23 | + labels: |
| 24 | + name: test-namespace-b |
| 25 | +--- |
| 26 | +apiVersion: v1 |
| 27 | +kind: Namespace |
| 28 | +metadata: |
| 29 | + name: test-namespace-c |
| 30 | + labels: |
| 31 | + name: test-namespace-c |
| 32 | +--- |
| 33 | +apiVersion: "k8s.cni.cncf.io/v1" |
| 34 | +kind: NetworkAttachmentDefinition |
| 35 | +metadata: |
| 36 | + namespace: test-namespace-a |
| 37 | + name: macvlan1-namespace-a |
| 38 | +spec: |
| 39 | + config: '{ |
| 40 | + "cniVersion": "0.3.1", |
| 41 | + "name": "macvlan1-namespace-a", |
| 42 | + "plugins": [ |
| 43 | + { |
| 44 | + "type": "macvlan", |
| 45 | + "mode": "bridge", |
| 46 | + "ipam":{ |
| 47 | + "type":"host-local", |
| 48 | + "subnet":"2.2.10.0/24", |
| 49 | + "rangeStart":"2.2.10.10", |
| 50 | + "rangeEnd":"2.2.10.19" |
| 51 | + } |
| 52 | + }] |
| 53 | + }' |
| 54 | +--- |
| 55 | +apiVersion: "k8s.cni.cncf.io/v1" |
| 56 | +kind: NetworkAttachmentDefinition |
| 57 | +metadata: |
| 58 | + namespace: test-namespace-b |
| 59 | + name: macvlan1-namespace-b |
| 60 | +spec: |
| 61 | + config: '{ |
| 62 | + "cniVersion": "0.3.1", |
| 63 | + "name": "macvlan1-namespace-b", |
| 64 | + "plugins": [ |
| 65 | + { |
| 66 | + "type": "macvlan", |
| 67 | + "mode": "bridge", |
| 68 | + "ipam":{ |
| 69 | + "type":"host-local", |
| 70 | + "subnet":"2.2.10.0/24", |
| 71 | + "rangeStart":"2.2.10.20", |
| 72 | + "rangeEnd":"2.2.10.29" |
| 73 | + } |
| 74 | + }] |
| 75 | + }' |
| 76 | +--- |
| 77 | +apiVersion: "k8s.cni.cncf.io/v1" |
| 78 | +kind: NetworkAttachmentDefinition |
| 79 | +metadata: |
| 80 | + namespace: test-namespace-c |
| 81 | + name: macvlan1-namespace-c |
| 82 | +spec: |
| 83 | + config: '{ |
| 84 | + "cniVersion": "0.3.1", |
| 85 | + "name": "macvlan1-namespace-c", |
| 86 | + "plugins": [ |
| 87 | + { |
| 88 | + "type": "macvlan", |
| 89 | + "mode": "bridge", |
| 90 | + "ipam":{ |
| 91 | + "type":"host-local", |
| 92 | + "subnet":"2.2.10.0/24", |
| 93 | + "rangeStart":"2.2.10.30", |
| 94 | + "rangeEnd":"2.2.10.39" |
| 95 | + } |
| 96 | + }] |
| 97 | + }' |
| 98 | +--- |
| 99 | + |
| 100 | + |
| 101 | +# Pods in namespace A |
| 102 | +apiVersion: v1 |
| 103 | +kind: Pod |
| 104 | +metadata: |
| 105 | + name: pod-1 |
| 106 | + namespace: test-namespace-a |
| 107 | + annotations: |
| 108 | + k8s.v1.cni.cncf.io/networks: macvlan1-namespace-a |
| 109 | + labels: |
| 110 | + name: pod-1 |
| 111 | +spec: |
| 112 | + containers: |
| 113 | + - name: macvlan-worker1 |
| 114 | + image: ghcr.io/k8snetworkplumbingwg/multi-networkpolicy-iptables:e2e-test |
| 115 | + command: ["nc", "-klp", "5555"] |
| 116 | + securityContext: |
| 117 | + privileged: true |
| 118 | +--- |
| 119 | +apiVersion: v1 |
| 120 | +kind: Pod |
| 121 | +metadata: |
| 122 | + name: pod-2 |
| 123 | + namespace: test-namespace-a |
| 124 | + annotations: |
| 125 | + k8s.v1.cni.cncf.io/networks: macvlan1-namespace-a |
| 126 | + labels: |
| 127 | + name: pod-2 |
| 128 | +spec: |
| 129 | + containers: |
| 130 | + - name: macvlan-worker1 |
| 131 | + image: ghcr.io/k8snetworkplumbingwg/multi-networkpolicy-iptables:e2e-test |
| 132 | + command: ["nc", "-klp", "5555"] |
| 133 | + securityContext: |
| 134 | + privileged: true |
| 135 | +--- |
| 136 | +# Pods in namespace B |
| 137 | +apiVersion: v1 |
| 138 | +kind: Pod |
| 139 | +metadata: |
| 140 | + name: pod-1 |
| 141 | + namespace: test-namespace-b |
| 142 | + annotations: |
| 143 | + k8s.v1.cni.cncf.io/networks: macvlan1-namespace-b |
| 144 | + labels: |
| 145 | + name: pod-1 |
| 146 | +spec: |
| 147 | + containers: |
| 148 | + - name: macvlan-worker1 |
| 149 | + image: ghcr.io/k8snetworkplumbingwg/multi-networkpolicy-iptables:e2e-test |
| 150 | + command: ["nc", "-klp", "5555"] |
| 151 | + securityContext: |
| 152 | + privileged: true |
| 153 | +--- |
| 154 | +apiVersion: v1 |
| 155 | +kind: Pod |
| 156 | +metadata: |
| 157 | + name: pod-2 |
| 158 | + namespace: test-namespace-b |
| 159 | + annotations: |
| 160 | + k8s.v1.cni.cncf.io/networks: macvlan1-namespace-b |
| 161 | + labels: |
| 162 | + name: pod-2 |
| 163 | +spec: |
| 164 | + containers: |
| 165 | + - name: macvlan-worker1 |
| 166 | + image: ghcr.io/k8snetworkplumbingwg/multi-networkpolicy-iptables:e2e-test |
| 167 | + command: ["nc", "-klp", "5555"] |
| 168 | + securityContext: |
| 169 | + privileged: true |
| 170 | +--- |
| 171 | +# Pods in namespace C |
| 172 | +apiVersion: v1 |
| 173 | +kind: Pod |
| 174 | +metadata: |
| 175 | + name: pod-1 |
| 176 | + namespace: test-namespace-c |
| 177 | + annotations: |
| 178 | + k8s.v1.cni.cncf.io/networks: macvlan1-namespace-c |
| 179 | + labels: |
| 180 | + name: pod-1 |
| 181 | +spec: |
| 182 | + containers: |
| 183 | + - name: macvlan-worker1 |
| 184 | + image: ghcr.io/k8snetworkplumbingwg/multi-networkpolicy-iptables:e2e-test |
| 185 | + command: ["nc", "-klp", "5555"] |
| 186 | + securityContext: |
| 187 | + privileged: true |
| 188 | +--- |
| 189 | +apiVersion: v1 |
| 190 | +kind: Pod |
| 191 | +metadata: |
| 192 | + name: pod-2 |
| 193 | + namespace: test-namespace-c |
| 194 | + annotations: |
| 195 | + k8s.v1.cni.cncf.io/networks: macvlan1-namespace-c |
| 196 | + labels: |
| 197 | + name: pod-2 |
| 198 | +spec: |
| 199 | + containers: |
| 200 | + - name: macvlan-worker1 |
| 201 | + image: ghcr.io/k8snetworkplumbingwg/multi-networkpolicy-iptables:e2e-test |
| 202 | + command: ["nc", "-klp", "5555"] |
| 203 | + securityContext: |
| 204 | + privileged: true |
| 205 | +--- |
| 206 | +apiVersion: k8s.cni.cncf.io/v1beta1 |
| 207 | +kind: MultiNetworkPolicy |
| 208 | +metadata: |
| 209 | + name: test-multinetwork-policy-namespace-a |
| 210 | + namespace: test-namespace-a |
| 211 | + annotations: |
| 212 | + k8s.v1.cni.cncf.io/policy-for: test-namespace-a/macvlan1-namespace-a,test-namespace-b/macvlan1-namespace-b,test-namespace-c/macvlan1-namespace-c |
| 213 | +spec: |
| 214 | + podSelector: |
| 215 | + matchLabels: |
| 216 | + name: pod-1 |
| 217 | + ingress: |
| 218 | + - from: |
| 219 | + - podSelector: |
| 220 | + matchLabels: |
| 221 | + name: pod-1 |
| 222 | + namespaceSelector: |
| 223 | + matchLabels: |
| 224 | + name: test-namespace-b |
| 225 | + egress: |
| 226 | + - to: |
| 227 | + - podSelector: |
| 228 | + matchLabels: |
| 229 | + name: pod-2 |
| 230 | + namespaceSelector: |
| 231 | + matchLabels: |
| 232 | + name: test-namespace-b |
| 233 | + policyTypes: |
| 234 | + - Ingress |
| 235 | + - Egress |
0 commit comments