Skip to content

Commit a00dd91

Browse files
committed
replace assertions on eks:DescribeCluster API by eks:DescribeUpdate API
1 parent c6d7b4e commit a00dd91

File tree

1 file changed

+41
-75
lines changed

1 file changed

+41
-75
lines changed

test/e2e/tests/test_cluster_automode_updates.py

Lines changed: 41 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -170,100 +170,66 @@ def test_enable_auto_mode_on_standard_cluster(self, eks_client, simple_cluster):
170170
},
171171
}
172172
}
173-
logging.info(f"Applying patch to enable auto-mode: {patch_enable_auto_mode}")
174173
k8s.patch_custom_resource(ref, patch_enable_auto_mode)
175174
time.sleep(MODIFY_WAIT_AFTER_SECONDS)
176175

177176
get_and_assert_status(ref, "UPDATING", False)
178177

179-
cr_updating = k8s.get_resource(ref)
180-
eks_describe_updating = eks_client.describe_cluster(name=cluster_name)
181-
182178
# Wait for cluster to become active after update
183179
wait_for_cluster_active(eks_client, cluster_name)
184180
time.sleep(CHECK_STATUS_WAIT_SECONDS)
185181

186182
get_and_assert_status(ref, "ACTIVE", True)
187183

188-
cr_after_update = k8s.get_resource(ref)
189-
eks_describe_after_update = eks_client.describe_cluster(name=cluster_name)
184+
# Verify auto-mode activation via EKS update history (since DescribeCluster may not reflect the fields immediately)
185+
updates_summary = eks_client.list_updates(name=cluster_name)
190186

191-
# Log current pending/active updates for diagnostic purposes
192-
try:
193-
updates_summary = eks_client.list_updates(name=cluster_name)
194-
logging.info(f"EKS list_updates response: {updates_summary}")
195-
for update_id in updates_summary.get("updateIds", []) or []:
196-
try:
197-
upd_desc = eks_client.describe_update(
198-
name=cluster_name, updateId=update_id
199-
)
200-
logging.info(f"EKS describe_update {update_id}: {upd_desc}")
201-
except Exception as e:
202-
logging.warning(f"Failed to describe update {update_id}: {e}")
203-
except Exception as e:
204-
logging.warning(f"Failed to list updates for cluster {cluster_name}: {e}")
205-
206-
# Verify on AWS EKS API that auto-mode is enabled with polling (in case propagation lags)
207-
max_poll_seconds = 180
208-
poll_interval = 10
209-
deadline = time.time() + max_poll_seconds
210-
last_aws_res = None
211-
while time.time() < deadline:
212-
last_aws_res = eks_client.describe_cluster(name=cluster_name)
213-
compute_config = last_aws_res["cluster"].get("computeConfig")
214-
storage_config = last_aws_res["cluster"].get("storageConfig")
215-
elb_config = (
216-
last_aws_res["cluster"]
217-
.get("kubernetesNetworkConfig", {})
218-
.get("elasticLoadBalancing")
219-
)
220-
if (
221-
compute_config
222-
and storage_config
223-
and storage_config.get("blockStorage", {}).get("enabled")
224-
and elb_config
225-
):
226-
break
227-
remaining = int(deadline - time.time())
228-
if remaining < 0:
229-
remaining = 0
230-
logging.info(
231-
f"Waiting for compute/storage/ELB config to appear in DescribeCluster... (remaining ~{remaining}s)"
232-
)
233-
time.sleep(poll_interval)
234-
aws_res = last_aws_res or eks_client.describe_cluster(name=cluster_name)
187+
update_ids = updates_summary.get("updateIds", [])
188+
assert len(update_ids) == 1, (
189+
f"Expected exactly 1 update, got {len(update_ids)}: {update_ids}"
190+
)
235191

236-
logging.info(f"custom resource while updating: {cr_updating}")
237-
logging.info(f"eks:DescribeCluster while updating: {eks_describe_updating}")
238-
logging.info(f"custom resource after update: {cr_after_update}")
239-
logging.info(f"eks:DescribeCluster after update: {eks_describe_after_update}")
240-
logging.info(f"eks:DescribeCluster after polling loop: {aws_res}")
192+
update_id = update_ids[0]
193+
upd_desc = eks_client.describe_update(name=cluster_name, updateId=update_id)
241194

242-
# Check compute config
243-
compute_config = aws_res["cluster"].get("computeConfig")
244-
assert compute_config is not None, "computeConfig should be present"
245-
assert compute_config.get("enabled") is True, (
246-
f"computeConfig.enabled should be True, got: {compute_config.get('enabled')}"
247-
)
195+
update_info = upd_desc["update"]
248196

249-
# Check storage config
250-
storage_config = aws_res["cluster"].get("storageConfig")
251-
assert storage_config is not None, "storageConfig should be present"
252-
block_storage = storage_config.get("blockStorage", {})
253-
assert block_storage.get("enabled") is True, (
254-
f"storageConfig.blockStorage.enabled should be True, got: {block_storage.get('enabled')}"
197+
# Verify update type and status
198+
assert update_info["type"] == "AutoModeUpdate", (
199+
f"Expected AutoModeUpdate, got: {update_info['type']}"
255200
)
256-
257-
# Check elastic load balancing config
258-
k8s_network_config = aws_res["cluster"].get("kubernetesNetworkConfig", {})
259-
elb_config = k8s_network_config.get("elasticLoadBalancing")
260-
assert elb_config is not None, (
261-
"kubernetesNetworkConfig.elasticLoadBalancing should be present"
201+
assert update_info["status"] == "Successful", (
202+
f"Expected Successful status, got: {update_info['status']}"
262203
)
263-
assert elb_config.get("enabled") is True, (
264-
f"kubernetesNetworkConfig.elasticLoadBalancing.enabled should be True, got: {elb_config.get('enabled')}"
204+
205+
# Verify update params contain the three Auto Mode configurations
206+
params = update_info.get("params", [])
207+
param_types = {param["type"] for param in params}
208+
expected_types = {"ComputeConfig", "StorageConfig", "KubernetesNetworkConfig"}
209+
assert param_types == expected_types, (
210+
f"Expected params {expected_types}, got: {param_types}"
265211
)
266212

213+
# Verify each param has correct enabled=true values
214+
for param in params:
215+
import json
216+
217+
value = json.loads(param["value"])
218+
if param["type"] == "ComputeConfig":
219+
assert value.get("enabled") is True, (
220+
f"ComputeConfig should have enabled=true, got: {value}"
221+
)
222+
elif param["type"] == "StorageConfig":
223+
block_storage = value.get("blockStorage", {})
224+
assert block_storage.get("enabled") is True, (
225+
f"StorageConfig.blockStorage should have enabled=true, got: {value}"
226+
)
227+
elif param["type"] == "KubernetesNetworkConfig":
228+
elb = value.get("elasticLoadBalancing", {})
229+
assert elb.get("enabled") is True, (
230+
f"KubernetesNetworkConfig.elasticLoadBalancing should have enabled=true, got: {value}"
231+
)
232+
267233
def test_disable_auto_mode_incorrectly(self, eks_client, auto_mode_cluster):
268234
(ref, cr) = auto_mode_cluster
269235
cluster_name = cr["spec"]["name"]

0 commit comments

Comments
 (0)