Skip to content

Commit

Permalink
configure-kubectl breaks if no existing kubeconfig file. this fixes it (
Browse files Browse the repository at this point in the history
  • Loading branch information
juandiegopalomino authored Feb 15, 2022
1 parent 0671a42 commit bc92f99
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions opta/core/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def purge_opta_kube_config(layer: "Layer") -> None:
if not exists(default_kube_config_filename):
return

default_kube_config = yaml.load(open(default_kube_config_filename))
default_kube_config = yaml.load(open(default_kube_config_filename)) or {}
opta_config_user = opta_config["users"][0]
opta_config_context = opta_config["contexts"][0]
opta_config_cluster = opta_config["clusters"][0]
Expand All @@ -114,13 +114,13 @@ def purge_opta_kube_config(layer: "Layer") -> None:
]:
current_indices = [
i
for i, x in enumerate(default_kube_config[key])
for i, x in enumerate(default_kube_config.get(key, []))
if x["name"] == opta_value["name"]
]
for index in sorted(current_indices, reverse=True):
del default_kube_config[key][index]

if default_kube_config["current-context"] == opta_config_context["name"]:
if default_kube_config.get("current-context") == opta_config_context["name"]:
default_kube_config["current-context"] = ""
with open(default_kube_config_filename, "w") as f:
yaml.dump(default_kube_config, f)
Expand Down

0 comments on commit bc92f99

Please sign in to comment.