@@ -19,6 +19,7 @@ import (
1919 "time"
2020
2121 "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
22+ "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/golden"
2223 "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
2324 "github.com/gruntwork-io/terratest/modules/k8s"
2425 "github.com/stretchr/testify/assert"
@@ -40,14 +41,17 @@ func TestNodePool(t *testing.T) {
4041 location := bpt .GetStringOutput ("location" )
4142 clusterName := bpt .GetStringOutput ("cluster_name" )
4243
43- //cluster := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId)
44+ // CAI
4445 clusterResourceName := fmt .Sprintf ("//container.googleapis.com/projects/%s/locations/%s/clusters/%s" , projectId , location , clusterName )
45- cluster := gkeutils .GetProjectResources (t , projectId , gkeutils .WithAssetType ("container.googleapis.com/Cluster" )).Get ("#(name=\" " + clusterResourceName + "\" ).resource.data" )
46+ cluster := gkeutils .GetProjectResources (t , projectId , gkeutils .WithAssetTypes ([]string {"container.googleapis.com/Cluster" })).Get ("#(name=\" " + clusterResourceName + "\" ).resource.data" )
47+
48+ // Equivalent gcloud describe command
49+ // cluster := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId)
4650
4751 // Cluster
4852 assert .Contains ([]string {"RUNNING" , "RECONCILING" }, cluster .Get ("status" ).String (), "Cluster is Running" )
4953 assert .Equal ("COS_CONTAINERD" , cluster .Get ("autoscaling.autoprovisioningNodePoolDefaults.imageType" ).String (), "has the expected image type" )
50- assert .Equal ("[ \n \" https://www.googleapis.com/auth/cloud-platform\" \n ]" , cluster .Get ("autoscaling.autoprovisioningNodePoolDefaults.oauthScopes" ).String (), "has the expected oauth scopes" )
54+ assert .Equal ("https://www.googleapis.com/auth/cloud-platform" , cluster .Get ("autoscaling.autoprovisioningNodePoolDefaults.oauthScopes.0 " ).String (), "has the expected oauth scopes" )
5155 assert .Equal ("default" , cluster .Get ("autoscaling.autoprovisioningNodePoolDefaults.serviceAccount" ).String (), "has the expected service account" )
5256 assert .Equal ("OPTIMIZE_UTILIZATION" , cluster .Get ("autoscaling.autoscalingProfile" ).String (), "has the expected autoscaling profile" )
5357 assert .True (cluster .Get ("autoscaling.enableNodeAutoprovisioning" ).Bool (), "has the expected node autoprovisioning" )
@@ -65,6 +69,29 @@ func TestNodePool(t *testing.T) {
6569 ]` ,
6670 cluster .Get ("autoscaling.resourceLimits" ).String (), "has the expected resource limits" )
6771
72+ // Cluster (using golden image with sanitizer)
73+ g := golden .NewOrUpdate (t , cluster .String (),
74+ golden .WithSanitizer (golden .StringSanitizer (projectId , "PROJECT_ID" )),
75+ golden .WithSanitizer (golden .StringSanitizer (location , "LOCATION" )),
76+ golden .WithSanitizer (golden .StringSanitizer (clusterName , "CLUSTER_NAME" )),
77+ )
78+ validateJSONPaths := []string {
79+ "autoscaling.autoprovisioningNodePoolDefaults.imageType" ,
80+ "autoscaling.autoprovisioningNodePoolDefaults.oauthScopes.0" ,
81+ "autoscaling.autoprovisioningNodePoolDefaults.serviceAccount" ,
82+ "autoscaling.autoscalingProfile" ,
83+ "autoscaling.enableNodeAutoprovisioning" ,
84+ "autoscaling.resourceLimits[0].maximum" ,
85+ "autoscaling.resourceLimits[0].minimum" ,
86+ "autoscaling.resourceLimits[0].resourceType" ,
87+ "autoscaling.resourceLimits[1].maximum" ,
88+ "autoscaling.resourceLimits[1].minimum" ,
89+ "autoscaling.resourceLimits[1].resourceType" ,
90+ }
91+ for _ , pth := range validateJSONPaths {
92+ g .JSONEq (assert , cluster , pth )
93+ }
94+
6895 // Pool-01
6996 assert .Equal ("pool-01" , cluster .Get ("nodePools.#(name==\" pool-01\" ).name" ).String (), "pool-1 exists" )
7097 assert .Equal ("e2-medium" , cluster .Get ("nodePools.#(name==\" pool-01\" ).config.machineType" ).String (), "is the expected machine type" )
@@ -148,6 +175,11 @@ func TestNodePool(t *testing.T) {
148175 "effect": "PreferNoSchedule",
149176 "key": "all-pools-example",
150177 "value": "true"
178+ },
179+ {
180+ "effect": "NoSchedule",
181+ "key": "nvidia.com/gpu",
182+ "value": "present"
151183 }
152184 ]` ,
153185 clusterNodes .Get ("items.#(metadata.labels.node_pool==\" pool-02\" ).spec.taints" ).String (), "has the expected all-pools-example taint" )
@@ -156,6 +188,11 @@ func TestNodePool(t *testing.T) {
156188 "effect": "PreferNoSchedule",
157189 "key": "all-pools-example",
158190 "value": "true"
191+ },
192+ {
193+ "effect": "NoSchedule",
194+ "key": "sandbox.gke.io/runtime",
195+ "value": "gvisor"
159196 }
160197 ]` ,
161198 clusterNodes .Get ("items.#(metadata.labels.node_pool==\" pool-03\" ).spec.taints" ).String (), "has the expected all-pools-example taint" )
0 commit comments