Basic error handling is added to the network policy manager
@@ -134,7 +134,9 @@ def is_sensitive_pod(pod):
def get_pods_owners_set(pods):
owners = set()
for pod in pods:
- owners.add(pod.metadata.labels.get(OWNER_LABEL))
+ pod_owner = pod.metadata.labels.get(OWNER_LABEL)
+ if pod_owner:
+ owners.add(pod_owner)
return owners
@@ -165,6 +167,7 @@ def drop_excess_policies(active_pods, active_policies):
def main():
log_message('===Starting run policies monitoring===')
while True:
+ try:
active_policies = load_all_active_policies()
sensitive_policies = []
common_policies = []
@@ -177,11 +180,20 @@ def main():
for pod in active_pods:
sensitive_pods.append(pod) if is_sensitive_pod(pod) else common_pods.append(pod)
+ try:
create_missed_policies(common_pods, common_policies, False)
create_missed_policies(sensitive_pods, sensitive_policies, True)
+ except Exception as creation_error:
+ log_message('[ERROR] Error ocurred while CREATING new policies:\n{}'.format(str(creation_error)))
+ try:
drop_excess_policies(common_pods, common_policies)
drop_excess_policies(sensitive_pods, sensitive_policies)
+ except Exception as deletion_error:
+ log_message('[ERROR] Error ocurred while DELETING policies:\n{}'.format(str(deletion_error)))
+
+ except Exception as general_error:
+ log_message('[ERROR] General error ocurred:\n{}'.format(str(general_error)))
time.sleep(float(MONITORING_PERIOD_SEC))
