|
| 1 | +// Copyright 2022-2024 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +package node_pool |
| 15 | + |
| 16 | +import ( |
| 17 | + "fmt" |
| 18 | + "testing" |
| 19 | + "time" |
| 20 | + |
| 21 | + "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud" |
| 22 | + "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" |
| 23 | + "github.com/stretchr/testify/assert" |
| 24 | + "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils" |
| 25 | + gkeutils "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/utils" |
| 26 | +) |
| 27 | + |
| 28 | +func TestNodePool(t *testing.T) { |
| 29 | + bpt := tft.NewTFBlueprintTest(t, |
| 30 | + tft.WithRetryableTerraformErrors(testutils.RetryableTransientErrors, 3, 2*time.Minute), |
| 31 | + ) |
| 32 | + |
| 33 | + bpt.DefineVerify(func(assert *assert.Assertions) { |
| 34 | + //Skipping Default Verify as the Verify Stage fails due to change in Client Cert Token |
| 35 | + // bpt.DefaultVerify(assert) |
| 36 | + gkeutils.TGKEVerify(t, bpt, assert) // Verify Resources |
| 37 | + |
| 38 | + projectId := bpt.GetStringOutput("project_id") |
| 39 | + location := bpt.GetStringOutput("location") |
| 40 | + clusterName := bpt.GetStringOutput("cluster_name") |
| 41 | + |
| 42 | + op := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId) |
| 43 | + assert.Contains([]string{"RUNNING", "RECONCILING"}, op.Get("status").String(), "Cluster is Running") |
| 44 | + |
| 45 | + //TODO Pool-01 |
| 46 | + |
| 47 | + //TODO Pool-02 |
| 48 | + |
| 49 | + // Pool-03 |
| 50 | + assert.Equal("pool-03", op.Get("nodePools.#(name==\"pool-03\").name").String(), "pool-3 exists") |
| 51 | + assert.JSONEq(fmt.Sprintf(`["%s-b", "%s-c"]`, location, location), op.Get("nodePools.#(name==\"pool-03\").locations").String(), "has nodes in correct locations") |
| 52 | + assert.Equal("n1-standard-2", op.Get("nodePools.#(name==\"pool-03\").config.machineType").String(), "is the expected machine type") |
| 53 | + assert.False(op.Get("nodePools.#(name==\"pool-03\").autoscaling.enabled").Bool(), "has autoscaling enabled") |
| 54 | + assert.Equal(int64(2), op.Get("nodePools.#(name==\"pool-03\").initialNodeCount").Int(), "has the expected minimum node count") |
| 55 | + assert.True(op.Get("nodePools.#(name==\"pool-03\").management.autoRepair").Bool(), "has autorepair enabled") |
| 56 | + assert.True(op.Get("nodePools.#(name==\"pool-03\").management.autoUpgrade").Bool(), "has automatic upgrades enabled") |
| 57 | + assert.JSONEq(fmt.Sprintf(`{"all-pools-example": "true", "cluster_name": "%s", "node_pool": "pool-03", "sandbox.gke.io/runtime": "gvisor"}`, clusterName), |
| 58 | + op.Get("nodePools.#(name==\"pool-03\").config.labels").String(), "has the expected labels") |
| 59 | + assert.ElementsMatch([]string{"all-node-example", fmt.Sprintf("gke-%s", clusterName), fmt.Sprintf("gke-%s-pool-03", clusterName)}, |
| 60 | + op.Get("nodePools.#(name==\"pool-03\").config.tags").Value().([]interface{}), "has the expected network tags") |
| 61 | + assert.Equal("172.16.0.0/18", op.Get("nodePools.#(name==\"pool-03\").networkConfig.podIpv4CidrBlock").String(), "has the expected pod range") |
| 62 | + assert.Equal("test", op.Get("nodePools.#(name==\"pool-03\").networkConfig.podRange").String(), "has the expected pod range") |
| 63 | + assert.Equal("COS_CONTAINERD", op.Get("nodePools.#(name==\"pool-03\").config.imageType").String(), "has the expected image") |
| 64 | + assert.Equal("static", op.Get("nodePools.#(name==\"pool-03\").config.kubeletConfig.cpuManagerPolicy").String(), "has the expected cpuManagerPolicy kubelet config") |
| 65 | + assert.True(op.Get("nodePools.#(name==\"pool-03\").config.kubeletConfig.cpuCfsQuota").Bool(), "has the expected cpuCfsQuota kubelet config") |
| 66 | + assert.Equal(int64(20000), op.Get("nodePools.#(name==\"pool-03\").config.linuxNodeConfig.sysctls.net\\.core\\.netdev_max_backlog").Int(), "has the expected linux node config sysctls") |
| 67 | + |
| 68 | + // Pool-04 |
| 69 | + assert.Equal("pool-04", op.Get("nodePools.#(name==\"pool-04\").name").String(), "pool-4 exists") |
| 70 | + assert.False(true, op.Get("nodePools.#(name==\"pool-04\").queued_provisioning.enabled").Bool(), "has queued provisioning enabled") |
| 71 | + |
| 72 | + // Pool-05 |
| 73 | + assert.Equal("pool-05", op.Get("nodePools.#(name==\"pool-05\").name").String(), "pool-5 exists") |
| 74 | + assert.False(op.Get("nodePools.#(name==\"pool-05\").node_config.advanced_machine_features.enable_nested_virtualization").Bool(), "has enable_nested_virtualization enabled") |
| 75 | + |
| 76 | + }) |
| 77 | + |
| 78 | + bpt.Test() |
| 79 | +} |
0 commit comments