Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Executor Runtimes#47496

Merged
Piszmog merged 225 commits into
mainfrom
rc/executor-runtime-interface
Apr 4, 2023
Merged

Executor Runtimes#47496
Piszmog merged 225 commits into
mainfrom
rc/executor-runtime-interface

Conversation

@Piszmog

@Piszmog Piszmog commented Feb 9, 2023

Copy link
Copy Markdown
Contributor

Closes #46175 and #46176.

Note: Most of the new lines are from adding Unit Tests. Over 120 new unit tests were added.

This PR will help position us into a situation where Executors can understand the environment they are deployed to and handle Jobs with that specific environment.

So for example if docker has been configured, the executor will handle all jobs with docker.

In the future, we will add runtimes for Firecracker, K8s, and more.

Changes

  • Split command into two packages
    • worker/command and worker/runner
    • This is to help with getting test coverage and to make integrating the worker/runtime package more easily
  • General housekeeping (fixing function names, remove variable shadowing when not necessary)
  • Created an interface Runtime in the executor app
    • This interface will prepare the workspace, create a runner (what will actually execute the steps), and build the commands for the runner to execute
    • At startup, the runtime is configured based on how the host is configured.
      • At the moment, I commented out this setup call to be backwards compatible
    • When a Job is processed, the configured runtime is used to execute the Job
  • Created a dockerRuntime struct to handle "docker" runtimes
  • Added a special case for src
    • If Job.CLISteps is set, then we fallback to the "legacy" way
  • Over 120 new Unit Tests

New Issues

Created the following Issue as I was implementing this PR.

Demo

The following is using the native SSBC for testing.

This just shows that,

  • A job is successfully processed
  • The logs confirm the commands

"Legacy" Flow

Screen.Recording.2023-03-03.at.11.40.51.mov

Runtime flow (docker)

Screen.Recording.2023-03-03.at.11.29.01.mov

Test plan

Added unit tests and did functional testing.

…executor-job-specific-tokens

# Conflicts:
#	enterprise/cmd/executor/internal/apiclient/queue/job/client.go
#	enterprise/cmd/executor/internal/apiclient/queue/job/client_test.go
#	enterprise/cmd/executor/internal/worker/store/store.go
# Conflicts:
#	internal/database/permission_sync_jobs.go
#	mockgen.test.yaml
@Piszmog

Piszmog commented Mar 23, 2023

Copy link
Copy Markdown
Contributor Author

Pushed these changes to executor-patch-notest/runtime-interface to get an image built without merging to main

Edit (3/30):

Updated GCP dogfood use use image

}

cmd.Env = env
cmd.Env = append(cmd.Env, env...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

does this still unset env vars from the host? We never want os.Environ to spill into this env.

@Piszmog Piszmog Mar 30, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yea not sure what my brain was thinking. I changed this back to cmd.Env = env

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now I remember why. This was allowing me to inject the ENV vars when running the unit test with the tricky cmd.Exec

@sanderginn sanderginn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I really like the patterns you implemented here. Awesome job 👍

Most of my comments are actually questions I have to understand executors better. A few nits otherwise.

Comment thread enterprise/cmd/executor/internal/run/install.go
Comment thread enterprise/cmd/executor/internal/run/install.go
Comment thread enterprise/cmd/executor/internal/run/install.go
Comment thread enterprise/cmd/executor/internal/run/run.go
Comment thread enterprise/cmd/executor/internal/run/run.go Outdated
Comment thread enterprise/cmd/executor/internal/worker/runner/docker.go
Comment thread enterprise/cmd/executor/internal/worker/runner/docker.go
Comment thread enterprise/cmd/executor/internal/worker/runner/firecracker.go
if err != nil {
return "", err
}
cniConfigFile := path.Join(cniConfigDir, "10-sourcegraph-executors.conflist")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the significance of the 10-?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question 🤔

@eseliger what is the significance of this? (I'll add a comment with the why)

Comment thread enterprise/cmd/executor/internal/worker/runner/runner.go
@Piszmog

Piszmog commented Apr 3, 2023

Copy link
Copy Markdown
Contributor Author

If there are no more comments, I will merge this tomorrow (one more day of running in dogfood)

@sanderginn

Copy link
Copy Markdown
Contributor

All good from me 👍

@Piszmog Piszmog merged commit 00b3bef into main Apr 4, 2023
@Piszmog Piszmog deleted the rc/executor-runtime-interface branch April 4, 2023 15:18
@Piszmog Piszmog mentioned this pull request Apr 4, 2023
almeidapaulooliveira pushed a commit that referenced this pull request Apr 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime Interface Spec

5 participants