xpk 0.17.3__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xpk/commands/cluster.py +33 -43
- xpk/commands/cluster_gcluster.py +19 -14
- xpk/commands/cluster_gcluster_test.py +2 -0
- xpk/commands/cluster_test.py +1 -21
- xpk/commands/common.py +39 -6
- xpk/commands/common_test.py +170 -0
- xpk/commands/info.py +9 -5
- xpk/commands/inspector.py +33 -4
- xpk/commands/inspector_test.py +142 -0
- xpk/commands/workload.py +32 -11
- xpk/commands/workload_test.py +71 -3
- xpk/core/blueprint/blueprint_generator.py +19 -8
- xpk/core/blueprint/testing/data/a3_ultra.yaml +3 -1
- xpk/core/blueprint/testing/data/a4.yaml +3 -1
- xpk/core/capacity.py +37 -17
- xpk/core/capacity_test.py +66 -1
- xpk/core/cluster.py +11 -10
- xpk/core/cluster_private.py +3 -3
- xpk/core/cluster_test.py +29 -2
- xpk/core/config.py +5 -2
- xpk/core/docker_container.py +31 -24
- xpk/core/docker_manager.py +4 -4
- xpk/core/docker_resources.py +4 -1
- xpk/core/kueue_manager.py +6 -8
- xpk/core/kueue_manager_test.py +6 -5
- xpk/core/nap.py +14 -3
- xpk/core/nodepool.py +52 -13
- xpk/core/nodepool_test.py +147 -8
- xpk/core/remote_state/fuse_remote_state.py +1 -1
- xpk/core/scheduling.py +32 -4
- xpk/core/scheduling_test.py +39 -2
- xpk/core/system_characteristics.py +44 -0
- xpk/core/system_characteristics_test.py +11 -0
- xpk/core/telemetry.py +11 -1
- xpk/core/telemetry_test.py +39 -0
- xpk/core/testing/commands_tester.py +26 -0
- xpk/core/testing/commands_tester_test.py +20 -1
- xpk/core/workload_decorators/rdma_decorator.py +9 -0
- xpk/parser/cluster.py +11 -1
- xpk/parser/cluster_test.py +59 -1
- xpk/parser/common.py +11 -17
- xpk/parser/core.py +0 -8
- xpk/parser/storage.py +3 -14
- xpk/utils/console.py +1 -1
- xpk/utils/feature_flags.py +8 -4
- {xpk-0.17.3.dist-info → xpk-1.1.0.dist-info}/METADATA +50 -23
- {xpk-0.17.3.dist-info → xpk-1.1.0.dist-info}/RECORD +51 -60
- xpk-1.1.0.dist-info/top_level.txt +1 -0
- integration/README.md +0 -19
- integration/__init__.py +0 -15
- integration/docker_manager_test.py +0 -102
- integration/gcluster_a3mega_test.py +0 -215
- integration/gcluster_a3ultra_test.py +0 -187
- integration/gcluster_a4_test.py +0 -187
- integration/gcluster_test.py +0 -107
- xpk/commands/kind.py +0 -265
- xpk/parser/kind.py +0 -95
- xpk/utils/user_input.py +0 -48
- xpk/utils/user_input_test.py +0 -92
- xpk-0.17.3.dist-info/top_level.txt +0 -2
- {xpk-0.17.3.dist-info → xpk-1.1.0.dist-info}/WHEEL +0 -0
- {xpk-0.17.3.dist-info → xpk-1.1.0.dist-info}/entry_points.txt +0 -0
- {xpk-0.17.3.dist-info → xpk-1.1.0.dist-info}/licenses/LICENSE +0 -0
integration/gcluster_test.py
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Copyright 2024 Google LLC
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
from xpk.core.docker_manager import DockerManager
|
|
18
|
-
from xpk.core.gcluster_manager import GclusterManager
|
|
19
|
-
from xpk.core.blueprint.blueprint_generator import BlueprintGenerator
|
|
20
|
-
import os
|
|
21
|
-
import pytest
|
|
22
|
-
import shutil
|
|
23
|
-
|
|
24
|
-
ctk_gcloud_cfg = os.getenv("GCLOUD_CFG_PATH")
|
|
25
|
-
project_id = os.getenv("PROJECT_ID")
|
|
26
|
-
region = os.getenv("REGION")
|
|
27
|
-
zone = os.getenv("ZONE")
|
|
28
|
-
auth_cidr = os.getenv("AUTH_CIDR")
|
|
29
|
-
cluster_name = os.getenv("GKE_ML_TEST_CLUSTER_NAME")
|
|
30
|
-
|
|
31
|
-
uploads_dir = "uploads"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def prepare_test(docker_path: str, bp_path: str) -> None:
|
|
35
|
-
if not os.path.exists(docker_path):
|
|
36
|
-
os.makedirs(docker_path)
|
|
37
|
-
if not os.path.exists(bp_path):
|
|
38
|
-
os.makedirs(bp_path)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
@pytest.mark.skip(reason="Credentails not working. Skipping for now")
|
|
42
|
-
def test_create_deployment():
|
|
43
|
-
assert project_id is not None
|
|
44
|
-
assert region is not None
|
|
45
|
-
assert zone is not None
|
|
46
|
-
assert auth_cidr is not None
|
|
47
|
-
assert ctk_gcloud_cfg is not None
|
|
48
|
-
assert cluster_name is not None
|
|
49
|
-
|
|
50
|
-
pwd = os.getcwd()
|
|
51
|
-
test_docker_working_dir = os.path.join(
|
|
52
|
-
pwd, "xpkclusters/tests/xpk_test_docker_dir"
|
|
53
|
-
)
|
|
54
|
-
test_bp_dir = os.path.join(pwd, "xpkclusters/tests/xpk_test_bp_dir")
|
|
55
|
-
prepare_test(test_docker_working_dir, test_bp_dir)
|
|
56
|
-
blueprint_name = "my-test-blueprint"
|
|
57
|
-
prefix = "prefix"
|
|
58
|
-
|
|
59
|
-
docker_manager = DockerManager(
|
|
60
|
-
gcloud_cfg_path=ctk_gcloud_cfg, working_dir=test_docker_working_dir
|
|
61
|
-
)
|
|
62
|
-
docker_manager.initialize()
|
|
63
|
-
|
|
64
|
-
bpm = BlueprintGenerator(storage_path=test_bp_dir)
|
|
65
|
-
ml_gke_blueprint = bpm.generate_gke_ml_blueprint(
|
|
66
|
-
cluster_name=cluster_name,
|
|
67
|
-
blueprint_name=blueprint_name,
|
|
68
|
-
prefix=prefix,
|
|
69
|
-
region=region,
|
|
70
|
-
project_id=project_id,
|
|
71
|
-
auth_cidr=auth_cidr,
|
|
72
|
-
)
|
|
73
|
-
blueprint_test_path = os.path.join(
|
|
74
|
-
test_bp_dir, prefix, f"{blueprint_name}.yaml"
|
|
75
|
-
)
|
|
76
|
-
# there are no files in ghcp stage for this blueprint
|
|
77
|
-
blueprint_deps_test_path = ""
|
|
78
|
-
|
|
79
|
-
assert ml_gke_blueprint.blueprint_file == blueprint_test_path
|
|
80
|
-
assert ml_gke_blueprint.blueprint_dependencies == blueprint_deps_test_path
|
|
81
|
-
|
|
82
|
-
assert os.path.exists(blueprint_test_path)
|
|
83
|
-
|
|
84
|
-
gcluster_manager = GclusterManager(
|
|
85
|
-
gcluster_command_runner=docker_manager, remote_state_client=None
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
staged_bp_path = gcluster_manager.stage_files(
|
|
89
|
-
blueprint_file=ml_gke_blueprint.blueprint_file,
|
|
90
|
-
blueprint_dependencies=ml_gke_blueprint.blueprint_dependencies,
|
|
91
|
-
prefix=prefix,
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
assert staged_bp_path == os.path.join(
|
|
95
|
-
"/out", uploads_dir, prefix, f"{blueprint_name}.yaml"
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
gcluster_manager.deploy(
|
|
99
|
-
blueprint_path=staged_bp_path,
|
|
100
|
-
deployment_name=blueprint_name,
|
|
101
|
-
prefix=prefix,
|
|
102
|
-
)
|
|
103
|
-
gcluster_manager.destroy_deployment(
|
|
104
|
-
deployment_name=blueprint_name, prefix=prefix
|
|
105
|
-
)
|
|
106
|
-
shutil.rmtree(test_docker_working_dir)
|
|
107
|
-
shutil.rmtree(test_bp_dir)
|
xpk/commands/kind.py
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Copyright 2024 Google LLC
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
from ..core.kueue_manager import (KueueConfig, KueueManager)
|
|
18
|
-
from ..core.commands import (
|
|
19
|
-
run_command_for_value,
|
|
20
|
-
run_command_with_updates,
|
|
21
|
-
)
|
|
22
|
-
from ..core.cluster import set_jobset_on_cluster, setup_k8s_env
|
|
23
|
-
from ..core.scheduling import get_total_chips_requested_from_args
|
|
24
|
-
from ..core.storage import install_storage_crd
|
|
25
|
-
from ..core.system_characteristics import (
|
|
26
|
-
SystemCharacteristics,
|
|
27
|
-
AcceleratorType,
|
|
28
|
-
DockerPlatform,
|
|
29
|
-
)
|
|
30
|
-
from ..utils.console import (xpk_exit, xpk_print)
|
|
31
|
-
from ..utils.validation import validate_dependencies_list, SystemDependency, should_validate_dependencies
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def cluster_create(args) -> None:
|
|
35
|
-
"""Function around cluster creation.
|
|
36
|
-
|
|
37
|
-
Args:
|
|
38
|
-
args: user provided arguments for running the command.
|
|
39
|
-
|
|
40
|
-
Returns:
|
|
41
|
-
0 if successful and 1 otherwise.
|
|
42
|
-
"""
|
|
43
|
-
if should_validate_dependencies(args):
|
|
44
|
-
validate_dependencies_list([
|
|
45
|
-
SystemDependency.KUBECTL,
|
|
46
|
-
SystemDependency.GCLOUD,
|
|
47
|
-
])
|
|
48
|
-
xpk_print(f'Starting cluster create for cluster {args.cluster}:', flush=True)
|
|
49
|
-
|
|
50
|
-
create_cluster_command_code = create_cluster_if_necessary(args)
|
|
51
|
-
if create_cluster_command_code != 0:
|
|
52
|
-
xpk_exit(create_cluster_command_code)
|
|
53
|
-
|
|
54
|
-
set_cluster_command_code = set_local_cluster_command(args)
|
|
55
|
-
if set_cluster_command_code != 0:
|
|
56
|
-
xpk_exit(set_cluster_command_code)
|
|
57
|
-
|
|
58
|
-
xpk_print(
|
|
59
|
-
'Enabling the jobset API on our cluster, to be deprecated when Jobset is'
|
|
60
|
-
' globally available'
|
|
61
|
-
)
|
|
62
|
-
set_jobset_on_cluster_code = set_jobset_on_cluster(args)
|
|
63
|
-
if set_jobset_on_cluster_code != 0:
|
|
64
|
-
xpk_exit(set_jobset_on_cluster_code)
|
|
65
|
-
|
|
66
|
-
k8s_client = setup_k8s_env(args)
|
|
67
|
-
install_storage_crd(k8s_client)
|
|
68
|
-
|
|
69
|
-
args.num_slices = 1
|
|
70
|
-
args.enable_pathways = False
|
|
71
|
-
system = SystemCharacteristics(
|
|
72
|
-
'N/A',
|
|
73
|
-
1,
|
|
74
|
-
'N/A',
|
|
75
|
-
'N/A',
|
|
76
|
-
1,
|
|
77
|
-
AcceleratorType.CPU,
|
|
78
|
-
'kind',
|
|
79
|
-
supports_sub_slicing=False,
|
|
80
|
-
supports_super_slicing=False,
|
|
81
|
-
docker_platform=DockerPlatform.ARM,
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
kueue_manager = KueueManager(project='', zone='')
|
|
85
|
-
kueue_manager.install_or_upgrade(
|
|
86
|
-
KueueConfig(
|
|
87
|
-
system,
|
|
88
|
-
total_chips=get_total_chips_requested_from_args(args, system),
|
|
89
|
-
autoprovisioning_enabled=False,
|
|
90
|
-
num_slices=args.num_slices,
|
|
91
|
-
memory_limit='',
|
|
92
|
-
cpu_limit=0,
|
|
93
|
-
is_pathways_cluster=False,
|
|
94
|
-
flex=False,
|
|
95
|
-
configure_sub_slicing=False,
|
|
96
|
-
configure_super_slicing=False,
|
|
97
|
-
),
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
xpk_print('Kind commands done! Resources are created.')
|
|
101
|
-
xpk_exit(0)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
def cluster_delete(args) -> None:
|
|
105
|
-
"""Function around cluster delete.
|
|
106
|
-
|
|
107
|
-
Args:
|
|
108
|
-
args: user provided arguments for running the command.
|
|
109
|
-
|
|
110
|
-
Returns:
|
|
111
|
-
0 if successful and 1 otherwise.
|
|
112
|
-
"""
|
|
113
|
-
if should_validate_dependencies(args):
|
|
114
|
-
validate_dependencies_list([SystemDependency.GCLOUD])
|
|
115
|
-
xpk_print(f'Starting cluster delete for cluster: {args.cluster}', flush=True)
|
|
116
|
-
|
|
117
|
-
run_kind_cluster_delete_command_code = run_kind_cluster_delete_command(args)
|
|
118
|
-
if run_kind_cluster_delete_command_code != 0:
|
|
119
|
-
xpk_exit(run_kind_cluster_delete_command_code)
|
|
120
|
-
xpk_print(f'Kind commands done! Cluster {args.cluster} deleted.')
|
|
121
|
-
xpk_exit(0)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
def cluster_list(args) -> None:
|
|
125
|
-
"""Function around cluster list.
|
|
126
|
-
|
|
127
|
-
Returns:
|
|
128
|
-
0 if successful and 1 otherwise.
|
|
129
|
-
"""
|
|
130
|
-
if should_validate_dependencies(args):
|
|
131
|
-
validate_dependencies_list([SystemDependency.GCLOUD])
|
|
132
|
-
if run_kind_clusters_list_command():
|
|
133
|
-
xpk_exit(1)
|
|
134
|
-
xpk_exit(0)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def create_cluster_if_necessary(args) -> int:
|
|
138
|
-
"""Creates cluster if not present in the project.
|
|
139
|
-
|
|
140
|
-
Args:
|
|
141
|
-
args: user provided arguments for running the command.
|
|
142
|
-
|
|
143
|
-
Returns:
|
|
144
|
-
0 if successful and 1 otherwise.
|
|
145
|
-
"""
|
|
146
|
-
all_clusters, return_code = get_all_local_clusters_programmatic()
|
|
147
|
-
if return_code > 0:
|
|
148
|
-
xpk_print('Listing all clusters failed!')
|
|
149
|
-
return 1
|
|
150
|
-
if args.cluster in all_clusters:
|
|
151
|
-
xpk_print('Skipping cluster creation since it already exists.')
|
|
152
|
-
return 0
|
|
153
|
-
else:
|
|
154
|
-
return run_kind_cluster_create_command(args)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
def run_kind_cluster_delete_command(args) -> int:
|
|
158
|
-
"""Run the Delete Kind Cluster request.
|
|
159
|
-
|
|
160
|
-
Args:
|
|
161
|
-
args: user provided arguments for running the command.
|
|
162
|
-
|
|
163
|
-
Returns:
|
|
164
|
-
0 if successful and 1 otherwise.
|
|
165
|
-
"""
|
|
166
|
-
command = 'kind delete cluster'
|
|
167
|
-
|
|
168
|
-
if args.cluster:
|
|
169
|
-
command += f' --name={args.cluster}'
|
|
170
|
-
|
|
171
|
-
return_code = run_command_with_updates(command, 'Cluster Delete')
|
|
172
|
-
if return_code != 0:
|
|
173
|
-
xpk_print(f'Cluster delete request returned ERROR {return_code}')
|
|
174
|
-
return 1
|
|
175
|
-
|
|
176
|
-
return 0
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
def run_kind_clusters_list_command() -> int:
|
|
180
|
-
"""List Kind Clusters within the project and location.
|
|
181
|
-
|
|
182
|
-
Returns:
|
|
183
|
-
0 if successful and 1 otherwise.
|
|
184
|
-
"""
|
|
185
|
-
command = 'kind get clusters'
|
|
186
|
-
return_code = run_command_with_updates(command, 'Cluster List')
|
|
187
|
-
if return_code != 0:
|
|
188
|
-
xpk_print(f'Cluster list request returned ERROR {return_code}')
|
|
189
|
-
return 1
|
|
190
|
-
|
|
191
|
-
return 0
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
def run_kind_cluster_create_command(args) -> int:
|
|
195
|
-
"""Run the Create Kind Cluster request.
|
|
196
|
-
|
|
197
|
-
Args:
|
|
198
|
-
args: user provided arguments for running the command.
|
|
199
|
-
|
|
200
|
-
Returns:
|
|
201
|
-
0 if successful and 1 otherwise.
|
|
202
|
-
"""
|
|
203
|
-
command = 'kind create cluster'
|
|
204
|
-
|
|
205
|
-
if args.cluster:
|
|
206
|
-
command += f' --name={args.cluster}'
|
|
207
|
-
|
|
208
|
-
if args.k8s_version:
|
|
209
|
-
command += f' --image=kindest/node:v{args.k8s_version}'
|
|
210
|
-
|
|
211
|
-
return_code = run_command_with_updates(command, 'Kind Cluster Create')
|
|
212
|
-
if return_code != 0:
|
|
213
|
-
xpk_print(f'GKE Cluster Create request returned ERROR {return_code}')
|
|
214
|
-
return 1
|
|
215
|
-
return 0
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
def get_all_local_clusters_programmatic() -> tuple[list[str], int]:
|
|
219
|
-
"""Gets all the local clusters.
|
|
220
|
-
|
|
221
|
-
Returns:
|
|
222
|
-
List of cluster names and 0 if successful and 1 otherwise.
|
|
223
|
-
"""
|
|
224
|
-
command = 'kind get clusters'
|
|
225
|
-
return_code, raw_cluster_output = run_command_for_value(
|
|
226
|
-
command, 'Find if Cluster Exists'
|
|
227
|
-
)
|
|
228
|
-
if return_code != 0:
|
|
229
|
-
xpk_print(f'Find if Cluster Exists returned ERROR {return_code}')
|
|
230
|
-
return [], return_code
|
|
231
|
-
|
|
232
|
-
return raw_cluster_output.splitlines(), 0
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
def set_local_cluster_command(args) -> int:
|
|
236
|
-
"""Run local cluster configuration command to set the kubectl config.
|
|
237
|
-
|
|
238
|
-
Args:
|
|
239
|
-
args: user provided arguments for running the command.
|
|
240
|
-
|
|
241
|
-
Returns:
|
|
242
|
-
0 if successful and 1 otherwise.
|
|
243
|
-
"""
|
|
244
|
-
if not args.cluster:
|
|
245
|
-
command = 'kubectl config current-context'
|
|
246
|
-
return_code, current_context = run_command_for_value(
|
|
247
|
-
command, 'get current-context'
|
|
248
|
-
)
|
|
249
|
-
xpk_print(
|
|
250
|
-
'No local cluster name specified. Using current-context'
|
|
251
|
-
f' `{current_context.strip()}`'
|
|
252
|
-
)
|
|
253
|
-
return return_code
|
|
254
|
-
|
|
255
|
-
command = (
|
|
256
|
-
f'kubectl config use-context kind-{args.cluster} --namespace=default'
|
|
257
|
-
)
|
|
258
|
-
task = f'switch to cluster {args.cluster}'
|
|
259
|
-
return_code = run_command_with_updates(
|
|
260
|
-
command,
|
|
261
|
-
task,
|
|
262
|
-
)
|
|
263
|
-
if return_code != 0:
|
|
264
|
-
xpk_print(f'{task} returned ERROR {return_code}')
|
|
265
|
-
return return_code
|
xpk/parser/kind.py
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Copyright 2024 Google LLC
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
from ..commands.kind import (
|
|
18
|
-
cluster_create,
|
|
19
|
-
cluster_delete,
|
|
20
|
-
cluster_list,
|
|
21
|
-
)
|
|
22
|
-
from .common import add_global_arguments
|
|
23
|
-
from .validators import name_type
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def set_kind_parser(kind_parser):
|
|
27
|
-
cluster_subcommands = kind_parser.add_subparsers(
|
|
28
|
-
title='kind subcommands',
|
|
29
|
-
dest='xpk_kind_subcommands',
|
|
30
|
-
help=(
|
|
31
|
-
'These are commands related to kind management. Look at help for'
|
|
32
|
-
' specific subcommands for more details.'
|
|
33
|
-
),
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
### "cluster create" command parser ###
|
|
37
|
-
cluster_create_parser = cluster_subcommands.add_parser(
|
|
38
|
-
'create', help='Create local clusters.'
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
### Optional Arguments
|
|
42
|
-
cluster_create_parser.add_argument(
|
|
43
|
-
'--cluster',
|
|
44
|
-
type=name_type,
|
|
45
|
-
default='kind',
|
|
46
|
-
help=(
|
|
47
|
-
'The name of the cluster. Will be used as the prefix for internal'
|
|
48
|
-
' objects in the cluster.'
|
|
49
|
-
),
|
|
50
|
-
required=False,
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
cluster_create_parser.add_argument(
|
|
54
|
-
'--k8s-version',
|
|
55
|
-
type=str,
|
|
56
|
-
default='',
|
|
57
|
-
help='The Kubernetes version of the cluster.',
|
|
58
|
-
required=False,
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
add_global_arguments(cluster_create_parser)
|
|
62
|
-
cluster_create_parser.set_defaults(func=cluster_create)
|
|
63
|
-
|
|
64
|
-
### "cluster delete" command parser ###
|
|
65
|
-
cluster_delete_parser = cluster_subcommands.add_parser(
|
|
66
|
-
'delete',
|
|
67
|
-
help='Delete cloud clusters.',
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
cluster_delete_required_arguments = cluster_delete_parser.add_argument_group(
|
|
71
|
-
'Required Arguments',
|
|
72
|
-
'Arguments required for cluster delete.',
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
### Required arguments
|
|
76
|
-
cluster_delete_required_arguments.add_argument(
|
|
77
|
-
'--cluster',
|
|
78
|
-
type=name_type,
|
|
79
|
-
default=None,
|
|
80
|
-
help='The name of the cluster to be deleted.',
|
|
81
|
-
required=True,
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
### Optional Arguments
|
|
85
|
-
add_global_arguments(cluster_delete_parser)
|
|
86
|
-
cluster_delete_parser.set_defaults(func=cluster_delete)
|
|
87
|
-
|
|
88
|
-
# "cluster list" command parser.
|
|
89
|
-
cluster_list_parser = cluster_subcommands.add_parser(
|
|
90
|
-
'list', help='List cloud clusters.'
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
### Optional Arguments
|
|
94
|
-
add_global_arguments(cluster_list_parser)
|
|
95
|
-
cluster_list_parser.set_defaults(func=cluster_list)
|
xpk/utils/user_input.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Copyright 2025 Google LLC
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
from typing import Literal
|
|
18
|
-
|
|
19
|
-
from .console import xpk_print
|
|
20
|
-
from .execution_context import is_quiet
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def ask_for_user_consent(
|
|
24
|
-
question: str, default_option: Literal["Y", "N"] = "N"
|
|
25
|
-
) -> bool:
|
|
26
|
-
"""Prompts user with the given question, asking for a yes/no answer and returns a relevant boolean.
|
|
27
|
-
Important: immediatelly returns `True` in quiet mode!
|
|
28
|
-
|
|
29
|
-
Example prompt for `question='Continue?'`: `[XPK] Continue? (y/N): `.
|
|
30
|
-
|
|
31
|
-
Args:
|
|
32
|
-
question: The question to ask the user.
|
|
33
|
-
default_option: Option to use when user response is empty.
|
|
34
|
-
"""
|
|
35
|
-
if is_quiet():
|
|
36
|
-
return True
|
|
37
|
-
|
|
38
|
-
options = "y/N" if default_option == "N" else "Y/n"
|
|
39
|
-
prompt = f"[XPK] {question} ({options}): "
|
|
40
|
-
|
|
41
|
-
while True:
|
|
42
|
-
user_input = input(prompt) or default_option
|
|
43
|
-
if user_input.lower() in ["yes", "y"]:
|
|
44
|
-
return True
|
|
45
|
-
elif user_input.lower() in ["no", "n"]:
|
|
46
|
-
return False
|
|
47
|
-
else:
|
|
48
|
-
xpk_print("Invalid input. Please enter: yes/no/y/n.")
|
xpk/utils/user_input_test.py
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Copyright 2025 Google LLC
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
from unittest.mock import MagicMock, patch
|
|
18
|
-
import pytest
|
|
19
|
-
from pytest_mock import MockerFixture
|
|
20
|
-
|
|
21
|
-
from xpk.utils.user_input import ask_for_user_consent
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@pytest.fixture(autouse=True)
|
|
25
|
-
def mock_is_quiet(mocker: MockerFixture):
|
|
26
|
-
return mocker.patch("xpk.utils.user_input.is_quiet", return_value=False)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@pytest.mark.parametrize(
|
|
30
|
-
"user_input,expected",
|
|
31
|
-
[
|
|
32
|
-
("yes", True),
|
|
33
|
-
("y", True),
|
|
34
|
-
("Y", True),
|
|
35
|
-
("Yes", True),
|
|
36
|
-
("YES", True),
|
|
37
|
-
("no", False),
|
|
38
|
-
("n", False),
|
|
39
|
-
("N", False),
|
|
40
|
-
("No", False),
|
|
41
|
-
("NO", False),
|
|
42
|
-
],
|
|
43
|
-
)
|
|
44
|
-
@patch("xpk.utils.user_input.input")
|
|
45
|
-
def test_ask_for_user_consent(mock_input: MagicMock, user_input, expected):
|
|
46
|
-
mock_input.return_value = user_input
|
|
47
|
-
|
|
48
|
-
assert ask_for_user_consent("Test question?") is expected
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def fake_input_factory(user_inputs: list[str]):
|
|
52
|
-
def fake_input(prompt: str) -> str:
|
|
53
|
-
return user_inputs.pop(0)
|
|
54
|
-
|
|
55
|
-
return fake_input
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
@patch("xpk.utils.user_input.input", wraps=fake_input_factory(["invalid", "y"]))
|
|
59
|
-
def test_ask_for_user_consent_invalid_input(mock_input: MagicMock):
|
|
60
|
-
agreed = ask_for_user_consent("Test question?")
|
|
61
|
-
|
|
62
|
-
assert agreed is True
|
|
63
|
-
assert mock_input.call_count == 2
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
@patch("xpk.utils.user_input.input", return_value="")
|
|
67
|
-
def test_ask_for_user_consent_default_No(mock_input: MagicMock):
|
|
68
|
-
agreed = ask_for_user_consent("Test question?", default_option="N")
|
|
69
|
-
|
|
70
|
-
assert agreed is False
|
|
71
|
-
mock_input.assert_called_once_with("[XPK] Test question? (y/N): ")
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
@patch("xpk.utils.user_input.input", return_value="")
|
|
75
|
-
def test_ask_for_user_consent_default_Yes(mock_input: MagicMock):
|
|
76
|
-
agreed = ask_for_user_consent("Test question?", default_option="Y")
|
|
77
|
-
|
|
78
|
-
assert agreed is True
|
|
79
|
-
mock_input.assert_called_once_with("[XPK] Test question? (Y/n): ")
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
@patch("xpk.utils.user_input.input")
|
|
83
|
-
def test_ask_for_user_consent_with_quiet_mode_always_agrees(
|
|
84
|
-
mock_input: MagicMock,
|
|
85
|
-
mock_is_quiet: MagicMock,
|
|
86
|
-
):
|
|
87
|
-
mock_is_quiet.return_value = True
|
|
88
|
-
|
|
89
|
-
agreed = ask_for_user_consent("Test question?", default_option="N")
|
|
90
|
-
|
|
91
|
-
assert agreed is True
|
|
92
|
-
mock_input.assert_not_called()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|