|
10 | 10 | delay: "{{ k8s_delay }}" |
11 | 11 | until: r_namespace_exists is success |
12 | 12 |
|
| 13 | +- name: "Ensure same-namespace NetworkPolicy exists" |
| 14 | + when: |
| 15 | + - operator.namespace != "openshift-operators" |
| 16 | + - not (operator.disableDefaultNetworkPolicies | default(false)) |
| 17 | + kubernetes.core.k8s: |
| 18 | + state: present |
| 19 | + definition: |
| 20 | + apiVersion: networking.k8s.io/v1 |
| 21 | + kind: NetworkPolicy |
| 22 | + metadata: |
| 23 | + name: allow-from-same-namespace |
| 24 | + namespace: "{{ operator.namespace }}" |
| 25 | + spec: |
| 26 | + podSelector: {} |
| 27 | + ingress: |
| 28 | + - from: |
| 29 | + - podSelector: {} |
| 30 | + policyTypes: |
| 31 | + - Ingress |
| 32 | + register: r_same_namespace_netpol |
| 33 | + retries: "{{ k8s_retries }}" |
| 34 | + delay: "{{ k8s_delay }}" |
| 35 | + until: r_same_namespace_netpol is success |
| 36 | + |
| 37 | +- name: "Ensure kube-apiserver NetworkPolicy exists" |
| 38 | + when: |
| 39 | + - operator.namespace != "openshift-operators" |
| 40 | + - not (operator.disableDefaultNetworkPolicies | default(false)) |
| 41 | + kubernetes.core.k8s: |
| 42 | + state: present |
| 43 | + definition: |
| 44 | + apiVersion: networking.k8s.io/v1 |
| 45 | + kind: NetworkPolicy |
| 46 | + metadata: |
| 47 | + name: allow-ingress-from-kube-apiserver |
| 48 | + namespace: "{{ operator.namespace }}" |
| 49 | + spec: |
| 50 | + podSelector: {} |
| 51 | + ingress: |
| 52 | + - from: |
| 53 | + - ipBlock: |
| 54 | + cidr: "{{ machineNetwork }}" |
| 55 | + policyTypes: |
| 56 | + - Ingress |
| 57 | + register: r_kube_apiserver_netpol |
| 58 | + retries: "{{ k8s_retries }}" |
| 59 | + delay: "{{ k8s_delay }}" |
| 60 | + until: r_kube_apiserver_netpol is success |
| 61 | + |
| 62 | +- name: "Ensure monitoring NetworkPolicy exists" |
| 63 | + when: |
| 64 | + - operator.namespace != "openshift-operators" |
| 65 | + - not (operator.disableDefaultNetworkPolicies | default(false)) |
| 66 | + kubernetes.core.k8s: |
| 67 | + state: present |
| 68 | + definition: |
| 69 | + apiVersion: networking.k8s.io/v1 |
| 70 | + kind: NetworkPolicy |
| 71 | + metadata: |
| 72 | + name: allow-ingress-from-monitoring |
| 73 | + namespace: "{{ operator.namespace }}" |
| 74 | + spec: |
| 75 | + podSelector: {} |
| 76 | + ingress: |
| 77 | + - from: |
| 78 | + - namespaceSelector: |
| 79 | + matchLabels: |
| 80 | + network.openshift.io/policy-group: monitoring |
| 81 | + policyTypes: |
| 82 | + - Ingress |
| 83 | + register: r_monitoring_netpol |
| 84 | + retries: "{{ k8s_retries }}" |
| 85 | + delay: "{{ k8s_delay }}" |
| 86 | + until: r_monitoring_netpol is success |
| 87 | + |
| 88 | +- name: "Ensure ingress NetworkPolicies exist" |
| 89 | + when: |
| 90 | + - operator.namespace != "openshift-operators" |
| 91 | + - not (operator.disableDefaultNetworkPolicies | default(false)) |
| 92 | + kubernetes.core.k8s: |
| 93 | + state: present |
| 94 | + definition: |
| 95 | + apiVersion: networking.k8s.io/v1 |
| 96 | + kind: NetworkPolicy |
| 97 | + metadata: |
| 98 | + name: "allow-ingress-from-{{ item.name }}" |
| 99 | + namespace: "{{ operator.namespace }}" |
| 100 | + spec: |
| 101 | + podSelector: {} |
| 102 | + ingress: |
| 103 | + - from: |
| 104 | + - namespaceSelector: |
| 105 | + matchLabels: "{{ item.namespaceSelector.matchLabels }}" |
| 106 | + policyTypes: |
| 107 | + - Ingress |
| 108 | + loop: "{{ operator.allowIngressFrom | default([]) }}" |
| 109 | + loop_control: |
| 110 | + label: "{{ item.name }}" |
| 111 | + register: r_ingress_netpols |
| 112 | + retries: "{{ k8s_retries }}" |
| 113 | + delay: "{{ k8s_delay }}" |
| 114 | + until: r_ingress_netpols is success |
| 115 | + |
13 | 116 | - name: "Check if OperatorGroup already exists in namespace" |
14 | 117 | when: operator.namespace != "openshift-operators" |
15 | 118 | kubernetes.core.k8s_info: |
|
0 commit comments