xpk 0.17.3__py3-none-any.whl → 1.0.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/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)
File without changes