Skip to content

Commit

Permalink
Add all AWS subnets to hosted deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewuolle committed Nov 29, 2024
1 parent f3f9c0f commit 4348814
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
26 changes: 12 additions & 14 deletions test/e2e/managedcluster/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

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

// find the first public subnet
for _, s := range subnets {
type awsSubnetMaps []map[string]any
subnetMaps := make(awsSubnetMaps, len(subnets))
for i, s := range subnets {
subnet, ok := s.(map[string]any)
Expect(ok).To(BeTrue(), "failed to cast subnet to map")

if isPublic, ok := subnet["isPublic"].(bool); ok && isPublic {
subnetID, ok := subnet["resourceID"].(string)
Expect(ok).To(BeTrue(), "failed to cast subnet ID to string")

subnetAZ, ok := subnet["availabilityZone"].(string)
Expect(ok).To(BeTrue(), "failed to cast subnet availability zone to string")

GinkgoT().Setenv(managedcluster.EnvVarAWSSubnetID, subnetID)
GinkgoT().Setenv(managedcluster.EnvVarAWSSubnetAvailabilityZone, subnetAZ)
break
subnetMaps[i] = map[string]any{
"isPublic": subnet["isPublic"],
"availabilityZone": subnet["availabilityZone"],
"id": subnet["resourceID"],
}
}

subnetYaml, err := yaml.Marshal(subnetMaps)
Expect(err).NotTo(HaveOccurred(), "failed to get marshall subnet maps")
GinkgoT().Setenv(managedcluster.EnvVarSubnets, string(subnetYaml))

securityGroupID, found, err := unstructured.NestedString(
awsCluster.Object, "status", "networkStatus", "securityGroups", "node", "id")
Expect(err).NotTo(HaveOccurred(), "failed to get AWS cluster security group ID")
Expect(found).To(BeTrue(), "AWS cluster has no security group ID")

GinkgoT().Setenv(managedcluster.EnvVarAWSVPCID, vpcID)

GinkgoT().Setenv(managedcluster.EnvVarAWSSecurityGroupID, securityGroupID)
}
2 changes: 1 addition & 1 deletion test/e2e/managedcluster/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
EnvVarAWSInstanceType = "AWS_INSTANCE_TYPE"
EnvVarAWSSecurityGroupID = "AWS_SG_ID"
EnvVarAWSClusterIdentity = "AWS_CLUSTER_IDENTITY"
EnvVarPublicIP = "AWS_PUBLIC_IP"
EnvVarSubnets = "AWS_SUBNETS"

// VSphere
EnvVarVSphereUser = "VSPHERE_USER"
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/managedcluster/resources/aws-hosted-cp.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ spec:
vpcID: ${AWS_VPC_ID}
region: ${AWS_REGION}
subnets:
- id: ${AWS_SUBNET_ID}
availabilityZone: ${AWS_SUBNET_AVAILABILITY_ZONE}
isPublic: true
${AWS_SUBNETS}
instanceType: ${AWS_INSTANCE_TYPE:=t3.medium}
securityGroupIDs:
- ${AWS_SG_ID}

0 comments on commit 4348814

Please sign in to comment.