|
20 | 20 |
|
21 | 21 | _log = logging.getLogger(__name__)
|
22 | 22 |
|
| 23 | + |
23 | 24 | # Raised upon receiving an error from the Kubernetes API.
|
24 | 25 | class KubernetesApiError(Exception):
|
25 | 26 | pass
|
@@ -60,7 +61,7 @@ def __init__(self):
|
60 | 61 | """
|
61 | 62 |
|
62 | 63 | elect = os.environ.get("LEADER_ELECTION", "false")
|
63 |
| - self._leader_elect = elect.lower() == "true" |
| 64 | + self._leader_elect = elect.lower() == "true" |
64 | 65 | """
|
65 | 66 | Whether or not leader election is enabled. If set to False, this
|
66 | 67 | policy controller will assume it is the only instance.
|
@@ -133,17 +134,24 @@ def run(self):
|
133 | 134 | self._wait_for_leadership()
|
134 | 135 | self._start_leader_thread()
|
135 | 136 |
|
| 137 | + # Remove old tier if it exists |
| 138 | + try: |
| 139 | + _log.debug("Attempting to remove old tier k8s-network-policy") |
| 140 | + self._client.delete_policy_tier("k8s-network-policy") |
| 141 | + except KeyError: |
| 142 | + pass |
| 143 | + |
136 | 144 | # Ensure the tier exists.
|
137 | 145 | metadata = {"order": NET_POL_TIER_ORDER}
|
138 |
| - self._client.set_policy_tier_metadata(NET_POL_TIER_NAME, metadata) |
| 146 | + self._client.set_policy_tier_metadata("default", metadata) |
139 | 147 |
|
140 |
| - # Ensure the backstop policy exists. This policy fowards |
| 148 | + # Ensure the backstop policy exists. This policy forwards |
141 | 149 | # any traffic to Kubernetes pods which doesn't match another policy
|
142 | 150 | # to the next-tier (i.e the per-namespace Profiles).
|
143 | 151 | selector = "has(%s)" % K8S_NAMESPACE_LABEL
|
144 | 152 | rules = Rules(inbound_rules=[Rule(action="next-tier")],
|
145 | 153 | outbound_rules=[Rule(action="next-tier")])
|
146 |
| - self._client.create_policy(NET_POL_TIER_NAME, |
| 154 | + self._client.create_policy("default", |
147 | 155 | "k8s-policy-no-match",
|
148 | 156 | selector,
|
149 | 157 | order=NET_POL_BACKSTOP_ORDER,
|
|
0 commit comments