Skip to content

Commit

Permalink
handle cases when kubectl returns an empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
kwmonroe committed Apr 8, 2022
1 parent 540eb19 commit eb8bf2a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions reactive/kubernetes_control_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -2639,7 +2639,7 @@ def _wait_for_svc_ip():
"-l",
"cdk-restart-on-ca-change=true",
).decode("UTF-8")
deployments = json.loads(output)["items"]
deployments = json.loads(output)["items"] if output else {}

# Now restart the addons
for deployment in deployments:
Expand Down Expand Up @@ -2812,7 +2812,7 @@ def get_pods(namespace="default"):
output = kubectl(
"get", "po", "-n", namespace, "-o", "json", "--request-timeout", "10s"
).decode("UTF-8")
result = json.loads(output)
result = json.loads(output) if output else None
except CalledProcessError:
hookenv.log("failed to get {} pod status".format(namespace))
return None
Expand All @@ -2825,7 +2825,7 @@ def get_svcs(namespace="default"):
output = kubectl(
"get", "svc", "-n", namespace, "-o", "json", "--request-timeout", "10s"
).decode("UTF-8")
result = json.loads(output)
result = json.loads(output) if output else None
except CalledProcessError:
hookenv.log("failed to get {} service status".format(namespace))
return None
Expand Down Expand Up @@ -2893,7 +2893,7 @@ def poke_network_unavailable():

try:
output = kubectl("get", "nodes", "-o", "json").decode("utf-8")
nodes = json.loads(output)["items"]
nodes = json.loads(output)["items"] if output else {}
except CalledProcessError:
hookenv.log("failed to get kube-system nodes")
return
Expand Down Expand Up @@ -3470,7 +3470,7 @@ def restart_addons_for_ca():
"-l",
"cdk-restart-on-ca-change=true",
).decode("UTF-8")
deployments = json.loads(output)["items"]
deployments = json.loads(output)["items"] if output else {}

# Get ServiceAccounts
service_account_names = set(
Expand All @@ -3487,8 +3487,9 @@ def restart_addons_for_ca():
output = kubectl(
"get", "ServiceAccount", name, "-o", "json", "-n", namespace
).decode("UTF-8")
service_account = json.loads(output)
service_accounts.append(service_account)
if output:
service_account = json.loads(output)
service_accounts.append(service_account)

# Get ServiceAccount secrets
secret_names = set()
Expand All @@ -3501,8 +3502,9 @@ def restart_addons_for_ca():
output = kubectl(
"get", "Secret", name, "-o", "json", "-n", namespace
).decode("UTF-8")
secret = json.loads(output)
secrets.append(secret)
if output:
secret = json.loads(output)
secrets.append(secret)

# Check secrets have updated CA
with open(ca_crt_path, "rb") as f:
Expand Down

0 comments on commit eb8bf2a

Please sign in to comment.