Skip to content

Commit 1224d45

Browse files
authored
Support GCP network configuration (#1752)
1 parent de1806c commit 1224d45

File tree

4 files changed

+87
-42
lines changed

4 files changed

+87
-42
lines changed

cli/cmd/cluster_gcp.go

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -434,53 +434,62 @@ func createGKECluster(clusterConfig *clusterconfig.GCPConfig, gcpClient *gcp.Cli
434434
gkeClusterParent := fmt.Sprintf("projects/%s/locations/%s", *clusterConfig.Project, *clusterConfig.Zone)
435435
gkeClusterName := fmt.Sprintf("%s/clusters/%s", gkeClusterParent, clusterConfig.ClusterName)
436436

437-
_, err := gcpClient.CreateCluster(&containerpb.CreateClusterRequest{
438-
Parent: gkeClusterParent,
439-
Cluster: &containerpb.Cluster{
440-
Name: clusterConfig.ClusterName,
441-
InitialClusterVersion: "1.17",
442-
NodePools: []*containerpb.NodePool{
443-
{
444-
Name: "ng-cortex-operator",
445-
Config: &containerpb.NodeConfig{
446-
MachineType: "n1-standard-2",
447-
OauthScopes: []string{
448-
"https://www.googleapis.com/auth/compute",
449-
"https://www.googleapis.com/auth/devstorage.read_only",
450-
},
451-
ServiceAccount: gcpClient.ClientEmail,
437+
gkeClusterConfig := containerpb.Cluster{
438+
Name: clusterConfig.ClusterName,
439+
InitialClusterVersion: "1.17",
440+
NodePools: []*containerpb.NodePool{
441+
{
442+
Name: "ng-cortex-operator",
443+
Config: &containerpb.NodeConfig{
444+
MachineType: "n1-standard-2",
445+
OauthScopes: []string{
446+
"https://www.googleapis.com/auth/compute",
447+
"https://www.googleapis.com/auth/devstorage.read_only",
452448
},
453-
InitialNodeCount: 1,
449+
ServiceAccount: gcpClient.ClientEmail,
454450
},
455-
{
456-
Name: "ng-cortex-worker-on-demand",
457-
Config: &containerpb.NodeConfig{
458-
MachineType: *clusterConfig.InstanceType,
459-
Labels: nodeLabels,
460-
Taints: []*containerpb.NodeTaint{
461-
{
462-
Key: "workload",
463-
Value: "true",
464-
Effect: containerpb.NodeTaint_NO_SCHEDULE,
465-
},
466-
},
467-
Accelerators: accelerators,
468-
OauthScopes: []string{
469-
"https://www.googleapis.com/auth/compute",
470-
"https://www.googleapis.com/auth/devstorage.read_only",
451+
InitialNodeCount: 1,
452+
},
453+
{
454+
Name: "ng-cortex-worker-on-demand",
455+
Config: &containerpb.NodeConfig{
456+
MachineType: *clusterConfig.InstanceType,
457+
Labels: nodeLabels,
458+
Taints: []*containerpb.NodeTaint{
459+
{
460+
Key: "workload",
461+
Value: "true",
462+
Effect: containerpb.NodeTaint_NO_SCHEDULE,
471463
},
472-
ServiceAccount: gcpClient.ClientEmail,
473464
},
474-
Autoscaling: &containerpb.NodePoolAutoscaling{
475-
Enabled: true,
476-
MinNodeCount: int32(*clusterConfig.MinInstances),
477-
MaxNodeCount: int32(*clusterConfig.MaxInstances),
465+
Accelerators: accelerators,
466+
OauthScopes: []string{
467+
"https://www.googleapis.com/auth/compute",
468+
"https://www.googleapis.com/auth/devstorage.read_only",
478469
},
479-
InitialNodeCount: int32(*clusterConfig.MinInstances),
470+
ServiceAccount: gcpClient.ClientEmail,
471+
},
472+
Autoscaling: &containerpb.NodePoolAutoscaling{
473+
Enabled: true,
474+
MinNodeCount: int32(*clusterConfig.MinInstances),
475+
MaxNodeCount: int32(*clusterConfig.MaxInstances),
480476
},
477+
InitialNodeCount: int32(*clusterConfig.MinInstances),
481478
},
482-
Locations: []string{*clusterConfig.Zone},
483479
},
480+
Locations: []string{*clusterConfig.Zone},
481+
}
482+
483+
if clusterConfig.Network != nil {
484+
gkeClusterConfig.Network = *clusterConfig.Network
485+
}
486+
if clusterConfig.Subnet != nil {
487+
gkeClusterConfig.Subnetwork = *clusterConfig.Subnet
488+
}
489+
490+
_, err := gcpClient.CreateCluster(&containerpb.CreateClusterRequest{
491+
Parent: gkeClusterParent,
492+
Cluster: &gkeClusterConfig,
484493
})
485494
if err != nil {
486495
return err

docs/clusters/gcp/install.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,20 @@ zone: us-central1-a
3131
# instance type
3232
instance_type: n1-standard-2
3333

34-
# GPU to attach to your instance (optional)
35-
accelerator_type: nvidia-tesla-t4
36-
3734
# minimum number of instances
3835
min_instances: 1
3936

4037
# maximum number of instances
4138
max_instances: 5
39+
40+
# GPU to attach to your instance (optional)
41+
# accelerator_type: nvidia-tesla-t4
42+
43+
# the name of the network in which to create your cluster
44+
# network: default
45+
46+
# the name of the subnetwork in which to create your cluster
47+
# subnet: default
4248
```
4349

4450
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):

pkg/types/clusterconfig/cluster_config_gcp.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type GCPConfig struct {
3838
Zone *string `json:"zone" yaml:"zone"`
3939
InstanceType *string `json:"instance_type" yaml:"instance_type"`
4040
AcceleratorType *string `json:"accelerator_type" yaml:"accelerator_type"`
41+
Network *string `json:"network" yaml:"network"`
42+
Subnet *string `json:"subnet" yaml:"subnet"`
4143
MinInstances *int64 `json:"min_instances" yaml:"min_instances"`
4244
MaxInstances *int64 `json:"max_instances" yaml:"max_instances"`
4345
ClusterName string `json:"cluster_name" yaml:"cluster_name"`
@@ -133,6 +135,18 @@ var UserGCPValidation = &cr.StructValidation{
133135
AllowExplicitNull: true,
134136
},
135137
},
138+
{
139+
StructField: "Network",
140+
StringPtrValidation: &cr.StringPtrValidation{
141+
AllowExplicitNull: true,
142+
},
143+
},
144+
{
145+
StructField: "Subnet",
146+
StringPtrValidation: &cr.StringPtrValidation{
147+
AllowExplicitNull: true,
148+
},
149+
},
136150
{
137151
StructField: "MinInstances",
138152
Int64PtrValidation: &cr.Int64PtrValidation{
@@ -473,6 +487,12 @@ func (cc *GCPConfig) UserTable() table.KeyValuePairs {
473487
if cc.AcceleratorType != nil {
474488
items.Add(AcceleratorTypeUserKey, *cc.AcceleratorType)
475489
}
490+
if cc.Network != nil {
491+
items.Add(NetworkUserKey, *cc.Network)
492+
}
493+
if cc.Subnet != nil {
494+
items.Add(SubnetUserKey, *cc.Subnet)
495+
}
476496
items.Add(TelemetryUserKey, cc.Telemetry)
477497
items.Add(ImageOperatorUserKey, cc.ImageOperator)
478498
items.Add(ImageManagerUserKey, cc.ImageManager)
@@ -501,6 +521,12 @@ func (cc *GCPConfig) TelemetryEvent() map[string]interface{} {
501521
event["accelerator_type._is_defined"] = true
502522
event["accelerator_type"] = *cc.AcceleratorType
503523
}
524+
if cc.Network != nil {
525+
event["network._is_defined"] = true
526+
}
527+
if cc.Subnet != nil {
528+
event["subnet._is_defined"] = true
529+
}
504530
if cc.MinInstances != nil {
505531
event["min_instances._is_defined"] = true
506532
event["min_instances"] = *cc.MinInstances

pkg/types/clusterconfig/config_key.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const (
2020
ProviderKey = "provider"
2121
InstanceTypeKey = "instance_type"
2222
AcceleratorTypeKey = "accelerator_type"
23+
NetworkKey = "network"
24+
SubnetKey = "subnet"
2325
MinInstancesKey = "min_instances"
2426
MaxInstancesKey = "max_instances"
2527
TagsKey = "tags"
@@ -76,6 +78,8 @@ const (
7678
SpotUserKey = "use spot instances"
7779
InstanceTypeUserKey = "instance type"
7880
AcceleratorTypeUserKey = "accelerator type"
81+
NetworkUserKey = "network"
82+
SubnetUserKey = "subnet"
7983
MinInstancesUserKey = "min instances"
8084
MaxInstancesUserKey = "max instances"
8185
TagsUserKey = "tags"

0 commit comments

Comments
 (0)