Răsfoiți Sursa

Merge pull request #2204 from porter-dev/nafees/hotfixes

[POR-584] Fetch subnets using the VPC ID
abelanger5 3 ani în urmă
părinte
comite
e88cc6e3b2

+ 30 - 14
api/server/handlers/cluster_integration/aws/get_cluster_info.go

@@ -89,26 +89,42 @@ func (c *GetClusterInfoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
 
 	ec2Svc := ec2.New(awsSession, awsConf)
 
-	subnetsInfo, err := ec2Svc.DescribeSubnets(&ec2.DescribeSubnetsInput{
-		SubnetIds: clusterInfo.Cluster.ResourcesVpcConfig.SubnetIds,
-	})
-
-	if err != nil || len(subnetsInfo.Subnets) == 0 {
-		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
-		return
-	}
-
 	res := &types.GetAWSClusterInfoResponse{
 		Name:       clusterName,
+		ARN:        *clusterInfo.Cluster.Arn,
+		Status:     *clusterInfo.Cluster.Status,
 		K8sVersion: *clusterInfo.Cluster.Version,
 		EKSVersion: *clusterInfo.Cluster.PlatformVersion,
 	}
 
-	for _, subnet := range subnetsInfo.Subnets {
-		res.Subnets = append(res.Subnets, &types.AWSSubnet{
-			AvailabilityZone:        *subnet.AvailabilityZone,
-			AvailableIPAddressCount: *subnet.AvailableIpAddressCount,
-		})
+	err = ec2Svc.DescribeSubnetsPages(&ec2.DescribeSubnetsInput{
+		Filters: []*ec2.Filter{
+			{
+				Name: aws.String("vpc-id"),
+				Values: []*string{
+					clusterInfo.Cluster.ResourcesVpcConfig.VpcId,
+				},
+			},
+		},
+	}, func(page *ec2.DescribeSubnetsOutput, lastPage bool) bool {
+		if page == nil {
+			return false
+		}
+
+		for _, subnet := range page.Subnets {
+			res.Subnets = append(res.Subnets, &types.AWSSubnet{
+				SubnetID:                *subnet.SubnetId,
+				AvailabilityZone:        *subnet.AvailabilityZone,
+				AvailableIPAddressCount: *subnet.AvailableIpAddressCount,
+			})
+		}
+
+		return !lastPage
+	})
+
+	if err != nil {
+		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
+		return
 	}
 
 	c.WriteResult(w, r, res)

+ 3 - 0
api/types/cluster_integration.go

@@ -1,13 +1,16 @@
 package types
 
 type AWSSubnet struct {
+	SubnetID                string `json:"subnet_id"`
 	AvailabilityZone        string `json:"availability_zone"`
 	AvailableIPAddressCount int64  `json:"available_ip_address_count"`
 }
 
 type GetAWSClusterInfoResponse struct {
 	Name       string       `json:"name"`
+	ARN        string       `json:"arn"`
 	K8sVersion string       `json:"kubernetes_server_version"`
 	EKSVersion string       `json:"eks_version"`
+	Status     string       `json:"status"`
 	Subnets    []*AWSSubnet `json:"subnets"`
 }