|
2 | 2 | // |
3 | 3 | // * networking/network_policy/editing-network-policy.adoc |
4 | 4 |
|
5 | | -[id="nw-networkpolicy-edit_{context}"] |
| 5 | +ifeval::[{product-version} >= 4.6] |
| 6 | +:ovn: |
| 7 | +endif::[] |
6 | 8 |
|
| 9 | +[id="nw-networkpolicy-edit_{context}"] |
7 | 10 | = Editing a network policy |
8 | 11 |
|
9 | 12 | You can edit a network policy in a namespace. |
10 | 13 |
|
| 14 | +[NOTE] |
| 15 | +==== |
| 16 | +If you log in with a user with the `cluster-admin` role, then you can edit a network policy in any namespace in the cluster. |
| 17 | +==== |
| 18 | + |
11 | 19 | .Prerequisites |
12 | 20 |
|
13 | | -* Your cluster is using a default CNI network provider that supports `NetworkPolicy` objects, such as the OpenShift SDN network provider with `mode: NetworkPolicy` set. This mode is the default for OpenShift SDN. |
| 21 | +* Your cluster is using a cluster network provider that supports `NetworkPolicy` objects, such as |
| 22 | +ifndef::ovn[] |
| 23 | +the OpenShift SDN network provider with `mode: NetworkPolicy` set. |
| 24 | +endif::ovn[] |
| 25 | +ifdef::ovn[] |
| 26 | +the OVN-Kubernetes network provider or the OpenShift SDN network provider with `mode: NetworkPolicy` set. |
| 27 | +endif::ovn[] |
| 28 | +This mode is the default for OpenShift SDN. |
14 | 29 | * You installed the OpenShift CLI (`oc`). |
15 | | -* You are logged in to the cluster with a user with `cluster-admin` privileges. |
| 30 | +* You are logged in to the cluster with a user with `admin` privileges. |
| 31 | +* You are working in the namespace where the network policy exists. |
16 | 32 |
|
17 | 33 | .Procedure |
18 | 34 |
|
19 | | -. Optional: List the current `NetworkPolicy` objects. |
20 | | -.. If you want to list the policy objects in a specific namespace, enter the following command. Replace `<namespace>` with the namespace for a project. |
| 35 | +. Optional: To list the network policy objects in a namespace, enter the following command: |
21 | 36 | + |
22 | 37 | [source,terminal] |
23 | 38 | ---- |
24 | 39 | $ oc get networkpolicy -n <namespace> |
25 | 40 | ---- |
26 | | - |
27 | | -.. If you want to list the policy objects for the entire cluster, enter the following command: |
28 | 41 | + |
29 | | -[source,terminal] |
30 | | ----- |
31 | | -$ oc get networkpolicy --all-namespaces |
32 | | ----- |
| 42 | +-- |
| 43 | +where: |
| 44 | + |
| 45 | +`<namespace>`:: Optional: Specifies the namespace if the object is defined in a different namespace than the current namespace. |
| 46 | +-- |
33 | 47 |
|
34 | 48 | . Edit the `NetworkPolicy` object. |
35 | 49 |
|
36 | | -.. If you saved the network policy definition in a file, edit the file and make any necessary changes, and then enter the following command. Replace `<policy-file>` with the name of the file containing the object definition. |
| 50 | +** If you saved the network policy definition in a file, edit the file and make any necessary changes, and then enter the following command. |
37 | 51 | + |
38 | 52 | [source,terminal] |
39 | 53 | ---- |
40 | | -$ oc apply -f <policy-file>.yaml |
| 54 | +$ oc apply -n <namespace> -f <policy_file>.yaml |
41 | 55 | ---- |
| 56 | ++ |
| 57 | +-- |
| 58 | +where: |
| 59 | + |
| 60 | +`<namespace>`:: Optional: Specifies the namespace if the object is defined in a different namespace than the current namespace. |
| 61 | +`<policy_file>`:: Specifies the name of the file containing the network policy. |
| 62 | +-- |
42 | 63 |
|
43 | | -.. If you need to update the `NetworkPolicy` object directly, you can enter the following command. Replace `<policy-name>` with the name of the `NetworkPolicy` object and `<namespace>` with the name of the project where the object exists. |
| 64 | +** If you need to update the `NetworkPolicy` object directly, enter the following command: |
44 | 65 | + |
45 | 66 | [source,terminal] |
46 | 67 | ---- |
47 | | -$ oc edit <policy-name> -n <namespace> |
| 68 | +$ oc edit networkpolicy <policy_name> -n <namespace> |
48 | 69 | ---- |
| 70 | ++ |
| 71 | +-- |
| 72 | +where: |
| 73 | + |
| 74 | +`<policy_name>`:: Specifies the name of the network policy. |
| 75 | +`<namespace>`:: Optional: Specifies the namespace if the object is defined in a different namespace than the current namespace. |
| 76 | +-- |
49 | 77 |
|
50 | | -. Confirm that the `NetworkPolicy` object is updated. Replace `<namespace>` with the name of the project where the object exists. |
| 78 | +. Confirm that the `NetworkPolicy` object is updated. |
51 | 79 | + |
52 | 80 | [source,terminal] |
53 | 81 | ---- |
54 | | -$ oc get networkpolicy -n <namespace> -o yaml |
| 82 | +$ oc describe networkpolicy <policy_name> -n <namespace> |
55 | 83 | ---- |
| 84 | ++ |
| 85 | +-- |
| 86 | +where: |
| 87 | + |
| 88 | +`<policy_name>`:: Specifies the name of the network policy. |
| 89 | +`<namespace>`:: Optional: Specifies the namespace if the object is defined in a different namespace than the current namespace. |
| 90 | +-- |
| 91 | + |
| 92 | +ifdef::ovn[] |
| 93 | +:!ovn: |
| 94 | +endif::ovn[] |
0 commit comments