Skip to content

Commit

Permalink
feat: add machine type param to gke cluster builder
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Mar 2, 2023
1 parent 4e1e258 commit b26addc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
42 changes: 29 additions & 13 deletions pkg/clusters/types/gke/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand All @@ -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.
//
Expand Down Expand Up @@ -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{
Expand All @@ -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 != "" {
Expand Down Expand Up @@ -235,7 +252,6 @@ func sanitizeCreatedByID(id string) string {
// disallowed character, replace it with a dash
builder.WriteString("-")
}

}

// Truncate to the maximum allowed length.
Expand Down

0 comments on commit b26addc

Please sign in to comment.