Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gulducat committed Dec 2, 2024
1 parent e2211f6 commit 5b573db
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 30 deletions.
15 changes: 8 additions & 7 deletions client/fingerprint/dynamic_host_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ func (h *DynamicHostVolumePluginFingerprint) Reload() {

func (h *DynamicHostVolumePluginFingerprint) Fingerprint(request *FingerprintRequest, response *FingerprintResponse) error {
// always add "mkdir" plugin
h.logger.Debug("detected plugin built-in", "plugin_id", "mkdir", "version", hvm.HostVolumePluginMkdirVersion)
defer response.AddAttribute("plugins.dhv.version.mkdir", hvm.HostVolumePluginMkdirVersion)
h.logger.Debug("detected plugin built-in",
"plugin_id", hvm.HostVolumePluginMkdirID, "version", hvm.HostVolumePluginMkdirVersion)
defer response.AddAttribute("plugins.host_volume.version."+hvm.HostVolumePluginMkdirID, hvm.HostVolumePluginMkdirVersion)
response.Detected = true

// this config value will be empty in -dev mode
Expand All @@ -55,22 +56,22 @@ func (h *DynamicHostVolumePluginFingerprint) Fingerprint(request *FingerprintReq

// if this was a reload, wipe what was there before
for k := range request.Node.Attributes {
if strings.HasPrefix(k, "plugins.dhv.") {
if strings.HasPrefix(k, "plugins.host_volume.") {
response.RemoveAttribute(k)
}
}

// set the attribute(s)
for plugin, version := range plugins {
h.logger.Debug("detected plugin", "plugin_id", plugin, "version", version)
response.AddAttribute("plugins.dhv.version."+plugin, version)
response.AddAttribute("plugins.host_volume.version."+plugin, version)
}

return nil
}

func (h *DynamicHostVolumePluginFingerprint) Periodic() (bool, time.Duration) {
return false, 0 // not periodic; db TODO(1.10.0): could be?
return false, 0
}

// GetHostVolumePluginVersions finds all the executable files on disk
Expand All @@ -94,11 +95,11 @@ func GetHostVolumePluginVersions(log hclog.Logger, pluginDir string) (map[string
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

log := log.With("plugin_id", file) // db TODO: "name" like CNI, instead of "ID" ?
log := log.With("plugin_id", file)

p, err := hvm.NewHostVolumePluginExternal(log, file, fullPath, "")
if err != nil {
log.Debug("error getting plugin", "error", err)
log.Warn("error getting plugin", "error", err)
return
}

Expand Down
8 changes: 4 additions & 4 deletions client/fingerprint/dynamic_host_volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func TestPluginsHostVolumeFingerprint(t *testing.T) {
err := fp.Fingerprint(req, &resp)
must.NoError(t, err)
must.Eq(t, map[string]string{
"plugins.dhv.version.happy-plugin": "0.0.1",
"plugins.dhv.version.mkdir": hvm.HostVolumePluginMkdirVersion, // built-in
"plugins.host_volume.version.happy-plugin": "0.0.1",
"plugins.host_volume.version.mkdir": hvm.HostVolumePluginMkdirVersion, // built-in
}, resp.Attributes)

// do it again after deleting our one good plugin.
Expand All @@ -82,8 +82,8 @@ func TestPluginsHostVolumeFingerprint(t *testing.T) {
err = fp.Fingerprint(req, &resp)
must.NoError(t, err)
must.Eq(t, map[string]string{
"plugins.dhv.version.happy-plugin": "", // will get cleaned up later
"plugins.host_volume.version.happy-plugin": "", // empty value means removed

"plugins.dhv.version.mkdir": hvm.HostVolumePluginMkdirVersion, // built-in
"plugins.host_volume.version.mkdir": hvm.HostVolumePluginMkdirVersion, // built-in
}, resp.Attributes)
}
1 change: 1 addition & 0 deletions client/hostvolumemanager/host_volume_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type HostVolumePluginCreateResponse struct {
Context map[string]string `json:"context"` // metadata
}

const HostVolumePluginMkdirID = "mkdir"
const HostVolumePluginMkdirVersion = "0.0.1"

var _ HostVolumePlugin = &HostVolumePluginMkdir{}
Expand Down
4 changes: 2 additions & 2 deletions client/hostvolumemanager/host_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func NewHostVolumeManager(logger hclog.Logger, pluginDir, sharedMountDir string)
func (hvm *HostVolumeManager) getPlugin(id string) (HostVolumePlugin, error) {
log := hvm.log.With("plugin_id", id)

if id == "mkdir" { // db TODO: constant?
if id == HostVolumePluginMkdirID {
return &HostVolumePluginMkdir{
ID: "mkdir",
ID: HostVolumePluginMkdirID,
TargetPath: hvm.sharedMountDir,
log: log,
}, nil
Expand Down
6 changes: 3 additions & 3 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ func convertClientConfig(agentConfig *Config) (*clientconfig.Config, error) {
conf.AllocDir = filepath.Join(agentConfig.DataDir, "alloc")
dataParent := filepath.Dir(agentConfig.DataDir)
conf.AllocMountsDir = filepath.Join(dataParent, "alloc_mounts")
conf.DynamicHostVolumePluginPath = filepath.Join(dataParent, "plugins-dhv")
conf.DynamicHostVolumePluginPath = filepath.Join(dataParent, "plugins-host-volume")
}
if agentConfig.Client.StateDir != "" {
conf.StateDir = agentConfig.Client.StateDir
Expand All @@ -737,8 +737,8 @@ func convertClientConfig(agentConfig *Config) (*clientconfig.Config, error) {
if agentConfig.Client.AllocMountsDir != "" {
conf.AllocMountsDir = agentConfig.Client.AllocMountsDir
}
if agentConfig.Client.DHVPluginDir != "" {
conf.DynamicHostVolumePluginPath = agentConfig.Client.DHVPluginDir
if agentConfig.Client.HostVolumePluginDir != "" {
conf.DynamicHostVolumePluginPath = agentConfig.Client.HostVolumePluginDir
}
if agentConfig.Client.NetworkInterface != "" {
conf.NetworkInterface = agentConfig.Client.NetworkInterface
Expand Down
21 changes: 11 additions & 10 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (c *Command) readConfig() *Config {
flags.StringVar(&cmdConfig.Client.StateDir, "state-dir", "", "")
flags.StringVar(&cmdConfig.Client.AllocDir, "alloc-dir", "", "")
flags.StringVar(&cmdConfig.Client.AllocMountsDir, "alloc-mounts-dir", "", "")
flags.StringVar(&cmdConfig.Client.DHVPluginDir, "dhv-plugin-dir", "", "")
flags.StringVar(&cmdConfig.Client.HostVolumePluginDir, "host-volume-plugin-dir", "", "")
flags.StringVar(&cmdConfig.Client.NodeClass, "node-class", "", "")
flags.StringVar(&cmdConfig.Client.NodePool, "node-pool", "", "")
flags.StringVar(&servers, "servers", "", "")
Expand Down Expand Up @@ -385,12 +385,12 @@ func (c *Command) IsValidConfig(config, cmdConfig *Config) bool {

// Verify the paths are absolute.
dirs := map[string]string{
"data-dir": config.DataDir,
"plugin-dir": config.PluginDir,
"alloc-dir": config.Client.AllocDir,
"alloc-mounts-dir": config.Client.AllocMountsDir,
"dhv-plugin-dir": config.Client.DHVPluginDir,
"state-dir": config.Client.StateDir,
"data-dir": config.DataDir,
"plugin-dir": config.PluginDir,
"alloc-dir": config.Client.AllocDir,
"alloc-mounts-dir": config.Client.AllocMountsDir,
"host-volume-plugin-dir": config.Client.HostVolumePluginDir,
"state-dir": config.Client.StateDir,
}
for k, dir := range dirs {
if dir == "" {
Expand Down Expand Up @@ -737,6 +737,7 @@ func (c *Command) AutocompleteFlags() complete.Flags {
"-region": complete.PredictAnything,
"-data-dir": complete.PredictDirs("*"),
"-plugin-dir": complete.PredictDirs("*"),
"-host-volume-plugin-dir": complete.PredictDirs("*"),
"-dc": complete.PredictAnything,
"-log-level": complete.PredictAnything,
"-json-logs": complete.PredictNothing,
Expand Down Expand Up @@ -1570,9 +1571,9 @@ Client Options:
The default speed for network interfaces in MBits if the link speed can not
be determined dynamically.
-dhv-plugin-dir
Directory containing dynamic host volume plugins. Defaults to "plugins-dhv"
next to "-state-dir".
-host-volume-plugin-dir
Directory containing dynamic host volume plugins. The default is
"plugins-host-volume" next to "-state-dir".
ACL Options:
Expand Down
8 changes: 4 additions & 4 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ type ClientConfig struct {
// AllocMountsDir is the directory for storing mounts into allocation data
AllocMountsDir string `hcl:"alloc_mounts_dir"`

// DHVPluginDir is the directory containing dynamic host volume plugins
// HostVolumePluginDir directory contains dynamic host volume plugins
// db TODO(1.10.0): document default directory is alongside alloc_mounts
DHVPluginDir string `hcl:"dhv_plugin_dir"` // db TODO(1.10.0): is this a good name?
HostVolumePluginDir string `hcl:"host_volume_plugin_dir"`

// Servers is a list of known server addresses. These are as "host:port"
Servers []string `hcl:"servers"`
Expand Down Expand Up @@ -2315,8 +2315,8 @@ func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig {
if b.AllocMountsDir != "" {
result.AllocMountsDir = b.AllocMountsDir
}
if b.DHVPluginDir != "" {
result.DHVPluginDir = b.DHVPluginDir
if b.HostVolumePluginDir != "" {
result.HostVolumePluginDir = b.HostVolumePluginDir
}
if b.NodeClass != "" {
result.NodeClass = b.NodeClass
Expand Down

0 comments on commit 5b573db

Please sign in to comment.