Skip to content

Commit 7a1a1f5

Browse files
feat: gcp kubernetes clusters and node pools (#332)
* feat: kubernetes gcp * gke node pools and test update * add zones to kubernetes node pools * change kuberentes e2e to work with multiple nodes * set gcp node count depending on the number of availability zones * install gke auth plugin
1 parent 617e5c4 commit 7a1a1f5

31 files changed

+1515
-234
lines changed

.github/workflows/e2e.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ jobs:
4444
go vet .
4545
golint .
4646
47+
- name: Install gke-cloud-auth-plugin
48+
run: |
49+
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
50+
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
51+
sudo apt-get update && sudo apt-get install google-cloud-sdk-gke-gcloud-auth-plugin
52+
gke-gcloud-auth-plugin --version
53+
4754
- name: Test
4855
run: go test ./test/e2e -tags=e2e -timeout=180m -parallel 10
4956
env:

.github/workflows/pr-e2e.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ jobs:
4646
go vet .
4747
golint .
4848
49+
- name: Set up Cloud SDK
50+
uses: 'google-github-actions/setup-gcloud@v0'
51+
52+
- name: Authenticate to Gcloud
53+
uses: 'google-github-actions/auth@v0'
54+
with:
55+
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
56+
57+
- name: Install gke-cloud-auth-plugin
58+
run: gcloud components install gke-gcloud-auth-plugin
59+
4960
- name: Test
5061
run: go test ./test/e2e -tags=e2e -timeout=180m -parallel 10
5162
env:
@@ -56,4 +67,5 @@ jobs:
5667
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET_E2E }}
5768
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
5869
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
59-
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
70+
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
71+
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}

api/proto/resourcespb/kubernetes_cluster.pb.go

Lines changed: 157 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/proto/resourcespb/kubernetes_cluster.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ message DeleteKubernetesClusterRequest {
2727
string resource_id = 1;
2828
}
2929

30+
message KubernetesClusterOverrides {
31+
string project = 1;
32+
}
33+
3034
message KubernetesClusterArgs {
3135
common.ResourceCommonArgs common_parameters = 1;
3236
string name = 2;
3337
string service_cidr = 3;
3438
string virtual_network_id = 4;
3539

3640
KubernetesNodePoolArgs default_node_pool = 5;
41+
KubernetesClusterOverrides gcp_override = 6;
3742
}
3843

3944
message KubernetesClusterResource {
@@ -42,6 +47,7 @@ message KubernetesClusterResource {
4247
string service_cidr = 3;
4348
KubernetesNodePoolResource default_node_pool = 4;
4449
string virtual_network_id = 5;
50+
KubernetesClusterOverrides gcp_override = 9;
4551

4652
// outputs
4753
string endpoint = 6;

api/proto/resourcespb/kubernetes_node_pool.pb.go

Lines changed: 96 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/proto/resourcespb/kubernetes_node_pool.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ message KubernetesNodePoolArgs {
4444
int32 max_node_count = 7;
4545
common.VmSize.Enum vm_size = 8;
4646
int64 disk_size_gb = 9;
47+
repeated int32 availability_zone = 13;
48+
4749
KubernetesNodePoolAwsOverride aws_override = 11;
4850
KubernetesNodePoolAzureOverride azure_override = 12;
4951

@@ -61,6 +63,8 @@ message KubernetesNodePoolResource {
6163
int32 max_node_count = 7;
6264
common.VmSize.Enum vm_size = 8;
6365
int64 disk_size_gb = 9;
66+
repeated int32 availability_zone = 13;
67+
6468
KubernetesNodePoolAwsOverride aws_override = 11;
6569
KubernetesNodePoolAzureOverride azure_override = 12;
6670

resources/common/helper.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ func RandomString(n int) string {
3939
// Prefix can be any size but will be sliced if bigger than 16 chars. Suffix can have 4 chars at most.
4040
// Returns a string with at most 24 chars.
4141
func UniqueId(prefix string, suffix string, formatFunc FormatFunc) string {
42-
if len(suffix) > 4 {
43-
validate.LogInternalError("suffix must be shorter than 4 chars")
42+
if len(suffix) > 10 {
43+
validate.LogInternalError("suffix must be shorter than 10 chars")
4444
}
4545
result := ""
4646
formattedPrefix := formatFunc(prefix)
47-
if len(formattedPrefix) > 16 {
48-
result += formattedPrefix[:12] + generateHash(prefix)
47+
maxPrefixLen := 20 - len(suffix)
48+
if len(formattedPrefix) > maxPrefixLen {
49+
result += formattedPrefix[:maxPrefixLen] + generateHash(prefix)
4950
} else {
5051
result += formattedPrefix
5152
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package iam
2+
3+
import "github.com/multycloud/multy/resources/common"
4+
5+
type GoogleServiceAccount struct {
6+
*common.GcpResource `hcl:",squash" default:"name=google_service_account"`
7+
AccountId string `hcl:"account_id"`
8+
DisplayName string `hcl:"display_name"`
9+
}

resources/output/kubernetes_node_pool/azure_aks_node_pool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ type AzureKubernetesNodePool struct {
1313
EnableAutoScaling bool `hcl:"enable_auto_scaling"`
1414
VmSize string `hcl:"vm_size"`
1515
VirtualNetworkSubnetId string `hcl:"vnet_subnet_id,expr"`
16+
Zones []string `hcl:"zones" hcle:"omitempty"`
1617
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package kubernetes_node_pool
2+
3+
import "github.com/multycloud/multy/resources/common"
4+
5+
type GoogleContainerNodePool struct {
6+
*common.GcpResource `hcl:",squash" default:"name=google_container_node_pool"`
7+
Cluster string `hcl:"cluster,expr"` //expr
8+
InitialNodeCount int `hcl:"initial_node_count"`
9+
NodeLocations []string `hcl:"node_locations" hcle:"omitempty"`
10+
Autoscaling GoogleContainerNodePoolAutoScaling `hcl:"autoscaling"`
11+
NodeConfig GoogleContainerNodeConfig `hcl:"node_config"`
12+
NetworkConfig GoogleContainerNetworkConfig `hcl:"network_config" hcle:"omitempty"`
13+
}
14+
15+
type GoogleContainerNodePoolAutoScaling struct {
16+
MinNodeCount int `hcl:"min_node_count"`
17+
MaxNodeCount int `hcl:"max_node_count"`
18+
}
19+
20+
type GoogleContainerNodeConfig struct {
21+
DiskSizeGb int `hcl:"disk_size_gb" hcle:"omitempty"`
22+
DiskType string `hcl:"disk_type" hcle:"omitempty"`
23+
ImageType string `hcl:"image_type" hcle:"omitempty"`
24+
Labels map[string]string `hcl:"labels" hcle:"omitempty"`
25+
MachineType string `hcl:"machine_type"`
26+
Metadata map[string]string `hcl:"metadata" hcle:"omitempty"`
27+
Tags []string `hcl:"tags" hcle:"omitempty"`
28+
29+
ServiceAccount string `hcl:"service_account,expr"`
30+
OAuthScopes []string `hcl:"oauth_scopes"`
31+
}
32+
33+
type GoogleContainerNetworkConfig struct {
34+
CreatePodRange bool `hcl:"create_pod_range"`
35+
PodIpv4CidrBlock string `hcl:"pod_ipv4_cidr_block"`
36+
}

0 commit comments

Comments
 (0)