Skip to content

Commit

Permalink
Clean up warts found by flake8
Browse files Browse the repository at this point in the history
This does not include missing trailing commas due to a bug in black:

  psf/black#274
  • Loading branch information
nbraud committed Sep 30, 2018
1 parent 9432b7c commit 67da0bb
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions k8sbalance.py
Expand Up @@ -10,11 +10,11 @@
ONIONBALANCE_CONTROL = "/tmp/onionbalance.control"


def get_onion_mapping(client, NAMESPACE):
l = client.list_namespaced_pod(NAMESPACE, label_selector=SERVICE_LABEL)
m = {}
def get_onion_mapping(client, namespace):
pods = client.list_namespaced_pod(namespace, label_selector=SERVICE_LABEL)
mapping = {}

for pod in l.items:
for pod in pods.items:
if not pod.metadata.annotations:
continue

Expand All @@ -24,16 +24,17 @@ def get_onion_mapping(client, NAMESPACE):
service = pod.metadata.labels[SERVICE_LABEL]
instance = pod.metadata.annotations[INSTANCE_ANNOT]

if service not in m:
m[service] = set()
if service not in mapping:
mapping[service] = set()

m[service].add(instance)
mapping[service].add(instance)

return m
return mapping


def onionbalance_config(mapping):
import json, os.path
import json
import os.path

return json.dumps(
{
Expand Down Expand Up @@ -86,7 +87,8 @@ def log_changes(oldmap, newmap, output=sys.stderr):


if __name__ == "__main__":
import itertools, os
import itertools
import os
from kubernetes import client, config, watch

NAMESPACE = os.environ["POD_NAMESPACE"]
Expand All @@ -101,7 +103,7 @@ def log_changes(oldmap, newmap, output=sys.stderr):
v1.list_namespaced_pod, NAMESPACE, label_selector=SERVICE_LABEL
)

for event in stream:
for _ in stream:
newmap = get_onion_mapping(v1, NAMESPACE)
if newmap == onionmap:
continue
Expand Down

0 comments on commit 67da0bb

Please sign in to comment.