From 45e006328307287e1e47600b6fda9d0825b4b648 Mon Sep 17 00:00:00 2001 From: Andriy Kopachevskyy Date: Mon, 18 Nov 2019 17:29:03 +0200 Subject: [PATCH] * Fix #93 Added tests for cluster auto scaling --- .kitchen.yml | 7 +++ build/int.cloudbuild.yaml | 20 +++++++ .../simple_regional_beta/controls/gcloud.rb | 57 +++++++++++++++++++ .../simple_regional_beta/inspec.yml | 17 ++++++ 4 files changed, 101 insertions(+) create mode 100644 test/integration/simple_regional_beta/controls/gcloud.rb create mode 100644 test/integration/simple_regional_beta/inspec.yml diff --git a/.kitchen.yml b/.kitchen.yml index 39faa2e1e3..fe003e767d 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -52,6 +52,13 @@ suites: systems: - name: simple_regional backend: local + - name: "simple_regional_beta" + driver: + root_module_directory: test/fixtures/simple_regional_beta + verifier: + systems: + - name: simple_regional_beta + backend: local - name: "simple_regional_with_networking" driver: root_module_directory: test/fixtures/simple_regional_with_networking diff --git a/build/int.cloudbuild.yaml b/build/int.cloudbuild.yaml index 09b5d3eb7e..113244aa10 100644 --- a/build/int.cloudbuild.yaml +++ b/build/int.cloudbuild.yaml @@ -81,6 +81,26 @@ steps: - verify simple-regional-local name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy simple-regional-local'] +- id: create simple-regional-beta-local + waitFor: + - prepare + name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' + args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create simple-regional-beta-local'] +- id: converge simple-regional-beta-local + waitFor: + - create simple-regional-beta-local + name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' + args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge simple-regional-beta-local'] +- id: verify simple-regional-beta-local + waitFor: + - converge simple-regional-beta-local + name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' + args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify simple-regional-beta-local'] +- id: destroy simple-regional-beta-local + waitFor: + - verify simple-regional-beta-local + name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' + args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy simple-regional-beta-local'] - id: create simple-regional-private-local waitFor: - prepare diff --git a/test/integration/simple_regional_beta/controls/gcloud.rb b/test/integration/simple_regional_beta/controls/gcloud.rb new file mode 100644 index 0000000000..3496f32792 --- /dev/null +++ b/test/integration/simple_regional_beta/controls/gcloud.rb @@ -0,0 +1,57 @@ +# Copyright 2019 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 +# +# https://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. + +project_id = attribute('project_id') +location = attribute('location') +cluster_name = attribute('cluster_name') + +control "gcloud" do + title "Google Compute Engine GKE cluster autoscaling configuration" + describe command("gcloud --project=#{project_id} container clusters --zone=#{location} describe #{cluster_name} --format=json") do + its(:exit_status) { should eq 0 } + its(:stderr) { should eq '' } + + let!(:data) do + if subject.exit_status == 0 + JSON.parse(subject.stdout) + else + {} + end + end + + describe "cluster-autoscaling" do + it "has the expected cluster autoscaling settings" do + expect(data['autoscaling']).to eq({ + "autoprovisioningNodePoolDefaults" => { + "oauthScopes" => %w(https://www.googleapis.com/auth/logging.write https://www.googleapis.com/auth/monitoring), + "serviceAccount" => "default" + }, + "enableNodeAutoprovisioning" => true, + "resourceLimits" => [ + { + "maximum" => "20", + "minimum" => "5", + "resourceType" => "cpu" + }, + { + "maximum" => "30", + "minimum" => "10", + "resourceType" => "memory" + } + ] + }) + end + end + end +end diff --git a/test/integration/simple_regional_beta/inspec.yml b/test/integration/simple_regional_beta/inspec.yml new file mode 100644 index 0000000000..e4c36b2028 --- /dev/null +++ b/test/integration/simple_regional_beta/inspec.yml @@ -0,0 +1,17 @@ +name: simple_regional_beta +attributes: + - name: project_id + required: true + type: string + - name: location + required: true + type: string + - name: cluster_name + required: true + type: string + - name: kubernetes_endpoint + required: true + type: string + - name: client_token + required: true + type: string