|
| 1 | +# Copyright 2019 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 | +# https://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 | + |
| 15 | +project_id = attribute('project_id') |
| 16 | +location = attribute('location') |
| 17 | +cluster_name = attribute('cluster_name') |
| 18 | + |
| 19 | +control "gcloud" do |
| 20 | + title "Google Compute Engine GKE configuration" |
| 21 | + describe command("gcloud --project=#{project_id} container clusters --zone=#{location} describe #{cluster_name} --format=json") do |
| 22 | + its(:exit_status) { should eq 0 } |
| 23 | + its(:stderr) { should eq '' } |
| 24 | + |
| 25 | + let!(:data) do |
| 26 | + if subject.exit_status == 0 |
| 27 | + JSON.parse(subject.stdout) |
| 28 | + else |
| 29 | + {} |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + describe "cluster" do |
| 34 | + it "is running" do |
| 35 | + expect(data['status']).to eq 'RUNNING' |
| 36 | + end |
| 37 | + |
| 38 | + it "is regional" do |
| 39 | + expect(data['location']).to match(/^.*[1-9]$/) |
| 40 | + end |
| 41 | + |
| 42 | + it "uses public nodes and master endpoint" do |
| 43 | + expect(data['privateClusterConfig']['enablePrivateEndpoint']).to eq nil |
| 44 | + expect(data['privateClusterConfig']['enablePrivateNodes']).to eq nil |
| 45 | + end |
| 46 | + |
| 47 | + it "has the expected addon settings" do |
| 48 | + expect(data['addonsConfig']).to include( |
| 49 | + "horizontalPodAutoscaling" => {}, |
| 50 | + "httpLoadBalancing" => {}, |
| 51 | + "kubernetesDashboard" => { |
| 52 | + "disabled" => true, |
| 53 | + }, |
| 54 | + "networkPolicyConfig" => { |
| 55 | + "disabled" => true, |
| 56 | + }, |
| 57 | + ) |
| 58 | + end |
| 59 | + |
| 60 | + it "has gateway api enabled" do |
| 61 | + expect(data['networkConfig']).to include( |
| 62 | + "gatewayApiConfig" => { |
| 63 | + "channel" => "CHANNEL_STANDARD", |
| 64 | + }, |
| 65 | + ) |
| 66 | + end |
| 67 | + |
| 68 | + it "has the expected databaseEncryption config" do |
| 69 | + expect(data['databaseEncryption']).to eq({ |
| 70 | + "state" => 'DECRYPTED', |
| 71 | + }) |
| 72 | + end |
| 73 | + |
| 74 | + it "has the expected shieldedNodes config" do |
| 75 | + expect(data['shieldedNodes']).to eq({ |
| 76 | + "enabled" => true, |
| 77 | + }) |
| 78 | + end |
| 79 | + |
| 80 | + it "has the expected binaryAuthorization config" do |
| 81 | + expect(data['binaryAuthorization']).to eq({ |
| 82 | + "evaluationMode" => "PROJECT_SINGLETON_POLICY_ENFORCE", |
| 83 | + }) |
| 84 | + end |
| 85 | + end |
| 86 | + |
| 87 | + describe "default node pool" do |
| 88 | + let(:default_node_pool) { data['nodePools'].select { |p| p['name'] == "default-pool" }.first } |
| 89 | + |
| 90 | + it "exists" do |
| 91 | + expect(data['nodePools']).to include( |
| 92 | + including( |
| 93 | + "name" => "default-pool", |
| 94 | + ) |
| 95 | + ) |
| 96 | + end |
| 97 | + end |
| 98 | + |
| 99 | + describe "node pool" do |
| 100 | + let(:node_pools) { data['nodePools'].reject { |p| p['name'] == "default-pool" } } |
| 101 | + |
| 102 | + it "has autoscaling enabled" do |
| 103 | + expect(node_pools).to include( |
| 104 | + including( |
| 105 | + "autoscaling" => including( |
| 106 | + "enabled" => true, |
| 107 | + ), |
| 108 | + ) |
| 109 | + ) |
| 110 | + end |
| 111 | + |
| 112 | + it "has the expected minimum node count" do |
| 113 | + expect(node_pools).to include( |
| 114 | + including( |
| 115 | + "autoscaling" => including( |
| 116 | + "minNodeCount" => 1, |
| 117 | + ), |
| 118 | + ) |
| 119 | + ) |
| 120 | + end |
| 121 | + |
| 122 | + it "has the expected maximum node count" do |
| 123 | + expect(node_pools).to include( |
| 124 | + including( |
| 125 | + "autoscaling" => including( |
| 126 | + "maxNodeCount" => 100, |
| 127 | + ), |
| 128 | + ) |
| 129 | + ) |
| 130 | + end |
| 131 | + |
| 132 | + it "is the expected machine type" do |
| 133 | + expect(node_pools).to include( |
| 134 | + including( |
| 135 | + "config" => including( |
| 136 | + "machineType" => "e2-medium", |
| 137 | + ), |
| 138 | + ) |
| 139 | + ) |
| 140 | + end |
| 141 | + |
| 142 | + it "has the expected disk size" do |
| 143 | + expect(node_pools).to include( |
| 144 | + including( |
| 145 | + "config" => including( |
| 146 | + "diskSizeGb" => 100, |
| 147 | + ), |
| 148 | + ) |
| 149 | + ) |
| 150 | + end |
| 151 | + |
| 152 | + it "has the expected labels" do |
| 153 | + expect(node_pools).to include( |
| 154 | + including( |
| 155 | + "config" => including( |
| 156 | + "labels" => including( |
| 157 | + "cluster_name" => cluster_name, |
| 158 | + "node_pool" => "default-node-pool", |
| 159 | + ), |
| 160 | + ), |
| 161 | + ) |
| 162 | + ) |
| 163 | + end |
| 164 | + |
| 165 | + it "has the expected network tags" do |
| 166 | + expect(node_pools).to include( |
| 167 | + including( |
| 168 | + "config" => including( |
| 169 | + "tags" => match_array([ |
| 170 | + "gke-#{cluster_name}", |
| 171 | + "gke-#{cluster_name}-default-node-pool", |
| 172 | + ]), |
| 173 | + ), |
| 174 | + ) |
| 175 | + ) |
| 176 | + end |
| 177 | + |
| 178 | + it "has autorepair enabled" do |
| 179 | + expect(node_pools).to include( |
| 180 | + including( |
| 181 | + "management" => including( |
| 182 | + "autoRepair" => true, |
| 183 | + ), |
| 184 | + ) |
| 185 | + ) |
| 186 | + end |
| 187 | + |
| 188 | + it "has autoupgrade enabled" do |
| 189 | + expect(node_pools).to include( |
| 190 | + including( |
| 191 | + "management" => including( |
| 192 | + "autoUpgrade" => true, |
| 193 | + ), |
| 194 | + ) |
| 195 | + ) |
| 196 | + end |
| 197 | + end |
| 198 | + end |
| 199 | +end |
0 commit comments