Skip to content

Commit 6f388ae

Browse files
authored
fix: skip reservation capacity assessment when no nodepools need to be created (#1125)
* fix: skip reservation capacity assessment when no nodepools need to be created * test: add test for skipping reservation check * test: improve unit test by mocking an empty reservation instead of patching get_reservations_list * test: remove comments from test function
1 parent 0dda886 commit 6f388ae

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

src/xpk/core/nodepool.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@ def run_gke_node_pool_create_command(
281281
np for np in desired_node_pool_names if np not in node_pools_to_remain
282282
]
283283
reservations_iter: Iterator[ReservationLink] | None = None
284-
if capacity_type == CapacityType.RESERVATION:
284+
if (
285+
capacity_type == CapacityType.RESERVATION
286+
and len(node_pools_to_create) > 0
287+
):
285288
reservations = get_reservations_list(args)
286289
if FeatureFlags.RESERVATIONS_VALIDATION_ENABLED:
287290
vms_per_pool = (

src/xpk/core/nodepool_test.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,3 +1159,64 @@ def test_run_gke_node_pool_create_command_no_ignore_errors_returns_1(
11591159
result = run_gke_node_pool_create_command(args, system, "1.2.3")
11601160

11611161
assert result == 1
1162+
1163+
1164+
def test_run_gke_node_pool_create_command_skips_reservation_check_when_no_nodepools_to_create_with_empty_reservation(
1165+
mocker,
1166+
commands_tester: CommandsTester,
1167+
):
1168+
mocker.patch(
1169+
"xpk.core.nodepool.get_cluster_location", return_value="us-central1"
1170+
)
1171+
mocker.patch("xpk.core.nodepool.ask_for_user_consent", return_value=True)
1172+
mocker.patch(
1173+
"xpk.core.nodepool.check_cluster_resources", return_value=(True, True)
1174+
)
1175+
args = mocker.Mock(
1176+
num_slices=2,
1177+
reservation="reservation1,reservation2",
1178+
tpu_type="v4-8",
1179+
device_type=None,
1180+
cluster="test-cluster",
1181+
project="test-project",
1182+
zone="us-central1-a",
1183+
on_demand=False,
1184+
spot=False,
1185+
flex=False,
1186+
enable_workload_identity=False,
1187+
enable_gcsfuse_csi_driver=False,
1188+
host_maintenance_interval="AS_NEEDED",
1189+
custom_nodepool_arguments="",
1190+
super_slicing=False,
1191+
enable_autoprovisioning=False,
1192+
)
1193+
system = SystemCharacteristics(
1194+
topology="2x2x1",
1195+
vms_per_slice=2,
1196+
gke_accelerator="tpu-v4",
1197+
gce_machine_type="ct4p-hightpu-4t",
1198+
chips_per_vm=4,
1199+
accelerator_type=AcceleratorType.TPU,
1200+
device_type="v4-8",
1201+
requires_workload_policy=False,
1202+
supports_sub_slicing=False,
1203+
supports_super_slicing=False,
1204+
supports_accelerator_network_profile=True,
1205+
docker_platform=DockerPlatform.AMD,
1206+
)
1207+
1208+
setup_mock_reservation(
1209+
commands_tester,
1210+
specific_reservation=SpecificReservation(
1211+
count=0, in_use_count=0, machine_type="ct4p-hightpu-4t"
1212+
),
1213+
)
1214+
1215+
commands_tester.set_result_for_command(
1216+
(0, "test-cluster-np-0\ntest-cluster-np-1"),
1217+
"gcloud beta container node-pools list",
1218+
)
1219+
1220+
result = run_gke_node_pool_create_command(args, system, "1.2.3")
1221+
1222+
assert result == 0

0 commit comments

Comments
 (0)