From cff68bbeacc0f47958280a2c1e127f0fa3d684c0 Mon Sep 17 00:00:00 2001 From: Stefan McShane Date: Thu, 28 Sep 2023 15:24:06 +0100 Subject: [PATCH] support kubernetes services vpc (#3673) --- dashboard/package-lock.json | 14 +++---- dashboard/package.json | 2 +- .../src/components/ProvisionerSettings.tsx | 37 +++++++++++++++---- go.mod | 4 +- go.sum | 4 +- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/dashboard/package-lock.json b/dashboard/package-lock.json index 30e4021db4..a48137de57 100644 --- a/dashboard/package-lock.json +++ b/dashboard/package-lock.json @@ -13,7 +13,7 @@ "@loadable/component": "^5.15.2", "@material-ui/core": "^4.11.3", "@material-ui/lab": "^4.0.0-alpha.61", - "@porter-dev/api-contracts": "^0.1.7", + "@porter-dev/api-contracts": "^0.2.1", "@react-spring/web": "^9.6.1", "@sentry/react": "^6.13.2", "@sentry/tracing": "^6.13.2", @@ -2455,9 +2455,9 @@ } }, "node_modules/@porter-dev/api-contracts": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/@porter-dev/api-contracts/-/api-contracts-0.1.7.tgz", - "integrity": "sha512-S7CyV3gr0vQq+H6aUprm1nP4OKjugAATmEBQAjzhJsnZw9Gk19jPsyVciCjCKXtkzeFYyYMJR4ulybVc/pllPA==", + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@porter-dev/api-contracts/-/api-contracts-0.2.1.tgz", + "integrity": "sha512-YNXlmHwoLOft1q3FEKoAOCa73t8wz0sG9DYMs7+lModWK/kljts1COculJEVs9e/CzkCs4rxTXSX4lH2BnDX2w==", "dependencies": { "@bufbuild/protobuf": "^1.1.0" } @@ -16956,9 +16956,9 @@ "integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==" }, "@porter-dev/api-contracts": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/@porter-dev/api-contracts/-/api-contracts-0.1.7.tgz", - "integrity": "sha512-S7CyV3gr0vQq+H6aUprm1nP4OKjugAATmEBQAjzhJsnZw9Gk19jPsyVciCjCKXtkzeFYyYMJR4ulybVc/pllPA==", + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@porter-dev/api-contracts/-/api-contracts-0.2.1.tgz", + "integrity": "sha512-YNXlmHwoLOft1q3FEKoAOCa73t8wz0sG9DYMs7+lModWK/kljts1COculJEVs9e/CzkCs4rxTXSX4lH2BnDX2w==", "requires": { "@bufbuild/protobuf": "^1.1.0" } diff --git a/dashboard/package.json b/dashboard/package.json index ab59514cb1..d6df94755c 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -8,7 +8,7 @@ "@loadable/component": "^5.15.2", "@material-ui/core": "^4.11.3", "@material-ui/lab": "^4.0.0-alpha.61", - "@porter-dev/api-contracts": "^0.1.7", + "@porter-dev/api-contracts": "^0.2.1", "@react-spring/web": "^9.6.1", "@sentry/react": "^6.13.2", "@sentry/tracing": "^6.13.2", diff --git a/dashboard/src/components/ProvisionerSettings.tsx b/dashboard/src/components/ProvisionerSettings.tsx index 1f09f59056..07f15b0c0c 100644 --- a/dashboard/src/components/ProvisionerSettings.tsx +++ b/dashboard/src/components/ProvisionerSettings.tsx @@ -23,8 +23,9 @@ import { EKSLogging, EKSPreflightValues, PreflightCheckRequest, - GKE + AWSClusterNetwork, } from "@porter-dev/api-contracts"; + import { ClusterType } from "shared/types"; import Button from "./porter/Button"; import Error from "./porter/Error"; @@ -94,6 +95,9 @@ const clusterVersionOptions = [ { value: "v1.24.0", label: "1.24.0" }, ]; +const defaultCidrVpc = "10.78.0.0/16" +const defaultCidrServices = "172.20.0.0/16" + type Props = RouteComponentProps & { selectedClusterVersion?: Contract; provisionerError?: string; @@ -134,7 +138,8 @@ const ProvisionerSettings: React.FC = (props) => { const [additionalNodePolicies, setAdditionalNodePolicies] = useState< string[] >([]); - const [cidrRange, setCidrRange] = useState("10.78.0.0/16"); + const [cidrRangeVPC, setCidrRangeVPC] = useState(defaultCidrVpc); + const [cidrRangeServices, setCidrRangeServices] = useState(defaultCidrServices); const [clusterVersion, setClusterVersion] = useState("v1.24.0"); const [isReadOnly, setIsReadOnly] = useState(false); const [errorMessage, setErrorMessage] = useState(undefined); @@ -295,12 +300,16 @@ const ProvisionerSettings: React.FC = (props) => { value: new EKS({ clusterName, clusterVersion: clusterVersion || "v1.24.0", - cidrRange: cidrRange || "10.78.0.0/16", + cidrRange: cidrRangeVPC || defaultCidrVpc, // deprecated in favour of network.cidrRangeVPC: can be removed after december 2023 region: awsRegion, loadBalancer: loadBalancerObj, logging: controlPlaneLogs, enableGuardDuty: guardDutyEnabled, enableKmsEncryption: kmsEncryptionEnabled, + network: new AWSClusterNetwork({ + vpcCidr: cidrRangeVPC || defaultCidrVpc, + serviceCidr: cidrRangeServices || defaultCidrServices, + }), nodeGroups: [ new EKSNodeGroup({ instanceType: "t3.medium", @@ -450,7 +459,11 @@ const ProvisionerSettings: React.FC = (props) => { setClusterName(eksValues.clusterName); setAwsRegion(eksValues.region); setClusterVersion(eksValues.clusterVersion); - setCidrRange(eksValues.cidrRange); + setCidrRangeVPC(eksValues.cidrRange); + if (eksValues.network != null) { + setCidrRangeVPC(eksValues.network?.vpcCidr || defaultCidrVpc); + setCidrRangeServices(eksValues.network?.serviceCidr || defaultCidrServices); + } if (eksValues.loadBalancer != null) { setIPAllowList(eksValues.loadBalancer.allowlistIpRanges); setWildCardDomain(eksValues.loadBalancer.wildcardDomain); @@ -618,12 +631,22 @@ const ProvisionerSettings: React.FC = (props) => { setCidrRange(x)} - label="VPC CIDR range" + setValue={(x: string) => setCidrRangeVPC(x)} + label="CIDR range for AWS VPC" placeholder="ex: 10.78.0.0/16" /> + + setCidrRangeServices(x)} + label="CIDR range for Kubernetes internal services" + placeholder="ex: 172.20.0.0/16" + /> {!currentProject.simplified_view_enabled && ( <> diff --git a/go.mod b/go.mod index e11ea66a14..ffec764854 100644 --- a/go.mod +++ b/go.mod @@ -82,7 +82,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.1.9 + github.com/porter-dev/api-contracts v0.2.1 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 @@ -230,7 +230,7 @@ require ( github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/gdamore/encoding v1.0.0 // indirect github.com/gdamore/tcell/v2 v2.5.1 // indirect - github.com/ghodss/yaml v1.0.0 + github.com/ghodss/yaml v1.0.0 // indirect github.com/go-errors/errors v1.4.2 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect diff --git a/go.sum b/go.sum index 53417d7122..43166618a7 100644 --- a/go.sum +++ b/go.sum @@ -1516,8 +1516,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.1.9 h1:EGNZjVjBKPIP+w7fcMhi3njWEt1V1kiK8cd2h87vFQk= -github.com/porter-dev/api-contracts v0.1.9/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8= +github.com/porter-dev/api-contracts v0.2.1 h1:Xb1ngCQuLJIa38OY/K+fE6uvCTEiJCSzcSnh7EFLHZ0= +github.com/porter-dev/api-contracts v0.2.1/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=