hashicorp / hashicorp/nomad

Clarify plugin driver state documentation

Open
#11,543 2 comments 1 reaction 0 assignees View on GitHub
stage/accepted theme/docs theme/plugin type/enhancement
Dominant language
Go
Stars
17k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
105

Description

### Proposal
Provide better documentation on the state storage for `plugins/drivers.TaskHandle`. Specifically explain the difference between `State` and `DriverState`, and how they should be used.

Currently there is scant documentation on these 2 fields. And what documentation there is seems contradictory.

The actual go documentation, which is what developers are used to is practically empty, providing only some hint that `DriverState` might be deprecated, thus implying you should use `State`. https://pkg.go.dev/github.com/hashicorp/nomad@v1.2.0/plugins/drivers#TaskHandle

Then there's the [nomadproject.io documentation](https://www.nomadproject.io/docs/internals/plugins/task-drivers#starttask-taskconfig-taskhandle-drivernetwork-error) which states that you should use `DriverState` and the helper functions.

Because of this contradiction, I have no idea which one I should be using.

On top of that, the pkg.go.dev doc says that the `Version` field is used to discriminate between them, and that version 0.9 deprecates `DriverState`. However the `Version` field is an integer, and cannot hold the value `0.9`. So what is supposed to go here?
This statement also mentions something about a "json encoded reattach config`, yet the word "json" is mentioned nowhere else anywhere in the documentation.

And also the fore-mentioned deprecation notice says:

> handle upgrading from an older DriverState struct

This is confusing as the `DriverState` field is not a struct, it's a `[]byte`. So maybe `DriverState` isn't what's deprecated, the documentation is wrong, and it meant to say the `TaskState` struct instead?

 

In general the pkg.go.dev needs to be greatly expanded. The majority of function/structs/fields/etc have no documentation at all. How are we suppose to understand how to properly use the API if it's not documented?

Why is the [pkg.go.dev documentation for StartTask](https://pkg.go.dev/github.com/hashicorp/nomad@v1.2.0/plugins/drivers#DriverPlugin) completely empty, but the [documentation in nomadproject.io](https://www.nomadproject.io/docs/internals/plugins/task-drivers#starttask-taskconfig-taskhandle-drivernetwork-error) is populated? Go developers expect packages to follow standard Go standards, which includes documentation. Doing this would probably also help solve this contradiction problem, as documentation would then be kept in sync with the code.
If documentation is to also be kept on nomadproject.io, I would suggest using a documentation generator to extract it from the Go package.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Go documentation for plugins/drivers.TaskHandle and DriverPlugin, then compare it with the linked nomadproject.io task-driver documentation. Clarify the intended roles of State, DriverState, Version, and the related upgrade wording, and document the agreed usage consistently across the referenced API and site documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.