Skip to content

Commit aa27d87

Browse files
authored
Opt-in for network-policies provided by hco-bundle for CNAO and its components pods (#2341)
* manifests: Add opt-in labels for hco-bundle network-policies The hco-bundle should provide network-policies allow operators work as expected under network restrictions (global deny-all network-policy). The provided NPs affects pods who has the appropriate labels. Opt-in for hco-bundle NPs by adding the following labels: 1. hco.kubevirt.io/allow-access-cluster-services Allow CNAO pods egress access the cluster API and DNS. 2. hco.kubevirt.io/allow-prometheus-access Allow prometheus pods ingress the metrics endpoint With this change the manifest-templator & csv-gen should produce the project Deployment and CSV with the above labels. Allowing CNAO to operate under network restrictions when installed by HCO. Signed-off-by: Or Mergi <[email protected]> * KMP: Add opt-in labels for hco-bundle network-policies The hco-bundle should provide network-policies allow operators work as expected under network restrictions (global deny-all network-policy). The provided NPs affects pods who have the appropriate labels. Opt-in for hco-bundle NPs by adding the following labels: 1. hco.kubevirt.io/allow-access-cluster-services    Allow KMP pods egress access the cluster API and DNS. 2. hco.kubevirt.io/allow-prometheus-access    Allow prometheus pods ingress the controller-manager metrics endpoint With this change CNAO should generate and install kubemacpool manifests with the above labels. Allowing kubemacpool operate under network restrictions when installed by CNAO and HCO. Signed-off-by: Or Mergi <[email protected]> * KSD: Add opt-in labels for hco-bundle network-policies The hco-bundle should provide network-policies allow operators work as expected under network restrictions (global deny-all network-policy). The provided NPs affects pods who have the appropriate labels. Opt-in for hco-bundle NPs by adding the "hco.kubevirt.io/allow-access-cluster-services" label. It allows kube-secondary-dns pods access the cluster API and DNS. With this change CNAO should generate and install kube-secondary- dns manifests with the above labels. Allowing ube-secondary-dns operate under network restrictions when installed by CNAO and HCO. Signed-off-by: Or Mergi <[email protected]> * ipam-ext: Add opt-in labels for hco-bundle network-policies The hco-bundle should provide network-policies allow operators work as expected under network restrictions (global deny-all network-policy). The provided NPs affects pods who have the appropriate labels. Opt-in for hco-bundle NPs by adding the "hco.kubevirt.io/allow-access-cluster-services" label. It allows kubevirt-ipam-contoller pods access the cluster API and DNS. With this change CNAO should generate and install kubevirt-ipam-contoller manifests with the above labels. Allowing kubevirt-ipam-contoller operate under network restrictions when installed by CNAO and HCO. Signed-off-by: Or Mergi <[email protected]> --------- Signed-off-by: Or Mergi <[email protected]>
1 parent 6fd50c0 commit aa27d87

File tree

7 files changed

+30
-0
lines changed

7 files changed

+30
-0
lines changed

data/kube-secondary-dns/secondarydns.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ spec:
7373
metadata:
7474
labels:
7575
k8s-app: secondary-dns
76+
hco.kubevirt.io/allow-access-cluster-services: ""
7677
annotations:
7778
kubectl.kubernetes.io/default-container: status-monitor
7879
openshift.io/required-scc: "restricted-v2"

data/kubemacpool/kubemacpool.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ spec:
153153
app: kubemacpool
154154
control-plane: cert-manager
155155
controller-tools.k8s.io: "1.0"
156+
hco.kubevirt.io/allow-access-cluster-services: ""
156157
spec:
157158
affinity: {{ toYaml .Placement.Affinity | nindent 8 }}
158159
containers:
@@ -245,6 +246,8 @@ spec:
245246
app: kubemacpool
246247
control-plane: mac-controller-manager
247248
controller-tools.k8s.io: "1.0"
249+
hco.kubevirt.io/allow-access-cluster-services: ""
250+
hco.kubevirt.io/allow-prometheus-access: ""
248251
spec:
249252
affinity: {{ toYaml .Placement.Affinity | nindent 8 }}
250253
containers:

data/kubevirt-ipam-controller/001-kubevirtipamcontroller.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ spec:
178178
labels:
179179
app: ipam-virt-workloads
180180
control-plane: manager
181+
hco.kubevirt.io/allow-access-cluster-services: ""
181182
spec:
182183
containers:
183184
- args:

hack/components/bump-kube-secondary-dns.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function __parametize_by_object() {
3535
yaml-utils::set_param ${f} spec.template.spec.affinity '{{ toYaml .Placement.Affinity | nindent 8 }}'
3636
yaml-utils::set_param ${f} spec.template.spec.tolerations '{{ toYaml .Placement.Tolerations | nindent 8 }}'
3737
yaml-utils::set_param ${f} 'spec.template.metadata.annotations."openshift.io/required-scc"' '"restricted-v2"'
38+
yaml-utils::set_param ${f} 'spec.template.metadata.labels."hco.kubevirt.io/allow-access-cluster-services"' '""'
3839
yaml-utils::remove_single_quotes_from_yaml ${f}
3940
;;
4041
./ServiceAccount_secondary.yaml)

hack/components/bump-kubemacpool.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ patches:
5959
target:
6060
version: v1
6161
kind: Namespace
62+
- path: add-pod-template-label-allow-access-cluster-services_patch.yaml
63+
target:
64+
version: v1
65+
kind: Deployment
66+
- path: add-pod-template-label-allow-prometheus-access_patch.yaml
67+
target:
68+
version: v1
69+
kind: Deployment
70+
name: mac-controller-manager
6271
EOF
6372

6473
cat <<EOF > config/cnao/cnao_kubemacpool_manager_patch.yaml
@@ -145,6 +154,16 @@ EOF
145154
path: /metadata/labels
146155
EOF
147156

157+
cat <<EOF > config/cnao/add-pod-template-label-allow-access-cluster-services_patch.yaml
158+
- op: add
159+
path: /spec/template/metadata/labels/hco.kubevirt.io~1allow-access-cluster-services
160+
value: ""
161+
EOF
162+
cat <<EOF > config/cnao/add-pod-template-label-allow-prometheus-access_patch.yaml
163+
- op: add
164+
path: /spec/template/metadata/labels/hco.kubevirt.io~1allow-prometheus-access
165+
value: ""
166+
EOF
148167

149168
(
150169
cd config/cnao

hack/components/bump-kubevirt-ipam-controller.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function __parametize_by_object() {
2929
yaml-utils::set_param ${f} spec.template.spec.nodeSelector '{{ toYaml .Placement.NodeSelector | nindent 8 }}'
3030
yaml-utils::set_param ${f} spec.template.spec.affinity '{{ toYaml .Placement.Affinity | nindent 8 }}'
3131
yaml-utils::set_param ${f} spec.template.spec.tolerations '{{ toYaml .Placement.Tolerations | nindent 8 }}'
32+
yaml-utils::set_param ${f} 'spec.template.metadata.labels."hco.kubevirt.io/allow-access-cluster-services"' '""'
3233
yaml-utils::remove_single_quotes_from_yaml ${f}
3334
;;
3435
./Service_kubevirt-ipam-controller-webhook-service.yaml)

pkg/components/components.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ func GetDeployment(version string, operatorVersion string, namespace string, rep
181181
Labels: map[string]string{
182182
"name": Name,
183183
names.PrometheusLabelKey: names.PrometheusLabelValue,
184+
// opt-in to hco-bundle network-policy allowing egress to cluster services
185+
"hco.kubevirt.io/allow-access-cluster-services": "",
186+
// opt-in to hco-bundle network-policy allowing ingress to the metrics endpoint
187+
"hco.kubevirt.io/allow-prometheus-access": "",
184188
},
185189
Annotations: map[string]string{
186190
"description": "cluster-network-addons-operator manages the lifecycle of different Kubernetes network components on top of Kubernetes cluster",

0 commit comments

Comments
 (0)