Skip to content

Commit 23adb2c

Browse files
Zach Howellcopybara-github
Zach Howell
authored andcommitted
Fix EKS when only one zone/region is set
My previous refactor likely broke this code, at least when specifying a singular region via eg `--zones=us-west-1`, which resulted in `--node-zones=us-west-1` being passed to eks create command. PiperOrigin-RevId: 751088507
1 parent e91628a commit 23adb2c

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

perfkitbenchmarker/providers/aws/elastic_kubernetes_service.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,21 @@ def _GetNodeFlags(
255255
) -> Dict[str, Any]:
256256
"""Get common flags for creating clusters and node_groups."""
257257
tags = util.MakeDefaultTags()
258-
return {
258+
node_flags = {
259259
'nodes': nodepool_config.num_nodes,
260260
'node-labels': f'pkb_nodepool={nodepool_config.name}',
261261
'node-type': nodepool_config.machine_type,
262262
'node-volume-size': nodepool_config.disk_size,
263-
# zone may be split a comma separated list
264-
'node-zones': nodepool_config.zone,
265263
'region': self.region,
266264
'tags': ','.join(f'{k}={v}' for k, v in tags.items()),
267265
'ssh-public-key': (
268266
aws_virtual_machine.AwsKeyFileManager.GetKeyNameForRun()
269267
),
270268
}
269+
if self.control_plane_zones:
270+
# zone may be split a comma separated list or simply a region
271+
node_flags['node-zones'] = nodepool_config.zone
272+
return node_flags
271273

272274
def _IsReady(self):
273275
"""Returns True if the workers are ready, else False."""

tests/providers/aws/elastic_kubernetes_service_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from perfkitbenchmarker.providers.aws import aws_network
88
from perfkitbenchmarker.providers.aws import elastic_kubernetes_service
99
from perfkitbenchmarker.providers.aws import util
10+
from tests import matchers
1011
from tests import pkb_common_test_case
1112

1213

@@ -55,6 +56,29 @@ def setUp(self):
5556
def testInitEksClusterWorks(self):
5657
elastic_kubernetes_service.EksCluster(EKS_SPEC)
5758

59+
def testEksClusterCreateNoSpec(self):
60+
issue_command = self.MockIssueCommand(
61+
{'create cluster': [('Cluster created', '', 0)]}
62+
)
63+
spec = container_spec.ContainerClusterSpec(
64+
'NAME',
65+
**{
66+
'cloud': 'AWS',
67+
'vm_spec': {
68+
'AWS': {'machine_type': 'm5.large', 'zone': 'us-east-1'}
69+
},
70+
},
71+
) # {}, flag_values=flags.FLAGS) #
72+
cluster = elastic_kubernetes_service.EksCluster(spec)
73+
cluster._Create()
74+
issue_command.func_to_mock.assert_has_calls([
75+
mock.call(
76+
matchers.NOT(['node-zones']),
77+
timeout=1800,
78+
raise_on_failure=False,
79+
),
80+
])
81+
5882
def testEksClusterCreate(self):
5983
issue_command = self.MockIssueCommand(
6084
{'create cluster': [('Cluster created', '', 0)]}

0 commit comments

Comments
 (0)