github.com/GoogleCloudPlatform/testgrid@v0.0.174/cluster/prod/knative/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  buckets=(
    21      gs://knative-prow
    22  )
    23  
    24  topic=projects/knative-tests/topics/prow-updates
    25  
    26  dir=$(dirname "$0")/../..
    27  list=$dir/list-gcs-prefixes.sh
    28  create_topic=$dir/create-topic.sh
    29  create_sub=$dir/create-subscription.sh
    30  
    31  
    32  log() {
    33      (
    34          set -o xtrace
    35          "$@"
    36      )
    37  }
    38  
    39  apply-subscription() {
    40      topic=$1
    41      project=$2
    42      sub=$3
    43      # Prod
    44      log "$create_sub" -t "$topic" \
    45          -b serviceAccount:testgrid-updater@knative-tests.iam.gserviceaccount.com \
    46          -p "$project" "$sub"
    47  }
    48  
    49  apply-topic() {
    50      topic=$1
    51      shift
    52      buckets=("$@")
    53      log "$create_topic" -t "$topic" -p logs/ "${buckets[@]}"
    54  }
    55  
    56  do-list() {
    57      "$list" gs://knative-own-testgrid/config
    58      echo "NOTICE: edit this file ($(basename "$0")) to add any additional paths" >&2
    59  }
    60  
    61  something=
    62  while getopts "lst" flag; do
    63      case "$flag" in
    64          s)
    65              apply-subscription "$topic" knative-tests testgrid
    66              something=yes
    67              ;;
    68          t)
    69              apply-topic "$topic" "${buckets[@]}"
    70              something=yes
    71              ;;
    72          l)
    73              do-list
    74              something=yes
    75              ;;
    76      esac
    77  done
    78  
    79  if [[ -z "$something" ]]; then
    80      echo "Usage: $(basename "$0") [-u] [-s] [-l]" >&2
    81      echo >&2
    82      echo "  -l: list buckets in use" >&2
    83      echo "  -t: configure topics for ${buckets[@]}" >&2
    84      echo "  -s: configure subscriptions" >&2
    85      exit 1
    86  fi