From 6634a9e57f8de774224303f27541b4fcc162b91b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Wed, 15 Feb 2023 11:26:39 +0100 Subject: [PATCH] feat: add machine type param to gke cluster builder --- CHANGELOG.md | 4 ++- pkg/clusters/types/gke/builder.go | 42 +++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b245570..9cbb1028 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,11 @@ # Changelog -## Unreleased +## v0.30.0 - Bump Kong Gateway Enterprise default image to 3.1.1.3 [#566](https://github.com/Kong/kubernetes-testing-framework/pull/566) +- Added the ability to specify node machine type with GKE cluster builder. + [#567](https://github.com/Kong/kubernetes-testing-framework/pull/567) ## v0.29.0 diff --git a/pkg/clusters/types/gke/builder.go b/pkg/clusters/types/gke/builder.go index 385b1267..3bb78a3b 100644 --- a/pkg/clusters/types/gke/builder.go +++ b/pkg/clusters/types/gke/builder.go @@ -26,21 +26,27 @@ type Builder struct { jsonCreds []byte waitForTeardown bool - createSubnet bool - addons clusters.Addons - clusterVersion *semver.Version - majorMinor string - labels map[string]string + createSubnet bool + addons clusters.Addons + clusterVersion *semver.Version + majorMinor string + nodeMachineType string + labels map[string]string } +const ( + defaultNodeMachineType = "e2-highcpu-4" +) + // NewBuilder provides a new *Builder object. func NewBuilder(gkeJSONCredentials []byte, project, location string) *Builder { return &Builder{ - Name: fmt.Sprintf("t-%s", uuid.NewString()), - project: project, - location: location, - jsonCreds: gkeJSONCredentials, - addons: make(clusters.Addons), + Name: fmt.Sprintf("t-%s", uuid.NewString()), + project: project, + location: location, + jsonCreds: gkeJSONCredentials, + nodeMachineType: defaultNodeMachineType, + addons: make(clusters.Addons), } } @@ -66,6 +72,11 @@ func (b *Builder) WithClusterMinorVersion(major, minor uint64) *Builder { return b } +func (b *Builder) WithNodeMachineType(machineType string) *Builder { + b.nodeMachineType = machineType + return b +} + // WithWaitForTeardown sets a flag telling whether the cluster should wait for // a cleanup operation synchronously. // @@ -120,7 +131,10 @@ func (b *Builder) Build(ctx context.Context) (clusters.Cluster, error) { // configure the cluster creation request parent := fmt.Sprintf("projects/%s/locations/%s", b.project, b.location) pbcluster := containerpb.Cluster{ - Name: b.Name, + Name: b.Name, + NodeConfig: &containerpb.NodeConfig{ + MachineType: b.nodeMachineType, + }, InitialNodeCount: 1, // disable the GKE ingress controller, which will otherwise interact with classless Ingresses AddonsConfig: &containerpb.AddonsConfig{ @@ -131,7 +145,10 @@ func (b *Builder) Build(ctx context.Context) (clusters.Cluster, error) { b.labels, ), } - req := &containerpb.CreateClusterRequest{Parent: parent, Cluster: &pbcluster} + req := &containerpb.CreateClusterRequest{ + Parent: parent, + Cluster: &pbcluster, + } // use any provided custom cluster version if b.clusterVersion != nil && b.majorMinor != "" { @@ -235,7 +252,6 @@ func sanitizeCreatedByID(id string) string { // disallowed character, replace it with a dash builder.WriteString("-") } - } // Truncate to the maximum allowed length.