Parcourir la source

give out general cluster information

Mohammed Nafees il y a 3 ans
Parent
commit
b958b92a71

+ 11 - 7
api/server/handlers/cluster_integration/aws/list_cluster_ips.go → api/server/handlers/cluster_integration/aws/get_cluster_info.go

@@ -18,21 +18,21 @@ import (
 	"gorm.io/gorm"
 )
 
-type ListClusterIPsHandler struct {
+type GetClusterInfoHandler struct {
 	handlers.PorterHandlerReadWriter
 }
 
-func NewListClusterIPsHandler(
+func NewGetClusterInfoHandler(
 	config *config.Config,
 	decoderValidator shared.RequestDecoderValidator,
 	writer shared.ResultWriter,
-) *ListClusterIPsHandler {
-	return &ListClusterIPsHandler{
+) *GetClusterInfoHandler {
+	return &GetClusterInfoHandler{
 		PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, decoderValidator, writer),
 	}
 }
 
-func (c *ListClusterIPsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+func (c *GetClusterInfoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	proj, _ := r.Context().Value(types.ProjectScope).(*models.Project)
 	cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster)
 
@@ -98,10 +98,14 @@ func (c *ListClusterIPsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
 		return
 	}
 
-	var res types.ListAWSClusterIPsResponse
+	res := &types.GetAWSClusterInfoResponse{
+		Name:       clusterName,
+		K8sVersion: *clusterInfo.Cluster.Version,
+		EKSVersion: *clusterInfo.Cluster.PlatformVersion,
+	}
 
 	for _, subnet := range subnetsInfo.Subnets {
-		res = append(res, &types.AWSClusterIP{
+		res.Subnets = append(res.Subnets, &types.AWSSubnet{
 			AvailabilityZone:        *subnet.AvailabilityZone,
 			AvailableIPAddressCount: *subnet.AvailableIpAddressCount,
 		})

+ 6 - 6
api/server/router/cluster_integration.go

@@ -53,14 +53,14 @@ func getClusterIntegrationRoutes(
 
 	routes := make([]*router.Route, 0)
 
-	// GET /api/projects/{project_id}/clusters/{cluster_id}/integrations/aws/ips -> awsClusterInt.NewListClusterIPsHandler
-	listAWSClusterIPsEndpoint := factory.NewAPIEndpoint(
+	// GET /api/projects/{project_id}/clusters/{cluster_id}/integrations/aws/info -> awsClusterInt.NewGetClusterInfoHandler
+	getAWSClusterInfoEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{
 			Verb:   types.APIVerbGet,
 			Method: types.HTTPVerbGet,
 			Path: &types.Path{
 				Parent:       basePath,
-				RelativePath: relPath + "/aws/ips",
+				RelativePath: relPath + "/aws/info",
 			},
 			Scopes: []types.PermissionScope{
 				types.UserScope,
@@ -70,15 +70,15 @@ func getClusterIntegrationRoutes(
 		},
 	)
 
-	listAWSClusterIPsHandler := awsClusterInt.NewListClusterIPsHandler(
+	getAWSClusterInfoHandler := awsClusterInt.NewGetClusterInfoHandler(
 		config,
 		factory.GetDecoderValidator(),
 		factory.GetResultWriter(),
 	)
 
 	routes = append(routes, &router.Route{
-		Endpoint: listAWSClusterIPsEndpoint,
-		Handler:  listAWSClusterIPsHandler,
+		Endpoint: getAWSClusterInfoEndpoint,
+		Handler:  getAWSClusterInfoHandler,
 		Router:   r,
 	})
 

+ 7 - 2
api/types/cluster_integration.go

@@ -1,8 +1,13 @@
 package types
 
-type AWSClusterIP struct {
+type AWSSubnet struct {
 	AvailabilityZone        string `json:"availability_zone"`
 	AvailableIPAddressCount int64  `json:"available_ip_address_count"`
 }
 
-type ListAWSClusterIPsResponse []*AWSClusterIP
+type GetAWSClusterInfoResponse struct {
+	Name       string       `json:"name"`
+	K8sVersion string       `json:"kubernetes_server_version"`
+	EKSVersion string       `json:"eks_version"`
+	Subnets    []*AWSSubnet `json:"subnets"`
+}