-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
212 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2022-2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package node_pool | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud" | ||
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils" | ||
gkeutils "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/utils" | ||
) | ||
|
||
func TestNodePool(t *testing.T) { | ||
bpt := tft.NewTFBlueprintTest(t, | ||
tft.WithRetryableTerraformErrors(testutils.RetryableTransientErrors, 3, 2*time.Minute), | ||
) | ||
|
||
bpt.DefineVerify(func(assert *assert.Assertions) { | ||
//Skipping Default Verify as the Verify Stage fails due to change in Client Cert Token | ||
// bpt.DefaultVerify(assert) | ||
gkeutils.TGKEVerify(t, bpt, assert) // Verify Resources | ||
|
||
projectId := bpt.GetStringOutput("project_id") | ||
location := bpt.GetStringOutput("location") | ||
clusterName := bpt.GetStringOutput("cluster_name") | ||
|
||
op := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId) | ||
assert.Contains([]string{"RUNNING", "RECONCILING"}, op.Get("status").String(), "Cluster is Running") | ||
|
||
//or _, np := range op.Get("nodePools").Array() { | ||
// npName := np.Get("name").String() | ||
// switch npName { | ||
|
||
//TODO | ||
|
||
// case "pool-03": | ||
// assert.JSONEq(fmt.Sprintf(`["%s-b", "%s-c"]`, location, location) , np.Get("locations").String()) | ||
|
||
// case "pool-05": | ||
|
||
// } | ||
//} | ||
assert.Equal("pool-03", op.Get("nodePools.#(name==\"pool-03\").name").String(), "pool-3 exists") | ||
assert.JSONEq(fmt.Sprintf(`["%s-b", "%s-c"]`, location, location), op.Get("nodePools.#(name==\"pool-03\").locations").String(), "has nodes in correct locations") | ||
assert.Equal("n1-standard-2", op.Get("nodePools.#(name==\"pool-03\").config.machineType").String(), "is the expected machine type") | ||
assert.True(op.Get("nodePools.#(name==\"pool-03\").autoscaling.enabled").Bool(), "has autoscaling enabled") | ||
assert.Equal(2, op.Get("nodePools.#(name==\"pool-03\").initialNodeCount").Float(), "is the expected machine type") | ||
assert.True(op.Get("nodePools.#(name==\"pool-03\").management.autoRepair").Bool(), "has autorepair enabled") | ||
assert.True(op.Get("nodePools.#(name==\"pool-03\").management.autoUpgrade").Bool(), "has automatic upgrades enabled") | ||
assert.JSONEq(fmt.Sprintf(`{"all-pools-example": "true", "cluster_name": %s, "node_pool": "pool-03", "sandbox.gke.io/runtime": "gvisor"}`, clusterName), | ||
op.Get("nodePools.#(name==\"pool-03\").config.labels").String(), "has the expected labels") | ||
assert.Contains([]string{"all-node-example", | ||
fmt.Sprintf("gke-%s", clusterName), | ||
fmt.Sprintf("gke-%s-pool-03", clusterName)}, | ||
op.Get("nodePools.#(name==\"pool-03\").config.tags").Array(), "has the expected network tags") | ||
assert.Equal("172.16.0.0/18", op.Get("nodePools.#(name==\"pool-03\").networkConfig.podIpv4CidrBlock").String(), "has the expected pod range") | ||
assert.Equal("test", op.Get("nodePools.#(name==\"pool-03\").networkConfig.podRange").String(), "has the expected pod range") | ||
assert.Equal("COS_CONTAINERD", op.Get("nodePools.#(name==\"pool-03\").config.imageType").String(), "has the expected image") | ||
assert.Equal("static", op.Get("nodePools.#(name==\"pool-03\").config.kubeletConfig.cpuManagerPolicy").String(), "has the expected kubelet config") | ||
assert.True(op.Get("nodePools.#(name==\"pool-03\").management.config.kubeletConfig.cpuCfsQuota").Bool(), "has the expected kubelet config") | ||
assert.Equal(20000, op.Get("nodePools.#(name==\"pool-03\").config.linuxNodeConfig.sysctls.net.core.netdev_max_backlog").Float(), "has the expected linux node config sysctls") | ||
|
||
|
||
assert.Equal("pool-04", op.Get("nodePools.#(name==\"pool-04\").name").String(), "pool-4 exists") | ||
assert.True(true, op.Get("nodePools.#(name==\"pool-04\").queued_provisioning.enabled").Bool(), "has queued provisioning enabled") | ||
|
||
assert.Equal("pool-05", op.Get("nodePools.#(name==\"pool-05\").name").String(), "pool-5 exists") | ||
assert.True(op.Get("nodePools.#(name==\"pool-05\").advanced_machine_features.enable_nested_virtualization").Bool(), "has enable_nested_virtualization enabled") | ||
|
||
}) | ||
|
||
bpt.Test() | ||
} |
37 changes: 0 additions & 37 deletions
37
test/integration/safer_cluster_iap_bastion/controls/e2e.rb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
test/integration/safer_cluster_iap_bastion/safer_cluster_iap_bastion_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2022-2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package safer_cluster_iap_bastion | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud" | ||
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils" | ||
gkeutils "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/utils" | ||
) | ||
|
||
func TestSaferClusterIapBastion(t *testing.T) { | ||
bpt := tft.NewTFBlueprintTest(t, | ||
tft.WithRetryableTerraformErrors(testutils.RetryableTransientErrors, 3, 2*time.Minute), | ||
) | ||
|
||
bpt.DefineVerify(func(assert *assert.Assertions) { | ||
//Skipping Default Verify as the Verify Stage fails due to change in Client Cert Token | ||
// bpt.DefaultVerify(assert) | ||
gkeutils.TGKEVerify(t, bpt, assert) // Verify Resources | ||
|
||
test_command, _ := strings.CutPrefix(bpt.GetStringOutput("test_command"), "gcloud ") | ||
|
||
//pre run ssh command so that ssh-keygen can run | ||
gcloud.RunCmd(t, test_command, | ||
gcloud.WithCommonArgs([]string{}), | ||
) | ||
|
||
cluster_version := fmt.Sprintf("v%s", bpt.GetStringOutput("cluster_version")) | ||
|
||
op := gcloud.Run(t, test_command, | ||
gcloud.WithCommonArgs([]string{}), | ||
) | ||
|
||
assert.Equal(cluster_version, op.Get("gitVersion").String(), "SSH into VM and verify connectivity to GKE") | ||
}) | ||
|
||
bpt.Test() | ||
} |
Oops, something went wrong.