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

clientv2: base driver plugin #4671

Merged
merged 25 commits into from
Sep 26, 2018
Merged

clientv2: base driver plugin #4671

merged 25 commits into from
Sep 26, 2018

Conversation

nickethier
Copy link
Member

Ignore most of the changes to executor here. That will come in a later PR.

"golang.org/x/net/context"
)

type DriverClient interface {
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 the point of this slimmed down interface?

Copy link
Member Author

Choose a reason for hiding this comment

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

So this interface isn't fully built out yet. I need to finish adding other methods.

If I remember correctly I opted to separate the client and plugin side interfaces so you could pass in a context where appropriate on the client. For example on WaitTask. It feels like I started that code ages ago though and now think that might not be necessary?


func (d *driverPluginClient) StartTask(c *TaskConfig) (*TaskHandle, error) {
resp, err := d.client.StartTask(context.Background(),
&proto.StartTaskRequest{
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks awkward. Can you make the request outside the call


func (d *driverPluginClient) WaitTask(ctx context.Context, id string) chan *TaskResult {
ch := make(chan *TaskResult)
go func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a waitTaskImpl instead of an anonymous function

"github.com/hashicorp/nomad/plugins/base"
)

const DriverGoPlugin = "driver"
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -0,0 +1,68 @@
package base
Copy link
Contributor

Choose a reason for hiding this comment

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

proto_utils -> utils.go? for consistency

func (h *DriverHarness) MkAllocDir(t *TaskConfig) func() {
allocDir, err := ioutil.TempDir("", "nomad_driver_harness-")
require.NoError(h.t, err)
os.Mkdir(filepath.Join(allocDir, t.Name), os.ModePerm)
Copy link
Contributor

Choose a reason for hiding this comment

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

require no error on these?

plugins/drivers/base/plugin_test.go Outdated Show resolved Hide resolved
plugins/drivers/base/client.go Outdated Show resolved Hide resolved
plugins/drivers/base/client.go Outdated Show resolved Hide resolved
plugins/drivers/base/driver.go Outdated Show resolved Hide resolved
plugins/drivers/base/driver.go Outdated Show resolved Hide resolved
}

func (tc *TaskConfig) EnvList() []string {
l := make([]string, len(tc.Env))
Copy link
Member

Choose a reason for hiding this comment

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

Set the cap=len(tc.Env), not the len: https://play.golang.org/p/JtF3Mhv4-i4

plugins/drivers/base/driver.go Outdated Show resolved Hide resolved
ID string
Name string
State TaskState
SizeOnDiskMB int64
Copy link
Member

Choose a reason for hiding this comment

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

From its placement in TaskStatus instead of TaskStats I assume this is EphemeralDisk.Size? I think we should name it EphemeralDiskSize if so to avoid confusion as to whether this is the static allocation vs a runtime measurement.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is meant to be a runtime measurement of the current disk usage.

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be in Stats with the other runtime measurements then? I don't think we've implemented this anywhere yet, so it can probably be removed entirely.

Copy link
Member Author

Choose a reason for hiding this comment

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

The original plan was that today InspectTask is actually never called, but we'd like to have a cli (and match UI) that allows you to inspect a task and get all the delicious debug information you need from it. This was one value that I thought should be included here.

plugins/drivers/base/utils.go Outdated Show resolved Hide resolved

// ValidateCommand validates that the command only has a single value and
// returns a user friendly error message telling them to use the passed
// argField.
Copy link
Member

Choose a reason for hiding this comment

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

argField isn't used.

@@ -0,0 +1,299 @@
package base
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are any of these files in a base sub package?

break
}
f := &Fingerprint{
Attributes: pb.Attributes,
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm shouldn't this expose the error to the caller

}
timestamp, _ := ptypes.Timestamp(ev.Timestamp)
event := &TaskEvent{
TaskID: ev.TaskId,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same err comment

plugins/drivers/base/driver.go Outdated Show resolved Hide resolved
"os/exec"
)

// TODO Figure out if this is needed in Wondows
Copy link
Contributor

Choose a reason for hiding this comment

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

Windows

@@ -249,6 +251,7 @@ func (d *driverPluginClient) handleTaskEvents(ch chan *TaskEvent, stream proto.D
}
if err != nil {
d.logger.Error("error receiving stream from TaskEvents driver RPC", "error", err)
ch <- &TaskEvent{Err: fmt.Errorf("error from RPC stream: %v", err)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm I don't think we should wrap it because that error is likely a gRPC error

@@ -67,6 +67,9 @@ type Fingerprint struct {
Attributes map[string]string
Health HealthState
HealthDescription string

// Err is only used if an error occured while consuming the RPC stream
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment is odd since this should be settable by the plugin as well.

@nickethier nickethier merged commit a73555f into r-clientv2 Sep 26, 2018
@nickethier nickethier deleted the f-base-driver-plugin branch September 26, 2018 18:05
schmichael pushed a commit that referenced this pull request Oct 16, 2018
Driver plugin framework to facilitate development of driver plugins.

Implementing plugins only need to implement the DriverPlugin interface.
The framework proxies this interface to the go-plugin GRPC interface generated
from the driver.proto spec.

A testing harness is provided to allow implementing drivers to test the full
lifecycle of the driver plugin. An example use:

func TestMyDriver(t *testing.T) {
    harness := NewDriverHarness(t, &MyDiverPlugin{})
    // The harness implements the DriverPlugin interface and can be used as such
    taskHandle, err := harness.StartTask(...)
}
schmichael pushed a commit that referenced this pull request Oct 16, 2018
Driver plugin framework to facilitate development of driver plugins.

Implementing plugins only need to implement the DriverPlugin interface.
The framework proxies this interface to the go-plugin GRPC interface generated
from the driver.proto spec.

A testing harness is provided to allow implementing drivers to test the full
lifecycle of the driver plugin. An example use:

func TestMyDriver(t *testing.T) {
    harness := NewDriverHarness(t, &MyDiverPlugin{})
    // The harness implements the DriverPlugin interface and can be used as such
    taskHandle, err := harness.StartTask(...)
}
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants