|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2021 The Kubernetes Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# Deploys this app to the aaa cluster, or whatever cluster is pointed to |
| 18 | +# by KUBECTL_CONTEXT if set. Assumes the app's namespace already exists. |
| 19 | +# |
| 20 | +# Members of k8s-infra-rbac-${app}@kubernetes.io can run this. |
| 21 | + |
| 22 | +set -o errexit |
| 23 | +set -o nounset |
| 24 | +set -o pipefail |
| 25 | + |
| 26 | +SCRIPT_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) |
| 27 | + |
| 28 | +app=$(basename "${SCRIPT_ROOT}") |
| 29 | + |
| 30 | +# coordinates to locate the target cluster in gke |
| 31 | +cluster_name="aaa" |
| 32 | +cluster_project="kubernetes-public" |
| 33 | +cluster_region="us-central1" |
| 34 | + |
| 35 | +# coordinates to locate the app on the target cluster |
| 36 | +namespace="${app}" |
| 37 | + |
| 38 | +# custom var(s) specific to this apps deployment |
| 39 | +perfdash_repo_url="https://raw.githubusercontent.com/kubernetes/perf-tests/master/perfdash" |
| 40 | + |
| 41 | +# well known name set by `gcloud container clusters get-credentials` |
| 42 | +gke_context="gke_${cluster_project}_${cluster_region}_${cluster_name}" |
| 43 | +context="${KUBECTL_CONTEXT:-${gke_context}}" |
| 44 | + |
| 45 | +# ensure we have a context to talk to the target cluster |
| 46 | +if ! kubectl config get-contexts "${context}" >/dev/null 2>&1; then |
| 47 | + gcloud container clusters get-credentials "${cluster_name}" --project="${cluster_project}" --region="${cluster_region}" |
| 48 | + context="${gke_context}" |
| 49 | +fi |
| 50 | + |
| 51 | +# deploy kubernetes resources |
| 52 | +pushd "${SCRIPT_ROOT}" >/dev/null |
| 53 | +kubectl --context="${context}" --namespace="${namespace}" apply -f "${perfdash_repo_url}/deployment.yaml" |
| 54 | +kubectl --context="${context}" --namespace="${namespace}" apply -f "${perfdash_repo_url}/perfdash-service.yaml" |
| 55 | +kubectl --context="${context}" --namespace="${namespace}" apply -f . |
0 commit comments