1414from rich .logging import RichHandler
1515from sys import exit
1616
17- from .console_logging import header , sub_header
18- from .env_config import check_os_support , USR_CONFIG_FILE , VERSION , HOME_DIR
19- from .env_config import CONSOLE
17+ # custom libs and constants
18+ from .console_logging import CONSOLE , header , sub_header
19+ from .env_config import check_os_support , HOME_DIR , USR_CONFIG_FILE , VERSION
20+ from .env_config import XDG_CACHE_DIR
2021from .help_text import RichCommand , options_help
2122
2223
23- SUPPORTED_DISTROS = ['k0s' , 'k3s' , 'kind' ]
24-
2524HELP = options_help ()
2625HELP_SETTINGS = dict (help_option_names = ['-h' , '--help' ])
26+ SUPPORTED_DISTROS = ['k0s' , 'k3s' , 'kind' ]
2727
2828
2929def setup_logger (level = "" , log_file = "" ):
3030 """
31- Sets up rich logger and stores the values for it in a db for future import
32- in other files. Returns logging.getLogger("rich")
31+ Sets up rich logger for the entire project.
32+ ꒰ᐢ. ̫ .ᐢ꒱ <---- who is he? :3
33+ Returns logging.getLogger("rich")
3334 """
3435 # determine logging level
3536 if not level :
@@ -76,8 +77,10 @@ def setup_logger(level="", log_file=""):
7677
7778def install_k8s_distro (k8s_distro = "" ):
7879 """
79- install a specific distro of k8s
80- options: k0s, k3s, kind
80+ Install a specific distro of k8s
81+ Takes one variable:
82+ k8s_distro - string. options: 'k0s', 'k3s', or 'kind'
83+ Returns True
8184 """
8285 if k8s_distro == "kind" :
8386 from .k8s_distros .kind import install_kind_cluster
@@ -88,6 +91,7 @@ def install_k8s_distro(k8s_distro=""):
8891 elif k8s_distro == "k0s" :
8992 from .k8s_distros .k0s import install_k0s_cluster
9093 install_k0s_cluster ()
94+ return True
9195
9296
9397def delete_cluster (k8s_distro = "k3s" ):
@@ -102,8 +106,8 @@ def delete_cluster(k8s_distro="k3s"):
102106 uninstall_k3s ()
103107
104108 elif k8s_distro == 'kind' :
105- from .k8s_distros .kind import uninstall_kind
106- uninstall_kind ()
109+ from .k8s_distros .kind import delete_kind_cluster
110+ delete_kind_cluster ()
107111
108112 elif k8s_distro == 'k0s' :
109113 from .k8s_distros .k0s import uninstall_k0s
@@ -112,7 +116,7 @@ def delete_cluster(k8s_distro="k3s"):
112116 else :
113117 header ("┌(・o・)┘≡З Whoops. {k8s_distro} not YET supported." )
114118
115- sub_header ("[green ]◝(ᵔᵕᵔ)◜ Success!" )
119+ sub_header ("[grn ]◝(ᵔᵕᵔ)◜ Success![/grn] " )
116120 exit ()
117121
118122
@@ -149,36 +153,35 @@ def main(k8s: str = "",
149153 Quickly install a k8s distro for a homelab setup. Installs k3s
150154 with metallb, ingess-nginx, cert-manager, and argocd
151155 """
152- # setup logging immediately
153- log = setup_logger (log_level , log_file )
154- log .info ("Logging configured" )
155-
156156 # only return the version if --version was passed in
157157 if version :
158158 print (f'\n 🎉 v{ VERSION } \n ' )
159159 return True
160160
161+ # setup logging immediately
162+ log = setup_logger (log_level , log_file )
163+ log .info ("Logging configured" )
164+
161165 # make sure we got a valid k8s distro
162166 if k8s not in SUPPORTED_DISTROS :
163167 CONSOLE .print (f'\n ☹ Sorry, "[b]{ k8s } [/]" is not a currently supported '
164168 'k8s distro. Please try again with any of '
165169 f'{ SUPPORTED_DISTROS } .\n ' )
166170 exit ()
167171
168- # before we do anything, we need to make sure this OS is supported
172+ # make sure this OS is supported
169173 check_os_support ()
170174
171175 if delete :
172- # this exist the script after deleting the cluster
176+ # exits the script after deleting the cluster
173177 delete_cluster (k8s )
174178
175- # TODO: make this follow XDG base directory spec
176- # make sure the cache directory exists, to store stuff
177- Path (f"{ HOME_DIR } /.cache/smol-k8s-lab" ).mkdir (exist_ok = True )
179+ # make sure the cache directory exists (typically ~/.cache/smol-k8s-lab)
180+ Path (XDG_CACHE_DIR ).mkdir (exist_ok = True )
178181
179182 # install the actual KIND or k3s cluster
180183 header (f'Installing [green]{ k8s } [/] cluster.' )
181- sub_header ('This could take a min ʕ•́ᴥ •̀ʔっ♡ ' , False )
184+ sub_header ('This could take a min ʕ•́ ̫ •̀ʔっ♡ ' , False )
182185 install_k8s_distro (k8s )
183186
184187 # make sure helm is installed and the repos are up to date
@@ -190,27 +193,28 @@ def main(k8s: str = "",
190193 from .k8s_apps .metallb import configure_metallb
191194 configure_metallb (USR_CONFIG_FILE ['metallb_address_pool' ])
192195
193- # this is so we can accept traffic from outside the cluster
196+ # ingress controller: so we can accept traffic from outside the cluster
194197 header ("Installing [b]ingress-nginx-controller[/b]..." )
195198 from .k8s_apps .nginx_ingress_controller import configure_ingress_nginx
196199 configure_ingress_nginx (k8s )
197200
198- # this is for manager SSL/TLS certificates via lets-encrypt
201+ # manager SSL/TLS certificates via lets-encrypt
199202 header ("Installing [b]cert-manager[/b] for TLS certificates..." )
200203 from .k8s_apps .certmanager import configure_cert_manager
201204 configure_cert_manager (USR_CONFIG_FILE ['email' ])
202205
203- # this is for external secrets, currently only supports gitlab
206+ # external secrets provider: currently only supports gitlab
204207 if external_secret_operator :
205- external_secrets = USR_CONFIG_FILE ['external_secrets' ]['gitlab' ]
206208 from .k8s_apps .external_secrets import configure_external_secrets
209+ external_secrets = USR_CONFIG_FILE ['external_secrets' ]['gitlab' ]
207210 configure_external_secrets (external_secrets )
208211
212+ # kyverno: kubernetes native policy manager
209213 if kyverno :
210214 from .k8s_apps .kyverno import install_kyverno
211215 install_kyverno ()
212216
213- # then install argo CD ꒰ᐢ. ̫ .ᐢ꒱ <---- who is he? :3
217+ # 🦑 Install Argo CD: continuous deployment app for k8s
214218 if argo :
215219 argocd_fqdn = "." .join ([USR_CONFIG_FILE ['domain' ]['argo_cd' ],
216220 USR_CONFIG_FILE ['domain' ]['base' ]])
0 commit comments