Skip to content

Commit

Permalink
fix: k3s: fill in $KUBECONFIG if empty; fix issue where bweso isn't s…
Browse files Browse the repository at this point in the history
…een 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
  • Loading branch information
jessebot authored Feb 13, 2024
1 parent ba935a0 commit 4524388
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 41 deletions.
67 changes: 38 additions & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "smol_k8s_lab"
version = "2.0.3"
version = "2.0.4"
description = "CLI and TUI to quickly install slimmer Kubernetes distros and then manage apps declaratively using Argo CD"
authors = ["Jesse Hitch <[email protected]>",
"Max Roby <[email protected]>"]
Expand Down Expand Up @@ -28,7 +28,7 @@ include = ["smol_k8s_lab/config/kind/kind_cluster_config.yaml",
[tool.poetry.dependencies]
bcrypt = "^4.0"
click = "^8.1"
cryptography = "^41.0.3"
cryptography = "^42.0.2"
kubernetes = "^28.1"
minio = "^7.1.17"
pyfiglet = "^1.0.2"
Expand Down
8 changes: 4 additions & 4 deletions smol_k8s_lab/k8s_apps/ingress/ingress_nginx_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def configure_ingress_nginx(k8s_obj: K8s, k8s_distro: str) -> None:
if k8s_distro == 'kind':
# this is to wait for the deployment to come up
k8s_obj.apply_manifests(
url,
"ingress-nginx",
"ingress-nginx-controller",
"app.kubernetes.io/component=controller"
manifest_file_name=url,
namespace="ingress-nginx",
deployment="ingress-nginx-controller",
selector="app.kubernetes.io/component=controller"
)
else:
values = {"controller.allowSnippetAnnotations": True}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def configure_external_secrets(k8s_obj: K8s,

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


def setup_bweso_provider(k8s_obj: K8s, distro: str, bitwarden: BwCLI = None) -> None:
Expand Down
12 changes: 10 additions & 2 deletions smol_k8s_lab/k8s_distros/k3s.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ def update_user_kubeconfig(cluster_name: str = 'smol-k8s-lab-k3s') -> None:

# if the kubeconfig already exists and is not empty, we update it
if path.exists(KUBECONFIG):
log.info(f"Updating your {KUBECONFIG}")
log.info(f"Updating your KUBECONFIG: {KUBECONFIG}")
with open(KUBECONFIG, 'r') as user_kubeconfig:
existing_config = safe_yaml.load(user_kubeconfig)
try:
existing_config = safe_yaml.load(user_kubeconfig)
except Exception as e:
log.error(e)

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

Expand Down
19 changes: 16 additions & 3 deletions smol_k8s_lab/k8s_tools/argocd_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,25 @@ def install_with_argocd(k8s_obj: K8s, app: str, argo_dict: dict) -> None:
log.debug(response)


def wait_for_argocd_app(app: str):
def wait_for_argocd_app(app: str, retry: bool = False) -> None:
"""
checks the status of an Argo CD app and waits till it is ready
"""
subproc([f"argocd app wait {app}"])
return True
if retry:
# set error to true by default
error = True
# while error still equals True, keep retrying the command
while error:
try:
subproc([f"argocd app wait {app} --health"])
except Exception as e:
log.debug(e)
error = True
log.debug(f"Retrying wait for for {app}")
else:
error = False
else:
subproc([f"argocd app wait {app} --health"])


def create_argocd_project(k8s_obj: K8s,
Expand Down

0 comments on commit 4524388

Please sign in to comment.