Skip to content

Commit edc8d37

Browse files
committed
switch to glcoud
1 parent cbfc3ab commit edc8d37

File tree

6 files changed

+59
-194
lines changed

6 files changed

+59
-194
lines changed

build/int.cloudbuild.yaml

Lines changed: 2 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -29,172 +29,21 @@ steps:
2929
- prepare
3030
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
3131
args: ['/bin/bash', '-c', 'cft test run TestNodePool --stage init --verbose']
32-
- id: converge node-pool-local
32+
- id: apply node-pool-local
3333
waitFor:
3434
- init node-pool-local
3535
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
3636
args: ['/bin/bash', '-c', 'cft test run TestNodePool --stage apply --verbose']
3737
- id: verify node-pool-local
3838
waitFor:
39-
- converge node-pool-local
39+
- apply node-pool-local
4040
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
4141
args: ['/bin/bash', '-c', 'cft test run TestNodePool --stage verify --verbose']
4242
- id: destroy node-pool-local
4343
waitFor:
4444
- verify node-pool-local
4545
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
4646
args: ['/bin/bash', '-c', 'cft test run TestNodePool --stage destroy --verbose']
47-
- id: apply sandbox-enabled-local
48-
waitFor:
49-
- create-all
50-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
51-
args: ['/bin/bash', '-c', 'cft test run TestSandboxEnabled --stage apply --verbose']
52-
- id: verify sandbox-enabled-local
53-
waitFor:
54-
- apply sandbox-enabled-local
55-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
56-
args: ['/bin/bash', '-c', 'cft test run TestSandboxEnabled --stage verify --verbose']
57-
- id: destroy sandbox-enabled-local
58-
waitFor:
59-
- verify sandbox-enabled-local
60-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
61-
args: ['/bin/bash', '-c', 'cft test run TestSandboxEnabled --stage destroy --verbose']
62-
- id: apply workload-identity-local
63-
waitFor:
64-
- create-all
65-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
66-
args: ['/bin/bash', '-c', 'cft test run TestWorkloadIdentity --stage apply --verbose']
67-
- id: verify workload-identity-local
68-
waitFor:
69-
- apply workload-identity-local
70-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
71-
args: ['/bin/bash', '-c', 'cft test run TestWorkloadIdentity --stage verify --verbose']
72-
- id: destroy workload-identity-local
73-
waitFor:
74-
- verify workload-identity-local
75-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
76-
args: ['/bin/bash', '-c', 'cft test run TestWorkloadIdentity --stage teardown --verbose']
77-
- id: apply safer-cluster-iap-bastion-local
78-
waitFor:
79-
- create-all
80-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
81-
args: ['/bin/bash', '-c', 'cft test run TestSaferClusterIapBastion --stage apply --verbose']
82-
- id: verify safer-cluster-iap-bastion-local
83-
waitFor:
84-
- apply safer-cluster-iap-bastion-local
85-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
86-
args: ['/bin/bash', '-c', 'cft test run TestSaferClusterIapBastion --stage verify --verbose']
87-
- id: destroy safer-cluster-iap-bastion-local
88-
waitFor:
89-
- verify safer-cluster-iap-bastion-local
90-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
91-
args: ['/bin/bash', '-c', 'cft test run TestSaferClusterIapBastion --stage teardown --verbose']
92-
- id: apply simple-zonal-with-asm-local
93-
waitFor:
94-
- create-all
95-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
96-
args: ['/bin/bash', '-c', 'cft test run TestSimpleZonalWithASM --stage apply --verbose']
97-
- id: verify simple-zonal-with-asm-local
98-
waitFor:
99-
- apply simple-zonal-with-asm-local
100-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
101-
args: ['/bin/bash', '-c', 'cft test run TestSimpleZonalWithASM --stage verify --verbose']
102-
- id: destroy simple-zonal-with-asm-local
103-
waitFor:
104-
- verify simple-zonal-with-asm-local
105-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
106-
args: ['/bin/bash', '-c', 'cft test run TestSimpleZonalWithASM --stage teardown --verbose']
107-
- id: apply simple-autopilot-private-local
108-
waitFor:
109-
- create-all
110-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
111-
args: ['/bin/bash', '-c', 'cft test run TestSimpleAutopilotPrivate --stage apply --verbose']
112-
- id: verify simple-autopilot-private-local
113-
waitFor:
114-
- apply simple-autopilot-private-local
115-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
116-
args: ['/bin/bash', '-c', 'cft test run TestSimpleAutopilotPrivate --stage verify --verbose']
117-
- id: destroy simple-autopilot-private-local
118-
waitFor:
119-
- verify simple-autopilot-private-local
120-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
121-
args: ['/bin/bash', '-c', 'cft test run TestSimpleAutopilotPrivate --stage teardown --verbose']
122-
- id: apply autopilot-private-firewalls
123-
waitFor:
124-
- create-all
125-
- destroy simple-autopilot-private-local
126-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
127-
args: ['/bin/bash', '-c', 'cft test run TestAutopilotPrivateFirewalls --stage apply --verbose']
128-
- id: verify autopilot-private-firewalls
129-
waitFor:
130-
- apply autopilot-private-firewalls
131-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
132-
args: ['/bin/bash', '-c', 'cft test run TestAutopilotPrivateFirewalls --stage verify --verbose']
133-
- id: destroy autopilot-private-firewalls
134-
waitFor:
135-
- verify autopilot-private-firewalls
136-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
137-
args: ['/bin/bash', '-c', 'cft test run TestAutopilotPrivateFirewalls --stage destroy --verbose']
138-
- id: apply simple-autopilot-public-local
139-
waitFor:
140-
- create-all
141-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
142-
args: ['/bin/bash', '-c', 'cft test run TestSimpleAutopilotPublic --stage apply --verbose']
143-
- id: verify simple-autopilot-public-local
144-
waitFor:
145-
- apply simple-autopilot-public-local
146-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
147-
args: ['/bin/bash', '-c', 'cft test run TestSimpleAutopilotPublic --stage verify --verbose']
148-
- id: destroy simple-autopilot-public-local
149-
waitFor:
150-
- verify simple-autopilot-public-local
151-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
152-
args: ['/bin/bash', '-c', 'cft test run TestSimpleAutopilotPublic --stage teardown --verbose']
153-
- id: apply private-zonal-with-networking
154-
waitFor:
155-
- create-all
156-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
157-
args: ['/bin/bash', '-c', 'cft test run TestPrivateZonalWithNetworking --stage apply --verbose --test-dir test/integration']
158-
- id: verify private-zonal-with-networking
159-
waitFor:
160-
- apply private-zonal-with-networking
161-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
162-
args: ['/bin/bash', '-c', 'cft test run TestPrivateZonalWithNetworking --stage verify --verbose --test-dir test/integration']
163-
- id: teardown private-zonal-with-networking
164-
waitFor:
165-
- verify private-zonal-with-networking
166-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
167-
args: ['/bin/bash', '-c', 'cft test run TestPrivateZonalWithNetworking --stage teardown --verbose --test-dir test/integration']
168-
- id: apply simple-autopilot-private-non-default-sa
169-
waitFor:
170-
- create-all
171-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
172-
args: ['/bin/bash', '-c', 'cft test run TestSimpleAutopilotPrivateNonDefaultSA --stage apply --verbose']
173-
- id: verify simple-autopilot-private-non-default-sa
174-
waitFor:
175-
- apply simple-autopilot-private-non-default-sa
176-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
177-
args: ['/bin/bash', '-c', 'cft test run TestSimpleAutopilotPrivateNonDefaultSA --stage verify --verbose']
178-
- id: teardown simple-autopilot-private-non-default-sa
179-
waitFor:
180-
- verify simple-autopilot-private-non-default-sa
181-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
182-
args: ['/bin/bash', '-c', 'cft test run TestSimpleAutopilotPrivateNonDefaultSA --stage teardown --verbose']
183-
- id: apply simple-fleet-app-operator-permissions
184-
waitFor:
185-
- create-all
186-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
187-
args: ['/bin/bash', '-c', 'cft test run TestSimpleFleetAppOperatorPermissions --stage apply --verbose']
188-
- id: verify simple-fleet-app-operator-permissions
189-
waitFor:
190-
- apply simple-fleet-app-operator-permissions
191-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
192-
args: ['/bin/bash', '-c', 'cft test run TestSimpleFleetAppOperatorPermissions --stage verify --verbose']
193-
- id: teardown simple-fleet-app-operator-permissions
194-
waitFor:
195-
- verify simple-fleet-app-operator-permissions
196-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
197-
args: ['/bin/bash', '-c', 'cft test run TestSimpleFleetAppOperatorPermissions --stage teardown --verbose']
19847
tags:
19948
- 'ci'
20049
- 'integration'

examples/node_pool/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module "gke" {
4343
disable_legacy_metadata_endpoints = false
4444
cluster_autoscaling = var.cluster_autoscaling
4545
deletion_protection = false
46-
service_account = "default"
46+
service_account = var.compute_engine_service_account
4747

4848
node_pools = [
4949
{

test/integration/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/gruntwork-io/terratest v0.48.1
1010
github.com/hashicorp/terraform-json v0.24.0
1111
github.com/stretchr/testify v1.10.0
12+
github.com/tidwall/gjson v1.18.0
1213
)
1314

1415
require (
@@ -103,7 +104,6 @@ require (
103104
github.com/pquerna/otp v1.4.0 // indirect
104105
github.com/russross/blackfriday/v2 v2.1.0 // indirect
105106
github.com/spf13/pflag v1.0.5 // indirect
106-
github.com/tidwall/gjson v1.18.0 // indirect
107107
github.com/tidwall/match v1.1.1 // indirect
108108
github.com/tidwall/pretty v1.2.1 // indirect
109109
github.com/tidwall/sjson v1.2.5 // indirect

test/integration/node_pool/node_pool_test.go

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ package node_pool
1515

1616
import (
1717
"fmt"
18-
"slices"
1918
"testing"
2019
"time"
2120

2221
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/cai"
2322
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
2423
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/golden"
2524
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
26-
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
27-
"github.com/gruntwork-io/terratest/modules/k8s"
2825
"github.com/stretchr/testify/assert"
2926
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
3027
)
@@ -45,20 +42,14 @@ func TestNodePool(t *testing.T) {
4542
randomString := bpt.GetStringOutput("random_string")
4643
kubernetesEndpoint := bpt.GetStringOutput("kubernetes_endpoint")
4744

48-
// Retrieve Project CAI
45+
// // Retrieve Project CAI
4946
projectCAI := cai.GetProjectResources(t, projectId, cai.WithAssetTypes([]string{"container.googleapis.com/Cluster", "k8s.io/Node"}))
50-
t.Log(projectCAI.Raw)
51-
// Retrieve Cluster from CAI
52-
clusterResourceName := fmt.Sprintf("//container.googleapis.com/projects/%s/locations/%s/clusters/%s", projectId, location, clusterName)
5347

54-
if !projectCAI.Get("#(name=\"" + clusterResourceName + "\").resource.data").Exists() {
55-
t.Fatalf("Cluster not found: %s", clusterResourceName)
56-
}
57-
58-
cluster := projectCAI.Get("#(name=\"" + clusterResourceName + "\").resource.data")
59-
t.Log(cluster.Raw)
48+
// // Retrieve Cluster from CAI
49+
// clusterResourceName := fmt.Sprintf("//container.googleapis.com/projects/%s/locations/%s/clusters/%s", projectId, location, clusterName)
50+
// cluster := projectCAI.Get("#(name=\"" + clusterResourceName + "\").resource.data")
6051
// Equivalent gcloud describe command (classic)
61-
// cluster := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId)
52+
cluster := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId)
6253

6354
// Cluster Assertions (classic)
6455
assert.Contains([]string{"RUNNING", "RECONCILING"}, cluster.Get("status").String(), "Cluster is Running")
@@ -87,19 +78,8 @@ func TestNodePool(t *testing.T) {
8778
golden.WithSanitizer(golden.StringSanitizer(randomString, "RANDOM_STRING")),
8879
golden.WithSanitizer(golden.StringSanitizer(kubernetesEndpoint, "KUBERNETES_ENDPOINT")),
8980
)
90-
checkPaths := utils.GetTerminalJSONPaths(g.GetJSON())
91-
92-
exemptPaths := []string{"nodePools"}
93-
checkPaths = slices.DeleteFunc(checkPaths, func(s string) bool {
94-
return slices.Contains(exemptPaths, s)
95-
})
96-
g.JSONPathEqs(assert, cluster, checkPaths)
9781

98-
// NodePool Assertions
99-
nodePools := []string{"pool-01", "pool-02", "pool-03", "pool-04", "pool-05"}
100-
for _, nodePool := range nodePools {
101-
g.JSONPathEqs(assert, cluster.Get(fmt.Sprintf("nodePools.#(name==%s).name", nodePool)), utils.GetTerminalJSONPaths(g.GetJSON().Get(fmt.Sprintf("nodePools.#(name==%s).name", nodePool))))
102-
}
82+
testutils.TGKEAssertGolden(t, assert, g, &cluster, []string{"pool-01", "pool-02", "pool-03", "pool-04", "pool-05"}, []string{"monitoringConfig.componentConfig.enableComponents"})
10383

10484
// nodePool-01 Assertions
10585
assert.Equal("pool-01", cluster.Get("nodePools.#(name==\"pool-01\").name").String(), "pool-1 exists")
@@ -161,11 +141,12 @@ func TestNodePool(t *testing.T) {
161141
assert.True(cluster.Get("nodePools.#(name==\"pool-05\").config.advancedMachineFeatures.enableNestedVirtualization").Bool(), "has enable_nested_virtualization enabled")
162142

163143
// K8s Assertions
164-
gcloud.Runf(t, "container clusters get-credentials %s --region %s --project %s", clusterName, location, projectId)
165-
k8sOpts := k8s.KubectlOptions{}
166-
clusterNodesOp, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "nodes", "-o", "json")
167-
assert.NoError(err)
168-
clusterNodes := utils.ParseKubectlJSONResult(t, clusterNodesOp)
144+
// gcloud.Runf(t, "container clusters get-credentials %s --region %s --project %s", clusterName, location, projectId)
145+
// k8sOpts := k8s.KubectlOptions{}
146+
// clusterNodesOp, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "nodes", "-o", "json")
147+
// assert.NoError(err)
148+
// clusterNodes := utils.ParseKubectlJSONResult(t, clusterNodesOp)
149+
169150
assert.JSONEq(`[
170151
{
171152
"effect": "PreferNoSchedule",
@@ -178,7 +159,7 @@ func TestNodePool(t *testing.T) {
178159
"value": "true"
179160
}
180161
]`,
181-
clusterNodes.Get("items.#(metadata.labels.node_pool==\"pool-01\").spec.taints").String(), "has the expected taints")
162+
projectCAI.Get("#(resource.data.metadata.labels.node_pool==\"pool-01\").resource.data.spec.taints").String(), "has the expected taints")
182163
assert.JSONEq(`[
183164
{
184165
"effect": "PreferNoSchedule",
@@ -191,7 +172,7 @@ func TestNodePool(t *testing.T) {
191172
"value": "present"
192173
}
193174
]`,
194-
clusterNodes.Get("items.#(metadata.labels.node_pool==\"pool-02\").spec.taints").String(), "has the expected all-pools-example taint")
175+
projectCAI.Get("#(resource.data.metadata.labels.node_pool==\"pool-02\").resource.data.spec.taints").String(), "has the expected all-pools-example taint")
195176
assert.JSONEq(`[
196177
{
197178
"effect": "PreferNoSchedule",
@@ -204,7 +185,7 @@ func TestNodePool(t *testing.T) {
204185
"value": "gvisor"
205186
}
206187
]`,
207-
clusterNodes.Get("items.#(metadata.labels.node_pool==\"pool-03\").spec.taints").String(), "has the expected all-pools-example taint")
188+
projectCAI.Get("#(resource.data.metadata.labels.node_pool==\"pool-03\").resource.data.spec.taints").String(), "has the expected all-pools-example taint")
208189
})
209190

210191
bpt.Test()

test/integration/safer_cluster_iap_bastion/safer_cluster_iap_bastion_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ func TestSaferClusterIapBastion(t *testing.T) {
3535
// bpt.DefaultVerify(assert)
3636
testutils.TGKEVerify(t, bpt, assert) // Verify Resources
3737

38-
test_command, _ := strings.CutPrefix(bpt.GetStringOutput("test_command"), "gcloud ")
38+
testCommand, _ := strings.CutPrefix(bpt.GetStringOutput("test_command"), "gcloud ")
3939

4040
// pre run ssh command so that ssh-keygen can run
41-
gcloud.RunCmd(t, test_command,
41+
gcloud.RunCmd(t, testCommand,
4242
gcloud.WithCommonArgs([]string{}),
4343
)
4444

45-
cluster_version := fmt.Sprintf("v%s", bpt.GetStringOutput("cluster_version"))
45+
clusterVersion := fmt.Sprintf("v%s", bpt.GetStringOutput("cluster_version"))
4646

47-
op := gcloud.Run(t, test_command,
47+
op := gcloud.Run(t, testCommand,
4848
gcloud.WithCommonArgs([]string{}),
4949
)
5050

51-
assert.Equal(cluster_version, op.Get("gitVersion").String(), "SSH into VM and verify connectivity to GKE")
51+
assert.Equal(clusterVersion, op.Get("gitVersion").String(), "SSH into VM and verify connectivity to GKE")
5252
})
5353

5454
bpt.Test()

test/integration/testutils/utils.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@
1515
package testutils
1616

1717
import (
18+
"fmt"
1819
"slices"
1920
"strings"
2021
"testing"
2122
"time"
2223

24+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/golden"
2325
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
26+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
2427
tfjson "github.com/hashicorp/terraform-json"
2528
"github.com/stretchr/testify/assert"
29+
"github.com/tidwall/gjson"
2630
)
2731

2832
var (
@@ -36,6 +40,8 @@ var (
3640
// API Rate limit exceeded errors can be retried.
3741
".*rateLimitExceeded.*": "Rate limit exceeded.",
3842
}
43+
44+
ClusterAlwaysExemptPaths = []string{"nodePools"} // node pools are checked by name
3945
)
4046

4147
func GetTestProjectFromSetup(t *testing.T, idx int) string {
@@ -67,3 +73,32 @@ func TGKEVerifyExemptResources(t *testing.T, b *tft.TFBlueprintTest, assert *ass
6773
assert.Equal(tfjson.Actions{tfjson.ActionNoop}, r.Change.Actions, "Plan must be no-op for resource: %s", r.Address)
6874
}
6975
}
76+
77+
// TGKEAssertGolden asserts a cluster and listed node pools against paths in golden image
78+
func TGKEAssertGolden(t *testing.T, assert *assert.Assertions, golden *golden.GoldenFile, clusterJson *gjson.Result, nodePools []string, exemptClusterPaths []string) {
79+
// Retrieve golden paths
80+
clusterCheckPaths := utils.GetTerminalJSONPaths(golden.GetJSON())
81+
exemptPaths := slices.Concat(exemptClusterPaths, ClusterAlwaysExemptPaths)
82+
83+
// Remove exempt cluster paths
84+
clusterCheckPaths = slices.DeleteFunc(clusterCheckPaths, func(s string) bool {
85+
for _, exempPath := range exemptPaths {
86+
if strings.HasPrefix(s, exempPath) {
87+
return true
88+
}
89+
}
90+
return false
91+
})
92+
93+
// Cluster assertions
94+
golden.JSONPathEqs(assert, *clusterJson, clusterCheckPaths)
95+
96+
// NodePool assertions
97+
for _, nodePool := range nodePools {
98+
if !clusterJson.Get(fmt.Sprintf("nodePools.#(name==%s).name", nodePool)).Exists() {
99+
t.Fatalf("NodePool not found: %s", nodePool)
100+
}
101+
nodeCheckPaths := utils.GetTerminalJSONPaths(golden.GetJSON().Get(fmt.Sprintf("nodePools.#(name==%s)", nodePool)))
102+
golden.JSONPathEqs(assert, clusterJson.Get(fmt.Sprintf("nodePools.#(name==%s)", nodePool)), nodeCheckPaths)
103+
}
104+
}

0 commit comments

Comments
 (0)