github.com/GoogleCloudPlatform/testgrid@v0.0.174/cluster/setup-pubsub.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2021 The TestGrid Authors. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 17 set -o nounset 18 set -o errexit 19 20 goog_buckets=( 21 gs://oss-prow 22 gs://istio-prow 23 ) 24 25 goog_topic=projects/k8s-testgrid/topics/prow-updates 26 27 k8s_topic=projects/kubernetes-jenkins/topics/prow-updates 28 29 k8s_buckets=( 30 gs://kubernetes-jenkins 31 ) 32 33 dir=$(dirname "$0") 34 list=$dir/list-gcs-prefixes.sh 35 create_topic=$dir/create-topic.sh 36 create_sub=$dir/create-subscription.sh 37 38 39 log() { 40 ( 41 set -o xtrace 42 "$@" 43 ) 44 } 45 46 apply-subscription() { 47 topic=$1 48 project=$2 49 sub=$3 50 canary=$4 51 # Prod 52 log "$create_sub" -t "$topic" \ 53 -b serviceAccount:updater@k8s-testgrid.iam.gserviceaccount.com \ 54 -p "$project" "$sub" 55 # Canary 56 log "$create_sub" -t "$topic" \ 57 -b serviceAccount:testgrid-canary@k8s-testgrid.iam.gserviceaccount.com \ 58 -p "$project" "$canary" 59 } 60 61 apply-topic() { 62 topic=$1 63 shift 64 buckets=("$@") 65 log "$create_topic" -t "$topic" -p logs/ -p pr-logs/ "${buckets[@]}" 66 } 67 68 do-list() { 69 "$list" gs://k8s-testgrid-canary/config 70 echo "NOTICE: edit this file ($(basename "$0")) to add any additional paths" >&2 71 } 72 73 something= 74 while getopts "lst" flag; do 75 case "$flag" in 76 s) 77 apply-subscription "$goog_topic" k8s-testgrid testgrid testgrid-canary 78 apply-subscription "$k8s_topic" kubernetes-jenkins testgrid testgrid-canary 79 something=yes 80 ;; 81 t) 82 apply-topic "$goog_topic" "${goog_buckets[@]}" 83 apply-topic "$k8s_topic" "${k8s_buckets[@]}" 84 something=yes 85 ;; 86 l) 87 do-list 88 something=yes 89 ;; 90 esac 91 done 92 93 if [[ -z "$something" ]]; then 94 echo "Usage: $(basename "$0") [-u] [-s] [-l]" >&2 95 echo >&2 96 echo " -l: list buckets in use" >&2 97 echo " -t: configure topics for ${buckets[@]}" >&2 98 echo " -s: configure subscriptions" >&2 99 exit 1 100 fi