From 0e167c0aca2a53a8e92ec8f2ab887760eaf4eb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Burzy=C5=84ski?= Date: Wed, 20 Dec 2023 12:13:59 +0100 Subject: [PATCH] feat: add WithReleaseChannel to GKE cluster builder (#911) --- CHANGELOG.md | 6 +++-- pkg/clusters/types/gke/builder.go | 39 +++++++++++++++++++++++++++++++ test/e2e/gke_cluster_test.go | 5 ++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a7a2493..14caf06a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/clusters/types/gke/builder.go b/pkg/clusters/types/gke/builder.go index 8b59f2df..b894894f 100644 --- a/pkg/clusters/types/gke/builder.go +++ b/pkg/clusters/types/gke/builder.go @@ -32,6 +32,7 @@ type Builder struct { majorMinor string nodeMachineType string labels map[string]string + releaseChannel *ReleaseChannel } const ( @@ -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 @@ -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 @@ -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) + } +} diff --git a/test/e2e/gke_cluster_test.go b/test/e2e/gke_cluster_test.go index 65087aeb..1ad03f97 100644 --- a/test/e2e/gke_cluster_test.go +++ b/test/e2e/gke_cluster_test.go @@ -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) @@ -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)