|
14 | 14 | limitations under the License. |
15 | 15 | """ |
16 | 16 |
|
| 17 | +from typing import List |
17 | 18 | from ..utils.console import get_user_input, xpk_print |
18 | 19 | from .capacity import ( |
19 | 20 | AUTOPROVISIONING_CONFIG_VALUE, |
@@ -90,20 +91,26 @@ def run_gke_node_pool_create_command( |
90 | 91 | xpk_print('Parsing capacity arguments failed!') |
91 | 92 | return return_code |
92 | 93 |
|
93 | | - if system.accelerator_type == AcceleratorType['GPU']: |
94 | | - xpk_print( |
95 | | - f'Creating 1 node pool with {args.num_nodes} nodes of' |
96 | | - f' {system.device_type}\nUnderlyingly, we assume that means: {system}' |
97 | | - ) |
98 | | - desired_node_pool_names = [f'{args.cluster}-np-0'] |
99 | | - else: |
100 | | - xpk_print( |
101 | | - f'Creating {args.num_slices} node pool or pools of' |
102 | | - f' {system.device_type}\nUnderlyingly, we assume that means: {system}' |
103 | | - ) |
104 | | - desired_node_pool_names = [ |
105 | | - f'{args.cluster}-np-{slice_num}' for slice_num in range(args.num_slices) |
106 | | - ] |
| 94 | + desired_node_pool_count = ( |
| 95 | + 1 |
| 96 | + if system.accelerator_type == AcceleratorType['GPU'] |
| 97 | + else args.num_slices |
| 98 | + ) |
| 99 | + message = ( |
| 100 | + ( |
| 101 | + f'Creating 1 node pool with {args.num_nodes} nodes of' |
| 102 | + f' {system.device_type}\nUnderlyingly, we assume that means: {system}' |
| 103 | + ) |
| 104 | + if system.accelerator_type == AcceleratorType['GPU'] |
| 105 | + else ( |
| 106 | + f'Creating {args.num_slices} node pool or pools of' |
| 107 | + f' {system.device_type}\nUnderlyingly, we assume that means: {system}' |
| 108 | + ) |
| 109 | + ) |
| 110 | + xpk_print(message) |
| 111 | + desired_node_pool_names = get_desired_node_pool_names( |
| 112 | + existing_node_pool_names, args.cluster, desired_node_pool_count |
| 113 | + ) |
107 | 114 |
|
108 | 115 | node_pools_to_remain = [] |
109 | 116 | delete_commands = [] |
@@ -602,3 +609,21 @@ def get_nodepool_workload_metadata_mode( |
602 | 609 | return 1, None |
603 | 610 |
|
604 | 611 | return 0, nodepool_WI_mode.strip() |
| 612 | + |
| 613 | + |
| 614 | +def get_desired_node_pool_names( |
| 615 | + existing_node_pool_names: List[str], |
| 616 | + cluster_name: str, |
| 617 | + desired_node_pool_count: int, |
| 618 | +) -> List[str]: |
| 619 | + cluster_node_pools = [ |
| 620 | + np |
| 621 | + for np in existing_node_pool_names |
| 622 | + if np.startswith(f'{cluster_name}-np-') |
| 623 | + ] |
| 624 | + result = set(cluster_node_pools[:desired_node_pool_count]) |
| 625 | + i = 0 |
| 626 | + while len(result) < desired_node_pool_count: |
| 627 | + result.add(f'{cluster_name}-np-{i}') |
| 628 | + i += 1 |
| 629 | + return list(result) |
0 commit comments