Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gke): allow passing labels #499

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
13 changes: 12 additions & 1 deletion pkg/clusters/types/gke/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}

Expand Down