diff --git a/prow/cmd/mkpod/.gitignore b/config/.gitignore similarity index 100% rename from prow/cmd/mkpod/.gitignore rename to config/.gitignore diff --git a/config/pj-on-kind.sh b/config/pj-on-kind.sh new file mode 100755 index 000000000000..4ae7d386769e --- /dev/null +++ b/config/pj-on-kind.sh @@ -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) "$@" diff --git a/prow/.gitignore b/prow/.gitignore index 65432e28287c..b337dab20864 100644 --- a/prow/.gitignore +++ b/prow/.gitignore @@ -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 diff --git a/prow/cmd/mkpod/local-kind-config.yaml b/prow/cmd/mkpod/local-kind-config.yaml deleted file mode 100644 index e57f07d60a8c..000000000000 --- a/prow/cmd/mkpod/local-kind-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# Example kind config for getting output on the machine running kind instead of the contain 'node'. -kind: Cluster -apiVersion: kind.sigs.k8s.io/v1alpha3 -nodes: - - extraMounts: - - containerPath: /output - hostPath: /tmp/prowjob-out diff --git a/prow/cmd/mkpod/local-kind.sh b/prow/cmd/mkpod/local-kind.sh deleted file mode 100755 index 64b9a47d6f45..000000000000 --- a/prow/cmd/mkpod/local-kind.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/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. - -set -o errexit -set -o nounset -set -o pipefail - -job=${1:-pull-test-infra-yamllint} -config=${CONFIG_PATH:-$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../../config.yaml)} -job_config=${JOB_CONFIG_PATH-$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../../../config/jobs)} - -echo job=${job} -echo config=${config} -echo job_config=${job_config} - -if [[ -n ${job_config} ]] -then - job_config="--job-config-path=${job_config}" -fi - -found="false" -for clust in $(kind get clusters) -do - if [[ ${clust} == "mkpod" ]] - then - found="true" - fi -done - -if [[ ${found} == "false" ]] -then - kind create cluster --name=mkpod --config=local-kind-config.yaml --wait=5m -fi -export KUBECONFIG="$(kind get kubeconfig-path --name="mkpod")" - -bazel run //prow/cmd/mkpj -- --config-path=${config} ${job_config} --job=${job} > ${PWD}/pj.yaml -bazel run //prow/cmd/mkpod -- --build-id=snowflake --prow-job=${PWD}/pj.yaml --local --out-dir=/output/${job} > ${PWD}/pod.yaml - -pod=$(kubectl apply -f ${PWD}/pod.yaml | cut -d ' ' -f 1) -kubectl get ${pod} -w diff --git a/prow/pj-on-kind.sh b/prow/pj-on-kind.sh new file mode 100755 index 000000000000..9e998847a546 --- /dev/null +++ b/prow/pj-on-kind.sh @@ -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 < "${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 "$@" \ No newline at end of file