Skip to content

Commit 8032cb7

Browse files
authoredSep 28, 2020
Enable users to specify CIDR for cluster VPC (#1388)
1 parent 788c490 commit 8032cb7

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed
 

‎cli/cmd/lib_cluster_config.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ func setConfigFieldsFromCached(userClusterConfig *clusterconfig.Config, cachedCl
360360

361361
userClusterConfig.SpotConfig = cachedClusterConfig.SpotConfig
362362

363+
if s.Obj(cachedClusterConfig.VPCCIDR) != s.Obj(userClusterConfig.VPCCIDR) {
364+
return clusterconfig.ErrorConfigCannotBeChangedOnUpdate(clusterconfig.VPCCIDRKey, cachedClusterConfig.VPCCIDR)
365+
}
366+
userClusterConfig.VPCCIDR = cachedClusterConfig.VPCCIDR
367+
363368
return nil
364369
}
365370

@@ -513,9 +518,9 @@ func clusterConfigConfirmationStr(clusterConfig clusterconfig.Config, awsCreds A
513518
items.Add(clusterconfig.InstanceTypeUserKey, *clusterConfig.InstanceType)
514519
items.Add(clusterconfig.MinInstancesUserKey, *clusterConfig.MinInstances)
515520
items.Add(clusterconfig.MaxInstancesUserKey, *clusterConfig.MaxInstances)
516-
items.Add(clusterconfig.TagsKey, s.ObjFlatNoQuotes(clusterConfig.Tags))
521+
items.Add(clusterconfig.TagsUserKey, s.ObjFlatNoQuotes(clusterConfig.Tags))
517522
if clusterConfig.SSLCertificateARN != nil {
518-
items.Add(clusterconfig.SSLCertificateARNKey, *clusterConfig.SSLCertificateARN)
523+
items.Add(clusterconfig.SSLCertificateARNUserKey, *clusterConfig.SSLCertificateARN)
519524
}
520525

521526
if clusterConfig.InstanceVolumeSize != defaultConfig.InstanceVolumeSize {
@@ -577,6 +582,10 @@ func clusterConfigConfirmationStr(clusterConfig clusterconfig.Config, awsCreds A
577582
}
578583
}
579584

585+
if clusterConfig.VPCCIDR != nil {
586+
items.Add(clusterconfig.VPCCIDRUserKey, clusterConfig.VPCCIDR)
587+
}
588+
580589
if clusterConfig.Telemetry != defaultConfig.Telemetry {
581590
items.Add(clusterconfig.TelemetryUserKey, clusterConfig.Telemetry)
582591
}

‎docs/cluster-management/config.md

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ spot: false
7575

7676
# see https://docs.cortex.dev/v/master/guides/custom-domain for instructions on how to set up a custom domain
7777
ssl_certificate_arn:
78+
79+
# primary CIDR block for the cluster's VPC (default: 192.168.0.0/16)
80+
# vpc_cidr: 192.168.0.0/16
7881
```
7982

8083
The default docker images used for your Predictors are listed in the instructions for [system packages](../deployments/system-packages.md), and can be overridden in your [Realtime API configuration](../deployments/realtime-api/api-configuration.md) and in your [Batch API configuration](../deployments/batch-api/api-configuration.md).

‎manager/generate_eks.py

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ def generate_eks(cluster_config_path):
202202
"nodeGroups": [operator_nodegroup, worker_nodegroup],
203203
}
204204

205+
if cluster_config.get("vpc_cidr", "") != "":
206+
eks["vpc"]["cidr"] = cluster_config["vpc_cidr"]
207+
205208
if cluster_config.get("spot_config") is not None and cluster_config["spot_config"].get(
206209
"on_demand_backup", False
207210
):

‎pkg/types/clusterconfig/clusterconfig.go

+20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package clusterconfig
1919
import (
2020
"fmt"
2121
"io/ioutil"
22+
"net"
2223
"net/http"
2324
"regexp"
2425
"strings"
@@ -73,6 +74,7 @@ type Config struct {
7374
APILoadBalancerScheme LoadBalancerScheme `json:"api_load_balancer_scheme" yaml:"api_load_balancer_scheme"`
7475
OperatorLoadBalancerScheme LoadBalancerScheme `json:"operator_load_balancer_scheme" yaml:"operator_load_balancer_scheme"`
7576
APIGatewaySetting APIGatewaySetting `json:"api_gateway" yaml:"api_gateway"`
77+
VPCCIDR *string `json:"vpc_cidr,omitempty" yaml:"vpc_cidr,omitempty"`
7678
Telemetry bool `json:"telemetry" yaml:"telemetry"`
7779
ImageOperator string `json:"image_operator" yaml:"image_operator"`
7880
ImageManager string `json:"image_manager" yaml:"image_manager"`
@@ -351,6 +353,12 @@ var UserValidation = &cr.StructValidation{
351353
return APIGatewaySettingFromString(str), nil
352354
},
353355
},
356+
{
357+
StructField: "VPCCIDR",
358+
StringPtrValidation: &cr.StringPtrValidation{
359+
Validator: validateVPCCIDR,
360+
},
361+
},
354362
{
355363
StructField: "ImageOperator",
356364
StringValidation: &cr.StringValidation{
@@ -1018,6 +1026,15 @@ func validateBucketName(bucket string) (string, error) {
10181026
return bucket, nil
10191027
}
10201028

1029+
func validateVPCCIDR(cidr string) (string, error) {
1030+
_, _, err := net.ParseCIDR(cidr)
1031+
if err != nil {
1032+
return "", errors.WithStack(err)
1033+
}
1034+
1035+
return cidr, nil
1036+
}
1037+
10211038
func validateInstanceType(instanceType string) (string, error) {
10221039
var foundInstance *aws.InstanceMetadata
10231040
for _, instanceMap := range aws.InstanceMetadatas {
@@ -1127,6 +1144,9 @@ func (cc *Config) UserTable() table.KeyValuePairs {
11271144
items.Add(APILoadBalancerSchemeUserKey, cc.APILoadBalancerScheme)
11281145
items.Add(OperatorLoadBalancerSchemeUserKey, cc.OperatorLoadBalancerScheme)
11291146
items.Add(APIGatewaySettingUserKey, cc.APIGatewaySetting)
1147+
if cc.VPCCIDR != nil {
1148+
items.Add(VPCCIDRKey, *cc.VPCCIDR)
1149+
}
11301150
items.Add(TelemetryUserKey, cc.Telemetry)
11311151
items.Add(ImageOperatorUserKey, cc.ImageOperator)
11321152
items.Add(ImageManagerUserKey, cc.ImageManager)

‎pkg/types/clusterconfig/config_key.go

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
APILoadBalancerSchemeKey = "api_load_balancer_scheme"
4444
OperatorLoadBalancerSchemeKey = "operator_load_balancer_scheme"
4545
APIGatewaySettingKey = "api_gateway"
46+
VPCCIDRKey = "vpc_cidr"
4647
TelemetryKey = "telemetry"
4748
ImageOperatorKey = "image_operator"
4849
ImageManagerKey = "image_manager"
@@ -87,6 +88,7 @@ const (
8788
APILoadBalancerSchemeUserKey = "api load balancer scheme"
8889
OperatorLoadBalancerSchemeUserKey = "operator load balancer scheme"
8990
APIGatewaySettingUserKey = "api gateway"
91+
VPCCIDRUserKey = "vpc cidr"
9092
TelemetryUserKey = "telemetry"
9193
ImageOperatorUserKey = "operator image"
9294
ImageManagerUserKey = "manager image"

0 commit comments

Comments
 (0)
Please sign in to comment.