Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a 'local' pod mode to the pod-utils and mkpod to generate decorated pods suitable for local testing. #13561

Merged
merged 4 commits into from
Jul 30, 2019

Conversation

cjwagner
Copy link
Member

@cjwagner cjwagner commented Jul 23, 2019

This PR is broken into 3 commits:

  • Allow mkpod to autogenerate buildID when 'snowflake' is specified.
  • Add local output mode to pod utilities.
    • In this mode the pod utilities don't require or mount a GCS secret and don't upload to GCS. Instead a hostPath output volume is mounted and files that would have been uploaded to GCS are copied there.
  • Add support for local pods to mkpod and include a script for running local pods with kind.
    • When mkpod is run with --local it configures the pod utilities to output locally and prompts for each volume that is not a hostPath or emptyDir to be replaced by an emptyDir, hostPath, or kept the same (this assumes the volume will be available in the cluster where the pod will run).
    • The included local-kind.sh script is a simple wrapper around mkpj, mkpod, and kind. It creates a kind cluster named mkpod if one doesn't exist and uses mkpj and mkpod to create a pod that is then applied to the kind cluster and watched.
      • I'm not set on this being a bash script, but I wrote it this way initially, because it makes it easy to modify for different workflows (e.g. any k8s resources the job depends on could be added to the script). I'm happy to change this.

Example usage after installing docker and kind:

./local-kind.sh pull-test-infra-verify-file-perms

Testing a job from a different Prow instance in a different repo (istio/test-infra):

CONFIG_PATH=$GOPATH/src/istio.io/test-infra/prow/config.yaml JOB_CONFIG_PATH=$GOPATH/src/istio.io/test-infra/prow/cluster/jobs ./local-kind.sh pull-test-infra-prow-checkconfig

I still need to add tests and documention, but I wanted to get some feedback on the direction first.
/assign @stevekuznetsov @fejta
fixes #13475

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 23, 2019
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. area/prow Issues or PRs related to prow area/prow/gcsupload Issues or PRs related to prow's gcsupload component area/prow/knative-build Issues or PRs related to prow's knative-build controller component area/prow/mkpod Issues or PRs related to prow's mkpod component area/prow/pod-utilities Issues or PRs related to prow's pod-utilities component sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Jul 23, 2019
prow/cmd/mkpod/local-kind-config.yaml Outdated Show resolved Hide resolved
prow/cmd/mkpod/local-kind.sh Outdated Show resolved Hide resolved
echo config=${config}
echo job_config=${job_config}

if [[ -n ${job_config} ]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you enforce that this is set above with :- so no need to check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used - not :- so I think the check is necessary.
Allowing JOB_CONFIG_PATH="" is necessary to override the default if you are using this script with a different Prow instance that doesn't have separate job config.

This seems like gross UX to me though. I'm open to suggestions.

prow/cmd/mkpod/main.go Show resolved Hide resolved
prow/gcsupload/options.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added area/config Issues or PRs related to code in /config size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 26, 2019
@cjwagner
Copy link
Member Author

Changed to having a general script and a prow.k8s.io specific one that defaults the config locations. We can create similar scripts for other prow instances.
PTAL.


export CONFIG_PATH="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../prow/config.yaml)"
export JOB_CONFIG_PATH="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/jobs)"
bash <(curl -s https://raw.githubusercontent.com/cjwagner/test-infra/local-pod-go/prow/pj-on-kind.sh) "$@"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cjwagner?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was pointed at my fork for testing. Fixed.


export CONFIG_PATH="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../prow/config.yaml)"
export JOB_CONFIG_PATH="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/jobs)"
bash <(curl -s https://raw.githubusercontent.com/kubernetes/test-infra/master/prow/pj-on-kind.sh) "$@"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a curl instead of relative path?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With curl, this script can be copied into any other repo with Prow config (e.g. istio/test-infra) and the only change needed to make everything work is to adjust the config envvars accordingly. Then, jobs for that Prow instance can be run with ./pj-on-kind.sh my-istio-job. Fetching the k/t-i/prow/pj-on-kind.sh file each time ensures that the latest version is always used.

In this case a relative path is equivalent, but I want a copy-pasteable example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to use a relative path, but left the commented out the curl version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to just package it in a container image for re-use

prow/cmd/mkpod/local-kind-config.yaml Outdated Show resolved Hide resolved
prow/cmd/mkpod/main.go Show resolved Hide resolved
job="${1:-""}"
config="${CONFIG_PATH:-""}"
job_config="${JOB_CONFIG_PATH:-""}"
out_dir="${OUT_DIR:-/tmp/prowjob-out}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if you're going to quote the empty strings for defaults above you might as well quote this default, too :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

echo JOB_CONFIG_PATH=${job_config}
echo OUT_DIR=${out_dir} "(May be different when reusing an existing kind cluster.)"

if [[ -z ${job} ]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quote your expansions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got them all.

out_dir="${OUT_DIR:-/tmp/prowjob-out}"

echo job=${job}
echo CONFIG_PATH=${config}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quote strings with embedded expansions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

fi

# Install kind and set up cluster if not already done.
if [[ -z $(which kind) ]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which will output something like /usr/bin/which: no kind in (${PATH}) on failure so this does not do what you want.

use:

if ! which kind >/dev/null 2>&1; then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and i think there was some weirdness with macos on this one, so you might have to use command -v

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to command -v based on this SO post: https://stackoverflow.com/a/677212

found="true"
fi
done
if [[ ${found} == "false" ]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could just inline this into the if where you find the match instead of doing it after the loop`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only want to do this if we don't find a match though.

fi
export KUBECONFIG="$(kind get kubeconfig-path --name="mkpod")"

# Install mkpj and mkpod if not already done.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe prefer running the published containers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to avoid the volume mounting and figured this workflow makes it easier to tweak mkpj and mkpod when needed.
I'll add a docker mode in a follow up and we can even make that the default if that seems preferable, but this mode is easier to start with while I'm developing.

@stevekuznetsov
Copy link
Contributor

GCSupload/ go code LGTM

Copy link
Member Author

@cjwagner cjwagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ready for review now. I tried to clean up the bash and I moved the LocalOutputDir field into the prowapi.GCSOptions type so that it could be specified in ProwJob config as well.

I'll keep improving this in follow up PRs, but I'd like to get this merged so that you don't have to update the prow config to use my forked versions of the pod utils to use this.

job="${1:-""}"
config="${CONFIG_PATH:-""}"
job_config="${JOB_CONFIG_PATH:-""}"
out_dir="${OUT_DIR:-/tmp/prowjob-out}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

out_dir="${OUT_DIR:-/tmp/prowjob-out}"

echo job=${job}
echo CONFIG_PATH=${config}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

echo JOB_CONFIG_PATH=${job_config}
echo OUT_DIR=${out_dir} "(May be different when reusing an existing kind cluster.)"

if [[ -z ${job} ]]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got them all.

fi

# Install kind and set up cluster if not already done.
if [[ -z $(which kind) ]]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to command -v based on this SO post: https://stackoverflow.com/a/677212

found="true"
fi
done
if [[ ${found} == "false" ]]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only want to do this if we don't find a match though.

fi
export KUBECONFIG="$(kind get kubeconfig-path --name="mkpod")"

# Install mkpj and mkpod if not already done.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to avoid the volume mounting and figured this workflow makes it easier to tweak mkpj and mkpod when needed.
I'll add a docker mode in a follow up and we can even make that the default if that seems preferable, but this mode is easier to start with while I'm developing.

prow/cmd/mkpod/main.go Show resolved Hide resolved
@cjwagner cjwagner marked this pull request as ready for review July 30, 2019 01:06
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 30, 2019
Copy link
Contributor

@stevekuznetsov stevekuznetsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One bash if nit otherwise good

# 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) ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're checking the result of a call just do

if ! command -v mkpj >/dev/null 2>&1; then

No need to test if the output string is or is not empty

Also switches to building mkpj and mkpod with go instead of bazel.
@stevekuznetsov
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 30, 2019
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: f367fcefb3c4bf5f2a3dd4a1b73ff72a1aa3d68b

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cjwagner, stevekuznetsov

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 9330dba into kubernetes:master Jul 30, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.16 milestone Jul 30, 2019
@cjwagner cjwagner deleted the local-pod branch July 31, 2019 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/config Issues or PRs related to code in /config area/prow/gcsupload Issues or PRs related to prow's gcsupload component area/prow/knative-build Issues or PRs related to prow's knative-build controller component area/prow/mkpod Issues or PRs related to prow's mkpod component area/prow/pod-utilities Issues or PRs related to prow's pod-utilities component area/prow Issues or PRs related to prow cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better local testing of decorated ProwJobs using Phaino.
4 participants