Skip to content

Commit 4524388

Browse files
authored
fix: k3s: fill in $KUBECONFIG if empty; fix issue where bweso isn't seen as ready; update python cryptography package (#146)
* fix: fill in /home/friend/.config/kube/config if it is empty when using k3s * retry bweso on failures * make args less vague for ingress nginx kind installs
1 parent ba935a0 commit 4524388

File tree

6 files changed

+71
-41
lines changed

6 files changed

+71
-41
lines changed

poetry.lock

Lines changed: 38 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "smol_k8s_lab"
3-
version = "2.0.3"
3+
version = "2.0.4"
44
description = "CLI and TUI to quickly install slimmer Kubernetes distros and then manage apps declaratively using Argo CD"
55
authors = ["Jesse Hitch <[email protected]>",
66
"Max Roby <[email protected]>"]
@@ -28,7 +28,7 @@ include = ["smol_k8s_lab/config/kind/kind_cluster_config.yaml",
2828
[tool.poetry.dependencies]
2929
bcrypt = "^4.0"
3030
click = "^8.1"
31-
cryptography = "^41.0.3"
31+
cryptography = "^42.0.2"
3232
kubernetes = "^28.1"
3333
minio = "^7.1.17"
3434
pyfiglet = "^1.0.2"

smol_k8s_lab/k8s_apps/ingress/ingress_nginx_controller.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def configure_ingress_nginx(k8s_obj: K8s, k8s_distro: str) -> None:
2424
if k8s_distro == 'kind':
2525
# this is to wait for the deployment to come up
2626
k8s_obj.apply_manifests(
27-
url,
28-
"ingress-nginx",
29-
"ingress-nginx-controller",
30-
"app.kubernetes.io/component=controller"
27+
manifest_file_name=url,
28+
namespace="ingress-nginx",
29+
deployment="ingress-nginx-controller",
30+
selector="app.kubernetes.io/component=controller"
3131
)
3232
else:
3333
values = {"controller.allowSnippetAnnotations": True}

smol_k8s_lab/k8s_apps/secrets_management/external_secrets_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def configure_external_secrets(k8s_obj: K8s,
3232

3333
if bitwarden:
3434
# wait for bitwarden external secrets provider to be up
35-
wait_for_argocd_app('bitwarden-eso-provider')
35+
wait_for_argocd_app('bitwarden-eso-provider', retry=True)
3636

3737

3838
def setup_bweso_provider(k8s_obj: K8s, distro: str, bitwarden: BwCLI = None) -> None:

smol_k8s_lab/k8s_distros/k3s.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ def update_user_kubeconfig(cluster_name: str = 'smol-k8s-lab-k3s') -> None:
106106

107107
# if the kubeconfig already exists and is not empty, we update it
108108
if path.exists(KUBECONFIG):
109-
log.info(f"Updating your {KUBECONFIG}")
109+
log.info(f"Updating your KUBECONFIG: {KUBECONFIG}")
110110
with open(KUBECONFIG, 'r') as user_kubeconfig:
111-
existing_config = safe_yaml.load(user_kubeconfig)
111+
try:
112+
existing_config = safe_yaml.load(user_kubeconfig)
113+
except Exception as e:
114+
log.error(e)
112115

113116
if existing_config:
114117
for obj in ['clusters', 'users', 'contexts']:
@@ -125,6 +128,11 @@ def update_user_kubeconfig(cluster_name: str = 'smol-k8s-lab-k3s') -> None:
125128
# write back the updated user kubeconfig file
126129
with open(KUBECONFIG, 'w') as user_kubeconfig:
127130
yaml.dump(existing_config, user_kubeconfig)
131+
else:
132+
log.info("Looks like your KUBECONFIG is empty, we'll fill it in for you.")
133+
# write updated k3s kubeconfig with new names for context, cluster, user
134+
with open(KUBECONFIG, 'w') as user_kubeconfig:
135+
yaml.dump(k3s_kubecfg, user_kubeconfig)
128136
else:
129137
log.info(f"Creating your new {KUBECONFIG} ✨")
130138

smol_k8s_lab/k8s_tools/argocd_util.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,25 @@ def install_with_argocd(k8s_obj: K8s, app: str, argo_dict: dict) -> None:
6060
log.debug(response)
6161

6262

63-
def wait_for_argocd_app(app: str):
63+
def wait_for_argocd_app(app: str, retry: bool = False) -> None:
6464
"""
6565
checks the status of an Argo CD app and waits till it is ready
6666
"""
67-
subproc([f"argocd app wait {app}"])
68-
return True
67+
if retry:
68+
# set error to true by default
69+
error = True
70+
# while error still equals True, keep retrying the command
71+
while error:
72+
try:
73+
subproc([f"argocd app wait {app} --health"])
74+
except Exception as e:
75+
log.debug(e)
76+
error = True
77+
log.debug(f"Retrying wait for for {app}")
78+
else:
79+
error = False
80+
else:
81+
subproc([f"argocd app wait {app} --health"])
6982

7083

7184
def create_argocd_project(k8s_obj: K8s,

0 commit comments

Comments
 (0)