From 4a62d991875f24677537615c811543cbbf052d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Burzy=C5=84ski?= Date: Wed, 18 Jan 2023 21:38:38 +0100 Subject: [PATCH] feat(gke): allow passing labels (#499) --- CHANGELOG.md | 2 ++ go.mod | 4 +++- go.sum | 4 ++++ pkg/clusters/types/gke/builder.go | 13 ++++++++++++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 468382fa..e860ff33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ - gRPC API is used instead of gcloud CLI when createSubnetwork is enabled in GKE cluster builder. [#498](https://github.com/Kong/kubernetes-testing-framework/pull/498) +- GKE cluster builder accepts custom labels. + [#499](https://github.com/Kong/kubernetes-testing-framework/pull/499) ## v0.25.0 diff --git a/go.mod b/go.mod index 22d354fd..543f472c 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/kong/deck v1.17.1 github.com/kong/go-kong v0.34.1-0.20221222170410-6c81ce561662 github.com/mitchellh/go-homedir v1.1.0 + github.com/samber/lo v1.37.0 github.com/sethvargo/go-password v0.2.0 github.com/sirupsen/logrus v1.9.0 github.com/spf13/cobra v1.6.1 @@ -20,7 +21,6 @@ require ( golang.org/x/oauth2 v0.4.0 golang.org/x/sync v0.1.0 google.golang.org/api v0.106.0 - google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef k8s.io/api v0.26.0 k8s.io/apiextensions-apiserver v0.26.0 k8s.io/apimachinery v0.26.0 @@ -127,12 +127,14 @@ require ( go.opencensus.io v0.24.0 // indirect go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect golang.org/x/crypto v0.1.0 // indirect + golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect golang.org/x/net v0.5.0 // indirect golang.org/x/sys v0.4.0 // indirect golang.org/x/term v0.4.0 // indirect golang.org/x/text v0.6.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/appengine v1.6.7 // indirect + google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef // indirect google.golang.org/grpc v1.51.0 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/go.sum b/go.sum index 0ba43837..d53db006 100644 --- a/go.sum +++ b/go.sum @@ -341,6 +341,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/samber/lo v1.37.0 h1:XjVcB8g6tgUp8rsPsJ2CvhClfImrpL04YpQHXeHPhRw= +github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sethvargo/go-password v0.2.0 h1:BTDl4CC/gjf/axHMaDQtw507ogrXLci6XRiLc7i/UHI= github.com/sethvargo/go-password v0.2.0/go.mod h1:Ym4Mr9JXLBycr02MFuVQ/0JHidNetSgbzutTr3zsYXE= @@ -439,6 +441,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM= +golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/pkg/clusters/types/gke/builder.go b/pkg/clusters/types/gke/builder.go index 685fa236..385b1267 100644 --- a/pkg/clusters/types/gke/builder.go +++ b/pkg/clusters/types/gke/builder.go @@ -12,6 +12,7 @@ import ( "cloud.google.com/go/container/apiv1/containerpb" "github.com/blang/semver/v4" "github.com/google/uuid" + "github.com/samber/lo" "github.com/kong/kubernetes-testing-framework/internal/utils" "github.com/kong/kubernetes-testing-framework/pkg/clusters" @@ -29,6 +30,7 @@ type Builder struct { addons clusters.Addons clusterVersion *semver.Version majorMinor string + labels map[string]string } // NewBuilder provides a new *Builder object. @@ -85,6 +87,12 @@ func (b *Builder) WithCreateSubnet(create bool) *Builder { return b } +// WithLabels adds labels that the created cluster is going to be labeled with. +func (b *Builder) WithLabels(labels map[string]string) *Builder { + b.labels = lo.Assign(b.labels, labels) + 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 @@ -118,7 +126,10 @@ func (b *Builder) Build(ctx context.Context) (clusters.Cluster, error) { AddonsConfig: &containerpb.AddonsConfig{ HttpLoadBalancing: &containerpb.HttpLoadBalancing{Disabled: true}, }, - ResourceLabels: map[string]string{GKECreateLabel: createdByID}, + ResourceLabels: lo.Assign( + map[string]string{GKECreateLabel: createdByID}, + b.labels, + ), } req := &containerpb.CreateClusterRequest{Parent: parent, Cluster: &pbcluster}