Skip to content

Commit

Permalink
multi asset types
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody committed Nov 26, 2024
1 parent e2c08b6 commit e33b3ea
Show file tree
Hide file tree
Showing 3 changed files with 925 additions and 15 deletions.
43 changes: 40 additions & 3 deletions test/integration/node_pool/node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/golden"
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/stretchr/testify/assert"
Expand All @@ -40,14 +41,17 @@ func TestNodePool(t *testing.T) {
location := bpt.GetStringOutput("location")
clusterName := bpt.GetStringOutput("cluster_name")

//cluster := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId)
// CAI
clusterResourceName := fmt.Sprintf("//container.googleapis.com/projects/%s/locations/%s/clusters/%s", projectId, location, clusterName)
cluster := gkeutils.GetProjectResources(t, projectId, gkeutils.WithAssetType("container.googleapis.com/Cluster")).Get("#(name=\"" + clusterResourceName + "\").resource.data")
cluster := gkeutils.GetProjectResources(t, projectId, gkeutils.WithAssetTypes([]string{"container.googleapis.com/Cluster"})).Get("#(name=\"" + clusterResourceName + "\").resource.data")

// Equivalent gcloud describe command
// cluster := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId)

// Cluster
assert.Contains([]string{"RUNNING", "RECONCILING"}, cluster.Get("status").String(), "Cluster is Running")
assert.Equal("COS_CONTAINERD", cluster.Get("autoscaling.autoprovisioningNodePoolDefaults.imageType").String(), "has the expected image type")
assert.Equal("[\n \"https://www.googleapis.com/auth/cloud-platform\"\n ]", cluster.Get("autoscaling.autoprovisioningNodePoolDefaults.oauthScopes").String(), "has the expected oauth scopes")
assert.Equal("https://www.googleapis.com/auth/cloud-platform", cluster.Get("autoscaling.autoprovisioningNodePoolDefaults.oauthScopes.0").String(), "has the expected oauth scopes")
assert.Equal("default", cluster.Get("autoscaling.autoprovisioningNodePoolDefaults.serviceAccount").String(), "has the expected service account")
assert.Equal("OPTIMIZE_UTILIZATION", cluster.Get("autoscaling.autoscalingProfile").String(), "has the expected autoscaling profile")
assert.True(cluster.Get("autoscaling.enableNodeAutoprovisioning").Bool(), "has the expected node autoprovisioning")
Expand All @@ -65,6 +69,29 @@ func TestNodePool(t *testing.T) {
]`,
cluster.Get("autoscaling.resourceLimits").String(), "has the expected resource limits")

// Cluster (using golden image with sanitizer)
g := golden.NewOrUpdate(t, cluster.String(),
golden.WithSanitizer(golden.StringSanitizer(projectId, "PROJECT_ID")),
golden.WithSanitizer(golden.StringSanitizer(location, "LOCATION")),
golden.WithSanitizer(golden.StringSanitizer(clusterName, "CLUSTER_NAME")),
)
validateJSONPaths := []string{
"autoscaling.autoprovisioningNodePoolDefaults.imageType",
"autoscaling.autoprovisioningNodePoolDefaults.oauthScopes.0",
"autoscaling.autoprovisioningNodePoolDefaults.serviceAccount",
"autoscaling.autoscalingProfile",
"autoscaling.enableNodeAutoprovisioning",
"autoscaling.resourceLimits[0].maximum",
"autoscaling.resourceLimits[0].minimum",
"autoscaling.resourceLimits[0].resourceType",
"autoscaling.resourceLimits[1].maximum",
"autoscaling.resourceLimits[1].minimum",
"autoscaling.resourceLimits[1].resourceType",
}
for _, pth := range validateJSONPaths {
g.JSONEq(assert, cluster, pth)
}

// Pool-01
assert.Equal("pool-01", cluster.Get("nodePools.#(name==\"pool-01\").name").String(), "pool-1 exists")
assert.Equal("e2-medium", cluster.Get("nodePools.#(name==\"pool-01\").config.machineType").String(), "is the expected machine type")
Expand Down Expand Up @@ -148,6 +175,11 @@ func TestNodePool(t *testing.T) {
"effect": "PreferNoSchedule",
"key": "all-pools-example",
"value": "true"
},
{
"effect": "NoSchedule",
"key": "nvidia.com/gpu",
"value": "present"
}
]`,
clusterNodes.Get("items.#(metadata.labels.node_pool==\"pool-02\").spec.taints").String(), "has the expected all-pools-example taint")
Expand All @@ -156,6 +188,11 @@ func TestNodePool(t *testing.T) {
"effect": "PreferNoSchedule",
"key": "all-pools-example",
"value": "true"
},
{
"effect": "NoSchedule",
"key": "sandbox.gke.io/runtime",
"value": "gvisor"
}
]`,
clusterNodes.Get("items.#(metadata.labels.node_pool==\"pool-03\").spec.taints").String(), "has the expected all-pools-example taint")
Expand Down
Loading

0 comments on commit e33b3ea

Please sign in to comment.