-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Conversation
I would prefer this to be a separate tool, as |
oikos it is then |
From Wikipedia ....
Also may cause confusion when used as a name for Prow components 🤦♂️ |
Horologium will be proud |
And let me know if you have an alternate and equally incomprehensible name (need to correct for my error in creating prow/cmd/build) |
Can someone review? /assign @amwat |
Ping! |
prow/cmd/phaino/local.go
Outdated
defer cancel() | ||
} | ||
args, err := convertToLocal(log, pj, priv) | ||
if err != nil { // see local.go |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
prow/cmd/phaino/local.go
Outdated
case err := <-ch: | ||
return err | ||
case <-ctx.Done(): | ||
if err := cmd.Process.Kill(); err != nil { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
prow/cmd/phaino/local.go
Outdated
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' { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(evidently I cannot read.)
Demo: bazel run //prow/cmd/phaino -- https://prow.k8s.io/rerun?prowjob=d08f1ca5-5d63-11e9-ab62-0a580a6c1281
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
LGTM label has been added. Git tree hash: 62e9507bb1a60b4c6da47a2c8c581f0f077580ab
|
[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 |
/hold cancel |
There was a problem hiding this 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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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") |
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `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` |
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `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` |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx
is unused.
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention what "Phaino" means.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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:
test-infra/prow/pod-utils/decorate/podspec.go
Lines 551 to 552 in 4ce54b1
if len(refs) > 0 { | |
spec.Containers[0].WorkingDir = clone.PathForRefs(codeMount.MountPath, refs[0]) |
We should probably keep the behavior identical.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: error level
There was a problem hiding this comment.
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)") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
We should also mention |
ref #6590 |
/assign @BenTheElder @stevekuznetsov @Katharine