Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better handling of subordinate departed states #214

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions reactive/kubernetes_control_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,8 +1398,10 @@ def get_dns_info():
dns_ip = kubernetes_control_plane.get_dns_ip()
except CalledProcessError:
hookenv.log("DNS addon service not ready yet")
if dns_ip:
return True, dns_ip, 53, dns_domain
else:
return False, None, None, None
Comment on lines +1401 to 1404
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random nit: this method could REALLY use some return typing

def get_dns_info() -> Tuple[bool, Optional[str], Optional[int], Optional[str]]:

Suggested change
if dns_ip:
return True, dns_ip, 53, dns_domain
else:
return False, None, None, None
if dns_ip:
return True, dns_ip, 53, dns_domain
return False, None, None, None

return True, dns_ip, 53, dns_domain


@when("kube-control.connected")
Expand Down Expand Up @@ -1656,7 +1658,11 @@ def reconfigure_cdk_addons():
"leadership.is_leader",
"leadership.set.cluster_tag",
)
@when_not("upgrade.series.in-progress")
@when_not(
"upgrade.series.in-progress",
"endpoint.cni.departed",
"endpoint.container-runtime.departed",
)
def configure_cdk_addons():
"""Configure CDK addons"""
remove_state("cdk-addons.reconfigure")
Expand Down Expand Up @@ -2633,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 @@ -2806,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 @@ -2819,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 @@ -2887,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 @@ -3464,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 @@ -3481,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 @@ -3495,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