Skip to content

Commit

Permalink
add suggestion for next cidr range (#4359)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmcshane authored Mar 1, 2024
1 parent 79b3513 commit f4b4c72
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
24 changes: 0 additions & 24 deletions api/server/handlers/api_contract/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ type PreflightCheckResponse struct {
Errors []PreflightCheckError `json:"errors"`
}

var recognizedPreflightCheckTypes = []string{
"eip",
"vcpu",
"vpc",
"natGateway",
"apiEnabled",
"cidrAvailability",
"iamPermissions",
"authz",
}

func (p *PreflightCheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx, span := telemetry.NewSpan(r.Context(), "serve-preflight-checks")
defer span.End()
Expand Down Expand Up @@ -92,10 +81,6 @@ func (p *PreflightCheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request

errors := []PreflightCheckError{}
for _, check := range checkResp.Msg.FailingPreflightChecks {
if check.Message == "" || !contains(recognizedPreflightCheckTypes, check.Type) {
continue
}

errors = append(errors, PreflightCheckError{
Name: check.Type,
Error: PorterError{
Expand All @@ -107,12 +92,3 @@ func (p *PreflightCheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
resp.Errors = errors
p.WriteResult(w, r, resp)
}

func contains(slice []string, elem string) bool {
for _, item := range slice {
if item == elem {
return true
}
}
return false
}
35 changes: 35 additions & 0 deletions dashboard/src/lib/clusters/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,26 @@ const AWS_VCPUS_QUOTA_RESOLUTION: PreflightCheckResolution = {
},
],
};
const OVERLAPPING_CIDR_RESOLUTION: PreflightCheckResolution = {
title: "Preventing Overlapping CIDR Blocks",
subtitle:
"You will need to select an unused CIDR Block in order to provision in the region specified.",
steps: [
{
text: "Change the CIDR blocks on this page to be unique and not overlap with any other CIDR blocks in your account.",
},
{
text: "The VPC CIDR block should be a /16 in the 10.0.0.0/8 range",
},
{
text: "The Service CIDR block should be a /16 in the 172.16.0.0/12 range in accordanc with RFC 1918",
externalLink: "https://datatracker.ietf.org/doc/html/rfc1918",
},
{
text: "Once you have selected unique CIDR blocks, return to Porter and retry the provision. If you have any issues or questions, please reach out to Porter support",
},
],
};
const AZURE_AUTHZ_RESOLUTION: PreflightCheckResolution = {
title: "Granting your service principal authorization to your subscription",
subtitle:
Expand Down Expand Up @@ -1220,6 +1240,11 @@ const SUPPORTED_AWS_PREFLIGHT_CHECKS: PreflightCheck[] = [
name: "cidrAvailability",
displayName: "CIDR availability",
},
{
name: "enforceCidrUniqueness",
displayName: "Overlapping CIDR blocks",
resolution: OVERLAPPING_CIDR_RESOLUTION,
},
];

const SUPPORTED_AZURE_PREFLIGHT_CHECKS: PreflightCheck[] = [
Expand All @@ -1238,6 +1263,11 @@ const SUPPORTED_AZURE_PREFLIGHT_CHECKS: PreflightCheck[] = [
displayName: "vCPU availability",
resolution: AZURE_VCPUS_QUOTA_RESOLUTION,
},
{
name: "enforceCidrUniqueness",
displayName: "Overlapping CIDR blocks",
resolution: OVERLAPPING_CIDR_RESOLUTION,
},
];

const SUPPORTED_GCP_PREFLIGHT_CHECKS: PreflightCheck[] = [
Expand All @@ -1253,6 +1283,11 @@ const SUPPORTED_GCP_PREFLIGHT_CHECKS: PreflightCheck[] = [
name: "iamPermissions",
displayName: "IAM permissions",
},
{
name: "enforceCidrUniqueness",
displayName: "Overlapping CIDR blocks",
resolution: OVERLAPPING_CIDR_RESOLUTION,
},
];

const DEFAULT_EKS_CONTRACT = new Contract({
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/lib/clusters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ const preflightCheckKeyValidator = z.enum([
"cidrAvailability",
"iamPermissions",
"authz",
"enforceCidrUniqueness",
]);
type PreflightCheckKey = z.infer<typeof preflightCheckKeyValidator>;
export const preflightCheckValidator = z.object({
Expand Down

0 comments on commit f4b4c72

Please sign in to comment.