-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprerequisites_check.py
More file actions
52 lines (38 loc) · 1.28 KB
/
prerequisites_check.py
File metadata and controls
52 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Prerequisite checks for the keras-remote CLI.
Delegates common credential checks (gcloud, auth plugin, ADC) to
:mod:`keras_remote.credentials` and converts ``RuntimeError`` into
``click.ClickException``. CLI-only tool checks (kubectl) remain here.
"""
import shutil
import click
from keras_remote import credentials
def check_gcloud():
"""Verify gcloud CLI is installed."""
try:
credentials.ensure_gcloud()
except RuntimeError as e:
raise click.ClickException(str(e)) # noqa: B904
def check_kubectl():
"""Verify kubectl is installed."""
if not shutil.which("kubectl"):
raise click.ClickException(
"kubectl not found. Install from: https://kubernetes.io/docs/tasks/tools/"
)
def check_gke_auth_plugin():
"""Verify gke-gcloud-auth-plugin is installed; auto-install if missing."""
try:
credentials.ensure_gke_auth_plugin()
except RuntimeError as e:
raise click.ClickException(str(e)) # noqa: B904
def check_gcloud_auth():
"""Check if gcloud Application Default Credentials are configured."""
try:
credentials.ensure_adc()
except RuntimeError as e:
raise click.ClickException(str(e)) # noqa: B904
def check_all():
"""Run all prerequisite checks."""
check_gcloud()
check_kubectl()
check_gke_auth_plugin()
check_gcloud_auth()