Skip to content

Commit

Permalink
Fix handling of internal LB response and missing endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsca committed May 5, 2021
1 parent 7da07a7 commit c4fefc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/charms/layer/kubernetes_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ def get_internal_api_endpoints(relation=None):

# If the internal LB relation is attached, use that or nothing. If it's
# not attached but the external LB relation is, use that or nothing.
for lb_endpoint in ("loadbalancer-internal", "loadbalancer-external"):
for lb_type in ("internal", "external"):
lb_endpoint = "loadbalancer-" + lb_type
request_name = "api-server-" + lb_type
if lb_endpoint in goal_state["relations"]:
lb_provider = endpoint_from_name(lb_endpoint)
lb_response = lb_provider.get_response("kube-api")
lb_response = lb_provider.get_response(request_name)
if not lb_response or lb_response.error:
return []
return [(lb_response.address, STANDARD_API_PORT)]
Expand Down Expand Up @@ -150,6 +152,8 @@ def get_api_url(endpoints):
"""
Choose an API endpoint from the list and build a URL from it.
"""
if not endpoints:
return None
urls = get_api_urls(endpoints)
return urls[kubernetes_common.get_unit_number() % len(urls)]

Expand Down
8 changes: 5 additions & 3 deletions reactive/kubernetes_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,8 @@ def request_load_balancers():
"""Request LBs from the related provider(s)."""
for lb_type in ("internal", "external"):
lb_provider = endpoint_from_name("loadbalancer-" + lb_type)
if not lb_provider.is_available:
continue
req = lb_provider.get_request("api-server-" + lb_type)
req.protocol = req.protocols.tcp
api_port = kubernetes_master.STANDARD_API_PORT
Expand Down Expand Up @@ -2084,12 +2086,12 @@ def build_kubeconfig():
"""Gather the relevant data for Kubernetes configuration objects and create
a config object with that information."""
internal_endpoints = kubernetes_master.get_internal_api_endpoints()
internal_url = kubernetes_master.get_api_url(internal_endpoints)
external_endpoints = kubernetes_master.get_external_api_endpoints()
external_url = kubernetes_master.get_api_url(external_endpoints)

# Do we have everything we need?
if ca_crt_path.exists():
if ca_crt_path.exists() and internal_endpoints and external_endpoints:
internal_url = kubernetes_master.get_api_url(internal_endpoints)
external_url = kubernetes_master.get_api_url(external_endpoints)
client_pass = get_token("admin")
if not client_pass:
# If we made it this far without a password, we're bootstrapping a new
Expand Down

0 comments on commit c4fefc9

Please sign in to comment.