-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
plugins/drivers/base/client.go
Outdated
"golang.org/x/net/context" | ||
) | ||
|
||
type DriverClient interface { |
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.
What is the point of this slimmed down interface?
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.
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?
plugins/drivers/base/client.go
Outdated
|
||
func (d *driverPluginClient) StartTask(c *TaskConfig) (*TaskHandle, error) { | ||
resp, err := d.client.StartTask(context.Background(), | ||
&proto.StartTaskRequest{ |
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 looks awkward. Can you make the request outside the call
plugins/drivers/base/client.go
Outdated
|
||
func (d *driverPluginClient) WaitTask(ctx context.Context, id string) chan *TaskResult { | ||
ch := make(chan *TaskResult) | ||
go func() { |
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.
Create a waitTaskImpl instead of an anonymous function
plugins/drivers/base/driver.go
Outdated
"github.com/hashicorp/nomad/plugins/base" | ||
) | ||
|
||
const DriverGoPlugin = "driver" |
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.
prefer base.PluginTypeDriver
https://github.com/hashicorp/nomad/blob/master/plugins/base/plugin.go#L19
plugins/drivers/base/proto_utils.go
Outdated
@@ -0,0 +1,68 @@ | |||
package base |
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.
proto_utils -> utils.go? for consistency
plugins/drivers/base/testing.go
Outdated
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) |
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.
require no error on these?
ba95b44
to
2b03e8b
Compare
1d7d12b
to
7f43217
Compare
393ee89
to
a333efb
Compare
23f59fe
to
e9b0ea5
Compare
e9b0ea5
to
f0e96a8
Compare
plugins/drivers/base/driver.go
Outdated
} | ||
|
||
func (tc *TaskConfig) EnvList() []string { | ||
l := make([]string, len(tc.Env)) |
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.
Set the cap=len(tc.Env), not the len: https://play.golang.org/p/JtF3Mhv4-i4
plugins/drivers/base/driver.go
Outdated
ID string | ||
Name string | ||
State TaskState | ||
SizeOnDiskMB int64 |
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.
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.
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 is meant to be a runtime measurement of the current disk usage.
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.
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.
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 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/utils/utils.go
Outdated
|
||
// ValidateCommand validates that the command only has a single value and | ||
// returns a user friendly error message telling them to use the passed | ||
// argField. |
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.
argField isn't used.
plugins/drivers/base/client.go
Outdated
@@ -0,0 +1,299 @@ | |||
package base |
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.
Why are any of these files in a base sub package?
plugins/drivers/base/client.go
Outdated
break | ||
} | ||
f := &Fingerprint{ | ||
Attributes: pb.Attributes, |
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.
Hm shouldn't this expose the error to the caller
plugins/drivers/base/client.go
Outdated
} | ||
timestamp, _ := ptypes.Timestamp(ev.Timestamp) | ||
event := &TaskEvent{ | ||
TaskID: ev.TaskId, |
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.
Same err comment
"os/exec" | ||
) | ||
|
||
// TODO Figure out if this is needed in Wondows |
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.
Windows
plugins/drivers/client.go
Outdated
@@ -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)} |
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.
Hm I don't think we should wrap it because that error is likely a gRPC error
plugins/drivers/driver.go
Outdated
@@ -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 |
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.
Comment is odd since this should be settable by the plugin as well.
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(...) }
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(...) }
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. |
Ignore most of the changes to executor here. That will come in a later PR.