Rename gke-serverless to gke and add test for fast gke stage

This commit is contained in:
Julio Castillo 2022-09-12 09:56:25 +02:00
parent d817bc5700
commit 72da12e377
14 changed files with 103 additions and 8 deletions

View File

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 43 KiB

View File

@ -17,7 +17,7 @@
# tfdoc:file:description GKE multitenant for development environment.
module "gke-multitenant" {
source = "../../../../blueprints/gke-serverless/multitenant-fleet"
source = "../../../../blueprints/gke/multitenant-fleet"
billing_account_id = var.billing_account.id
folder_id = var.folder_ids.gke-dev
project_id = "gke-clusters-0"

View File

@ -11,7 +11,6 @@
# 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.
"Shared fixtures"
import inspect
@ -21,28 +20,39 @@ import types
import pytest
import tftest
BASEDIR = os.path.dirname(os.path.dirname(__file__))
@pytest.fixture(scope='session')
def fast_e2e_plan_runner(_plan_runner):
"Plan runner for end-to-end root module, returns modules and resources."
def run_plan(fixture_path=None, targets=None, refresh=True,
include_bare_resources=False, compute_sums=True, **tf_vars):
"Runs Terraform plan on a root module using defaults, returns data."
plan = _plan_runner(fixture_path, targets=targets, refresh=refresh,
**tf_vars)
root_module = plan.root_module['child_modules'][0]
modules = {
m['address'].removeprefix(root_module['address'])[1:]: m['resources']
for m in root_module['child_modules']
}
# Count all modules and resources up to 2 levels deep. We include
# the second level to account for wrapper modules used by stages 3
modules = {}
for m in root_module['child_modules']:
key = m['address'].removeprefix(root_module['address'])[1:]
modules[key] = m.get('resources', [])
if m.get('child_modules'):
for m2 in m['child_modules']:
key2 = m2['address'].removeprefix(root_module['address'])[1:]
modules[key2] = m2.get('resources', [])
resources = [r for m in modules.values() for r in m]
if include_bare_resources:
bare_resources = root_module['resources']
resources.extend(bare_resources)
if compute_sums:
return len(modules), len(resources), {k: len(v) for k, v in modules.items()}
return len(modules), len(resources), {
k: len(v) for k, v in modules.items()
}
return modules, resources
return run_plan

View File

@ -0,0 +1,65 @@
/**
* Copyright 2022 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.
*/
# tfdoc: Data platform stage test
module "stage" {
source = "../../../../../fast/stages/03-gke-multitenant/dev/"
automation = {
outputs_bucket = "test"
}
billing_account = {
id = "012345-67890A-BCDEF0",
organization_id = 123456
}
clusters = {
mycluster = {
cluster_autoscaling = null
description = "My cluster"
dns_domain = null
location = "europe-west1"
labels = {}
net = {
master_range = "172.17.16.0/28"
pods = "pods"
services = "services"
subnet = "projects/my-host-project-id/regions/europe-west1/subnetworks/mycluster-subnet"
}
overrides = null
}
}
nodepools = {
mycluster = {
mynodepool = {
initial_node_count = 1
node_count = 1
node_type = "n2-standard-4"
overrides = null
spot = false
}
}
}
folder_ids = {
gke-dev = "folders/12345678"
}
host_project_ids = {
dev-spoke-0 = "fast-dev-net-spoke-0"
}
prefix = "fast"
vpc_self_links = {
dev-spoke-0 = "projects/fast-dev-net-spoke-0/global/networks/dev-spoke-0"
}
}

View File

@ -0,0 +1,20 @@
# Copyright 2022 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.
def test_counts(fast_e2e_plan_runner):
"Test stage."
num_modules, num_resources, _ = fast_e2e_plan_runner()
# TODO: to re-enable per-module resource count check print _, then test
assert num_modules > 0 and num_resources > 0