@@ -28,6 +28,45 @@ const MetricNamespace = "NetworkingAZConnectivity"
28
28
29
29
var f * framework.Framework
30
30
31
+ func getClusterAZs (ctx context.Context , clusterName string ) ([]string , error ) {
32
+ // Step 1: Get all AZs in the region
33
+ describeAZOutput , err := f .CloudServices .EC2 ().DescribeAvailabilityZones (ctx )
34
+ if err != nil {
35
+ return nil , fmt .Errorf ("failed to describe availability zones: %w" , err )
36
+ }
37
+
38
+ // Step 2: Get cluster info
39
+ clusterInfo , err := f .CloudServices .EKS ().DescribeCluster (ctx , clusterName )
40
+ if err != nil {
41
+ return nil , fmt .Errorf ("failed to describe cluster: %w" , err )
42
+ }
43
+
44
+ // Step 3: Get subnet info
45
+ subnetIDs := clusterInfo .Cluster .ResourcesVpcConfig .SubnetIds
46
+ describeSubnetsOutput , err := f .CloudServices .EC2 ().DescribeSubnets (ctx , subnetIDs )
47
+ if err != nil {
48
+ return nil , fmt .Errorf ("failed to describe subnets: %w" , err )
49
+ }
50
+
51
+ // Step 4: Create a map of cluster AZs
52
+ clusterAZs := make (map [string ]bool )
53
+ for _ , subnet := range describeSubnetsOutput .Subnets {
54
+ clusterAZs [* subnet .AvailabilityZone ] = true
55
+ }
56
+
57
+ // Step 5: Filter and deduplicate AZs
58
+ var filteredAZs []string
59
+ azSet := make (map [string ]bool )
60
+ for _ , az := range describeAZOutput .AvailabilityZones {
61
+ if clusterAZs [* az .ZoneName ] && ! azSet [* az .ZoneName ] {
62
+ filteredAZs = append (filteredAZs , * az .ZoneName )
63
+ azSet [* az .ZoneName ] = true
64
+ }
65
+ }
66
+
67
+ return filteredAZs , nil
68
+ }
69
+
31
70
var _ = Describe ("[STATIC_CANARY] AZ Node Presence" , FlakeAttempts (retries ), func () {
32
71
33
72
Context ("While testing AZ availability" , func () {
@@ -37,11 +76,11 @@ var _ = Describe("[STATIC_CANARY] AZ Node Presence", FlakeAttempts(retries), fun
37
76
nodes , err := f .K8sResourceManagers .NodeManager ().GetNodes (f .Options .NgNameLabelKey , f .Options .NgNameLabelVal )
38
77
Expect (err ).ToNot (HaveOccurred ())
39
78
40
- describeAZOutput , err := f . CloudServices . EC2 (). DescribeAvailabilityZones ( context .TODO ())
79
+ clusterAZs , err := getClusterAZs ( context .TODO (), f . Options . ClusterName )
41
80
Expect (err ).ToNot (HaveOccurred ())
42
81
43
- for _ , az := range describeAZOutput . AvailabilityZones {
44
- nodePresenceInAZ [* az . ZoneName ] = false
82
+ for _ , az := range clusterAZs {
83
+ nodePresenceInAZ [az ] = false
45
84
}
46
85
for i := range nodes .Items {
47
86
// node label key "topology.kubernetes.io/zone" is well known label populated by cloud controller manager
0 commit comments