Skip to content

Commit 138e5fb

Browse files
authored
[virtual-machine] Use external IP for egress traffic for PortList method too (#1349)
Signed-off-by: Andrei Kvapil <[email protected]> <!-- Thank you for making a contribution! Here are some tips for you: - Start the PR title with the [label] of Cozystack component: - For system components: [platform], [system], [linstor], [cilium], [kube-ovn], [dashboard], [cluster-api], etc. - For managed apps: [apps], [tenant], [kubernetes], [postgres], [virtual-machine] etc. - For development and maintenance: [tests], [ci], [docs], [maintenance]. - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same [label] as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note [virtual-machine] Use external IP for egress traffic for PortList method too ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Default network policies for Virtual Machine and VM Instance: ingress from cluster/world, egress to world, optional port-based ingress when using a port list. - Services now always include whole-IP annotation. - VM workloads default to blocking external communication via annotation. - Tenant network policy now applies only to workloads explicitly labeled to allow external communication. - **Chores** - Version bumps: Tenant 1.13.0, Virtual Machine 0.14.0, VM Instance 0.12.0. - Updated versions map and added a migration script to advance cluster component versions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 33691c2 + a4aeeca commit 138e5fb

10 files changed

Lines changed: 83 additions & 55 deletions

File tree

‎packages/apps/tenant/Chart.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ description: Separated tenant namespace
44
icon: /logos/tenant.svg
55

66
type: application
7-
version: 1.12.0
7+
version: 1.13.0

‎packages/apps/tenant/templates/networkpolicy.yaml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ metadata:
2020
name: allow-external-communication
2121
namespace: {{ include "tenant.name" . }}
2222
spec:
23-
endpointSelector: {}
23+
endpointSelector:
24+
matchExpressions:
25+
- key: policy.cozystack.io/allow-external-communication
26+
operator: NotIn
27+
values: ["false"]
2428
ingress:
2529
- fromEntities:
2630
- world

‎packages/apps/versions_map‎

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -164,55 +164,15 @@ tcp-balancer 0.4.2 4369b031
164164
tcp-balancer 0.5.0 08cb7c0f
165165
tcp-balancer 0.5.1 c02a3818
166166
tcp-balancer 0.6.0 HEAD
167-
tenant 1.10.0 4369b031
168-
tenant 1.11.0 08cb7c0f
169-
tenant 1.11.1 28c9fcd6
170-
tenant 1.11.2 c02a3818
171-
tenant 1.12.0 HEAD
172-
virtual-machine 0.1.4 f2015d65
173-
virtual-machine 0.1.5 263e47be
174-
virtual-machine 0.2.0 c0685f43
175-
virtual-machine 0.3.0 6c5cf5bf
176-
virtual-machine 0.4.0 b8e33d19
177-
virtual-machine 0.5.0 1ec10165
178-
virtual-machine 0.6.0 4e68e65c
179-
virtual-machine 0.7.0 e23286a3
180-
virtual-machine 0.7.1 0ab39f20
181-
virtual-machine 0.8.0 3fa4dd3a
182-
virtual-machine 0.8.1 93c46161
183-
virtual-machine 0.8.2 de19450f
184-
virtual-machine 0.9.0 721c12a7
185-
virtual-machine 0.9.1 93bdf411
186-
virtual-machine 0.10.0 6130f43d
187-
virtual-machine 0.10.2 632224a3
188-
virtual-machine 0.11.0 4369b031
189-
virtual-machine 0.12.0 acd4663a
190-
virtual-machine 0.12.1 909208ba
191-
virtual-machine 0.12.2 8ddbe32e
192-
virtual-machine 0.12.3 c02a3818
193-
virtual-machine 0.13.0 HEAD
167+
tenant 1.13.0 HEAD
168+
virtual-machine 0.14.0 HEAD
194169
vm-disk 0.1.0 d971f2ff
195170
vm-disk 0.1.1 6130f43d
196171
vm-disk 0.1.2 632224a3
197172
vm-disk 0.2.0 4369b031
198173
vm-disk 0.3.0 c02a3818
199174
vm-disk 0.4.0 HEAD
200-
vm-instance 0.1.0 1ec10165
201-
vm-instance 0.2.0 84f3ccc0
202-
vm-instance 0.3.0 4e68e65c
203-
vm-instance 0.4.0 e23286a3
204-
vm-instance 0.4.1 0ab39f20
205-
vm-instance 0.5.0 3fa4dd3a
206-
vm-instance 0.5.1 de19450f
207-
vm-instance 0.6.0 721c12a7
208-
vm-instance 0.7.0 6130f43d
209-
vm-instance 0.7.2 632224a3
210-
vm-instance 0.8.0 4369b031
211-
vm-instance 0.9.0 acd4663a
212-
vm-instance 0.10.0 909208ba
213-
vm-instance 0.10.1 8ddbe32e
214-
vm-instance 0.10.2 c02a3818
215-
vm-instance 0.11.0 HEAD
175+
vm-instance 0.12.0 HEAD
216176
vpn 0.1.0 263e47be
217177
vpn 0.2.0 53f2365e
218178
vpn 0.3.0 6c5cf5bf

‎packages/apps/virtual-machine/Chart.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ type: application
1717
# This is the chart version. This version number should be incremented each time you make changes
1818
# to the chart and its templates, including the app version.
1919
# Versions are expected to follow Semantic Versioning (https://semver.org/)
20-
version: 0.13.0
20+
version: 0.14.0
2121

2222
# This is the version number of the application being deployed. This version number should be
2323
# incremented each time you make changes to the application. Versions are not expected to
2424
# follow Semantic Versioning. They should reflect the version the application is using.
2525
# It is recommended to use it with quotes.
26-
appVersion: 0.13.0
26+
appVersion: 0.14.0

‎packages/apps/virtual-machine/templates/service.yaml‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ metadata:
66
name: {{ include "virtual-machine.fullname" . }}
77
labels:
88
{{- include "virtual-machine.labels" . | nindent 4 }}
9-
{{- if eq .Values.externalMethod "WholeIP" }}
109
annotations:
1110
networking.cozystack.io/wholeIP: "true"
12-
{{- end }}
1311
spec:
1412
type: {{ ternary "LoadBalancer" "ClusterIP" .Values.external }}
1513
externalTrafficPolicy: Local
16-
{{- if (include "cozy-lib.network.disableLoadBalancerNodePorts" $ | fromYaml) }}
14+
{{- if ((include "cozy-lib.network.disableLoadBalancerNodePorts" $) | fromYaml) }}
1715
allocateLoadBalancerNodePorts: false
1816
{{- end }}
1917
selector:
@@ -29,3 +27,27 @@ spec:
2927
{{- end }}
3028
{{- end }}
3129
{{- end }}
30+
---
31+
apiVersion: cilium.io/v2
32+
kind: CiliumNetworkPolicy
33+
metadata:
34+
name: {{ include "virtual-machine.fullname" . }}
35+
spec:
36+
endpointSelector:
37+
matchLabels:
38+
{{- include "virtual-machine.selectorLabels" . | nindent 6 }}
39+
ingress:
40+
- fromEntities:
41+
- cluster
42+
- fromEntities:
43+
- world
44+
{{- if eq .Values.externalMethod "PortList" }}
45+
toPorts:
46+
- ports:
47+
{{- range .Values.externalPorts }}
48+
- port: {{ quote . }}
49+
{{- end }}
50+
{{- end }}
51+
egress:
52+
- toEntities:
53+
- world

‎packages/apps/virtual-machine/templates/vm.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ spec:
6262
template:
6363
metadata:
6464
annotations:
65+
policy.cozystack.io/allow-external-communication: "false"
6566
kubevirt.io/allow-pod-bridge-network-live-migration: "true"
6667
labels:
6768
{{- include "virtual-machine.labels" . | nindent 8 }}

‎packages/apps/vm-instance/Chart.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ type: application
1717
# This is the chart version. This version number should be incremented each time you make changes
1818
# to the chart and its templates, including the app version.
1919
# Versions are expected to follow Semantic Versioning (https://semver.org/)
20-
version: 0.11.0
20+
version: 0.12.0
2121

2222
# This is the version number of the application being deployed. This version number should be
2323
# incremented each time you make changes to the application. Versions are not expected to
2424
# follow Semantic Versioning. They should reflect the version the application is using.
2525
# It is recommended to use it with quotes.
26-
appVersion: 0.11.0
26+
appVersion: 0.12.0

‎packages/apps/vm-instance/templates/service.yaml‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ metadata:
66
name: {{ include "virtual-machine.fullname" . }}
77
labels:
88
{{- include "virtual-machine.labels" . | nindent 4 }}
9-
{{- if eq .Values.externalMethod "WholeIP" }}
109
annotations:
1110
networking.cozystack.io/wholeIP: "true"
12-
{{- end }}
1311
spec:
1412
type: {{ ternary "LoadBalancer" "ClusterIP" .Values.external }}
1513
externalTrafficPolicy: Local
16-
{{- if (include "cozy-lib.network.disableLoadBalancerNodePorts" $ | fromYaml) }}
14+
{{- if ((include "cozy-lib.network.disableLoadBalancerNodePorts" $) | fromYaml) }}
1715
allocateLoadBalancerNodePorts: false
1816
{{- end }}
1917
selector:
@@ -29,3 +27,27 @@ spec:
2927
{{- end }}
3028
{{- end }}
3129
{{- end }}
30+
---
31+
apiVersion: cilium.io/v2
32+
kind: CiliumNetworkPolicy
33+
metadata:
34+
name: {{ include "virtual-machine.fullname" . }}
35+
spec:
36+
endpointSelector:
37+
matchLabels:
38+
{{- include "virtual-machine.selectorLabels" . | nindent 6 }}
39+
ingress:
40+
- fromEntities:
41+
- cluster
42+
- fromEntities:
43+
- world
44+
{{- if eq .Values.externalMethod "PortList" }}
45+
toPorts:
46+
- ports:
47+
{{- range .Values.externalPorts }}
48+
- port: {{ quote . }}
49+
{{- end }}
50+
{{- end }}
51+
egress:
52+
- toEntities:
53+
- world

‎packages/apps/vm-instance/templates/vm.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ spec:
2626
template:
2727
metadata:
2828
annotations:
29+
policy.cozystack.io/allow-external-communication: "false"
2930
kubevirt.io/allow-pod-bridge-network-live-migration: "true"
3031
labels:
3132
{{- include "virtual-machine.labels" . | nindent 8 }}

‎scripts/migrations/18‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
# Migration 18 --> 19
3+
4+
# Upgrade tenants.apps to new chart version
5+
kubectl get tenants.apps.cozystack.io -A --no-headers --output=custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' | while read NAMESPACE NAME; do
6+
kubectl patch tenants.apps.cozystack.io -n "$NAMESPACE" "$NAME" --type merge -p '{"appVersion":"1.13.0"}'
7+
done
8+
9+
# Upgrade virtualmachines.apps to new chart version
10+
kubectl get virtualmachines.apps.cozystack.io -A --no-headers --output=custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' | while read NAMESPACE NAME; do
11+
kubectl patch virtualmachines.apps.cozystack.io -n "$NAMESPACE" "$NAME" --type merge -p '{"appVersion":"1.14.0"}'
12+
done
13+
kubectl get vminstances.apps.cozystack.io -A --no-headers --output=custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' | while read NAMESPACE NAME; do
14+
kubectl patch vminstances.apps.cozystack.io -n "$NAMESPACE" "$NAME" --type merge -p '{"appVersion":"1.12.0"}'
15+
done
16+
17+
# Write version to cozystack-version config
18+
kubectl create configmap -n cozy-system cozystack-version --from-literal=version=19 --dry-run=client -o yaml | kubectl apply -f-

0 commit comments

Comments
 (0)