Skip to content

Support specifying GCP network and subnet #1752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 48 additions & 39 deletions cli/cmd/cluster_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,53 +434,62 @@ func createGKECluster(clusterConfig *clusterconfig.GCPConfig, gcpClient *gcp.Cli
gkeClusterParent := fmt.Sprintf("projects/%s/locations/%s", *clusterConfig.Project, *clusterConfig.Zone)
gkeClusterName := fmt.Sprintf("%s/clusters/%s", gkeClusterParent, clusterConfig.ClusterName)

_, err := gcpClient.CreateCluster(&containerpb.CreateClusterRequest{
Parent: gkeClusterParent,
Cluster: &containerpb.Cluster{
Name: clusterConfig.ClusterName,
InitialClusterVersion: "1.17",
NodePools: []*containerpb.NodePool{
{
Name: "ng-cortex-operator",
Config: &containerpb.NodeConfig{
MachineType: "n1-standard-2",
OauthScopes: []string{
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
},
ServiceAccount: gcpClient.ClientEmail,
gkeClusterConfig := containerpb.Cluster{
Name: clusterConfig.ClusterName,
InitialClusterVersion: "1.17",
NodePools: []*containerpb.NodePool{
{
Name: "ng-cortex-operator",
Config: &containerpb.NodeConfig{
MachineType: "n1-standard-2",
OauthScopes: []string{
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
},
InitialNodeCount: 1,
ServiceAccount: gcpClient.ClientEmail,
},
{
Name: "ng-cortex-worker-on-demand",
Config: &containerpb.NodeConfig{
MachineType: *clusterConfig.InstanceType,
Labels: nodeLabels,
Taints: []*containerpb.NodeTaint{
{
Key: "workload",
Value: "true",
Effect: containerpb.NodeTaint_NO_SCHEDULE,
},
},
Accelerators: accelerators,
OauthScopes: []string{
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
InitialNodeCount: 1,
},
{
Name: "ng-cortex-worker-on-demand",
Config: &containerpb.NodeConfig{
MachineType: *clusterConfig.InstanceType,
Labels: nodeLabels,
Taints: []*containerpb.NodeTaint{
{
Key: "workload",
Value: "true",
Effect: containerpb.NodeTaint_NO_SCHEDULE,
},
ServiceAccount: gcpClient.ClientEmail,
},
Autoscaling: &containerpb.NodePoolAutoscaling{
Enabled: true,
MinNodeCount: int32(*clusterConfig.MinInstances),
MaxNodeCount: int32(*clusterConfig.MaxInstances),
Accelerators: accelerators,
OauthScopes: []string{
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
},
InitialNodeCount: int32(*clusterConfig.MinInstances),
ServiceAccount: gcpClient.ClientEmail,
},
Autoscaling: &containerpb.NodePoolAutoscaling{
Enabled: true,
MinNodeCount: int32(*clusterConfig.MinInstances),
MaxNodeCount: int32(*clusterConfig.MaxInstances),
},
InitialNodeCount: int32(*clusterConfig.MinInstances),
},
Locations: []string{*clusterConfig.Zone},
},
Locations: []string{*clusterConfig.Zone},
}

if clusterConfig.Network != nil {
gkeClusterConfig.Network = *clusterConfig.Network
}
if clusterConfig.Subnet != nil {
gkeClusterConfig.Subnetwork = *clusterConfig.Subnet
}

_, err := gcpClient.CreateCluster(&containerpb.CreateClusterRequest{
Parent: gkeClusterParent,
Cluster: &gkeClusterConfig,
})
if err != nil {
return err
Expand Down
12 changes: 9 additions & 3 deletions docs/clusters/gcp/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ zone: us-central1-a
# instance type
instance_type: n1-standard-2

# GPU to attach to your instance (optional)
accelerator_type: nvidia-tesla-t4

# minimum number of instances
min_instances: 1

# maximum number of instances
max_instances: 5

# GPU to attach to your instance (optional)
# accelerator_type: nvidia-tesla-t4

# the name of the network in which to create your cluster
# network: default

# the name of the subnetwork in which to create your cluster
# subnet: default
```

The docker images used by the Cortex cluster can also be overridden, although this is not common. They can be configured by adding any of these keys to your cluster configuration file (default values are shown):
Expand Down
26 changes: 26 additions & 0 deletions pkg/types/clusterconfig/cluster_config_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type GCPConfig struct {
Zone *string `json:"zone" yaml:"zone"`
InstanceType *string `json:"instance_type" yaml:"instance_type"`
AcceleratorType *string `json:"accelerator_type" yaml:"accelerator_type"`
Network *string `json:"network" yaml:"network"`
Subnet *string `json:"subnet" yaml:"subnet"`
MinInstances *int64 `json:"min_instances" yaml:"min_instances"`
MaxInstances *int64 `json:"max_instances" yaml:"max_instances"`
ClusterName string `json:"cluster_name" yaml:"cluster_name"`
Expand Down Expand Up @@ -133,6 +135,18 @@ var UserGCPValidation = &cr.StructValidation{
AllowExplicitNull: true,
},
},
{
StructField: "Network",
StringPtrValidation: &cr.StringPtrValidation{
AllowExplicitNull: true,
},
},
{
StructField: "Subnet",
StringPtrValidation: &cr.StringPtrValidation{
AllowExplicitNull: true,
},
},
{
StructField: "MinInstances",
Int64PtrValidation: &cr.Int64PtrValidation{
Expand Down Expand Up @@ -473,6 +487,12 @@ func (cc *GCPConfig) UserTable() table.KeyValuePairs {
if cc.AcceleratorType != nil {
items.Add(AcceleratorTypeUserKey, *cc.AcceleratorType)
}
if cc.Network != nil {
items.Add(NetworkUserKey, *cc.Network)
}
if cc.Subnet != nil {
items.Add(SubnetUserKey, *cc.Subnet)
}
items.Add(TelemetryUserKey, cc.Telemetry)
items.Add(ImageOperatorUserKey, cc.ImageOperator)
items.Add(ImageManagerUserKey, cc.ImageManager)
Expand Down Expand Up @@ -501,6 +521,12 @@ func (cc *GCPConfig) TelemetryEvent() map[string]interface{} {
event["accelerator_type._is_defined"] = true
event["accelerator_type"] = *cc.AcceleratorType
}
if cc.Network != nil {
event["network._is_defined"] = true
}
if cc.Subnet != nil {
event["subnet._is_defined"] = true
}
if cc.MinInstances != nil {
event["min_instances._is_defined"] = true
event["min_instances"] = *cc.MinInstances
Expand Down
4 changes: 4 additions & 0 deletions pkg/types/clusterconfig/config_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
ProviderKey = "provider"
InstanceTypeKey = "instance_type"
AcceleratorTypeKey = "accelerator_type"
NetworkKey = "network"
SubnetKey = "subnet"
MinInstancesKey = "min_instances"
MaxInstancesKey = "max_instances"
TagsKey = "tags"
Expand Down Expand Up @@ -76,6 +78,8 @@ const (
SpotUserKey = "use spot instances"
InstanceTypeUserKey = "instance type"
AcceleratorTypeUserKey = "accelerator type"
NetworkUserKey = "network"
SubnetUserKey = "subnet"
MinInstancesUserKey = "min instances"
MaxInstancesUserKey = "max instances"
TagsUserKey = "tags"
Expand Down