Skip to content

Commit

Permalink
Make general and k8s specific versions of pj-on-kind.sh.
Browse files Browse the repository at this point in the history
Also switches to building mkpj and mkpod with go instead of bazel.
  • Loading branch information
cjwagner committed Jul 30, 2019
1 parent 1a9b974 commit e57d667
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 59 deletions.
File renamed without changes.
27 changes: 27 additions & 0 deletions config/pj-on-kind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# 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.

# Runs prow/pj-on-kind.sh with config arguments specific to the prow.k8s.io instance.

set -o errexit
set -o nounset
set -o pipefail

export CONFIG_PATH="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../prow/config.yaml)"
export JOB_CONFIG_PATH="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/jobs)"

../prow/pj-on-kind.sh "$@"
# Swap the above command for the following one for use outside kubernetes/test-infra.
# bash <(curl -s https://raw.githubusercontent.com/kubernetes/test-infra/master/prow/pj-on-kind.sh) "$@"
2 changes: 2 additions & 0 deletions prow/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ cmd/tot/tot
external-plugins/cherrypicker/cherrypicker
external-plugins/needs-rebase/needs-rebase
external-plugins/refresh/refresh
pj.yaml
pod.yaml
7 changes: 0 additions & 7 deletions prow/cmd/mkpod/local-kind-config.yaml

This file was deleted.

52 changes: 0 additions & 52 deletions prow/cmd/mkpod/local-kind.sh

This file was deleted.

107 changes: 107 additions & 0 deletions prow/pj-on-kind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# 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.

# Requires go, docker, and kubectl.

set -o errexit
set -o nounset
set -o pipefail

function main() {
parseArgs "$@"
ensureInstall

# Generate PJ and Pod.
mkpj "--config-path=${config}" "${job_config}" "--job=${job}" > "${PWD}/pj.yaml"
mkpod --build-id=snowflake "--prow-job=${PWD}/pj.yaml" --local "--out-dir=/output/${job}" > "${PWD}/pod.yaml"

# Deploy pod and watch.
pod=$(kubectl apply -f "${PWD}/pod.yaml" | cut -d ' ' -f 1)
kubectl get "${pod}" -w
}

# Prep and check args.
function parseArgs() {
job="${1:-""}"
config="${CONFIG_PATH:-""}"
job_config="${JOB_CONFIG_PATH:-""}"
out_dir="${OUT_DIR:-"/tmp/prowjob-out"}"
kind_config="${KIND_CONFIG:-""}"

local new_only=" (Only used when creating a new kind cluster.)"
echo "job=${job}"
echo "CONFIG_PATH=${config}"
echo "JOB_CONFIG_PATH=${job_config}"
echo "OUT_DIR=${out_dir} ${new_only}"
echo "KIND_CONFIG=${kind_config} ${new_only}"

if [[ -z "${job}" ]]; then
echo "Must specify a job name as the first argument."
exit 2
fi
if [[ -z "${config}" ]]; then
echo "Must specify config.yaml location via CONFIG_PATH env var."
exit 2
fi
if [[ -n "${job_config}" ]]; then
job_config="--job-config-path=${job_config}"
fi
}

# Ensures installation of prow tools, kind, and a kind cluster named "mkpod".
function ensureInstall() {
# Install mkpj and mkpod if not already done.
if ! command -v mkpj >/dev/null 2>&1; then
go get k8s.io/test-infra/prow/cmd/mkpj
fi
if ! command -v mkpod >/dev/null 2>&1; then
go get k8s.io/test-infra/prow/cmd/mkpod
fi

# Install kind and set up cluster if not already done.
if ! command -v kind >/dev/null 2>&1; then
GO111MODULE="on" go get sigs.k8s.io/kind@v0.4.0 && kind create cluster
fi
local found="false"
for clust in $(kind get clusters); do
if [[ "${clust}" == "mkpod" ]]; then
found="true"
break
fi
done
if [[ "${found}" == "false" ]]; then
# Need to create the "mkpod" kind cluster.
if [[ -n "${kind_config}" ]]; then
kind create cluster --name=mkpod "--config=${kind_config}" --wait=5m
else
# Create a temporary kind config file.
local temp_config="${PWD}/temp-mkpod-kind-config.yaml"
cat <<EOF > "${temp_config}"
kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
nodes:
- extraMounts:
- containerPath: /output
hostPath: ${out_dir}
EOF
kind create cluster --name=mkpod "--config=${temp_config}" --wait=5m
rm "${temp_config}"
fi
fi
# Point kubectl at the mkpod cluster.
export KUBECONFIG="$(kind get kubeconfig-path --name="mkpod")"
}

main "$@"

0 comments on commit e57d667

Please sign in to comment.