From b793f946c277d00afd6dff79deb790d30c949442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Burzy=C5=84ski?= Date: Wed, 20 Dec 2023 10:06:54 +0100 Subject: [PATCH] feat: add WithReleaseChannel to GKE cluster builder --- CHANGELOG.md | 6 ++++-- pkg/clusters/types/gke/builder.go | 36 +++++++++++++++++++++++++++++++ test/e2e/gke_cluster_test.go | 1 + 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a7a24934..d1eb59ea1 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. + [#903]() ## v0.42.0 diff --git a/pkg/clusters/types/gke/builder.go b/pkg/clusters/types/gke/builder.go index 8b59f2dfc..c43778398 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,19 @@ func (b *Builder) WithLabels(labels map[string]string) *Builder { return b } +type ReleaseChannel string + +const ( + ReleaseChannelRapid ReleaseChannel = "rapid" + ReleaseChannelRegular ReleaseChannel = "regular" + ReleaseChannelStable ReleaseChannel = "stable" +) + +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 +193,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 +287,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 65087aebf..fcb800d88 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)