Skip to content

Commit 674a7e9

Browse files
committed
setup: check that docker desktop users have enabled kubernetes
1 parent 43831a5 commit 674a7e9

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/warnet/project.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,22 @@ def is_docker_desktop_running() -> tuple[bool, str]:
151151
except FileNotFoundError as err:
152152
return False, str(err)
153153

154+
def is_docker_desktop_kube_running() -> tuple[bool, str]:
155+
try:
156+
cluster_info = subprocess.run(
157+
["kubectl", "cluster-info", "--request-timeout=1"],
158+
capture_output=True,
159+
text=True,
160+
)
161+
if cluster_info.returncode == 0:
162+
return True, f"\n\t{cluster_info.stdout.strip().replace('\n', '\n\t')}"
163+
else:
164+
return False, ""
165+
except Exception:
166+
print()
167+
return False, "Please enable kubernetes in Docker Desktop"
168+
169+
154170
def is_kubectl_installed_and_offer_if_not() -> tuple[bool, str]:
155171
try:
156172
version_result = subprocess.run(
@@ -264,6 +280,12 @@ def check_installation(tool_info: ToolInfo) -> ToolStatus:
264280
install_instruction="Please make sure docker is running",
265281
install_url="https://docs.docker.com/engine/install/",
266282
)
283+
docker_desktop_kube_running = ToolInfo(
284+
tool_name="Kubernetes Running in Docker Desktop",
285+
is_installed_func=is_docker_desktop_kube_running,
286+
install_instruction="Please enable the local kubernetes cluster in Docker Desktop",
287+
install_url="https://docs.docker.com/desktop/kubernetes/",
288+
)
267289
minikube_running_info = ToolInfo(
268290
tool_name="Running Minikube",
269291
is_installed_func=is_minikube_running,
@@ -319,19 +341,20 @@ def check_installation(tool_info: ToolInfo) -> ToolStatus:
319341

320342
check_results: list[ToolStatus] = []
321343
if answers:
344+
check_results.append(check_installation(kubectl_info))
345+
check_results.append(check_installation(helm_info))
322346
if answers["platform"] == "Docker Desktop":
323347
check_results.append(check_installation(docker_info))
324348
check_results.append(check_installation(docker_desktop_info))
325349
check_results.append(check_installation(docker_running_info))
350+
check_results.append(check_installation(docker_desktop_kube_running))
326351
elif answers["platform"] == "Minikube":
327352
check_results.append(check_installation(docker_info))
328353
check_results.append(check_installation(docker_running_info))
329354
check_results.append(check_installation(minikube_info))
330355
if is_platform_darwin():
331356
check_results.append(check_installation(minikube_version_info))
332357
check_results.append(check_installation(minikube_running_info))
333-
check_results.append(check_installation(kubectl_info))
334-
check_results.append(check_installation(helm_info))
335358
else:
336359
click.secho("Please re-run setup.", fg="yellow")
337360
sys.exit(1)

0 commit comments

Comments
 (0)