@@ -18,13 +18,15 @@ import (
1818 "testing"
1919 "time"
2020
21+ "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/cai"
2122 "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
2223 "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/golden"
2324 "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
25+ "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
2426 "github.com/gruntwork-io/terratest/modules/k8s"
2527 "github.com/stretchr/testify/assert"
2628 "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
27- gkeutils "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/utils "
29+ "golang.org/x/sync/errgroup "
2830)
2931
3032func TestNodePool (t * testing.T ) {
@@ -35,15 +37,18 @@ func TestNodePool(t *testing.T) {
3537 bpt .DefineVerify (func (assert * assert.Assertions ) {
3638 // Skipping Default Verify as the Verify Stage fails due to change in Client Cert Token
3739 // bpt.DefaultVerify(assert)
38- gkeutils .TGKEVerify (t , bpt , assert ) // Verify Resources
40+ testutils .TGKEVerify (t , bpt , assert ) // Verify Resources
3941
4042 projectId := bpt .GetStringOutput ("project_id" )
4143 location := bpt .GetStringOutput ("location" )
4244 clusterName := bpt .GetStringOutput ("cluster_name" )
45+ randomString := bpt .GetStringOutput ("random_string" )
46+ kubernetesEndpoint := bpt .GetStringOutput ("kubernetes_endpoint" )
47+ serviceAccount := bpt .GetStringOutput ("service_account" )
4348
4449 // CAI
4550 clusterResourceName := fmt .Sprintf ("//container.googleapis.com/projects/%s/locations/%s/clusters/%s" , projectId , location , clusterName )
46- cluster := gkeutils .GetProjectResources (t , projectId , gkeutils .WithAssetTypes ([]string {"container.googleapis.com/Cluster" })).Get ("#(name=\" " + clusterResourceName + "\" ).resource.data" )
51+ cluster := cai .GetProjectResources (t , projectId , cai .WithAssetTypes ([]string {"container.googleapis.com/Cluster" })).Get ("#(name=\" " + clusterResourceName + "\" ).resource.data" )
4752
4853 // Equivalent gcloud describe command
4954 // cluster := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId)
@@ -74,6 +79,9 @@ func TestNodePool(t *testing.T) {
7479 golden .WithSanitizer (golden .StringSanitizer (projectId , "PROJECT_ID" )),
7580 golden .WithSanitizer (golden .StringSanitizer (location , "LOCATION" )),
7681 golden .WithSanitizer (golden .StringSanitizer (clusterName , "CLUSTER_NAME" )),
82+ golden .WithSanitizer (golden .StringSanitizer (randomString , "RANDOM_STRING" )),
83+ golden .WithSanitizer (golden .StringSanitizer (kubernetesEndpoint , "KUBERNETES_ENDPOINT" )),
84+ golden .WithSanitizer (golden .StringSanitizer (serviceAccount , "SERVICE_ACCOUNT" )),
7785 )
7886 validateJSONPaths := []string {
7987 "autoscaling.autoprovisioningNodePoolDefaults.imageType" ,
@@ -92,6 +100,59 @@ func TestNodePool(t *testing.T) {
92100 g .JSONEq (assert , cluster , pth )
93101 }
94102
103+ fmt .Println ("one path" )
104+ g .JSONPathEqs (assert , cluster , []string {"autoscaling.autoprovisioningNodePoolDefaults.imageType" })
105+
106+ fmt .Println ("multi path" )
107+ g .JSONPathEqs (assert , cluster , validateJSONPaths )
108+
109+ fmt .Println ("START all paths 1" )
110+ // Test validating all Paths
111+ jsonPaths := utils .GetTerminalJSONPaths (cluster )
112+
113+ // List of paths exempt from validation
114+ //exemptJSONPaths := []string{
115+ //"createTime",
116+ //"id",
117+ //"etag",
118+ //"controlPlaneEndpointsConfig.dnsEndpointConfig.endpoint",
119+ //"instanceGroupUrls.0",
120+ //"instanceGroupUrls.1",
121+ //"instanceGroupUrls.2",
122+ //"instanceGroupUrls.3",
123+ //"instanceGroupUrls.4",
124+ //"instanceGroupUrls.5",
125+ //"instanceGroupUrls.6",
126+ //"instanceGroupUrls.7",
127+ //"masterAuth.clusterCaCertificate",
128+ //}
129+
130+ // Remove exempt tags
131+ //jsonPaths = slices.DeleteFunc(jsonPaths, func(s string) bool {
132+ // return slices.Contains(exemptJSONPaths, s)
133+ //})
134+
135+ syncGroup := new (errgroup.Group )
136+ syncGroup .SetLimit (24 )
137+ t .Logf ("Checking %d JSON paths with max %d goroutines" , len (jsonPaths ), 24 )
138+ for _ , jsonPath := range jsonPaths {
139+ jsonPath := jsonPath
140+ syncGroup .Go (func () error {
141+ g .JSONEq (assert , cluster , jsonPath )
142+ return nil
143+ })
144+ }
145+ if err := syncGroup .Wait (); err != nil {
146+ t .Fatal (err )
147+ }
148+ fmt .Println ("END all paths 1" )
149+
150+ //fmt.Println("all paths 2")
151+ // Test validating all Paths
152+ //evalPaths := utils.GetJSONPaths(cluster)
153+ //fmt.Println(evalPaths)
154+ //g.JSONPathEqs(assert, cluster, evalPaths)
155+
95156 // Pool-01
96157 assert .Equal ("pool-01" , cluster .Get ("nodePools.#(name==\" pool-01\" ).name" ).String (), "pool-1 exists" )
97158 assert .Equal ("e2-medium" , cluster .Get ("nodePools.#(name==\" pool-01\" ).config.machineType" ).String (), "is the expected machine type" )
@@ -156,7 +217,7 @@ func TestNodePool(t *testing.T) {
156217 k8sOpts := k8s.KubectlOptions {}
157218 clusterNodesOp , err := k8s .RunKubectlAndGetOutputE (t , & k8sOpts , "get" , "nodes" , "-o" , "json" )
158219 assert .NoError (err )
159- clusterNodes := testutils .ParseKubectlJSONResult (t , clusterNodesOp )
220+ clusterNodes := utils .ParseKubectlJSONResult (t , clusterNodesOp )
160221 assert .JSONEq (`[
161222 {
162223 "effect": "PreferNoSchedule",
0 commit comments