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

Add sleeps to node ip search and zitadel api health queries; also improve env var tooltip for sensitive init values #174

Merged
merged 3 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "smol_k8s_lab"
version = "3.0.3"
version = "3.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
33 changes: 25 additions & 8 deletions smol_k8s_lab/k8s_apps/identity_provider/zitadel_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
Small Zitadel API wrapper using k8s service accounts
"""

# external libraries
import cryptography
from datetime import datetime, timezone, timedelta
import logging as log
from json import dumps
import jwt
from requests import request
from requests.exceptions import SSLError
from rich.prompt import Prompt
from time import sleep

# internal libraries
from smol_k8s_lab.bitwarden.bw_cli import BwCLI
from smol_k8s_lab.utils.passwords import create_password


class Zitadel():
"""
Python Wrapper for the Zitadel API
Expand Down Expand Up @@ -52,15 +56,28 @@ def check_api_health(self,) -> True:
Loops and checks https://{self.api_url}healthz for an HTTP status.
Returns True when the status code is 200 (success).
"""
res = None
while True:
log.debug("checking if api is up by querying the healthz endpoint")
res = request("GET", f"{self.api_url}healthz", verify=self.verify)

if res.status_code == 200:
log.info("Zitadel API is up now :)")
break
log.debug("checking if api is up by querying the healthz endpoint"
f" by querying {self.api_url} using verify={self.verify}")

try:
res = request("GET", f"{self.api_url}healthz", verify=self.verify)
except SSLError:
log.warn(f"Looks like querying {self.api_url} gave an SSL error,"
"but we'll try again")
pass

if res:
if res.status_code == 200:
log.info("Zitadel API is up now :)")
break
else:
# sleep just a couple of seconds to avoid being locked out or something
sleep(2)
log.debug("Zitadel API is not yet up :(")
else:
log.debug("Zitadel API is not yet up")
sleep(2)

return True

Expand Down
3 changes: 3 additions & 0 deletions smol_k8s_lab/k8s_distros/k3s.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import requests
import stat
from ruamel.yaml import YAML
from time import sleep


def install_k3s_cluster(cluster_name: str,
Expand Down Expand Up @@ -79,6 +80,8 @@ def join_k3s_nodes(extra_nodes: dict) -> None:

# we loop b/c sometimes the server isn't ready yet, so this might return None
while not k3s_control_plane_ip:
# sleep 3 seconds to avoid clogging the logs
sleep(3)
k3s_control_plane_ip = subproc([ip_cmd])

# strips new line character from end of ip address
Expand Down
5 changes: 3 additions & 2 deletions smol_k8s_lab/tui/app_widgets/input_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ def generate_input_row(self, key: str, value: str = "") -> Grid:
tooltip = self.tooltips.get(key, None)
if not tooltip:
if self.sensitive:
tooltip = (f"To avoid needing to fill {key} in manually, "
"you can export an environment variable.")
env_var = "_".join([self.app_name.upper(), key.upper()])
tooltip = (f"To avoid needing to fill in this value manually, you"
f" can export ${env_var} as an environment variable.")
else:
if key == "s3_provider":
tooltip = "Choose between minio and seaweedfs for a local s3 provider"
Expand Down