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

Improvements and docs for pj-on-kind.sh. #14355

Merged
merged 1 commit into from
Sep 17, 2019

Conversation

cjwagner
Copy link
Member

@k8s-ci-robot k8s-ci-robot added 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. 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 Issues or PRs related to prow 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 Sep 17, 2019
@cjwagner cjwagner force-pushed the pj-on-kind branch 2 times, most recently from 220c867 to cc7b95e Compare September 17, 2019 02:34

../prow/pj-on-kind.sh "$@"
$(dirname "${BASH_SOURCE[0]}")/../prow/pj-on-kind.sh "$@"
Copy link
Contributor

@clarketm clarketm Sep 17, 2019

Choose a reason for hiding this comment

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

Looks good! To promote readability you could tweak to something like:

dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"

export CONFIG_PATH="$dir/../prow/config.yaml"
export JOB_CONFIG_PATH="$dir/jobs"

"$dir/../prow/pj-on-kind.sh" "$@"

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 17, 2019
Copy link
Contributor

@clarketm clarketm left a comment

Choose a reason for hiding this comment

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

Documentation and code looks good! I made one suggestion that you can choose to take. Unhold at your leisure.
/lgtm
/hold

@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: daff4f9f6bca3b87ba5ae2e025b46f8d8ef83abe

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 17, 2019
export CONFIG_PATH="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../prow/config.yaml)"
export JOB_CONFIG_PATH="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/jobs)"
export CONFIG_PATH="$(realpath $(dirname "${BASH_SOURCE[0]}")/../prow/config.yaml)"
export JOB_CONFIG_PATH="$(realpath $(dirname "${BASH_SOURCE[0]}")/jobs)"
Copy link
Member

Choose a reason for hiding this comment

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

realpath is not natively installed on mac FWIW.

instead this is more portable:

Suggested change
export JOB_CONFIG_PATH="$(realpath $(dirname "${BASH_SOURCE[0]}")/jobs)"
export JOB_CONFIG_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)/jobs"

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I'm surprised there isn't a portable command to canonicalize paths.

Copy link
Member

@BenTheElder BenTheElder Sep 17, 2019

Choose a reason for hiding this comment

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

Yeah, cd "${path}" && pwd -P is pretty much the only method doable on POSIX, unless you write your own binary against the C stdlib.

Copy link
Member

Choose a reason for hiding this comment

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

pwd -P (-P == "physical" will follow symlinks for the current working directory and is in all POSIX versions IIRC. -L == logical will not)

@@ -77,7 +82,7 @@ function ensureInstall() {
# Install kind and set up cluster if not already done.
if ! command -v kind >/dev/null 2>&1; then
echo "Installing kind..."
GO111MODULE="on" go get sigs.k8s.io/kind@v0.4.0
GO111MODULE="on" go get sigs.k8s.io/kind@v0.5.0
Copy link
Member

Choose a reason for hiding this comment

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

v0.5.1 has minor fixes (windows mainly but...) and is otherwise compatible

job_config="${JOB_CONFIG_PATH:-}"
out_dir="${OUT_DIR:-/etc/prowjob-out/${job}}"
kind_config="${KIND_CONFIG:-}"
node_dir="${NODE_DIR:-/etc/kind-node}" # Any pod hostPath mounts should be under this dir to reach the true host via the kind node.
Copy link
Member

Choose a reason for hiding this comment

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

nit: this is sort of a mis-use of /etc, this should probably under /var/, /run or /mnt?
https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
./shrug

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 was going off of https://cloud.google.com/container-optimized-os/docs/concepts/disks-and-filesystem

Looks like I can use /mnt/disks/kind-node instead. Should I change /etc/prowjob-out to /mnt/disks/prowjob-out as well?

Copy link
Member

Choose a reason for hiding this comment

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

So inside the kind node you should be able to do any path, I would do one of the listed ones or invent your own /prow just because these are fairly standardized.

On the host machine I'd think you'd write to something in Home owned by the user. /etc is for system config.

Why is this running on COS directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why is this running on COS directly?

I want the generated pod.yaml files to be suitable for use in a real cluster in addition to the kind cluster. I tried to use a path like /prow, but COS doesn't allow that.

@@ -25,29 +25,34 @@ function main() {

# 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"
mkpod --build-id=snowflake "--prow-job=${PWD}/pj.yaml" --local "--out-dir=${out_dir}" > "${PWD}/pod.yaml"
Copy link
Member

Choose a reason for hiding this comment

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

might be better to write to a tempdir instead of PWD?

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 a tempdir initially, but I switched to using PWD so that the pj.yaml and pod.yaml can be easily inspected and modified. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm yeah. I tend to avoid writing to PWD in tools but...

You could also tee them to the shell?

Copy link
Member Author

Choose a reason for hiding this comment

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

You could also tee them to the shell?

Yeah that would work, but seems a little less convenient. pod.yaml and pj.yaml are in the .gitignore for config/ and prow/ at least so I think this is probably ok for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that tee would result in too much stdout clutter.

I would prefer it if it wrote to a tempdir and echoed something like Created foo/dir.yaml. It's a nit, but this way I don't have to delete them to get them off my git status readout.

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 fixed the .gitignore so that the files will be ignored anywhere in the repo. Echoing the temp dir could work, but switching directories every time pj-on-kind.sh is run would be annoying when trying to make iterative changes to the pod.yaml and pj.yaml. It would also make it harder to modify the files (currently you can just comment out the file generation to use your own pj.yaml and pod.yaml, but using a temp dir would make this harder)

@@ -174,6 +174,11 @@ type localFileWriter struct {

func (w *localFileWriter) Write(b []byte) (int, error) {
if w.file == nil {
if dir := path.Dir(w.filePath); dir != "." {
Copy link
Member

Choose a reason for hiding this comment

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

this check should be unecessary?

package main

import (
	"os"
	"fmt"
)

func main() {
	fmt.Println(os.Mkdir(".", os.ModePerm))
	fmt.Println(os.MkdirAll(".", os.ModePerm))
}
mkdir .: File exists
<nil>

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13

Copy link
Contributor

@chases2 chases2 left a comment

Choose a reason for hiding this comment

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

This doc is incredibly helpful, especially as someone who started using this script to test things.

The script does the following:
1. Installs [mkpj], [mkpod], and [Kind] if they are not found in the path. A [Kind]
cluster named `mkpod` is created if one does not already exist.
1. Uses [mkpj] to generate a YAML ProwJob CRD given job name, config, and git refs (if applicable).
Copy link
Contributor

Choose a reason for hiding this comment

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

What is a CRD?
(CRD is mentioned earlier in the doc, but it would make the most sense to explain the acronym here)

for [prow.istio.io](https://prow.istio.io).
To test ProwJobs for the [prow.k8s.io] instance use [`config/pj-on-kind.sh`](/config/pj-on-kind.sh).

##### Example
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
##### Example
##### Example
This command runs the Prow job [`pull-test-infra-yamllint`](https://github.com/kubernetes/test-infra/blob/170921984a34ca40f2763f9e71d6ce6e033dec03/config/jobs/kubernetes/test-infra/test-infra-presubmits.yaml#L94-L107) locally

This explicitly calls out that the command is a Prow Job name, and that it's identical to the name of the configuration objects in config/jobs/...

@@ -25,29 +25,34 @@ function main() {

# 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"
mkpod --build-id=snowflake "--prow-job=${PWD}/pj.yaml" --local "--out-dir=${out_dir}" > "${PWD}/pod.yaml"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that tee would result in too much stdout clutter.

I would prefer it if it wrote to a tempdir and echoed something like Created foo/dir.yaml. It's a nit, but this way I don't have to delete them to get them off my git status readout.

@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Sep 17, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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 removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 17, 2019
@cjwagner
Copy link
Member Author

I think I've addressed everything. PTAL.

@cjwagner
Copy link
Member Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 17, 2019
and become visible to users by posting results to GitHub (if desired). Changes
to existing jobs can be trialed on canary jobs.

ProwJobs can also be manually triggered by generating a YAML ProwJob [CRD](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) resource
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "Custom Resource Definition resource"


# Deploy pod and watch.
echo "Applying pod to the mkpod cluster. Configure kubectl for the mkpod cluster with:"
echo '> export KUBECONFIG="$(kind get kubeconfig-path --name="mkpod")"'
echo '> export KUBECONFIG="$(kind get kubeconfig-path --name=mkpod)"'
Copy link
Member

Choose a reason for hiding this comment

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

slightly off topic but kubernetes-sigs/kind#850 for future direction there

@BenTheElder
Copy link
Member

code lgtm

@cjwagner cjwagner added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 17, 2019
@k8s-ci-robot k8s-ci-robot merged commit 1b781b8 into kubernetes:master Sep 17, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.16 milestone Sep 17, 2019
@cjwagner cjwagner deleted the pj-on-kind branch September 18, 2019 00:17
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/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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants