<commit_before>#!/bin/bash

# Copyright 2018 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.

set -o errexit

source "$(dirname $(readlink -f ${BASH_SOURCE}))/../test/library.sh"

: ${PROJECT_ID:="knative-environments"}
readonly PROJECT_ID
readonly K8S_CLUSTER_NAME=${1:?"First argument must be the kubernetes cluster name."}
readonly K8S_CLUSTER_ZONE=us-central1-a
readonly K8S_CLUSTER_MACHINE=n1-standard-8
readonly K8S_CLUSTER_NODES=5
readonly SERVING_RELEASE=https://storage.googleapis.com/knative-releases/latest/release.yaml
readonly ISTIO_YAML=https://storage.googleapis.com/knative-releases/latest/istio.yaml
readonly PROJECT_USER=$(gcloud config get-value core/account)
readonly CURRENT_PROJECT=$(gcloud config get-value project)

function cleanup() {
  gcloud config set project ${CURRENT_PROJECT}
}

cd ${SERVING_ROOT_DIR}
trap cleanup EXIT

echo "Using project ${PROJECT_ID} and user ${PROJECT_USER}"
gcloud config set project ${PROJECT_ID}

existing_cluster=$(gcloud container clusters list \
    --zone=${K8S_CLUSTER_ZONE} --filter="name=${K8S_CLUSTER_NAME}")
if [[ -n "${existing_cluster}" ]]; then
  header "Deleting previous cluster ${K8S_CLUSTER_NAME} in ${PROJECT_ID}"
  gcloud -q container clusters delete \
    --zone=${K8S_CLUSTER_ZONE} ${K8S_CLUSTER_NAME}
fi

header "Creating cluster ${K8S_CLUSTER_NAME} in ${PROJECT_ID}"
gcloud --project=${PROJECT_ID} container clusters create \
  --cluster-version=${SERVING_GKE_VERSION} \
  --image-type "${SERVING_GKE_IMAGE^^}" \
  --zone=${K8S_CLUSTER_ZONE} \
  --scopes=cloud-platform \
  --machine-type=${K8S_CLUSTER_MACHINE} \
  --enable-autoscaling --min-nodes=1 --max-nodes=${K8S_CLUSTER_NODES} \
  ${K8S_CLUSTER_NAME}

header "Setting cluster admin"
acquire_cluster_admin_role ${PROJECT_USER} ${K8S_CLUSTER_NAME} ${K8S_CLUSTER_ZONE}

header "Installing istio"
kubectl apply -f ${ISTIO_YAML}
wait_until_pods_running istio-system

kubectl label namespace default istio-injection=enabled

header "Installing Knative Serving"
# Install might fail before succeding, so we retry a few times.
# For details, see https://github.com/knative/install/issues/13
installed=0
for i in {1..10}; do
  kubectl apply -f ${SERVING_RELEASE} && installed=1 && break
  sleep 30
done
if (( ! installed )); then
  echo "ERROR: could not install Knative Serving"
  exit 1
fi

wait_until_pods_running knative-serving-system
wait_until_pods_running build-system
<commit_msg>Remove workaround for https://github.com/knative/install/issues/13 (#1201)<commit_after>#!/bin/bash

# Copyright 2018 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.

set -o errexit

source "$(dirname $(readlink -f ${BASH_SOURCE}))/../test/library.sh"

: ${PROJECT_ID:="knative-environments"}
readonly PROJECT_ID
readonly K8S_CLUSTER_NAME=${1:?"First argument must be the kubernetes cluster name."}
readonly K8S_CLUSTER_ZONE=us-central1-a
readonly K8S_CLUSTER_MACHINE=n1-standard-8
readonly K8S_CLUSTER_NODES=5
readonly SERVING_RELEASE=https://storage.googleapis.com/knative-releases/latest/release.yaml
readonly ISTIO_YAML=https://storage.googleapis.com/knative-releases/latest/istio.yaml
readonly PROJECT_USER=$(gcloud config get-value core/account)
readonly CURRENT_PROJECT=$(gcloud config get-value project)

function cleanup() {
  gcloud config set project ${CURRENT_PROJECT}
}

cd ${SERVING_ROOT_DIR}
trap cleanup EXIT

echo "Using project ${PROJECT_ID} and user ${PROJECT_USER}"
gcloud config set project ${PROJECT_ID}

existing_cluster=$(gcloud container clusters list \
    --zone=${K8S_CLUSTER_ZONE} --filter="name=${K8S_CLUSTER_NAME}")
if [[ -n "${existing_cluster}" ]]; then
  header "Deleting previous cluster ${K8S_CLUSTER_NAME} in ${PROJECT_ID}"
  gcloud -q container clusters delete \
    --zone=${K8S_CLUSTER_ZONE} ${K8S_CLUSTER_NAME}
fi

header "Creating cluster ${K8S_CLUSTER_NAME} in ${PROJECT_ID}"
gcloud --project=${PROJECT_ID} container clusters create \
  --cluster-version=${SERVING_GKE_VERSION} \
  --image-type "${SERVING_GKE_IMAGE^^}" \
  --zone=${K8S_CLUSTER_ZONE} \
  --scopes=cloud-platform \
  --machine-type=${K8S_CLUSTER_MACHINE} \
  --enable-autoscaling --min-nodes=1 --max-nodes=${K8S_CLUSTER_NODES} \
  ${K8S_CLUSTER_NAME}

header "Setting cluster admin"
acquire_cluster_admin_role ${PROJECT_USER} ${K8S_CLUSTER_NAME} ${K8S_CLUSTER_ZONE}

header "Installing istio"
kubectl apply -f ${ISTIO_YAML}
wait_until_pods_running istio-system

kubectl label namespace default istio-injection=enabled

header "Installing Knative Serving"
kubectl apply -f ${SERVING_RELEASE}

wait_until_pods_running knative-serving-system
wait_until_pods_running build-system

{'fraction_non_alphanumeric': 0.11226831421006178, 'fraction_numerical': 0.013415710503089144, 'mean_word_length': 5.424036281179139, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2303545', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1882, 'n_words': 503}