Skip to content

Commit

Permalink
Add GKE as a provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbforbes committed Dec 19, 2014
1 parent 5807b3d commit c3efef8
Show file tree
Hide file tree
Showing 11 changed files with 415 additions and 43 deletions.
37 changes: 14 additions & 23 deletions cluster/gce/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function detect-project () {
echo "'gcloud config set project <PROJECT>'" >&2
exit 1
fi
echo "Project: $PROJECT (autodetected from gcloud config)"
echo "Project: $PROJECT" >&2
}


Expand Down Expand Up @@ -139,11 +139,9 @@ function upload-server-tars() {
# MINION_NAMES
# ZONE
# Vars set:
# KUBE_MINION_IP_ADDRESS (array)
# KUBE_MINION_IP_ADDRESSES (array)
function detect-minions () {
if [[ -z "${PROJECT-}" ]]; then
detect-project
fi
detect-project
KUBE_MINION_IP_ADDRESSES=()
for (( i=0; i<${#MINION_NAMES[@]}; i++)); do
local minion_ip=$(gcloud compute instances describe --project "${PROJECT}" --zone "${ZONE}" \
Expand All @@ -166,15 +164,12 @@ function detect-minions () {
#
# Assumed vars:
# MASTER_NAME
# PROJECT (if unset, will detect-project)
# ZONE
# Vars set:
# KUBE_MASTER
# KUBE_MASTER_IP
function detect-master () {
if [[ -z "${PROJECT-}" ]]; then
detect-project
fi
detect-project
KUBE_MASTER=${MASTER_NAME}
if [[ -z "${KUBE_MASTER_IP-}" ]]; then
KUBE_MASTER_IP=$(gcloud compute instances describe --project "${PROJECT}" --zone "${ZONE}" \
Expand Down Expand Up @@ -251,14 +246,15 @@ function wait-for-jobs {
# $2: IP ranges.
# $3: Target tags for this firewall rule.
function create-firewall-rule {
detect-project
local attempt=0
while true; do
if ! gcloud compute firewall-rules create "$1" \
--project "${PROJECT}" \
--network "${NETWORK}" \
--source-ranges "$2" \
--target-tags "$3" \
--allow tcp udp icmp esp ah sctp; then
--allow tcp udp icmp esp ah sctp; then
if (( attempt > 5 )); then
echo -e "${color_red}Failed to create firewall rule $1 ${color_norm}"
exit 2
Expand All @@ -275,6 +271,7 @@ function create-firewall-rule {
# $1: The name of the route.
# $2: IP range.
function create-route {
detect-project
local attempt=0
while true; do
if ! gcloud compute routes create "$1" \
Expand All @@ -300,6 +297,7 @@ function create-route {
# $2: The scopes flag.
# $3: The minion start script.
function create-instance {
detect-project
local attempt=0
while true; do
if ! gcloud compute instances create "$1" \
Expand Down Expand Up @@ -334,7 +332,6 @@ function create-instance {
# KUBE_ROOT
# <Various vars set in config file>
function kube-up {
# Detect the project into $PROJECT if it isn't set
detect-project

# Make sure we have the tar files staged on Google Storage
Expand Down Expand Up @@ -570,18 +567,16 @@ EOF

}

# Delete a kubernetes cluster.
# Delete a kubernetes cluster. This is called from test-teardown.
#
# Assumed vars:
# MASTER_NAME
# INSTANCE_PREFIX
# ZONE
# PROJECT
# This function tears down cluster resources 10 at a time to avoid issuing too many
# API calls and exceeding API quota. It is important to bring down the instances before bringing
# down the firewall rules and routes.
function kube-down {
# Detect the project into $PROJECT
detect-project

echo "Bringing down cluster"
Expand Down Expand Up @@ -685,15 +680,12 @@ function test-build-release {
}

# Execute prior to running tests to initialize required structure. This is
# called from hack/e2e-test.sh.
# called from hack/e2e.go only when running -up (it is run after kube-up).
#
# Assumed vars:
# PROJECT
# Variables from config.sh
function test-setup {

# Detect the project into $PROJECT if it isn't set
# gce specific
detect-project

# Open up port 80 & 8080 so common containers on minions can be reached
Expand All @@ -705,12 +697,10 @@ function test-setup {
"${MINION_TAG}-${INSTANCE_PREFIX}-http-alt"
}

# Execute after running tests to perform any required clean-up. This is called
# from hack/e2e-test.sh
#
# Assumed Vars:
# PROJECT
# Execute after running tests to perform any required clean-up. This is called
# from hack/e2e.go
function test-teardown {
detect-project
echo "Shutting down test cluster in background."
gcloud compute firewall-rules delete \
--project "${PROJECT}" \
Expand All @@ -735,6 +725,7 @@ function restart-kube-proxy {
function setup-monitoring {
if [[ "${ENABLE_CLUSTER_MONITORING}" == "true" ]]; then
echo "Setting up cluster monitoring using Heapster."

detect-project
if ! gcloud compute firewall-rules describe monitoring-heapster &>/dev/null; then
if ! gcloud compute firewall-rules create monitoring-heapster \
Expand Down
34 changes: 34 additions & 0 deletions cluster/gke/config-common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Copyright 2014 Google Inc. All rights reserved.
#
# 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.

# This script should be sourced as a part of config-test or config-default.
# Specifically, the following environment variables are assumed:
# - CLUSTER_NAME (the name of the cluster)

MASTER_NAME="k8s-${CLUSTER_NAME}-master"
ZONE="${ZONE:-us-central1-f}"
NUM_MINIONS="${NUM_MINIONS:-2}"
CLUSTER_API_VERSION="${CLUSTER_API_VERSION:-}"
# TODO(mbforbes): Actually plumb this through; this currently only works
# because we use the 'default' network by default.
NETWORK="${NETWORK:-default}"
GCLOUD="${GCLOUD:-gcloud}"
GCLOUD_CONFIG_DIR="${GCLOUD_CONFIG_DIR:-${HOME}/.config/gcloud/kubernetes}"

# This is a hack, but I keep setting this when I run commands manually, and
# then things grossly fail during normal runs because cluster/kubecfg.sh and
# cluster/kubectl.sh both use this if it's set.
unset KUBERNETES_MASTER
22 changes: 22 additions & 0 deletions cluster/gke/config-default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Copyright 2014 Google Inc. All rights reserved.
#
# 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.

# The following are default-specific settings.
CLUSTER_NAME="${CLUSTER_NAME:-${USER}-gke}"

# For ease of maintenance, extract any pieces that do not vary between default
# and test in a common config.
source $(dirname "${BASH_SOURCE}")/config-common.sh
22 changes: 22 additions & 0 deletions cluster/gke/config-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Copyright 2014 Google Inc. All rights reserved.
#
# 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.

# The following are test-specific settings.
CLUSTER_NAME="${CLUSTER_NAME:-${USER}-gke-e2e}"

# For ease of maintenance, extract any pieces that do not vary between default
# and test in a common config.
source $(dirname "${BASH_SOURCE}")/config-common.sh
Loading

0 comments on commit c3efef8

Please sign in to comment.