Skip to content

Commit 493aeb1

Browse files
authored
Merge pull request #650 from pinheadmz/dd-k8s
setup: check that docker desktop users have enabled kubernetes
2 parents f76c753 + 4f7eca1 commit 493aeb1

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/warnet/project.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ 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+
154169
def is_kubectl_installed_and_offer_if_not() -> tuple[bool, str]:
155170
try:
156171
version_result = subprocess.run(
@@ -264,6 +279,12 @@ def check_installation(tool_info: ToolInfo) -> ToolStatus:
264279
install_instruction="Please make sure docker is running",
265280
install_url="https://docs.docker.com/engine/install/",
266281
)
282+
docker_desktop_kube_running = ToolInfo(
283+
tool_name="Kubernetes Running in Docker Desktop",
284+
is_installed_func=is_docker_desktop_kube_running,
285+
install_instruction="Please enable the local kubernetes cluster in Docker Desktop",
286+
install_url="https://docs.docker.com/desktop/kubernetes/",
287+
)
267288
minikube_running_info = ToolInfo(
268289
tool_name="Running Minikube",
269290
is_installed_func=is_minikube_running,
@@ -319,19 +340,20 @@ def check_installation(tool_info: ToolInfo) -> ToolStatus:
319340

320341
check_results: list[ToolStatus] = []
321342
if answers:
343+
check_results.append(check_installation(kubectl_info))
344+
check_results.append(check_installation(helm_info))
322345
if answers["platform"] == "Docker Desktop":
323346
check_results.append(check_installation(docker_info))
324347
check_results.append(check_installation(docker_desktop_info))
325348
check_results.append(check_installation(docker_running_info))
349+
check_results.append(check_installation(docker_desktop_kube_running))
326350
elif answers["platform"] == "Minikube":
327351
check_results.append(check_installation(docker_info))
328352
check_results.append(check_installation(docker_running_info))
329353
check_results.append(check_installation(minikube_info))
330354
if is_platform_darwin():
331355
check_results.append(check_installation(minikube_version_info))
332356
check_results.append(check_installation(minikube_running_info))
333-
check_results.append(check_installation(kubectl_info))
334-
check_results.append(check_installation(helm_info))
335357
else:
336358
click.secho("Please re-run setup.", fg="yellow")
337359
sys.exit(1)

0 commit comments

Comments
 (0)