Skip to content

Commit e9dd1b5

Browse files
authored
chore: bump ktf and use its new features (#3406)
- Bumps KTF to v0.26.0 - Uses labels to determine if the cluster was created for test purposes
1 parent 91bd96d commit e9dd1b5

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/google/uuid v1.3.0
1616
github.com/kong/deck v1.17.1
1717
github.com/kong/go-kong v0.34.1-0.20221222170410-6c81ce561662
18-
github.com/kong/kubernetes-testing-framework v0.25.0
18+
github.com/kong/kubernetes-testing-framework v0.26.0
1919
github.com/lithammer/dedent v1.1.0
2020
github.com/miekg/dns v1.1.50
2121
github.com/mitchellh/mapstructure v1.5.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,8 @@ github.com/kong/deck v1.17.1 h1:mBtd5CBv+Ouwz6SbOWfpvQvSMsiD3jwIeiKVU0oNvFI=
567567
github.com/kong/deck v1.17.1/go.mod h1:IH/Ic9dgBwvb1WHOx3+0BUzo+SYiVjd9inEe+JIIeK4=
568568
github.com/kong/go-kong v0.34.1-0.20221222170410-6c81ce561662 h1:IIIAzs6eNp+lA+E0k9oooAyqmAJyAA/9Ebyb0y19mrU=
569569
github.com/kong/go-kong v0.34.1-0.20221222170410-6c81ce561662/go.mod h1:G30uJtuJOjJXFL1vulIrz/27KhPdE2g0GtJZlNINU6U=
570-
github.com/kong/kubernetes-testing-framework v0.25.0 h1:teuhY67W9/TDaBNjfQFBHUuptda6o8ilpjSW7/sXeKc=
571-
github.com/kong/kubernetes-testing-framework v0.25.0/go.mod h1:5LiOMyPajmukMTx41vxiUrzx8kvFoVcZfpqpcHtEIkE=
570+
github.com/kong/kubernetes-testing-framework v0.26.0 h1:rusiPJVMUdgpKm08/1hGcCRkQYY2Ct2iQ66TukLwUIM=
571+
github.com/kong/kubernetes-testing-framework v0.26.0/go.mod h1:clm6sSUBFEXGBA427BN8AEBdF0VCNeVmG3O4uPjF84g=
572572
github.com/kong/semver/v4 v4.0.1 h1:DIcNR8W3gfx0KabFBADPalxxsp+q/5COwIFkkhrFQ2Y=
573573
github.com/kong/semver/v4 v4.0.1/go.mod h1:LImQ0oT15pJvSns/hs2laLca2zcYoHu5EsSNY0J6/QA=
574574
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=

hack/cleanup_gke_clusters.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func findOrphanedClusters(ctx context.Context, mgrc *container.ClusterManagerCli
114114

115115
var orphanedClusterNames []string
116116
for _, cluster := range clusterListResp.Clusters {
117-
if isCreatedByTests(cluster) {
117+
if e2e.IsGKETestCluster(cluster) {
118118
createdAt, err := time.Parse(time.RFC3339, cluster.CreateTime)
119119
if err != nil {
120120
return nil, err
@@ -131,11 +131,3 @@ func findOrphanedClusters(ctx context.Context, mgrc *container.ClusterManagerCli
131131

132132
return orphanedClusterNames, nil
133133
}
134-
135-
func isCreatedByTests(cluster *containerpb.Cluster) bool {
136-
if cluster == nil {
137-
return false
138-
}
139-
140-
return e2e.IsCreatedByE2ETests(cluster.Name)
141-
}

test/e2e/clusters.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
package e2e
22

3-
import "strings"
3+
import (
4+
"cloud.google.com/go/container/apiv1/containerpb"
5+
)
46

57
const (
6-
// GKETestClusterNamePrefix defines a prefix that is used for naming GKE clusters created in tests.
7-
// It allows hack/cleanup_gke_clusters.go script to deterministically tell whether a cluster should
8-
// be taken into account in the cleanup procedure.
9-
gkeTestClusterNamePrefix = "e2e-"
8+
gkeTestClusterLabel = "test-cluster"
9+
gkeLabelValueTrue = "true"
1010
)
1111

12-
func IsCreatedByE2ETests(clusterName string) bool {
13-
return strings.HasPrefix(clusterName, gkeTestClusterNamePrefix)
12+
// IsGKETestCluster tells if the GKE cluster has been created for test purposes.
13+
func IsGKETestCluster(cluster *containerpb.Cluster) bool {
14+
if cluster == nil {
15+
return false
16+
}
17+
18+
if labels := cluster.GetResourceLabels(); labels != nil {
19+
return labels[gkeTestClusterLabel] == gkeLabelValueTrue
20+
}
21+
22+
return false
23+
}
24+
25+
func gkeTestClusterLabels() map[string]string {
26+
return map[string]string{
27+
gkeTestClusterLabel: gkeLabelValueTrue,
28+
}
1429
}

test/e2e/helpers_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func createExistingGKEBuilder(ctx context.Context, name string) (*environments.B
137137

138138
func createGKEBuilder() (*environments.Builder, error) {
139139
var (
140-
name = gkeTestClusterNamePrefix + uuid.NewString()
140+
name = "e2e-" + uuid.NewString()
141141
gkeCreds = os.Getenv(gke.GKECredsVar)
142142
gkeProject = os.Getenv(gke.GKEProjectVar)
143143
gkeLocation = os.Getenv(gke.GKELocationVar)
@@ -149,7 +149,8 @@ func createGKEBuilder() (*environments.Builder, error) {
149149
NewBuilder([]byte(gkeCreds), gkeProject, gkeLocation).
150150
WithName(name).
151151
WithWaitForTeardown(true).
152-
WithCreateSubnet(true)
152+
WithCreateSubnet(true).
153+
WithLabels(gkeTestClusterLabels())
153154

154155
if clusterVersionStr != "" {
155156
k8sVersion, err := semver.Parse(strings.TrimPrefix(clusterVersionStr, "v"))

0 commit comments

Comments
 (0)