Skip to content

Commit 4348814

Browse files
committed
Add all AWS subnets to hosted deploy
1 parent f3f9c0f commit 4348814

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

test/e2e/managedcluster/aws/aws.go

+12-14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
. "github.com/onsi/ginkgo/v2"
2323
. "github.com/onsi/gomega"
24+
"gopkg.in/yaml.v3"
2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2627
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -52,30 +53,27 @@ func PopulateHostedTemplateVars(ctx context.Context, kc *kubeclient.KubeClient,
5253
Expect(err).NotTo(HaveOccurred(), "failed to get AWS cluster subnets")
5354
Expect(found).To(BeTrue(), "AWS cluster has no subnets")
5455

55-
// find the first public subnet
56-
for _, s := range subnets {
56+
type awsSubnetMaps []map[string]any
57+
subnetMaps := make(awsSubnetMaps, len(subnets))
58+
for i, s := range subnets {
5759
subnet, ok := s.(map[string]any)
5860
Expect(ok).To(BeTrue(), "failed to cast subnet to map")
59-
60-
if isPublic, ok := subnet["isPublic"].(bool); ok && isPublic {
61-
subnetID, ok := subnet["resourceID"].(string)
62-
Expect(ok).To(BeTrue(), "failed to cast subnet ID to string")
63-
64-
subnetAZ, ok := subnet["availabilityZone"].(string)
65-
Expect(ok).To(BeTrue(), "failed to cast subnet availability zone to string")
66-
67-
GinkgoT().Setenv(managedcluster.EnvVarAWSSubnetID, subnetID)
68-
GinkgoT().Setenv(managedcluster.EnvVarAWSSubnetAvailabilityZone, subnetAZ)
69-
break
61+
subnetMaps[i] = map[string]any{
62+
"isPublic": subnet["isPublic"],
63+
"availabilityZone": subnet["availabilityZone"],
64+
"id": subnet["resourceID"],
7065
}
7166
}
7267

68+
subnetYaml, err := yaml.Marshal(subnetMaps)
69+
Expect(err).NotTo(HaveOccurred(), "failed to get marshall subnet maps")
70+
GinkgoT().Setenv(managedcluster.EnvVarSubnets, string(subnetYaml))
71+
7372
securityGroupID, found, err := unstructured.NestedString(
7473
awsCluster.Object, "status", "networkStatus", "securityGroups", "node", "id")
7574
Expect(err).NotTo(HaveOccurred(), "failed to get AWS cluster security group ID")
7675
Expect(found).To(BeTrue(), "AWS cluster has no security group ID")
7776

7877
GinkgoT().Setenv(managedcluster.EnvVarAWSVPCID, vpcID)
79-
8078
GinkgoT().Setenv(managedcluster.EnvVarAWSSecurityGroupID, securityGroupID)
8179
}

test/e2e/managedcluster/constants.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const (
3333
EnvVarAWSInstanceType = "AWS_INSTANCE_TYPE"
3434
EnvVarAWSSecurityGroupID = "AWS_SG_ID"
3535
EnvVarAWSClusterIdentity = "AWS_CLUSTER_IDENTITY"
36-
EnvVarPublicIP = "AWS_PUBLIC_IP"
36+
EnvVarSubnets = "AWS_SUBNETS"
3737

3838
// VSphere
3939
EnvVarVSphereUser = "VSPHERE_USER"

test/e2e/managedcluster/resources/aws-hosted-cp.yaml.tpl

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ spec:
1212
vpcID: ${AWS_VPC_ID}
1313
region: ${AWS_REGION}
1414
subnets:
15-
- id: ${AWS_SUBNET_ID}
16-
availabilityZone: ${AWS_SUBNET_AVAILABILITY_ZONE}
17-
isPublic: true
15+
${AWS_SUBNETS}
1816
instanceType: ${AWS_INSTANCE_TYPE:=t3.medium}
1917
securityGroupIDs:
2018
- ${AWS_SG_ID}

0 commit comments

Comments
 (0)