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

Create phaino to run prowjobs locally #12163

Merged
merged 1 commit into from
Apr 16, 2019
Merged

Conversation

fejta
Copy link
Contributor

@fejta fejta commented Apr 11, 2019

@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/prow Issues or PRs related to prow area/prow/mkpj Issues or PRs related to prow's mkpj component sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Apr 11, 2019
@stevekuznetsov
Copy link
Contributor

I would prefer this to be a separate tool, as mkpj does one thing and does it well

@fejta
Copy link
Contributor Author

fejta commented Apr 11, 2019

oikos it is then

@stevekuznetsov
Copy link
Contributor

From Wikipedia ....

The ancient Greek word oikos refers to three related but distinct concepts: the family, the family's property, and the house. Its meaning shifts even within texts, which can lead to confusion.

Also may cause confusion when used as a name for Prow components 🤦‍♂️

@fejta
Copy link
Contributor Author

fejta commented Apr 11, 2019

may cause confusion

Horologium will be proud

@fejta
Copy link
Contributor Author

fejta commented Apr 11, 2019

And let me know if you have an alternate and equally incomprehensible name (need to correct for my error in creating prow/cmd/build)

@k8s-ci-robot k8s-ci-robot added 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 Apr 12, 2019
@fejta fejta changed the title Add --local flag to mkpj. Create phaino to run prowjobs locally Apr 12, 2019
@fejta
Copy link
Contributor Author

fejta commented Apr 12, 2019

Can someone review?

/assign @amwat

@fejta
Copy link
Contributor Author

fejta commented Apr 15, 2019

Ping!

defer cancel()
}
args, err := convertToLocal(log, pj, priv)
if err != nil { // see local.go
Copy link
Member

Choose a reason for hiding this comment

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

Stale comment? (albeit technically true)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

case err := <-ch:
return err
case <-ctx.Done():
if err := cmd.Process.Kill(); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually going to stop the job running, or just detach the client from it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a TODO. Assuming killing a docker run --rm=true process doesn't also kill the container (quite likely) it will be mildly annoying to get the container id first.

fmt.Fprint(os.Stderr, "Privileged jobs are unsafe. Remove from local run? [yes]: ")
var out string
fmt.Scanln(&out)
if out == "" || out[0] == 'y' || out[0] == 'Y' {
Copy link
Member

Choose a reason for hiding this comment

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

"yes" (or other case variations thereof?)

Possibly: require an understandable "no" to not remove, rather than an understandable "yes" to remove, because "no" is the unsafe choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

(yes will match out[0] == 'y', right?)

Copy link
Member

Choose a reason for hiding this comment

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

(evidently I cannot read.)

Copy link
Member

@Katharine Katharine left a comment

Choose a reason for hiding this comment

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

/hold

case err := <-ch:
return err
case <-ctx.Done():
if err := cmd.Process.Kill(); err != nil { // TODO(fejta): docker rm
Copy link
Member

Choose a reason for hiding this comment

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

Ideally, I'd like to see a warning here that despite timing out the job will keep running, but I'm not terribly hung up about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't want to leave it this way :)

@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 Apr 16, 2019
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 16, 2019
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 62e9507bb1a60b4c6da47a2c8c581f0f077580ab

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fejta, Katharine

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

@fejta
Copy link
Contributor Author

fejta commented Apr 16, 2019

/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 Apr 16, 2019
@k8s-ci-robot k8s-ci-robot merged commit 94d8a27 into kubernetes:master Apr 16, 2019
Copy link
Member

@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.

I'm excited to try this out! Sorry for the late review.

@@ -262,6 +268,9 @@ func main() {
logrus.WithError(err).Fatal("Error marshalling YAML.")
}
fmt.Print(string(b))
if o.local {
logrus.Info("Use 'bazel run //prow/cmd/oikos' to run this job locally in docker")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logrus.Info("Use 'bazel run //prow/cmd/oikos' to run this job locally in docker")
logrus.Info("Use 'bazel run //prow/cmd/phaino' to run this job locally in docker")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

- For prow.k8s.io jobs use `//config:mkpj`
* `bazel run //config:mkpj -- --job=pull-test-infra-bazel | bazel run //prow/cmd/bazel`
- Other deployments will need to clone that rule and/or pass in extra flags:
* `bazel run //prow/cmd/mkpj -- --config=/my/config.yaml --job=my-job | bazel run //prow/cmd/bazel`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `bazel run //prow/cmd/mkpj -- --config=/my/config.yaml --job=my-job | bazel run //prow/cmd/bazel`
* `bazel run //prow/cmd/mkpj -- --config-path=/my/config.yaml --job=my-job | bazel run //prow/cmd/phaino`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


* Use `mkpj` to create the job and pipe this to `phaino`
- For prow.k8s.io jobs use `//config:mkpj`
* `bazel run //config:mkpj -- --job=pull-test-infra-bazel | bazel run //prow/cmd/bazel`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `bazel run //config:mkpj -- --job=pull-test-infra-bazel | bazel run //prow/cmd/bazel`
* `bazel run //config:mkpj -- --job=pull-test-infra-bazel | bazel run //prow/cmd/phaino`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return readPJ(resp.Body)
}

func readPJs(ctx context.Context, jobs []string) (<-chan prowapi.ProwJob, <-chan error) {
Copy link
Member

Choose a reason for hiding this comment

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

ctx is unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,43 @@
# Phaino

Run prowjobs on your local workstation with `phaino`.
Copy link
Member

Choose a reason for hiding this comment

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

Mention what "Phaino" means.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if workingDir == "" {
workingDir = dest
}
localArgs = append(localArgs, "-v", repo+":"+dest)
Copy link
Member

Choose a reason for hiding this comment

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

This ignores BaseRef, BaseSHA, and the Pulls fields of the Refs. Ideally we would respect these, but at a minimum we should warn that they are not respected if they are specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't think this is necessary as we explicitly ask the user to provide the source for this ref.

Agree that long-term we should support a mode where we check out the repos for you (probably after we add knative-build job support, which will also have to deal with multiple containers).

}
}
if workingDir == "" {
workingDir = "/random-location"
Copy link
Member

Choose a reason for hiding this comment

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

The pod utilities will use the existing value for spec.Containers[0].WorkingDir if there are no refs specified:

if len(refs) > 0 {
spec.Containers[0].WorkingDir = clone.PathForRefs(codeMount.MountPath, refs[0])

We should probably keep the behavior identical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return err
case <-ctx.Done():
if err := cmd.Process.Kill(); err != nil { // TODO(fejta): docker rm
log.WithError(err).Warn("Kill error")
Copy link
Member

Choose a reason for hiding this comment

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

nit: error level

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO warning is correct here. We'll log an error line later

fs.BoolVar(&o.priv, "privileged", false, "Allow privileged local runs")
fs.DurationVar(&o.timeout, "timeout", 10*time.Minute, "Maximum duration for each job (0 for unlimited)")
fs.DurationVar(&o.totalTimeout, "total-timeout", 0, "Maximum duration for all jobs (0 for unlimited)")
fs.DurationVar(&o.grace, "grace", 10*time.Second, "Terminate timed out jobs after this grace period (1s minimum)")
Copy link
Member

Choose a reason for hiding this comment

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

Can we consume the timeout and grace period from the decoration_config if available and if the flags are unspecified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (TODO)

}
if pj.Kind != "ProwJob" {
return nil, fmt.Errorf("bad kind: %q", pj.Kind)
}
Copy link
Member

Choose a reason for hiding this comment

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

We also need to require agent: kubernetes and that the podspec is non-nil.

Once we have a ProwJob admission controller we can share the ProwJob validation logic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@cjwagner
Copy link
Member

We should also mention Phaino and link to its README here: https://github.com/kubernetes/test-infra/blob/master/prow/build_test_update.md#how-to-test-a-prowjob

@fejta fejta deleted the local branch April 16, 2019 23:06
@fejta fejta mentioned this pull request Apr 16, 2019
@fejta
Copy link
Contributor Author

fejta commented Apr 18, 2019

ref #6590

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/prow/mkpj Issues or PRs related to prow's mkpj 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.

7 participants