Files
floci/src/test/java
Sumedh 66fd109ad6 fix(eks): validate subnet IDs exist before creating a cluster (#1943)
* fix(eks): validate subnet IDs exist before creating a cluster

CreateCluster previously accepted any subnet ID, including ones that
don't exist, and returned a successful cluster with an empty vpcId.
Real EKS validates resourcesVpcConfig.subnetIds against EC2 and
rejects the request with InvalidParameterException if a subnet is
not found.

EksService now delegates to Ec2Service.requireSubnet for each subnet
ID given at cluster creation, mirroring the pattern RdsService already
uses for DB subnet groups.

* fix(eks): resolve subnet validation against the request's region

Subnet validation in createCluster used config.defaultRegion() instead
of the region the request actually targeted, so a cluster created in a
non-default region with real, existing subnets would be wrongly
rejected as InvalidParameterException.

RegionResolver gains getRegion(), mirroring the existing getAccountId()
pattern (reads the per-request region set by AccountContextFilter,
falling back to the configured default outside request scope).
EksService.createCluster now uses regionResolver.getRegion() instead of
config.defaultRegion(), which also fixes the cluster ARN's region to
match the actual request.

Found via review feedback on #1943.

* fix(eks): pin the region test properly and resolve vpcId from the subnets

Addresses both blocking points from review.

1. The region regression test could not fail.

   It used subnet-default-a, and requireSubnet() calls ensureDefaultResources()
   on whatever region it is handed, which seeds subnet-default-a/b/c there on
   the spot. The subnet therefore resolves in every region, so validation passed
   with or without the fix and only the ARN assertion discriminated — exactly as
   pointed out.

   Verified by reverting `regionResolver.getRegion()` back to
   `config.defaultRegion()` and re-running: the old test failed at the ARN
   assertion on line 276, which means createCluster had already returned without
   throwing. Validation was never being exercised.

   Split into two honestly named tests:

     createClusterBuildsArnFromRequestRegionNotDefaultRegion
         what the old test actually pinned

     createClusterValidatesSubnetsInRequestRegionNotDefaultRegion
         creates a subnet explicitly in us-east-1 and requests a cluster in
         eu-west-2 with that id. An explicitly created subnet is not seeded
         elsewhere, so this is the only shape that discriminates.

   With the fix reverted it now fails with "Expected AwsException to be thrown,
   but nothing was thrown" — the cluster is created from a subnet in the wrong
   region, which is the bug. With the fix it passes.

2. resourcesVpcConfig.vpcId was still blank (the other half of #1942).

   CreateCluster carries no vpcId; real EKS derives it from the subnets.
   requireSubnet already returns the resolved Subnet, and validateSubnets threw
   it away. It now carries the vpcId through to buildVpcConfigResponse, with a
   caller-supplied value still taking precedence.

   New test createClusterResolvesVpcIdFromTheSubnets fails before the change
   with "expected: <vpc-default> but was: <>".

EksServiceTest 28 pass, Ec2ServiceTest 17 pass. Other failures in a full run are
pre-existing on this machine and unrelated — confirmed by stashing these changes
and reproducing ZipExtractorTest's backslash-path failure on the untouched tree.

Leaving the `catch (AwsException e)` narrowing for the separate PR as suggested.
2026-08-08 21:32:28 -05:00
..