Skip to content

Commit

Permalink
feat: add WithReleaseChannel to GKE cluster builder (#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo authored Dec 20, 2023
1 parent d302987 commit 0e167c0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Changelog

## Unreleased
## v0.43.0

Nothing
- Added `WithReleaseChannel` to the GKE cluster builder to allow specifying
a release channel for the cluster.
[#911](https://github.com/Kong/kubernetes-testing-framework/pull/911)

## v0.42.0

Expand Down
39 changes: 39 additions & 0 deletions pkg/clusters/types/gke/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Builder struct {
majorMinor string
nodeMachineType string
labels map[string]string
releaseChannel *ReleaseChannel
}

const (
Expand Down Expand Up @@ -104,6 +105,22 @@ func (b *Builder) WithLabels(labels map[string]string) *Builder {
return b
}

// ReleaseChannel is a type for specifying the release channel of the cluster.
// See https://cloud.google.com/kubernetes-engine/docs/release-notes for more details.
type ReleaseChannel string

const (
ReleaseChannelRapid ReleaseChannel = "rapid"
ReleaseChannelRegular ReleaseChannel = "regular"
ReleaseChannelStable ReleaseChannel = "stable"
)

// WithReleaseChannel sets the release channel of the cluster.
func (b *Builder) WithReleaseChannel(ch ReleaseChannel) *Builder {
b.releaseChannel = &ch
return b
}

// Build creates and configures clients for a GKE-based Kubernetes clusters.Cluster.
func (b *Builder) Build(ctx context.Context) (clusters.Cluster, error) {
// validate the credential contents by finding the IAM service account
Expand Down Expand Up @@ -179,6 +196,15 @@ func (b *Builder) Build(ctx context.Context) (clusters.Cluster, error) {
ServicesIpv4CidrBlock: "/27",
}
}
if b.releaseChannel != nil {
channel, err := mapReleaseChannel(*b.releaseChannel)
if err != nil {
return nil, fmt.Errorf("faield mapping release channel to proto: %s", err)
}
pbcluster.ReleaseChannel = &containerpb.ReleaseChannel{
Channel: channel,
}
}

if _, err = mgrc.CreateCluster(ctx, req); err != nil {
return nil, err
Expand Down Expand Up @@ -264,3 +290,16 @@ func sanitizeCreatedByID(id string) string {
}
return s
}

func mapReleaseChannel(ch ReleaseChannel) (containerpb.ReleaseChannel_Channel, error) {
switch ch {
case ReleaseChannelRapid:
return containerpb.ReleaseChannel_RAPID, nil
case ReleaseChannelRegular:
return containerpb.ReleaseChannel_REGULAR, nil
case ReleaseChannelStable:
return containerpb.ReleaseChannel_STABLE, nil
default:
return 0, fmt.Errorf("unknown release channel %s", ch)
}
}
5 changes: 5 additions & 0 deletions test/e2e/gke_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func testGKECluster(t *testing.T, createSubnet bool) {
builder.WithWaitForTeardown(false)
builder.WithCreateSubnet(createSubnet)
builder.WithLabels(map[string]string{"test-cluster": "true"})
builder.WithReleaseChannel(gke.ReleaseChannelRapid)

t.Logf("building cluster %s (this can take some time)", builder.Name)
cluster, err := builder.Build(ctx)
Expand Down Expand Up @@ -103,6 +104,10 @@ func testGKECluster(t *testing.T, createSubnet bool) {
require.NotEqual(t, "default", gkeCluster.Subnetwork)
}

t.Log("verify rapid release channel used")
require.NotNil(t, gkeCluster.ReleaseChannel)
require.Equal(t, containerpb.ReleaseChannel_RAPID, gkeCluster.ReleaseChannel.Channel)

t.Log("loading the gke cluster into a testing environment and deploying kong addon")
env, err := environments.NewBuilder().WithAddons(kong.New()).WithExistingCluster(cluster).Build(ctx)
require.NoError(t, err)
Expand Down

0 comments on commit 0e167c0

Please sign in to comment.