Просмотр исходного кода

Add provision resources to shared vpc (#4020)

jose-fully-ported 2 лет назад
Родитель
Сommit
fcfefe4fe5

+ 18 - 11
api/server/handlers/release/create_addon.go

@@ -281,35 +281,42 @@ func (c *CreateAddonHandler) getVPCConfig(ctx context.Context, request *types.Cr
 		return vpcConfig, nil
 	}
 
-	awsTemplates := map[string]bool{
-		"rds-postgresql":        true,
-		"rds-postgresql-aurora": true,
+	awsTemplates := map[string]string{
+		"elasticache-redis":     "elasticache",
+		"rds-postgresql":        "rds",
+		"rds-postgresql-aurora": "rds",
 	}
 
-	if !awsTemplates[request.TemplateName] {
+	serviceType, ok := awsTemplates[request.TemplateName]
+	if !ok {
 		return vpcConfig, nil
 	}
 
-	req := connect.NewRequest(&porterv1.ClusterNetworkSettingsRequest{
-		ProjectId: int64(project.ID),
-		ClusterId: int64(cluster.ID),
+	req := connect.NewRequest(&porterv1.SharedNetworkSettingsRequest{
+		ProjectId:   int64(project.ID),
+		ClusterId:   int64(cluster.ID),
+		ServiceType: serviceType,
 	})
 
-	resp, err := c.Config().ClusterControlPlaneClient.ClusterNetworkSettings(ctx, req)
+	resp, err := c.Config().ClusterControlPlaneClient.SharedNetworkSettings(ctx, req)
 	if err != nil {
 		return vpcConfig, telemetry.Error(ctx, span, err, "error fetching cluster network settings from ccp")
 	}
 
-	vpcConfig["awsRegion"] = resp.Msg.Region
+	vpcConfig["cidrBlock"] = resp.Msg.CidrRange
 	vpcConfig["subnetIDs"] = resp.Msg.SubnetIds
 	switch resp.Msg.CloudProvider {
 	case *porterv1.EnumCloudProvider_ENUM_CLOUD_PROVIDER_AWS.Enum():
+		vpcConfig["awsRegion"] = resp.Msg.Region
 		vpcConfig["vpcID"] = resp.Msg.GetEksCloudProviderNetwork().Id
-		telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "vpc-id", Value: resp.Msg.GetEksCloudProviderNetwork().Id})
+		telemetry.WithAttributes(span,
+			telemetry.AttributeKV{Key: "aws-region", Value: resp.Msg.Region},
+			telemetry.AttributeKV{Key: "vpc-id", Value: resp.Msg.GetEksCloudProviderNetwork().Id},
+		)
 	}
 
 	telemetry.WithAttributes(span,
-		telemetry.AttributeKV{Key: "aws-region", Value: resp.Msg.Region},
+		telemetry.AttributeKV{Key: "cidr-block", Value: resp.Msg.CidrRange},
 		telemetry.AttributeKV{Key: "subnet-ids", Value: strings.Join(resp.Msg.SubnetIds, ",")},
 	)
 

+ 15 - 14
dashboard/src/main/home/database-dashboard/DatabaseDashboard.tsx

@@ -1,46 +1,47 @@
+import _ from "lodash";
 import React, {
-  useState,
+  useCallback,
   useContext,
   useEffect,
   useMemo,
-  useCallback,
+  useState,
 } from "react";
 import styled from "styled-components";
-import _ from "lodash";
 
-import time from "assets/time.png";
+import calendar from "assets/calendar-number.svg";
+import database from "assets/database.svg";
 import grid from "assets/grid.png";
 import list from "assets/list.png";
+import notFound from "assets/not-found.png";
 import healthy from "assets/status-healthy.png";
+import time from "assets/time.png";
 import letter from "assets/vector.svg";
-import calendar from "assets/calendar-number.svg";
-import database from "assets/database.svg";
-import notFound from "assets/not-found.png";
 
 import { Context } from "shared/Context";
-import { search } from "shared/search";
 import api from "shared/api";
 import { hardcodedIcons } from "shared/hardcodedNameDict";
+import { search } from "shared/search";
 
-import Container from "components/porter/Container";
+import Loading from "components/Loading";
 import Button from "components/porter/Button";
+import Container from "components/porter/Container";
+import Fieldset from "components/porter/Fieldset";
+import PorterLink from "components/porter/Link";
+import SearchBar from "components/porter/SearchBar";
 import Spacer from "components/porter/Spacer";
 import Text from "components/porter/Text";
-import SearchBar from "components/porter/SearchBar";
 import Toggle from "components/porter/Toggle";
-import PorterLink from "components/porter/Link";
-import Loading from "components/Loading";
-import Fieldset from "components/porter/Fieldset";
 import { Link } from "react-router-dom";
 import { readableDate } from "shared/string_utils";
 
-import DashboardHeader from "main/home/cluster-dashboard/DashboardHeader";
 import ClusterProvisioningPlaceholder from "components/ClusterProvisioningPlaceholder";
 import DashboardPlaceholder from "components/porter/DashboardPlaceholder";
+import DashboardHeader from "main/home/cluster-dashboard/DashboardHeader";
 
 type Props = {};
 
 const templateWhitelist = [
+  "elasticache-redis",
   "rds-postgresql",
   "rds-postgresql-aurora",
 ];

+ 6 - 2
dashboard/src/shared/hardcodedNameDict.tsx

@@ -1,5 +1,6 @@
-import lightning from "../assets/lightning.png";
 import awsRDS from "assets/amazon-rds.png";
+import awsElasticache from "assets/aws-elasticache.png";
+import lightning from "../assets/lightning.png";
 
 const hardcodedNames: { [key: string]: string } = {
   agones: "Agones System",
@@ -32,6 +33,7 @@ const hardcodedNames: { [key: string]: string } = {
 };
 
 const hardcodedIcons: { [key: string]: string } = {
+  "elasticache-redis": awsElasticache,
   "https-issuer":
     "https://cdn4.iconfinder.com/data/icons/macster-2/100/https__-512.png",
   metabase:
@@ -46,6 +48,7 @@ const hardcodedIcons: { [key: string]: string } = {
   postgresql:
     "https://cdn.jsdelivr.net/gh/devicons/devicon/icons/postgresql/postgresql-original.svg",
   "rds-postgresql": awsRDS,
+  "rds-postgresql-aurora": awsRDS,
   redis:
     "https://cdn4.iconfinder.com/data/icons/redis-2/1451/Untitled-2-512.png",
   ubuntu: "Ubuntu",
@@ -83,4 +86,5 @@ const DISPLAY_TAGS_MAP = {
   "MISC": { label: "Misc.", color: "#616163" },
 };
 
-export { hardcodedNames, hardcodedIcons, DISPLAY_TAGS_MAP };
+export { DISPLAY_TAGS_MAP, hardcodedIcons, hardcodedNames };
+

+ 1 - 1
go.mod

@@ -83,7 +83,7 @@ require (
 	github.com/matryer/is v1.4.0
 	github.com/nats-io/nats.go v1.24.0
 	github.com/open-policy-agent/opa v0.44.0
-	github.com/porter-dev/api-contracts v0.2.53
+	github.com/porter-dev/api-contracts v0.2.54
 	github.com/riandyrn/otelchi v0.5.1
 	github.com/santhosh-tekuri/jsonschema/v5 v5.0.1
 	github.com/stefanmcshane/helm v0.0.0-20221213002717-88a4a2c6e77d

+ 2 - 2
go.sum

@@ -1520,8 +1520,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
-github.com/porter-dev/api-contracts v0.2.53 h1:dksPN2aPsN/LT97b0pMXqbGt2E/0YKJt0o0XR1ipqNs=
-github.com/porter-dev/api-contracts v0.2.53/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
+github.com/porter-dev/api-contracts v0.2.54 h1:EgA0iACycQhsQ3jahjKr5/niNLGC0s6QEHWb9vYYXs0=
+github.com/porter-dev/api-contracts v0.2.54/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
 github.com/porter-dev/switchboard v0.0.3 h1:dBuYkiVLa5Ce7059d6qTe9a1C2XEORFEanhbtV92R+M=
 github.com/porter-dev/switchboard v0.0.3/go.mod h1:xSPzqSFMQ6OSbp42fhCi4AbGbQbsm6nRvOkrblFeXU4=
 github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=