From a74b6899b4ecf6e0452299d0e362d10b43cf6d1a Mon Sep 17 00:00:00 2001 From: Grant Date: Wed, 9 Oct 2024 21:30:52 -0500 Subject: [PATCH 1/2] users: check for ~/.kube and create if needed --- src/warnet/users.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/warnet/users.py b/src/warnet/users.py index d061f08a9..dca3d84f0 100644 --- a/src/warnet/users.py +++ b/src/warnet/users.py @@ -22,6 +22,9 @@ def auth(auth_config): is_first_config = False if not os.path.exists(KUBECONFIG): + kube_folder = os.path.join(os.path.expanduser("~"), ".kube") + if not os.path.exists(kube_folder): + os.makedirs(kube_folder) try: write_kubeconfig(auth_config, KUBECONFIG) is_first_config = True From 2713057fa6d019f9a424681c3cf3e9b8b7439096 Mon Sep 17 00:00:00 2001 From: Grant Date: Wed, 9 Oct 2024 22:26:40 -0500 Subject: [PATCH 2/2] users: make the .kube directory creation better I didn't like the way I originally checked for the directory, then created it -- all the while using hard-coded values. This one-liner will attempt to make the directory based on KUBECONFIG and if it exists, then it won't complain. However, if it does not exist, it will create it. This also should solve the case of the user having a bespoke KUBECONFIG directory in which they deleted their "config" file. Now, we will use their bespoke path and create the config file in their preferred location. --- src/warnet/users.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/warnet/users.py b/src/warnet/users.py index dca3d84f0..52a2c1080 100644 --- a/src/warnet/users.py +++ b/src/warnet/users.py @@ -22,9 +22,7 @@ def auth(auth_config): is_first_config = False if not os.path.exists(KUBECONFIG): - kube_folder = os.path.join(os.path.expanduser("~"), ".kube") - if not os.path.exists(kube_folder): - os.makedirs(kube_folder) + os.makedirs(os.path.dirname(KUBECONFIG), exist_ok=True) try: write_kubeconfig(auth_config, KUBECONFIG) is_first_config = True