diff --git a/GNUmakefile b/GNUmakefile index 71f34a4fc..19cf292fd 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -280,7 +280,7 @@ travis: ## Run Nomad test suites with output to prevent timeouts under Travis CI @if [ ! $(SKIP_NOMAD_TESTS) ]; then \ make generate-structs; \ fi - @sh -C "$(PROJECT_ROOT)/scripts/travis.sh" + @"$(PROJECT_ROOT)/scripts/travis.sh" .PHONY: testcluster testcluster: ## Bring up a Linux test cluster using Vagrant. Set PROVIDER if necessary. diff --git a/api/api.go b/api/api.go index 1ea032ae5..3a346267b 100644 --- a/api/api.go +++ b/api/api.go @@ -15,7 +15,7 @@ import ( "strings" "time" - "github.com/hashicorp/go-cleanhttp" + cleanhttp "github.com/hashicorp/go-cleanhttp" rootcerts "github.com/hashicorp/go-rootcerts" ) diff --git a/api/structsync_test.go b/api/structsync_test.go new file mode 100644 index 000000000..2cb2ebc94 --- /dev/null +++ b/api/structsync_test.go @@ -0,0 +1,101 @@ +package api + +import ( + "encoding/json" + "testing" + + "github.com/hashicorp/nomad/nomad/structs" + "github.com/stretchr/testify/require" +) + +// Tests that api and struct values are equivalent +// +// Given that vendoring libraries prune tests by default, test dependencies +// aren't leaked to clients of the package - so it should be safe to add +// such dependency without affecting api clients. + +func TestDefaultResourcesAreInSync(t *testing.T) { + apiR := DefaultResources() + structsR := structs.DefaultResources() + + require.EqualValues(t, *structsR, toStructsResource(t, apiR)) + + // match after canonicalization + apiR.Canonicalize() + structsR.Canonicalize() + require.EqualValues(t, *structsR, toStructsResource(t, apiR)) +} + +func TestMinResourcesAreInSync(t *testing.T) { + apiR := MinResources() + structsR := structs.MinResources() + + require.EqualValues(t, *structsR, toStructsResource(t, apiR)) + + // match after canonicalization + apiR.Canonicalize() + structsR.Canonicalize() + require.EqualValues(t, *structsR, toStructsResource(t, apiR)) +} + +func TestNewDefaultRescheulePolicyInSync(t *testing.T) { + cases := []struct { + typ string + expected structs.ReschedulePolicy + }{ + {"service", structs.DefaultServiceJobReschedulePolicy}, + {"batch", structs.DefaultBatchJobReschedulePolicy}, + {"system", structs.ReschedulePolicy{}}, + } + + for _, c := range cases { + t.Run(c.typ, func(t *testing.T) { + apiP := NewDefaultReschedulePolicy(c.typ) + + var found structs.ReschedulePolicy + toStructs(t, &found, apiP) + + require.EqualValues(t, c.expected, found) + }) + } +} + +func TestNewDefaultRestartPolicyInSync(t *testing.T) { + cases := []struct { + typ string + expected structs.RestartPolicy + }{ + {"service", structs.DefaultServiceJobRestartPolicy}, + {"batch", structs.DefaultBatchJobRestartPolicy}, + {"system", structs.DefaultServiceJobRestartPolicy}, + } + + for _, c := range cases { + t.Run(c.typ, func(t *testing.T) { + job := Job{Type: &c.typ} + var tg TaskGroup + tg.Canonicalize(&job) + + apiP := tg.RestartPolicy + + var found structs.RestartPolicy + toStructs(t, &found, apiP) + + require.EqualValues(t, c.expected, found) + }) + } +} + +func toStructsResource(t *testing.T, in *Resources) structs.Resources { + var out structs.Resources + toStructs(t, &out, in) + return out +} + +func toStructs(t *testing.T, out, in interface{}) { + bytes, err := json.Marshal(in) + require.NoError(t, err) + + err = json.Unmarshal(bytes, &out) + require.NoError(t, err) +} diff --git a/client/allocdir/alloc_dir.go b/client/allocdir/alloc_dir.go index 793c5c81d..8c3b2ce64 100644 --- a/client/allocdir/alloc_dir.go +++ b/client/allocdir/alloc_dir.go @@ -12,7 +12,7 @@ import ( "time" hclog "github.com/hashicorp/go-hclog" - "github.com/hashicorp/go-multierror" + multierror "github.com/hashicorp/go-multierror" cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/nomad/structs" "github.com/hpcloud/tail/watch" diff --git a/client/allocrunner/alloc_runner_hooks.go b/client/allocrunner/alloc_runner_hooks.go index e1e3885f2..1090d37cc 100644 --- a/client/allocrunner/alloc_runner_hooks.go +++ b/client/allocrunner/alloc_runner_hooks.go @@ -46,10 +46,11 @@ func (a *allocHealthSetter) SetHealth(healthy, isDeploy bool, trackerTaskEvents a.ar.stateLock.Lock() a.ar.state.SetDeploymentStatus(time.Now(), healthy) a.ar.persistDeploymentStatus(a.ar.state.DeploymentStatus) + terminalDesiredState := a.ar.alloc.ServerTerminalStatus() a.ar.stateLock.Unlock() // If deployment is unhealthy emit task events explaining why - if !healthy && isDeploy { + if !healthy && isDeploy && !terminalDesiredState { for task, event := range trackerTaskEvents { if tr, ok := a.ar.tasks[task]; ok { // Append but don't emit event since the server diff --git a/client/allocrunner/taskrunner/logmon_hook.go b/client/allocrunner/taskrunner/logmon_hook.go index f983ddaa4..06617f686 100644 --- a/client/allocrunner/taskrunner/logmon_hook.go +++ b/client/allocrunner/taskrunner/logmon_hook.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/nomad/client/allocrunner/interfaces" "github.com/hashicorp/nomad/client/logmon" "github.com/hashicorp/nomad/helper/uuid" - "github.com/hashicorp/nomad/plugins/shared" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) // logmonHook launches logmon and manages task logging @@ -76,13 +76,13 @@ func reattachConfigFromHookData(data map[string]string) (*plugin.ReattachConfig, return nil, nil } - var cfg *shared.ReattachConfig + var cfg *pstructs.ReattachConfig err := json.Unmarshal([]byte(data["reattach_config"]), cfg) if err != nil { return nil, err } - return shared.ReattachConfigToGoPlugin(cfg) + return pstructs.ReattachConfigToGoPlugin(cfg) } func (h *logmonHook) Prestart(ctx context.Context, @@ -117,7 +117,7 @@ func (h *logmonHook) Prestart(ctx context.Context, } } - rCfg := shared.ReattachConfigFromGoPlugin(h.logmonPluginClient.ReattachConfig()) + rCfg := pstructs.ReattachConfigFromGoPlugin(h.logmonPluginClient.ReattachConfig()) jsonCfg, err := json.Marshal(rCfg) if err != nil { return err diff --git a/client/allocrunner/taskrunner/stats_hook.go b/client/allocrunner/taskrunner/stats_hook.go index 4d0e0bc1c..e227f9524 100644 --- a/client/allocrunner/taskrunner/stats_hook.go +++ b/client/allocrunner/taskrunner/stats_hook.go @@ -143,12 +143,8 @@ func (h *statsHook) collectResourceUsageStats(ctx context.Context, handle interf // Update stats on TaskRunner and emit them h.updater.UpdateStats(ru) - default: - select { - case <-ctx.Done(): - return - default: - } + case <-ctx.Done(): + return } } } diff --git a/client/allocrunner/taskrunner/task_runner.go b/client/allocrunner/taskrunner/task_runner.go index 5ee294ffe..153999069 100644 --- a/client/allocrunner/taskrunner/task_runner.go +++ b/client/allocrunner/taskrunner/task_runner.go @@ -26,12 +26,12 @@ import ( cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/client/vaultclient" + "github.com/hashicorp/nomad/helper/pluginutils/hclspecutils" + "github.com/hashicorp/nomad/helper/pluginutils/hclutils" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/structs" bstructs "github.com/hashicorp/nomad/plugins/base/structs" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/hclutils" ) const ( @@ -697,7 +697,7 @@ func (tr *TaskRunner) initDriver() error { if err != nil { return err } - spec, diag := hclspec.Convert(schema) + spec, diag := hclspecutils.Convert(schema) if diag.HasErrors() { return multierror.Append(errors.New("failed to convert task schema"), diag.Errs()...) } diff --git a/client/allocwatcher/alloc_watcher.go b/client/allocwatcher/alloc_watcher.go index 192a9a0f0..35d395402 100644 --- a/client/allocwatcher/alloc_watcher.go +++ b/client/allocwatcher/alloc_watcher.go @@ -12,7 +12,7 @@ import ( "time" "github.com/hashicorp/consul/lib" - "github.com/hashicorp/go-hclog" + hclog "github.com/hashicorp/go-hclog" nomadapi "github.com/hashicorp/nomad/api" "github.com/hashicorp/nomad/client/allocdir" "github.com/hashicorp/nomad/client/config" diff --git a/client/client_test.go b/client/client_test.go index d94b00bef..a2f0b8e6a 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -9,11 +9,12 @@ import ( "testing" "time" - "github.com/hashicorp/go-memdb" + memdb "github.com/hashicorp/go-memdb" "github.com/hashicorp/nomad/client/config" consulApi "github.com/hashicorp/nomad/client/consul" "github.com/hashicorp/nomad/client/fingerprint" "github.com/hashicorp/nomad/command/agent/consul" + "github.com/hashicorp/nomad/helper/pluginutils/catalog" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad" @@ -21,12 +22,11 @@ import ( "github.com/hashicorp/nomad/nomad/structs" nconfig "github.com/hashicorp/nomad/nomad/structs/config" "github.com/hashicorp/nomad/plugins/device" - "github.com/hashicorp/nomad/plugins/shared/catalog" psstructs "github.com/hashicorp/nomad/plugins/shared/structs" "github.com/hashicorp/nomad/testutil" "github.com/stretchr/testify/assert" - "github.com/hashicorp/go-hclog" + hclog "github.com/hashicorp/go-hclog" cstate "github.com/hashicorp/nomad/client/state" ctestutil "github.com/hashicorp/nomad/client/testutil" "github.com/stretchr/testify/require" diff --git a/client/config/config.go b/client/config/config.go index eb8408e78..287d8826d 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -11,10 +11,10 @@ import ( log "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/client/state" "github.com/hashicorp/nomad/helper" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/nomad/structs/config" "github.com/hashicorp/nomad/plugins/base" - "github.com/hashicorp/nomad/plugins/shared/loader" "github.com/hashicorp/nomad/version" ) diff --git a/client/config/testing.go b/client/config/testing.go index 1097e5bcd..8966ac831 100644 --- a/client/config/testing.go +++ b/client/config/testing.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/mock" - "github.com/mitchellh/go-testing-interface" + testing "github.com/mitchellh/go-testing-interface" ) // TestClientConfig returns a default client configuration for test clients and diff --git a/client/devicemanager/instance.go b/client/devicemanager/instance.go index 0837abf10..3119f7207 100644 --- a/client/devicemanager/instance.go +++ b/client/devicemanager/instance.go @@ -8,12 +8,12 @@ import ( log "github.com/hashicorp/go-hclog" multierror "github.com/hashicorp/go-multierror" + "github.com/hashicorp/nomad/helper/pluginutils/loader" + "github.com/hashicorp/nomad/helper/pluginutils/singleton" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/base" bstructs "github.com/hashicorp/nomad/plugins/base/structs" "github.com/hashicorp/nomad/plugins/device" - "github.com/hashicorp/nomad/plugins/shared/loader" - "github.com/hashicorp/nomad/plugins/shared/singleton" ) const ( diff --git a/client/devicemanager/manager.go b/client/devicemanager/manager.go index 86bc0eca3..d2dad3972 100644 --- a/client/devicemanager/manager.go +++ b/client/devicemanager/manager.go @@ -12,11 +12,11 @@ import ( plugin "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/devicemanager/state" "github.com/hashicorp/nomad/client/pluginmanager" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/device" - "github.com/hashicorp/nomad/plugins/shared" - "github.com/hashicorp/nomad/plugins/shared/loader" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) // Manager is the interface used to manage device plugins @@ -103,7 +103,7 @@ type manager struct { instances map[loader.PluginID]*instanceManager // reattachConfigs stores the plugin reattach configs - reattachConfigs map[loader.PluginID]*shared.ReattachConfig + reattachConfigs map[loader.PluginID]*pstructs.ReattachConfig reattachConfigLock sync.Mutex } @@ -119,7 +119,7 @@ func New(c *Config) *manager { pluginConfig: c.PluginConfig, updater: c.Updater, instances: make(map[loader.PluginID]*instanceManager), - reattachConfigs: make(map[loader.PluginID]*shared.ReattachConfig), + reattachConfigs: make(map[loader.PluginID]*pstructs.ReattachConfig), fingerprintResCh: make(chan struct{}, 1), } } @@ -280,7 +280,7 @@ func (m *manager) cleanupStalePlugins() error { // For each plugin go through and try to shut it down var mErr multierror.Error for name, c := range s.ReattachConfigs { - rc, err := shared.ReattachConfigToGoPlugin(c) + rc, err := pstructs.ReattachConfigToGoPlugin(c) if err != nil { multierror.Append(&mErr, fmt.Errorf("failed to convert reattach config: %v", err)) continue @@ -306,11 +306,11 @@ func (m *manager) storePluginReattachConfig(id loader.PluginID, c *plugin.Reatta defer m.reattachConfigLock.Unlock() // Store the new reattach config - m.reattachConfigs[id] = shared.ReattachConfigFromGoPlugin(c) + m.reattachConfigs[id] = pstructs.ReattachConfigFromGoPlugin(c) // Persist the state s := &state.PluginState{ - ReattachConfigs: make(map[string]*shared.ReattachConfig, len(m.reattachConfigs)), + ReattachConfigs: make(map[string]*pstructs.ReattachConfig, len(m.reattachConfigs)), } for id, c := range m.reattachConfigs { diff --git a/client/devicemanager/manager_test.go b/client/devicemanager/manager_test.go index ac82be354..044fb6f26 100644 --- a/client/devicemanager/manager_test.go +++ b/client/devicemanager/manager_test.go @@ -11,12 +11,12 @@ import ( plugin "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/state" "github.com/hashicorp/nomad/helper" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/device" - "github.com/hashicorp/nomad/plugins/shared/loader" psstructs "github.com/hashicorp/nomad/plugins/shared/structs" "github.com/hashicorp/nomad/testutil" "github.com/stretchr/testify/require" diff --git a/client/devicemanager/state/state.go b/client/devicemanager/state/state.go index 003c554c0..e74be11ac 100644 --- a/client/devicemanager/state/state.go +++ b/client/devicemanager/state/state.go @@ -1,11 +1,11 @@ package state -import "github.com/hashicorp/nomad/plugins/shared" +import pstructs "github.com/hashicorp/nomad/plugins/shared/structs" // PluginState is used to store the device managers state across restarts of the // agent type PluginState struct { // ReattachConfigs are the set of reattach configs for plugin's launched by // the device manager - ReattachConfigs map[string]*shared.ReattachConfig + ReattachConfigs map[string]*pstructs.ReattachConfig } diff --git a/client/fingerprint/env_aws.go b/client/fingerprint/env_aws.go index ba7d2cbf8..28bc7e9f5 100644 --- a/client/fingerprint/env_aws.go +++ b/client/fingerprint/env_aws.go @@ -12,7 +12,7 @@ import ( log "github.com/hashicorp/go-hclog" - "github.com/hashicorp/go-cleanhttp" + cleanhttp "github.com/hashicorp/go-cleanhttp" "github.com/hashicorp/nomad/nomad/structs" ) diff --git a/client/fingerprint/env_gce.go b/client/fingerprint/env_gce.go index 4d0f7f13d..a197f3f5a 100644 --- a/client/fingerprint/env_gce.go +++ b/client/fingerprint/env_gce.go @@ -12,9 +12,9 @@ import ( "strings" "time" + cleanhttp "github.com/hashicorp/go-cleanhttp" log "github.com/hashicorp/go-hclog" - "github.com/hashicorp/go-cleanhttp" "github.com/hashicorp/nomad/helper/useragent" "github.com/hashicorp/nomad/nomad/structs" ) diff --git a/client/fingerprint_manager.go b/client/fingerprint_manager.go index 03a2b3ca9..84efed5bc 100644 --- a/client/fingerprint_manager.go +++ b/client/fingerprint_manager.go @@ -7,8 +7,8 @@ import ( log "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/client/config" "github.com/hashicorp/nomad/client/fingerprint" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/nomad/structs" - "github.com/hashicorp/nomad/plugins/shared/loader" ) // FingerprintManager runs a client fingerprinters on a continuous basis, and diff --git a/client/pluginmanager/drivermanager/instance.go b/client/pluginmanager/drivermanager/instance.go index 59a8541c3..e04e50b4d 100644 --- a/client/pluginmanager/drivermanager/instance.go +++ b/client/pluginmanager/drivermanager/instance.go @@ -7,12 +7,12 @@ import ( "time" log "github.com/hashicorp/go-hclog" + "github.com/hashicorp/nomad/helper/pluginutils/loader" + "github.com/hashicorp/nomad/helper/pluginutils/singleton" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/base" bstructs "github.com/hashicorp/nomad/plugins/base/structs" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared/loader" - "github.com/hashicorp/nomad/plugins/shared/singleton" ) const ( diff --git a/client/pluginmanager/drivermanager/manager.go b/client/pluginmanager/drivermanager/manager.go index 9c8c6af80..ab3722c41 100644 --- a/client/pluginmanager/drivermanager/manager.go +++ b/client/pluginmanager/drivermanager/manager.go @@ -9,11 +9,11 @@ import ( plugin "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/pluginmanager" "github.com/hashicorp/nomad/client/pluginmanager/drivermanager/state" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" - "github.com/hashicorp/nomad/plugins/shared/loader" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) // ErrDriverNotFound is returned during Dispense when the requested driver @@ -117,7 +117,7 @@ type manager struct { instancesMu sync.RWMutex // reattachConfigs stores the plugin reattach configs - reattachConfigs map[loader.PluginID]*shared.ReattachConfig + reattachConfigs map[loader.PluginID]*pstructs.ReattachConfig reattachConfigLock sync.Mutex // allows/block lists @@ -141,7 +141,7 @@ func New(c *Config) *manager { updater: c.Updater, eventHandlerFactory: c.EventHandlerFactory, instances: make(map[string]*instanceManager), - reattachConfigs: make(map[loader.PluginID]*shared.ReattachConfig), + reattachConfigs: make(map[loader.PluginID]*pstructs.ReattachConfig), allowedDrivers: c.AllowedDrivers, blockedDrivers: c.BlockedDrivers, readyCh: make(chan struct{}), @@ -296,8 +296,8 @@ func (m *manager) loadReattachConfigs() error { // shutdownBlockedDriver is used to forcefully shutdown a running driver plugin // when it has been blocked due to allow/block lists -func (m *manager) shutdownBlockedDriver(name string, reattach *shared.ReattachConfig) { - c, err := shared.ReattachConfigToGoPlugin(reattach) +func (m *manager) shutdownBlockedDriver(name string, reattach *pstructs.ReattachConfig) { + c, err := pstructs.ReattachConfigToGoPlugin(reattach) if err != nil { m.logger.Warn("failed to reattach and kill blocked driver plugin", "driver", name, "error", err) @@ -323,11 +323,11 @@ func (m *manager) storePluginReattachConfig(id loader.PluginID, c *plugin.Reatta defer m.reattachConfigLock.Unlock() // Store the new reattach config - m.reattachConfigs[id] = shared.ReattachConfigFromGoPlugin(c) + m.reattachConfigs[id] = pstructs.ReattachConfigFromGoPlugin(c) // Persist the state s := &state.PluginState{ - ReattachConfigs: make(map[string]*shared.ReattachConfig, len(m.reattachConfigs)), + ReattachConfigs: make(map[string]*pstructs.ReattachConfig, len(m.reattachConfigs)), } for id, c := range m.reattachConfigs { @@ -345,7 +345,7 @@ func (m *manager) fetchPluginReattachConfig(id loader.PluginID) (*plugin.Reattac defer m.reattachConfigLock.Unlock() if cfg, ok := m.reattachConfigs[id]; ok { - c, err := shared.ReattachConfigToGoPlugin(cfg) + c, err := pstructs.ReattachConfigToGoPlugin(cfg) if err != nil { m.logger.Warn("failed to read plugin reattach config", "config", cfg, "error", err) delete(m.reattachConfigs, id) diff --git a/client/pluginmanager/drivermanager/manager_test.go b/client/pluginmanager/drivermanager/manager_test.go index 3e8de7014..5b44b9bfe 100644 --- a/client/pluginmanager/drivermanager/manager_test.go +++ b/client/pluginmanager/drivermanager/manager_test.go @@ -11,12 +11,12 @@ import ( plugin "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/pluginmanager" "github.com/hashicorp/nomad/client/state" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" dtu "github.com/hashicorp/nomad/plugins/drivers/testutils" - "github.com/hashicorp/nomad/plugins/shared/loader" "github.com/hashicorp/nomad/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/client/pluginmanager/drivermanager/state/state.go b/client/pluginmanager/drivermanager/state/state.go index 53be7616e..529499cff 100644 --- a/client/pluginmanager/drivermanager/state/state.go +++ b/client/pluginmanager/drivermanager/state/state.go @@ -1,11 +1,11 @@ package state -import "github.com/hashicorp/nomad/plugins/shared" +import pstructs "github.com/hashicorp/nomad/plugins/shared/structs" // PluginState is used to store the driver managers state across restarts of the // agent type PluginState struct { // ReattachConfigs are the set of reattach configs for plugin's launched by // the driver manager - ReattachConfigs map[string]*shared.ReattachConfig + ReattachConfigs map[string]*pstructs.ReattachConfig } diff --git a/client/pluginmanager/drivermanager/testing.go b/client/pluginmanager/drivermanager/testing.go index e26af558f..080bf1c2d 100644 --- a/client/pluginmanager/drivermanager/testing.go +++ b/client/pluginmanager/drivermanager/testing.go @@ -7,12 +7,12 @@ import ( "testing" log "github.com/hashicorp/go-hclog" + "github.com/hashicorp/nomad/helper/pluginutils/catalog" + "github.com/hashicorp/nomad/helper/pluginutils/loader" + "github.com/hashicorp/nomad/helper/pluginutils/singleton" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared/catalog" - "github.com/hashicorp/nomad/plugins/shared/loader" - "github.com/hashicorp/nomad/plugins/shared/singleton" ) type testManager struct { diff --git a/client/state/08types.go b/client/state/08types.go index 3d4cf209d..95acd7328 100644 --- a/client/state/08types.go +++ b/client/state/08types.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/nomad/client/allocrunner/taskrunner/state" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) // allocRunnerMutableState08 is state that had to be written on each save as it @@ -62,8 +62,8 @@ type TaskRunnerHandle08 struct { } `json:"PluginConfig"` } -func (t *TaskRunnerHandle08) ReattachConfig() *shared.ReattachConfig { - return &shared.ReattachConfig{ +func (t *TaskRunnerHandle08) ReattachConfig() *pstructs.ReattachConfig { + return &pstructs.ReattachConfig{ Network: t.PluginConfig.AddrNet, Addr: t.PluginConfig.AddrName, Pid: t.PluginConfig.Pid, diff --git a/client/state/upgrade_int_test.go b/client/state/upgrade_int_test.go index 436bca413..f81e371bf 100644 --- a/client/state/upgrade_int_test.go +++ b/client/state/upgrade_int_test.go @@ -22,7 +22,7 @@ import ( "github.com/hashicorp/nomad/helper/boltdd" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" - "github.com/hashicorp/nomad/plugins/shared" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -103,7 +103,7 @@ func TestBoltStateDB_UpgradeOld_Ok(t *testing.T) { require.Nil(t, ps) ps = &dmstate.PluginState{ - ReattachConfigs: map[string]*shared.ReattachConfig{ + ReattachConfigs: map[string]*pstructs.ReattachConfig{ "test": {Pid: 1}, }, } diff --git a/client/testing.go b/client/testing.go index 1a4ab5d13..8b881c0e9 100644 --- a/client/testing.go +++ b/client/testing.go @@ -8,9 +8,9 @@ import ( consulApi "github.com/hashicorp/nomad/client/consul" "github.com/hashicorp/nomad/client/fingerprint" "github.com/hashicorp/nomad/command/agent/consul" + "github.com/hashicorp/nomad/helper/pluginutils/catalog" + "github.com/hashicorp/nomad/helper/pluginutils/singleton" "github.com/hashicorp/nomad/helper/testlog" - "github.com/hashicorp/nomad/plugins/shared/catalog" - "github.com/hashicorp/nomad/plugins/shared/singleton" testing "github.com/mitchellh/go-testing-interface" ) diff --git a/client/vaultclient/vaultclient.go b/client/vaultclient/vaultclient.go index 8d9dff28d..2adcec105 100644 --- a/client/vaultclient/vaultclient.go +++ b/client/vaultclient/vaultclient.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/armon/go-metrics" + metrics "github.com/armon/go-metrics" hclog "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/nomad/structs/config" diff --git a/command/agent/agent.go b/command/agent/agent.go index 34588c341..b9ecbd0f4 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -23,11 +23,11 @@ import ( clientconfig "github.com/hashicorp/nomad/client/config" "github.com/hashicorp/nomad/client/state" "github.com/hashicorp/nomad/command/agent/consul" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/nomad/structs/config" - "github.com/hashicorp/nomad/plugins/shared/loader" "github.com/hashicorp/raft" ) diff --git a/command/agent/bindata_assetfs.go b/command/agent/bindata_assetfs.go index 6c0c1c63c..4ef264459 100644 --- a/command/agent/bindata_assetfs.go +++ b/command/agent/bindata_assetfs.go @@ -26,13 +26,8 @@ import ( "compress/gzip" "fmt" "io" - "io/ioutil" "os" - "path/filepath" - "strings" "time" - - "github.com/elazarl/go-bindata-assetfs" ) func bindataRead(data []byte, name string) ([]byte, error) { diff --git a/command/agent/command.go b/command/agent/command.go index 39998a7ea..47da7e272 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -15,18 +15,18 @@ import ( "syscall" "time" - "github.com/armon/go-metrics" + metrics "github.com/armon/go-metrics" "github.com/armon/go-metrics/circonus" "github.com/armon/go-metrics/datadog" "github.com/armon/go-metrics/prometheus" "github.com/hashicorp/consul/lib" - "github.com/hashicorp/go-checkpoint" - "github.com/hashicorp/go-discover" - "github.com/hashicorp/go-syslog" + checkpoint "github.com/hashicorp/go-checkpoint" + discover "github.com/hashicorp/go-discover" + gsyslog "github.com/hashicorp/go-syslog" "github.com/hashicorp/logutils" "github.com/hashicorp/nomad/helper" - "github.com/hashicorp/nomad/helper/flag-helpers" - "github.com/hashicorp/nomad/helper/gated-writer" + flaghelper "github.com/hashicorp/nomad/helper/flag-helpers" + gatedwriter "github.com/hashicorp/nomad/helper/gated-writer" "github.com/hashicorp/nomad/nomad/structs/config" "github.com/hashicorp/nomad/version" "github.com/mitchellh/cli" diff --git a/command/agent/plugins.go b/command/agent/plugins.go index 0cc73a816..8f96d471d 100644 --- a/command/agent/plugins.go +++ b/command/agent/plugins.go @@ -3,9 +3,9 @@ package agent import ( "fmt" - "github.com/hashicorp/nomad/plugins/shared/catalog" - "github.com/hashicorp/nomad/plugins/shared/loader" - "github.com/hashicorp/nomad/plugins/shared/singleton" + "github.com/hashicorp/nomad/helper/pluginutils/catalog" + "github.com/hashicorp/nomad/helper/pluginutils/loader" + "github.com/hashicorp/nomad/helper/pluginutils/singleton" ) // setupPlugins is used to setup the plugin loaders. diff --git a/command/agent/syslog.go b/command/agent/syslog.go index 7acc5679f..90b44742f 100644 --- a/command/agent/syslog.go +++ b/command/agent/syslog.go @@ -3,7 +3,7 @@ package agent import ( "bytes" - "github.com/hashicorp/go-syslog" + gsyslog "github.com/hashicorp/go-syslog" "github.com/hashicorp/logutils" ) diff --git a/command/agent/syslog_test.go b/command/agent/syslog_test.go index 39ee0eee4..37c4e6fff 100644 --- a/command/agent/syslog_test.go +++ b/command/agent/syslog_test.go @@ -5,7 +5,7 @@ import ( "runtime" "testing" - "github.com/hashicorp/go-syslog" + gsyslog "github.com/hashicorp/go-syslog" "github.com/hashicorp/logutils" ) diff --git a/command/agent/testagent.go b/command/agent/testagent.go index 87219fcee..b8d5f55a7 100644 --- a/command/agent/testagent.go +++ b/command/agent/testagent.go @@ -13,7 +13,7 @@ import ( "strings" "time" - "github.com/mitchellh/go-testing-interface" + testing "github.com/mitchellh/go-testing-interface" metrics "github.com/armon/go-metrics" "github.com/hashicorp/consul/lib/freeport" diff --git a/command/node_status.go b/command/node_status.go index e07bb47e8..934ef2f97 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -530,6 +530,9 @@ func (c *NodeStatusCommand) formatAttributes(node *api.Node) { } func (c *NodeStatusCommand) formatDeviceAttributes(node *api.Node) { + if node.NodeResources == nil { + return + } devices := node.NodeResources.Devices if len(devices) == 0 { return diff --git a/drivers/docker/config.go b/drivers/docker/config.go index 0398137e0..10776eef2 100644 --- a/drivers/docker/config.go +++ b/drivers/docker/config.go @@ -8,10 +8,10 @@ import ( docker "github.com/fsouza/go-dockerclient" hclog "github.com/hashicorp/go-hclog" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/loader" ) const ( diff --git a/drivers/docker/driver.go b/drivers/docker/driver.go index e3059fe62..b83f38678 100644 --- a/drivers/docker/driver.go +++ b/drivers/docker/driver.go @@ -23,7 +23,7 @@ import ( nstructs "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) var ( @@ -138,7 +138,7 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error { return fmt.Errorf("failed to inspect container for id %q: %v", handleState.ContainerID, err) } - reattach, err := shared.ReattachConfigToGoPlugin(handleState.ReattachConfig) + reattach, err := pstructs.ReattachConfigToGoPlugin(handleState.ReattachConfig) if err != nil { return err } diff --git a/drivers/docker/driver_pre09.go b/drivers/docker/driver_pre09.go index b227feff8..9e34b8a03 100644 --- a/drivers/docker/driver_pre09.go +++ b/drivers/docker/driver_pre09.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { @@ -17,7 +17,7 @@ func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { return fmt.Errorf("failed to decode pre09 driver handle: %v", err) } - reattach, err := shared.ReattachConfigToGoPlugin(handle.ReattachConfig()) + reattach, err := pstructs.ReattachConfigToGoPlugin(handle.ReattachConfig()) if err != nil { return fmt.Errorf("failed to decode reattach config from pre09 handle: %v", err) } diff --git a/drivers/docker/driver_test.go b/drivers/docker/driver_test.go index 47c0cfc70..c3b4f9dbf 100644 --- a/drivers/docker/driver_test.go +++ b/drivers/docker/driver_test.go @@ -19,13 +19,13 @@ import ( "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/client/testutil" "github.com/hashicorp/nomad/devices/gpu/nvidia" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" dtestutil "github.com/hashicorp/nomad/plugins/drivers/testutils" - "github.com/hashicorp/nomad/plugins/shared/loader" tu "github.com/hashicorp/nomad/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/drivers/docker/handle.go b/drivers/docker/handle.go index 219aea403..891c0eeba 100644 --- a/drivers/docker/handle.go +++ b/drivers/docker/handle.go @@ -14,7 +14,7 @@ import ( plugin "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/drivers/docker/docklog" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" "golang.org/x/net/context" ) @@ -44,7 +44,7 @@ func (h *taskHandle) ExitResult() *drivers.ExitResult { type taskHandleState struct { // ReattachConfig for the docker logger plugin - ReattachConfig *shared.ReattachConfig + ReattachConfig *pstructs.ReattachConfig ContainerID string DriverNetwork *drivers.DriverNetwork @@ -52,7 +52,7 @@ type taskHandleState struct { func (h *taskHandle) buildState() *taskHandleState { return &taskHandleState{ - ReattachConfig: shared.ReattachConfigFromGoPlugin(h.dloggerPluginClient.ReattachConfig()), + ReattachConfig: pstructs.ReattachConfigFromGoPlugin(h.dloggerPluginClient.ReattachConfig()), ContainerID: h.containerID, DriverNetwork: h.net, } diff --git a/drivers/exec/driver.go b/drivers/exec/driver.go index 2f8880895..eca6e213b 100644 --- a/drivers/exec/driver.go +++ b/drivers/exec/driver.go @@ -15,12 +15,11 @@ import ( "github.com/hashicorp/nomad/drivers/shared/eventer" "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/helper" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/drivers/utils" - "github.com/hashicorp/nomad/plugins/shared" "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/loader" pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) @@ -118,7 +117,7 @@ type TaskConfig struct { // StartTask. This information is needed to rebuild the task state and handler // during recovery. type TaskState struct { - ReattachConfig *shared.ReattachConfig + ReattachConfig *pstructs.ReattachConfig TaskConfig *drivers.TaskConfig Pid int StartedAt time.Time @@ -280,7 +279,7 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error { } // Create client for reattached executor - plugRC, err := shared.ReattachConfigToGoPlugin(taskState.ReattachConfig) + plugRC, err := pstructs.ReattachConfigToGoPlugin(taskState.ReattachConfig) if err != nil { d.logger.Error("failed to build ReattachConfig from task state", "error", err, "task_id", handle.Config.ID) return fmt.Errorf("failed to build ReattachConfig from task state: %v", err) @@ -373,7 +372,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive } driverState := TaskState{ - ReattachConfig: shared.ReattachConfigFromGoPlugin(pluginClient.ReattachConfig()), + ReattachConfig: pstructs.ReattachConfigFromGoPlugin(pluginClient.ReattachConfig()), Pid: ps.Pid, TaskConfig: cfg, StartedAt: h.startedAt, diff --git a/drivers/exec/driver_pre09.go b/drivers/exec/driver_pre09.go index 2f7f65e3f..a81835194 100644 --- a/drivers/exec/driver_pre09.go +++ b/drivers/exec/driver_pre09.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { @@ -17,7 +17,7 @@ func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { return fmt.Errorf("failed to decode pre09 driver handle: %v", err) } - reattach, err := shared.ReattachConfigToGoPlugin(handle.ReattachConfig()) + reattach, err := pstructs.ReattachConfigToGoPlugin(handle.ReattachConfig()) if err != nil { return fmt.Errorf("failed to decode reattach config from pre09 handle: %v", err) } diff --git a/drivers/exec/driver_test.go b/drivers/exec/driver_test.go index 9e35ec966..b53b359fa 100644 --- a/drivers/exec/driver_test.go +++ b/drivers/exec/driver_test.go @@ -13,7 +13,6 @@ import ( "testing" "time" - "github.com/hashicorp/hcl2/hcl" ctestutils "github.com/hashicorp/nomad/client/testutil" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/testtask" @@ -21,8 +20,6 @@ import ( "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/drivers" dtestutil "github.com/hashicorp/nomad/plugins/drivers/testutils" - "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/hclutils" "github.com/hashicorp/nomad/testutil" "github.com/stretchr/testify/require" ) @@ -103,11 +100,11 @@ func TestExecDriver_StartWait(t *testing.T) { Resources: testResources, } - taskConfig := map[string]interface{}{ - "command": "cat", - "args": []string{"/proc/self/cgroup"}, + tc := &TaskConfig{ + Command: "cat", + Args: []string{"/proc/self/cgroup"}, } - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) cleanup := harness.MkAllocDir(task, false) defer cleanup() @@ -135,11 +132,11 @@ func TestExecDriver_StartWaitStopKill(t *testing.T) { Resources: testResources, } - taskConfig := map[string]interface{}{ - "command": "/bin/bash", - "args": []string{"-c", "echo hi; sleep 600"}, + tc := &TaskConfig{ + Command: "/bin/bash", + Args: []string{"-c", "echo hi; sleep 600"}, } - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) cleanup := harness.MkAllocDir(task, false) defer cleanup() @@ -196,11 +193,11 @@ func TestExecDriver_StartWaitRecover(t *testing.T) { Resources: testResources, } - taskConfig := map[string]interface{}{ - "command": "/bin/sleep", - "args": []string{"5"}, + tc := &TaskConfig{ + Command: "/bin/sleep", + Args: []string{"5"}, } - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) cleanup := harness.MkAllocDir(task, false) defer cleanup() @@ -266,11 +263,11 @@ func TestExecDriver_Stats(t *testing.T) { Resources: testResources, } - taskConfig := map[string]interface{}{ - "command": "/bin/sleep", - "args": []string{"5"}, + tc := &TaskConfig{ + Command: "/bin/sleep", + Args: []string{"5"}, } - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) cleanup := harness.MkAllocDir(task, false) defer cleanup() @@ -311,14 +308,14 @@ func TestExecDriver_Start_Wait_AllocDir(t *testing.T) { exp := []byte{'w', 'i', 'n'} file := "output.txt" - taskConfig := map[string]interface{}{ - "command": "/bin/bash", - "args": []string{ + tc := &TaskConfig{ + Command: "/bin/bash", + Args: []string{ "-c", fmt.Sprintf(`sleep 1; echo -n %s > /alloc/%s`, string(exp), file), }, } - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) handle, _, err := harness.StartTask(task) require.NoError(err) @@ -359,11 +356,11 @@ func TestExecDriver_User(t *testing.T) { cleanup := harness.MkAllocDir(task, false) defer cleanup() - taskConfig := map[string]interface{}{ - "command": "/bin/sleep", - "args": []string{"100"}, + tc := &TaskConfig{ + Command: "/bin/sleep", + Args: []string{"100"}, } - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) handle, _, err := harness.StartTask(task) require.Error(err) @@ -392,11 +389,11 @@ func TestExecDriver_HandlerExec(t *testing.T) { cleanup := harness.MkAllocDir(task, false) defer cleanup() - taskConfig := map[string]interface{}{ - "command": "/bin/sleep", - "args": []string{"9000"}, + tc := &TaskConfig{ + Command: "/bin/sleep", + Args: []string{"9000"}, } - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) handle, _, err := harness.StartTask(task) require.NoError(err) @@ -502,9 +499,9 @@ func TestExecDriver_DevicesAndMounts(t *testing.T) { require.NoError(ioutil.WriteFile(task.StdoutPath, []byte{}, 660)) require.NoError(ioutil.WriteFile(task.StderrPath, []byte{}, 660)) - taskConfig := map[string]interface{}{ - "command": "/bin/bash", - "args": []string{"-c", ` + tc := &TaskConfig{ + Command: "/bin/bash", + Args: []string{"-c", ` export LANG=en.UTF-8 echo "mounted device /inserted-random: $(stat -c '%t:%T' /dev/inserted-random)" echo "reading from ro path: $(cat /tmp/task-path-ro/testfile)" @@ -516,7 +513,7 @@ touch /tmp/task-path-ro/testfile-from-ro && echo from-exec > /tmp/task-path-ro/ exit 0 `}, } - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) cleanup := harness.MkAllocDir(task, false) defer cleanup() @@ -549,15 +546,3 @@ touch: cannot touch '/tmp/task-path-ro/testfile-from-ro': Read-only file system` require.NoError(err) require.Equal("from-exec", strings.TrimSpace(string(fromRWContent))) } - -func encodeDriverHelper(require *require.Assertions, task *drivers.TaskConfig, taskConfig map[string]interface{}) { - evalCtx := &hcl.EvalContext{ - Functions: hclutils.GetStdlibFuncs(), - } - spec, diag := hclspec.Convert(taskConfigSpec) - require.False(diag.HasErrors()) - taskConfigCtyVal, diag := hclutils.ParseHclInterface(taskConfig, spec, evalCtx) - require.False(diag.HasErrors()) - err := task.EncodeDriverConfig(taskConfigCtyVal) - require.Nil(err) -} diff --git a/drivers/exec/driver_unix_test.go b/drivers/exec/driver_unix_test.go index 6de52e6cb..3d2844ba7 100644 --- a/drivers/exec/driver_unix_test.go +++ b/drivers/exec/driver_unix_test.go @@ -35,7 +35,7 @@ func TestExecDriver_StartWaitStop(t *testing.T) { "command": "/bin/sleep", "args": []string{"600"}, } - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&taskConfig)) cleanup := harness.MkAllocDir(task, false) defer cleanup() diff --git a/drivers/java/driver.go b/drivers/java/driver.go index 6c5c2e13e..5a8a6a41a 100644 --- a/drivers/java/driver.go +++ b/drivers/java/driver.go @@ -14,12 +14,11 @@ import ( "github.com/hashicorp/nomad/client/fingerprint" "github.com/hashicorp/nomad/drivers/shared/eventer" "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/drivers/utils" - "github.com/hashicorp/nomad/plugins/shared" "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/loader" pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) @@ -108,7 +107,7 @@ type TaskConfig struct { // StartTask. This information is needed to rebuild the taskConfig state and handler // during recovery. type TaskState struct { - ReattachConfig *shared.ReattachConfig + ReattachConfig *pstructs.ReattachConfig TaskConfig *drivers.TaskConfig Pid int StartedAt time.Time @@ -266,7 +265,7 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error { return fmt.Errorf("failed to decode taskConfig state from handle: %v", err) } - plugRC, err := shared.ReattachConfigToGoPlugin(taskState.ReattachConfig) + plugRC, err := pstructs.ReattachConfigToGoPlugin(taskState.ReattachConfig) if err != nil { d.logger.Error("failed to build ReattachConfig from taskConfig state", "error", err, "task_id", handle.Config.ID) return fmt.Errorf("failed to build ReattachConfig from taskConfig state: %v", err) @@ -371,7 +370,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive } driverState := TaskState{ - ReattachConfig: shared.ReattachConfigFromGoPlugin(pluginClient.ReattachConfig()), + ReattachConfig: pstructs.ReattachConfigFromGoPlugin(pluginClient.ReattachConfig()), Pid: ps.Pid, TaskConfig: cfg, StartedAt: h.startedAt, diff --git a/drivers/java/driver_pre09.go b/drivers/java/driver_pre09.go index a8061e5e5..6682f9fa1 100644 --- a/drivers/java/driver_pre09.go +++ b/drivers/java/driver_pre09.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { @@ -17,7 +17,7 @@ func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { return fmt.Errorf("failed to decode pre09 driver handle: %v", err) } - reattach, err := shared.ReattachConfigToGoPlugin(handle.ReattachConfig()) + reattach, err := pstructs.ReattachConfigToGoPlugin(handle.ReattachConfig()) if err != nil { return fmt.Errorf("failed to decode reattach config from pre09 handle: %v", err) } diff --git a/drivers/java/driver_test.go b/drivers/java/driver_test.go index ce0ab2221..7833106a6 100644 --- a/drivers/java/driver_test.go +++ b/drivers/java/driver_test.go @@ -13,14 +13,11 @@ import ( "context" "time" - "github.com/hashicorp/hcl2/hcl" ctestutil "github.com/hashicorp/nomad/client/testutil" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/hclutils" "github.com/hashicorp/nomad/testutil" "github.com/stretchr/testify/require" ) @@ -66,11 +63,12 @@ func TestJavaDriver_Jar_Start_Wait(t *testing.T) { d := NewDriver(testlog.HCLogger(t)) harness := dtestutil.NewDriverHarness(t, d) - task := basicTask(t, "demo-app", map[string]interface{}{ - "jar_path": "demoapp.jar", - "args": []string{"1"}, - "jvm_options": []string{"-Xmx64m", "-Xms32m"}, - }) + tc := &TaskConfig{ + JarPath: "demoapp.jar", + Args: []string{"1"}, + JvmOpts: []string{"-Xmx64m", "-Xms32m"}, + } + task := basicTask(t, "demo-app", tc) cleanup := harness.MkAllocDir(task, true) defer cleanup() @@ -105,11 +103,12 @@ func TestJavaDriver_Jar_Stop_Wait(t *testing.T) { d := NewDriver(testlog.HCLogger(t)) harness := dtestutil.NewDriverHarness(t, d) - task := basicTask(t, "demo-app", map[string]interface{}{ - "jar_path": "demoapp.jar", - "args": []string{"600"}, - "jvm_options": []string{"-Xmx64m", "-Xms32m"}, - }) + tc := &TaskConfig{ + JarPath: "demoapp.jar", + Args: []string{"600"}, + JvmOpts: []string{"-Xmx64m", "-Xms32m"}, + } + task := basicTask(t, "demo-app", tc) cleanup := harness.MkAllocDir(task, true) defer cleanup() @@ -165,10 +164,11 @@ func TestJavaDriver_Class_Start_Wait(t *testing.T) { d := NewDriver(testlog.HCLogger(t)) harness := dtestutil.NewDriverHarness(t, d) - task := basicTask(t, "demo-app", map[string]interface{}{ - "class": "Hello", - "args": []string{"1"}, - }) + tc := &TaskConfig{ + Class: "Hello", + Args: []string{"1"}, + } + task := basicTask(t, "demo-app", tc) cleanup := harness.MkAllocDir(task, true) defer cleanup() @@ -242,7 +242,7 @@ func TestJavaCmdArgs(t *testing.T) { } } -func basicTask(t *testing.T, name string, taskConfig map[string]interface{}) *drivers.TaskConfig { +func basicTask(t *testing.T, name string, taskConfig *TaskConfig) *drivers.TaskConfig { t.Helper() task := &drivers.TaskConfig{ @@ -264,25 +264,10 @@ func basicTask(t *testing.T, name string, taskConfig map[string]interface{}) *dr }, } - encodeDriverHelper(t, task, taskConfig) + require.NoError(t, task.EncodeConcreteDriverConfig(&taskConfig)) return task } -func encodeDriverHelper(t *testing.T, task *drivers.TaskConfig, taskConfig map[string]interface{}) { - t.Helper() - - evalCtx := &hcl.EvalContext{ - Functions: hclutils.GetStdlibFuncs(), - } - spec, diag := hclspec.Convert(taskConfigSpec) - require.False(t, diag.HasErrors()) - taskConfigCtyVal, diag := hclutils.ParseHclInterface(taskConfig, spec, evalCtx) - require.Empty(t, diag.Errs()) - err := task.EncodeDriverConfig(taskConfigCtyVal) - require.Nil(t, err) - -} - // copyFile moves an existing file to the destination func copyFile(src, dst string, t *testing.T) { in, err := os.Open(src) diff --git a/drivers/java/handle.go b/drivers/java/handle.go index 8ef2dc6a0..e2d677365 100644 --- a/drivers/java/handle.go +++ b/drivers/java/handle.go @@ -6,8 +6,8 @@ import ( "sync" "time" - "github.com/hashicorp/go-hclog" - "github.com/hashicorp/go-plugin" + hclog "github.com/hashicorp/go-hclog" + plugin "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/plugins/drivers" ) diff --git a/drivers/mock/driver.go b/drivers/mock/driver.go index f80b81514..0f63d7302 100644 --- a/drivers/mock/driver.go +++ b/drivers/mock/driver.go @@ -12,11 +12,11 @@ import ( hclog "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/drivers/shared/eventer" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/loader" pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) diff --git a/drivers/qemu/driver.go b/drivers/qemu/driver.go index 8183222c3..65df76668 100644 --- a/drivers/qemu/driver.go +++ b/drivers/qemu/driver.go @@ -16,11 +16,10 @@ import ( hclog "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/drivers/shared/eventer" "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/loader" pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) @@ -118,7 +117,7 @@ type TaskConfig struct { // This information is needed to rebuild the taskConfig state and handler // during recovery. type TaskState struct { - ReattachConfig *shared.ReattachConfig + ReattachConfig *pstructs.ReattachConfig TaskConfig *drivers.TaskConfig Pid int StartedAt time.Time @@ -264,7 +263,7 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error { return fmt.Errorf("failed to decode taskConfig state from handle: %v", err) } - plugRC, err := shared.ReattachConfigToGoPlugin(taskState.ReattachConfig) + plugRC, err := pstructs.ReattachConfigToGoPlugin(taskState.ReattachConfig) if err != nil { d.logger.Error("failed to build ReattachConfig from taskConfig state", "error", err, "task_id", handle.Config.ID) return fmt.Errorf("failed to build ReattachConfig from taskConfig state: %v", err) @@ -456,7 +455,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive } qemuDriverState := TaskState{ - ReattachConfig: shared.ReattachConfigFromGoPlugin(pluginClient.ReattachConfig()), + ReattachConfig: pstructs.ReattachConfigFromGoPlugin(pluginClient.ReattachConfig()), Pid: ps.Pid, TaskConfig: cfg, StartedAt: h.startedAt, diff --git a/drivers/qemu/driver_pre09.go b/drivers/qemu/driver_pre09.go index 02b4e10b2..15ce5f39f 100644 --- a/drivers/qemu/driver_pre09.go +++ b/drivers/qemu/driver_pre09.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { @@ -17,7 +17,7 @@ func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { return fmt.Errorf("failed to decode pre09 driver handle: %v", err) } - reattach, err := shared.ReattachConfigToGoPlugin(handle.ReattachConfig()) + reattach, err := pstructs.ReattachConfigToGoPlugin(handle.ReattachConfig()) if err != nil { return fmt.Errorf("failed to decode reattach config from pre09 handle: %v", err) } diff --git a/drivers/qemu/driver_test.go b/drivers/qemu/driver_test.go index eea8562b2..01df3ae57 100644 --- a/drivers/qemu/driver_test.go +++ b/drivers/qemu/driver_test.go @@ -9,15 +9,12 @@ import ( "testing" "time" - "github.com/hashicorp/hcl2/hcl" ctestutil "github.com/hashicorp/nomad/client/testutil" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/drivers" dtestutil "github.com/hashicorp/nomad/plugins/drivers/testutils" - "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/hclutils" pstructs "github.com/hashicorp/nomad/plugins/shared/structs" "github.com/hashicorp/nomad/testutil" "github.com/stretchr/testify/require" @@ -57,17 +54,17 @@ func TestQemuDriver_Start_Wait_Stop(t *testing.T) { }, } - taskConfig := map[string]interface{}{ - "image_path": "linux-0.2.img", - "accelerator": "tcg", - "graceful_shutdown": false, - "port_map": []map[string]int{{ + tc := &TaskConfig{ + ImagePath: "linux-0.2.img", + Accelerator: "tcg", + GracefulShutdown: false, + PortMap: map[string]int{ "main": 22, "web": 8080, - }}, - "args": []string{"-nodefconfig", "-nodefaults"}, + }, + Args: []string{"-nodefconfig", "-nodefaults"}, } - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) cleanup := harness.MkAllocDir(task, true) defer cleanup() @@ -199,19 +196,6 @@ func TestQemuDriver_GetMonitorPathNewQemu(t *testing.T) { require.Nil(err) } -//encodeDriverhelper sets up the task config spec and encodes qemu specific driver configuration -func encodeDriverHelper(require *require.Assertions, task *drivers.TaskConfig, taskConfig map[string]interface{}) { - evalCtx := &hcl.EvalContext{ - Functions: hclutils.GetStdlibFuncs(), - } - spec, diag := hclspec.Convert(taskConfigSpec) - require.False(diag.HasErrors(), diag.Error()) - taskConfigCtyVal, diag := hclutils.ParseHclInterface(taskConfig, spec, evalCtx) - require.False(diag.HasErrors(), diag.Error()) - err := task.EncodeDriverConfig(taskConfigCtyVal) - require.Nil(err) -} - // copyFile moves an existing file to the destination func copyFile(src, dst string, t *testing.T) { in, err := os.Open(src) @@ -268,17 +252,17 @@ func TestQemuDriver_User(t *testing.T) { }, } - taskConfig := map[string]interface{}{ - "image_path": "linux-0.2.img", - "accelerator": "tcg", - "graceful_shutdown": false, - "port_map": map[string]int{ + tc := &TaskConfig{ + ImagePath: "linux-0.2.img", + Accelerator: "tcg", + GracefulShutdown: false, + PortMap: map[string]int{ "main": 22, "web": 8080, }, - "args": []string{"-nodefconfig", "-nodefaults"}, + Args: []string{"-nodefconfig", "-nodefaults"}, } - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) cleanup := harness.MkAllocDir(task, true) defer cleanup() @@ -324,17 +308,17 @@ func TestQemuDriver_Stats(t *testing.T) { }, } - taskConfig := map[string]interface{}{ - "image_path": "linux-0.2.img", - "accelerator": "tcg", - "graceful_shutdown": false, - "port_map": []map[string]int{{ + tc := &TaskConfig{ + ImagePath: "linux-0.2.img", + Accelerator: "tcg", + GracefulShutdown: false, + PortMap: map[string]int{ "main": 22, "web": 8080, - }}, - "args": []string{"-nodefconfig", "-nodefaults"}, + }, + Args: []string{"-nodefconfig", "-nodefaults"}, } - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) cleanup := harness.MkAllocDir(task, true) defer cleanup() diff --git a/drivers/qemu/handle.go b/drivers/qemu/handle.go index 63223f1c2..ae1619183 100644 --- a/drivers/qemu/handle.go +++ b/drivers/qemu/handle.go @@ -6,8 +6,8 @@ import ( "sync" "time" - "github.com/hashicorp/go-hclog" - "github.com/hashicorp/go-plugin" + hclog "github.com/hashicorp/go-hclog" + plugin "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/plugins/drivers" ) diff --git a/drivers/rawexec/driver.go b/drivers/rawexec/driver.go index dc6a5a71b..ff9ab9987 100644 --- a/drivers/rawexec/driver.go +++ b/drivers/rawexec/driver.go @@ -14,11 +14,10 @@ import ( hclog "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/drivers/shared/eventer" "github.com/hashicorp/nomad/drivers/shared/executor" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/loader" pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) @@ -148,7 +147,7 @@ type TaskConfig struct { // StartTask. This information is needed to rebuild the task state and handler // during recovery. type TaskState struct { - ReattachConfig *shared.ReattachConfig + ReattachConfig *pstructs.ReattachConfig TaskConfig *drivers.TaskConfig Pid int StartedAt time.Time @@ -271,7 +270,7 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error { return fmt.Errorf("failed to decode task state from handle: %v", err) } - plugRC, err := shared.ReattachConfigToGoPlugin(taskState.ReattachConfig) + plugRC, err := pstructs.ReattachConfigToGoPlugin(taskState.ReattachConfig) if err != nil { d.logger.Error("failed to build ReattachConfig from task state", "error", err, "task_id", handle.Config.ID) return fmt.Errorf("failed to build ReattachConfig from task state: %v", err) @@ -360,7 +359,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive } driverState := TaskState{ - ReattachConfig: shared.ReattachConfigFromGoPlugin(pluginClient.ReattachConfig()), + ReattachConfig: pstructs.ReattachConfigFromGoPlugin(pluginClient.ReattachConfig()), Pid: ps.Pid, TaskConfig: cfg, StartedAt: h.startedAt, diff --git a/drivers/rawexec/driver_pre09.go b/drivers/rawexec/driver_pre09.go index 72ddf8db3..a6fd2d7c1 100644 --- a/drivers/rawexec/driver_pre09.go +++ b/drivers/rawexec/driver_pre09.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { @@ -17,7 +17,7 @@ func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { return fmt.Errorf("failed to decode pre09 driver handle: %v", err) } - reattach, err := shared.ReattachConfigToGoPlugin(handle.ReattachConfig()) + reattach, err := pstructs.ReattachConfigToGoPlugin(handle.ReattachConfig()) if err != nil { return fmt.Errorf("failed to decode reattach config from pre09 handle: %v", err) } diff --git a/drivers/rawexec/driver_test.go b/drivers/rawexec/driver_test.go index 31c25e085..bc8083f93 100644 --- a/drivers/rawexec/driver_test.go +++ b/drivers/rawexec/driver_test.go @@ -13,7 +13,6 @@ import ( "testing" "time" - "github.com/hashicorp/hcl2/hcl" ctestutil "github.com/hashicorp/nomad/client/testutil" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/testtask" @@ -21,8 +20,6 @@ import ( basePlug "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" dtestutil "github.com/hashicorp/nomad/plugins/drivers/testutils" - "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/hclutils" pstructs "github.com/hashicorp/nomad/plugins/shared/structs" "github.com/hashicorp/nomad/testutil" "github.com/stretchr/testify/require" @@ -143,11 +140,13 @@ func TestRawExecDriver_StartWait(t *testing.T) { Name: "test", } - taskConfig := map[string]interface{}{} - taskConfig["command"] = "go" - taskConfig["args"] = []string{"version"} + tc := &TaskConfig{ + Command: testtask.Path(), + Args: []string{"sleep", "10ms"}, + } + require.NoError(task.EncodeConcreteDriverConfig(&tc)) + testtask.SetTaskConfigEnv(task) - encodeDriverHelper(require, task, taskConfig) cleanup := harness.MkAllocDir(task, false) defer cleanup() @@ -156,7 +155,14 @@ func TestRawExecDriver_StartWait(t *testing.T) { ch, err := harness.WaitTask(context.Background(), handle.Config.ID) require.NoError(err) - result := <-ch + + var result *drivers.ExitResult + select { + case result = <-ch: + case <-time.After(5 * time.Second): + t.Fatal("timed out") + } + require.Zero(result.ExitCode) require.Zero(result.Signal) require.False(result.OOMKilled) @@ -183,11 +189,11 @@ func TestRawExecDriver_StartWaitRecoverWaitStop(t *testing.T) { ID: uuid.Generate(), Name: "sleep", } - taskConfig := map[string]interface{}{} - taskConfig["command"] = testtask.Path() - taskConfig["args"] = []string{"sleep", "100s"} - - encodeDriverHelper(require, task, taskConfig) + tc := &TaskConfig{ + Command: testtask.Path(), + Args: []string{"sleep", "100s"}, + } + require.NoError(task.EncodeConcreteDriverConfig(&tc)) testtask.SetTaskConfigEnv(task) cleanup := harness.MkAllocDir(task, false) @@ -267,10 +273,11 @@ func TestRawExecDriver_Start_Wait_AllocDir(t *testing.T) { file := "output.txt" outPath := fmt.Sprintf(`%s/%s`, task.TaskDir().SharedAllocDir, file) - taskConfig := map[string]interface{}{} - taskConfig["command"] = testtask.Path() - taskConfig["args"] = []string{"sleep", "1s", "write", string(exp), outPath} - encodeDriverHelper(require, task, taskConfig) + tc := &TaskConfig{ + Command: testtask.Path(), + Args: []string{"sleep", "1s", "write", string(exp), outPath}, + } + require.NoError(task.EncodeConcreteDriverConfig(&tc)) testtask.SetTaskConfigEnv(task) _, _, err := harness.StartTask(task) @@ -318,10 +325,11 @@ func TestRawExecDriver_Start_Kill_Wait_Cgroup(t *testing.T) { cleanup := harness.MkAllocDir(task, false) defer cleanup() - taskConfig := map[string]interface{}{} - taskConfig["command"] = testtask.Path() - taskConfig["args"] = []string{"fork/exec", pidFile, "pgrp", "0", "sleep", "20s"} - encodeDriverHelper(require, task, taskConfig) + tc := &TaskConfig{ + Command: testtask.Path(), + Args: []string{"fork/exec", pidFile, "pgrp", "0", "sleep", "20s"}, + } + require.NoError(task.EncodeConcreteDriverConfig(&tc)) testtask.SetTaskConfigEnv(task) _, _, err := harness.StartTask(task) @@ -406,10 +414,11 @@ func TestRawExecDriver_Exec(t *testing.T) { cleanup := harness.MkAllocDir(task, false) defer cleanup() - taskConfig := map[string]interface{}{} - taskConfig["command"] = testtask.Path() - taskConfig["args"] = []string{"sleep", "9000s"} - encodeDriverHelper(require, task, taskConfig) + tc := &TaskConfig{ + Command: testtask.Path(), + Args: []string{"sleep", "9000s"}, + } + require.NoError(task.EncodeConcreteDriverConfig(&tc)) testtask.SetTaskConfigEnv(task) _, _, err := harness.StartTask(task) @@ -443,15 +452,3 @@ func TestRawExecDriver_Exec(t *testing.T) { require.NoError(harness.DestroyTask(task.ID, true)) } - -func encodeDriverHelper(require *require.Assertions, task *drivers.TaskConfig, taskConfig map[string]interface{}) { - evalCtx := &hcl.EvalContext{ - Functions: hclutils.GetStdlibFuncs(), - } - spec, diag := hclspec.Convert(taskConfigSpec) - require.False(diag.HasErrors()) - taskConfigCtyVal, diag := hclutils.ParseHclInterface(taskConfig, spec, evalCtx) - require.False(diag.HasErrors()) - err := task.EncodeDriverConfig(taskConfigCtyVal) - require.Nil(err) -} diff --git a/drivers/rawexec/driver_unix_test.go b/drivers/rawexec/driver_unix_test.go index 568f16ebe..07491574f 100644 --- a/drivers/rawexec/driver_unix_test.go +++ b/drivers/rawexec/driver_unix_test.go @@ -43,11 +43,11 @@ func TestRawExecDriver_User(t *testing.T) { cleanup := harness.MkAllocDir(task, false) defer cleanup() - taskConfig := map[string]interface{}{} - taskConfig["command"] = testtask.Path() - taskConfig["args"] = []string{"sleep", "45s"} - - encodeDriverHelper(require, task, taskConfig) + tc := &TaskConfig{ + Command: testtask.Path(), + Args: []string{"sleep", "45s"}, + } + require.NoError(task.EncodeConcreteDriverConfig(&tc)) testtask.SetTaskConfigEnv(task) _, _, err := harness.StartTask(task) @@ -74,11 +74,11 @@ func TestRawExecDriver_Signal(t *testing.T) { cleanup := harness.MkAllocDir(task, true) defer cleanup() - taskConfig := map[string]interface{}{} - taskConfig["command"] = "/bin/bash" - taskConfig["args"] = []string{"test.sh"} - - encodeDriverHelper(require, task, taskConfig) + tc := &TaskConfig{ + Command: "/bin/bash", + Args: []string{"test.sh"}, + } + require.NoError(task.EncodeConcreteDriverConfig(&tc)) testtask.SetTaskConfigEnv(task) testFile := filepath.Join(task.TaskDir().Dir, "test.sh") @@ -94,7 +94,6 @@ done `) require.NoError(ioutil.WriteFile(testFile, testData, 0777)) - testtask.SetTaskConfigEnv(task) _, _, err := harness.StartTask(task) require.NoError(err) @@ -155,7 +154,7 @@ func TestRawExecDriver_StartWaitStop(t *testing.T) { taskConfig["command"] = testtask.Path() taskConfig["args"] = []string{"sleep", "100s"} - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&taskConfig)) cleanup := harness.MkAllocDir(task, false) defer cleanup() diff --git a/drivers/rkt/api.go b/drivers/rkt/api.go new file mode 100644 index 000000000..2a0eac467 --- /dev/null +++ b/drivers/rkt/api.go @@ -0,0 +1,28 @@ +package rkt + +import ( + "net" +) + +// This file contains the structrs used by this driver. +// Embedding structs here helps avoid depending on a linux only library + +// Pod is the pod object, as defined in +// https://github.com/rkt/rkt/blob/03285a7db960311faf887452538b2b8ae4304488/api/v1/json.go#L68-L88 +type Pod struct { + UUID string `json:"name"` + State string `json:"state"` + Networks []NetInfo `json:"networks,omitempty"` +} + +// A type and some structure to represent rkt's view of a *runtime* +// network instance. +// https://github.com/rkt/rkt/blob/4080b1743e0c46fa1645f4de64f1b75a980d82a3/networking/netinfo/netinfo.go#L29-L48 +type NetInfo struct { + NetName string `json:"netName"` + ConfPath string `json:"netConf"` + PluginPath string `json:"pluginPath"` + IfName string `json:"ifName"` + IP net.IP `json:"ip"` + Args string `json:"args"` +} diff --git a/drivers/rkt/driver.go b/drivers/rkt/driver.go index 6a28fd9f2..1acd672db 100644 --- a/drivers/rkt/driver.go +++ b/drivers/rkt/driver.go @@ -1,5 +1,3 @@ -// +build linux - package rkt import ( @@ -29,13 +27,11 @@ import ( "github.com/hashicorp/nomad/drivers/shared/eventer" "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/helper" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/loader" pstructs "github.com/hashicorp/nomad/plugins/shared/structs" - rktv1 "github.com/rkt/rkt/api/v1" ) const ( @@ -164,7 +160,7 @@ type TaskConfig struct { // StartTask. This information is needed to rebuild the taskConfig state and handler // during recovery. type TaskState struct { - ReattachConfig *shared.ReattachConfig + ReattachConfig *pstructs.ReattachConfig TaskConfig *drivers.TaskConfig Pid int StartedAt time.Time @@ -378,7 +374,7 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error { return fmt.Errorf("failed to decode taskConfig state from handle: %v", err) } - plugRC, err := shared.ReattachConfigToGoPlugin(taskState.ReattachConfig) + plugRC, err := pstructs.ReattachConfigToGoPlugin(taskState.ReattachConfig) if err != nil { d.logger.Error("failed to build ReattachConfig from taskConfig state", "error", err, "task_id", handle.Config.ID) return fmt.Errorf("failed to build ReattachConfig from taskConfig state: %v", err) @@ -734,7 +730,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive } rktDriverState := TaskState{ - ReattachConfig: shared.ReattachConfigFromGoPlugin(pluginClient.ReattachConfig()), + ReattachConfig: pstructs.ReattachConfigFromGoPlugin(pluginClient.ReattachConfig()), Pid: ps.Pid, TaskConfig: cfg, StartedAt: h.startedAt, @@ -982,7 +978,7 @@ func rktManifestMakePortMap(manifest *appcschema.PodManifest, configPortMap map[ } // Retrieve pod status for the pod with the given UUID. -func rktGetStatus(uuid string, logger hclog.Logger) (*rktv1.Pod, error) { +func rktGetStatus(uuid string, logger hclog.Logger) (*Pod, error) { statusArgs := []string{ "status", "--format=json", @@ -1002,7 +998,7 @@ func rktGetStatus(uuid string, logger hclog.Logger) (*rktv1.Pod, error) { logger.Debug("status error output", "uuid", uuid, "error", elide(errBuf)) return nil, fmt.Errorf("%s. stderr: %q", err, elide(errBuf)) } - var status rktv1.Pod + var status Pod if err := json.Unmarshal(outBuf.Bytes(), &status); err != nil { return nil, err } diff --git a/drivers/rkt/driver_pre09.go b/drivers/rkt/driver_pre09.go index 7bdea1245..ed4f9adba 100644 --- a/drivers/rkt/driver_pre09.go +++ b/drivers/rkt/driver_pre09.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/nomad/drivers/shared/executor" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/plugins/drivers" - "github.com/hashicorp/nomad/plugins/shared" + pstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { @@ -17,7 +17,7 @@ func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { return fmt.Errorf("failed to decode pre09 driver handle: %v", err) } - reattach, err := shared.ReattachConfigToGoPlugin(handle.ReattachConfig()) + reattach, err := pstructs.ReattachConfigToGoPlugin(handle.ReattachConfig()) if err != nil { return fmt.Errorf("failed to decode reattach config from pre09 handle: %v", err) } diff --git a/drivers/rkt/driver_test.go b/drivers/rkt/driver_test.go index 37ba6e9a3..c4b22179c 100644 --- a/drivers/rkt/driver_test.go +++ b/drivers/rkt/driver_test.go @@ -1,5 +1,3 @@ -// +build linux - package rkt import ( @@ -13,7 +11,6 @@ import ( "testing" "time" - "github.com/hashicorp/hcl2/hcl" ctestutil "github.com/hashicorp/nomad/client/testutil" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/testtask" @@ -22,8 +19,6 @@ import ( basePlug "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" dtestutil "github.com/hashicorp/nomad/plugins/drivers/testutils" - "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/hclutils" "github.com/hashicorp/nomad/testutil" "github.com/stretchr/testify/require" "golang.org/x/sys/unix" @@ -109,16 +104,15 @@ func TestRktDriver_Start_Wait_Stop_DNS(t *testing.T) { }, } - taskConfig := map[string]interface{}{ - "trust_prefix": "coreos.com/etcd", - "image": "coreos.com/etcd:v2.0.4", - "command": "/etcd", - "dns_servers": []string{"8.8.8.8", "8.8.4.4"}, - "dns_search_domains": []string{"example.com", "example.org", "example.net"}, - "net": []string{"host"}, + tc := &TaskConfig{ + TrustPrefix: "coreos.com/etcd", + ImageName: "coreos.com/etcd:v2.0.4", + Command: "/etcd", + DNSServers: []string{"8.8.8.8", "8.8.4.4"}, + DNSSearchDomains: []string{"example.com", "example.org", "example.net"}, + Net: []string{"host"}, } - - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) testtask.SetTaskConfigEnv(task) cleanup := harness.MkAllocDir(task, true) defer cleanup() @@ -193,16 +187,15 @@ func TestRktDriver_Start_Wait_Stop(t *testing.T) { }, } - taskConfig := map[string]interface{}{ - "trust_prefix": "coreos.com/etcd", - "image": "coreos.com/etcd:v2.0.4", - "command": "/etcd", - "args": []string{"--version"}, - "net": []string{"none"}, - "debug": true, + tc := &TaskConfig{ + TrustPrefix: "coreos.com/etcd", + ImageName: "coreos.com/etcd:v2.0.4", + Command: "/etcd", + Args: []string{"--version"}, + Net: []string{"none"}, + Debug: true, } - - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) cleanup := harness.MkAllocDir(task, true) defer cleanup() @@ -252,15 +245,14 @@ func TestRktDriver_Start_Wait_Skip_Trust(t *testing.T) { }, } - taskConfig := map[string]interface{}{ - "image": "coreos.com/etcd:v2.0.4", - "command": "/etcd", - "args": []string{"--version"}, - "net": []string{"none"}, - "debug": true, + tc := &TaskConfig{ + ImageName: "coreos.com/etcd:v2.0.4", + Command: "/etcd", + Args: []string{"--version"}, + Net: []string{"none"}, + Debug: true, } - - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) testtask.SetTaskConfigEnv(task) cleanup := harness.MkAllocDir(task, true) @@ -311,16 +303,15 @@ func TestRktDriver_InvalidTrustPrefix(t *testing.T) { }, } - taskConfig := map[string]interface{}{ - "trust_prefix": "example.com/invalid", - "image": "coreos.com/etcd:v2.0.4", - "command": "/etcd", - "args": []string{"--version"}, - "net": []string{"none"}, - "debug": true, + tc := &TaskConfig{ + TrustPrefix: "example.com/invalid", + ImageName: "coreos.com/etcd:v2.0.4", + Command: "/etcd", + Args: []string{"--version"}, + Net: []string{"none"}, + Debug: true, } - - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) testtask.SetTaskConfigEnv(task) cleanup := harness.MkAllocDir(task, true) @@ -366,12 +357,11 @@ func TestRktDriver_StartWaitRecoverWaitStop(t *testing.T) { }, } - taskConfig := map[string]interface{}{ - "image": "coreos.com/etcd:v2.0.4", - "command": "/etcd", + tc := &TaskConfig{ + ImageName: "coreos.com/etcd:v2.0.4", + Command: "/etcd", } - - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) cleanup := harness.MkAllocDir(task, true) defer cleanup() @@ -412,23 +402,21 @@ func TestRktDriver_StartWaitRecoverWaitStop(t *testing.T) { ch, err = harness.WaitTask(context.Background(), task.ID) require.NoError(err) - wg.Add(1) - waitDone = false - go func() { - defer wg.Done() - result := <-ch + require.NoError(d.StopTask(task.ID, 0, "SIGKILL")) + + select { + case result := <-ch: require.NoError(result.Err) require.NotZero(result.ExitCode) - require.Equal(9, result.Signal) - waitDone = true - }() - time.Sleep(300 * time.Millisecond) - require.NoError(d.StopTask(task.ID, 0, "SIGKILL")) - wg.Wait() + // when killing a task, signal might not propagate + // when executor proc.Wait() call gets "wait: no child processes" error + //require.Equal(9, result.Signal) + case <-time.After(time.Duration(testutil.TestMultiplier()*5) * time.Second): + require.Fail("WaitTask timeout") + } + require.NoError(d.DestroyTask(task.ID, false)) - require.True(waitDone) - } // Verifies mounting a volume from the host machine and writing @@ -477,18 +465,18 @@ func TestRktDriver_Start_Wait_Volume(t *testing.T) { defer os.RemoveAll(tmpvol) hostpath := filepath.Join(tmpvol, file) - taskConfig := map[string]interface{}{ - "image": "docker://redis:3.2-alpine", - "command": "/bin/sh", - "args": []string{ + tc := &TaskConfig{ + ImageName: "docker://redis:3.2-alpine", + Command: "/bin/sh", + Args: []string{ "-c", fmt.Sprintf("echo -n %s > /foo/%s", string(exp), file), }, - "net": []string{"none"}, - "volumes": []string{fmt.Sprintf("%s:/foo", tmpvol)}, + Net: []string{"none"}, + Volumes: []string{fmt.Sprintf("%s:/foo", tmpvol)}, } + require.NoError(task.EncodeConcreteDriverConfig(&tc)) - encodeDriverHelper(require, task, taskConfig) testtask.SetTaskConfigEnv(task) cleanup := harness.MkAllocDir(task, true) @@ -566,17 +554,16 @@ func TestRktDriver_Start_Wait_TaskMounts(t *testing.T) { file := "output.txt" hostpath := filepath.Join(tmpvol, file) - taskConfig := map[string]interface{}{ - "image": "docker://redis:3.2-alpine", - "command": "/bin/sh", - "args": []string{ + tc := &TaskConfig{ + ImageName: "docker://redis:3.2-alpine", + Command: "/bin/sh", + Args: []string{ "-c", fmt.Sprintf("echo -n %s > /foo/%s", string(exp), file), }, - "net": []string{"none"}, + Net: []string{"none"}, } - - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) testtask.SetTaskConfigEnv(task) cleanup := harness.MkAllocDir(task, true) @@ -638,15 +625,14 @@ func TestRktDriver_PortMapping(t *testing.T) { }, } - taskConfig := map[string]interface{}{ - "image": "docker://redis:3.2-alpine", - "port_map": map[string]string{ + tc := &TaskConfig{ + ImageName: "docker://redis:3.2-alpine", + PortMap: map[string]string{ "main": "6379-tcp", }, - "debug": "true", + Debug: true, } - - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) cleanup := harness.MkAllocDir(task, true) defer cleanup() @@ -690,15 +676,15 @@ func TestRktDriver_UserGroup(t *testing.T) { }, } - taskConfig := map[string]interface{}{ - "image": "docker://redis:3.2-alpine", - "group": "nogroup", - "command": "sleep", - "args": []string{"9000"}, - "net": []string{"none"}, + tc := &TaskConfig{ + ImageName: "docker://redis:3.2-alpine", + Group: "nogroup", + Command: "sleep", + Args: []string{"9000"}, + Net: []string{"none"}, } + require.NoError(task.EncodeConcreteDriverConfig(&tc)) - encodeDriverHelper(require, task, taskConfig) testtask.SetTaskConfigEnv(task) cleanup := harness.MkAllocDir(task, true) @@ -756,13 +742,12 @@ func TestRktDriver_Exec(t *testing.T) { }, } - taskConfig := map[string]interface{}{ - "trust_prefix": "coreos.com/etcd", - "image": "coreos.com/etcd:v2.0.4", - "net": []string{"none"}, + tc := &TaskConfig{ + TrustPrefix: "coreos.com/etcd", + ImageName: "coreos.com/etcd:v2.0.4", + Net: []string{"none"}, } - - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) testtask.SetTaskConfigEnv(task) cleanup := harness.MkAllocDir(task, true) @@ -838,14 +823,13 @@ func TestRktDriver_Stats(t *testing.T) { }, } - taskConfig := map[string]interface{}{ - "trust_prefix": "coreos.com/etcd", - "image": "coreos.com/etcd:v2.0.4", - "command": "/etcd", - "net": []string{"none"}, + tc := &TaskConfig{ + TrustPrefix: "coreos.com/etcd", + ImageName: "coreos.com/etcd:v2.0.4", + Command: "/etcd", + Net: []string{"none"}, } - - encodeDriverHelper(require, task, taskConfig) + require.NoError(task.EncodeConcreteDriverConfig(&tc)) testtask.SetTaskConfigEnv(task) cleanup := harness.MkAllocDir(task, true) @@ -878,18 +862,3 @@ func TestRktDriver_Stats(t *testing.T) { require.NoError(harness.DestroyTask(task.ID, true)) } - -func encodeDriverHelper(require *require.Assertions, task *drivers.TaskConfig, taskConfig map[string]interface{}) { - evalCtx := &hcl.EvalContext{ - Functions: hclutils.GetStdlibFuncs(), - } - spec, diag := hclspec.Convert(taskConfigSpec) - require.False(diag.HasErrors()) - taskConfigCtyVal, diag := hclutils.ParseHclInterface(taskConfig, spec, evalCtx) - if diag.HasErrors() { - fmt.Println("conversion error", diag.Error()) - } - require.False(diag.HasErrors()) - err := task.EncodeDriverConfig(taskConfigCtyVal) - require.Nil(err) -} diff --git a/drivers/rkt/handle.go b/drivers/rkt/handle.go index e9965a22f..ce234d7ea 100644 --- a/drivers/rkt/handle.go +++ b/drivers/rkt/handle.go @@ -1,5 +1,3 @@ -// +build linux - package rkt import ( diff --git a/drivers/rkt/state.go b/drivers/rkt/state.go index 2e5791bfc..b46c9292a 100644 --- a/drivers/rkt/state.go +++ b/drivers/rkt/state.go @@ -1,5 +1,3 @@ -// +build linux - package rkt import ( diff --git a/drivers/shared/executor/executor_plugin.go b/drivers/shared/executor/executor_plugin.go index f9e661ed6..6eb7b3564 100644 --- a/drivers/shared/executor/executor_plugin.go +++ b/drivers/shared/executor/executor_plugin.go @@ -4,7 +4,7 @@ import ( "context" hclog "github.com/hashicorp/go-hclog" - "github.com/hashicorp/go-plugin" + plugin "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/drivers/shared/executor/proto" "google.golang.org/grpc" ) diff --git a/helper/fields/data.go b/helper/fields/data.go index fb22bbc59..8423fb67f 100644 --- a/helper/fields/data.go +++ b/helper/fields/data.go @@ -3,7 +3,7 @@ package fields import ( "fmt" - "github.com/hashicorp/go-multierror" + multierror "github.com/hashicorp/go-multierror" "github.com/mitchellh/mapstructure" ) diff --git a/plugins/shared/catalog/catalog.go b/helper/pluginutils/catalog/catalog.go similarity index 96% rename from plugins/shared/catalog/catalog.go rename to helper/pluginutils/catalog/catalog.go index 36bb7c6c0..6d12de4a3 100644 --- a/plugins/shared/catalog/catalog.go +++ b/helper/pluginutils/catalog/catalog.go @@ -5,7 +5,7 @@ package catalog import ( "sync" - "github.com/hashicorp/nomad/plugins/shared/loader" + "github.com/hashicorp/nomad/helper/pluginutils/loader" ) var ( diff --git a/plugins/shared/catalog/register.go b/helper/pluginutils/catalog/register.go similarity index 100% rename from plugins/shared/catalog/register.go rename to helper/pluginutils/catalog/register.go diff --git a/plugins/shared/catalog/register_linux.go b/helper/pluginutils/catalog/register_linux.go similarity index 100% rename from plugins/shared/catalog/register_linux.go rename to helper/pluginutils/catalog/register_linux.go diff --git a/plugins/shared/catalog/register_testing.go b/helper/pluginutils/catalog/register_testing.go similarity index 100% rename from plugins/shared/catalog/register_testing.go rename to helper/pluginutils/catalog/register_testing.go diff --git a/plugins/shared/catalog/testing.go b/helper/pluginutils/catalog/testing.go similarity index 93% rename from plugins/shared/catalog/testing.go rename to helper/pluginutils/catalog/testing.go index 19ed78bb2..82dcbe630 100644 --- a/plugins/shared/catalog/testing.go +++ b/helper/pluginutils/catalog/testing.go @@ -1,10 +1,11 @@ package catalog import ( + testing "github.com/mitchellh/go-testing-interface" + + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs/config" - "github.com/hashicorp/nomad/plugins/shared/loader" - "github.com/mitchellh/go-testing-interface" ) // TestPluginLoader returns a plugin loader populated only with internal plugins diff --git a/plugins/shared/grpcutils/utils.go b/helper/pluginutils/grpcutils/utils.go similarity index 100% rename from plugins/shared/grpcutils/utils.go rename to helper/pluginutils/grpcutils/utils.go diff --git a/plugins/shared/hclspec/dec.go b/helper/pluginutils/hclspecutils/dec.go similarity index 83% rename from plugins/shared/hclspec/dec.go rename to helper/pluginutils/hclspecutils/dec.go index 6b6ef4b03..7288b0c0c 100644 --- a/plugins/shared/hclspec/dec.go +++ b/helper/pluginutils/hclspecutils/dec.go @@ -1,4 +1,4 @@ -package hclspec +package hclspecutils import ( "fmt" @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/hcl2/hcl" "github.com/hashicorp/hcl2/hcl/hclsyntax" "github.com/hashicorp/hcl2/hcldec" + "github.com/hashicorp/nomad/plugins/shared/hclspec" ) var ( @@ -31,7 +32,7 @@ var ( ) // Convert converts a Spec to an hcl specification. -func Convert(spec *Spec) (hcldec.Spec, hcl.Diagnostics) { +func Convert(spec *hclspec.Spec) (hcldec.Spec, hcl.Diagnostics) { if spec == nil { return nil, hcl.Diagnostics([]*hcl.Diagnostic{nilSpecDiagnostic}) } @@ -41,37 +42,37 @@ func Convert(spec *Spec) (hcldec.Spec, hcl.Diagnostics) { // decodeSpecBlock is the recursive entry point that converts between the two // spec types. -func decodeSpecBlock(spec *Spec, impliedName string) (hcldec.Spec, hcl.Diagnostics) { +func decodeSpecBlock(spec *hclspec.Spec, impliedName string) (hcldec.Spec, hcl.Diagnostics) { switch spec.Block.(type) { - case *Spec_Object: + case *hclspec.Spec_Object: return decodeObjectSpec(spec.GetObject()) - case *Spec_Array: + case *hclspec.Spec_Array: return decodeArraySpec(spec.GetArray()) - case *Spec_Attr: + case *hclspec.Spec_Attr: return decodeAttrSpec(spec.GetAttr(), impliedName) - case *Spec_BlockValue: + case *hclspec.Spec_BlockValue: return decodeBlockSpec(spec.GetBlockValue(), impliedName) - case *Spec_BlockAttrs: + case *hclspec.Spec_BlockAttrs: return decodeBlockAttrsSpec(spec.GetBlockAttrs(), impliedName) - case *Spec_BlockList: + case *hclspec.Spec_BlockList: return decodeBlockListSpec(spec.GetBlockList(), impliedName) - case *Spec_BlockSet: + case *hclspec.Spec_BlockSet: return decodeBlockSetSpec(spec.GetBlockSet(), impliedName) - case *Spec_BlockMap: + case *hclspec.Spec_BlockMap: return decodeBlockMapSpec(spec.GetBlockMap(), impliedName) - case *Spec_Default: + case *hclspec.Spec_Default: return decodeDefaultSpec(spec.GetDefault()) - case *Spec_Literal: + case *hclspec.Spec_Literal: return decodeLiteralSpec(spec.GetLiteral()) default: @@ -87,7 +88,7 @@ func decodeSpecBlock(spec *Spec, impliedName string) (hcldec.Spec, hcl.Diagnosti } } -func decodeObjectSpec(obj *Object) (hcldec.Spec, hcl.Diagnostics) { +func decodeObjectSpec(obj *hclspec.Object) (hcldec.Spec, hcl.Diagnostics) { var diags hcl.Diagnostics spec := make(hcldec.ObjectSpec) for attr, block := range obj.GetAttributes() { @@ -99,7 +100,7 @@ func decodeObjectSpec(obj *Object) (hcldec.Spec, hcl.Diagnostics) { return spec, diags } -func decodeArraySpec(a *Array) (hcldec.Spec, hcl.Diagnostics) { +func decodeArraySpec(a *hclspec.Array) (hcldec.Spec, hcl.Diagnostics) { values := a.GetValues() var diags hcl.Diagnostics spec := make(hcldec.TupleSpec, 0, len(values)) @@ -112,7 +113,7 @@ func decodeArraySpec(a *Array) (hcldec.Spec, hcl.Diagnostics) { return spec, diags } -func decodeAttrSpec(attr *Attr, impliedName string) (hcldec.Spec, hcl.Diagnostics) { +func decodeAttrSpec(attr *hclspec.Attr, impliedName string) (hcldec.Spec, hcl.Diagnostics) { // Convert the string type to an hcl.Expression typeExpr, diags := hclsyntax.ParseExpression([]byte(attr.GetType()), "proto", emptyPos) if diags.HasErrors() { @@ -144,7 +145,7 @@ func decodeAttrSpec(attr *Attr, impliedName string) (hcldec.Spec, hcl.Diagnostic return spec, diags } -func decodeBlockSpec(block *Block, impliedName string) (hcldec.Spec, hcl.Diagnostics) { +func decodeBlockSpec(block *hclspec.Block, impliedName string) (hcldec.Spec, hcl.Diagnostics) { spec := &hcldec.BlockSpec{ TypeName: impliedName, Required: block.GetRequired(), @@ -159,7 +160,7 @@ func decodeBlockSpec(block *Block, impliedName string) (hcldec.Spec, hcl.Diagnos return spec, diags } -func decodeBlockAttrsSpec(block *BlockAttrs, impliedName string) (hcldec.Spec, hcl.Diagnostics) { +func decodeBlockAttrsSpec(block *hclspec.BlockAttrs, impliedName string) (hcldec.Spec, hcl.Diagnostics) { // Convert the string type to an hcl.Expression typeExpr, diags := hclsyntax.ParseExpression([]byte(block.GetType()), "proto", emptyPos) if diags.HasErrors() { @@ -191,7 +192,7 @@ func decodeBlockAttrsSpec(block *BlockAttrs, impliedName string) (hcldec.Spec, h return spec, diags } -func decodeBlockListSpec(block *BlockList, impliedName string) (hcldec.Spec, hcl.Diagnostics) { +func decodeBlockListSpec(block *hclspec.BlockList, impliedName string) (hcldec.Spec, hcl.Diagnostics) { spec := &hcldec.BlockListSpec{ TypeName: impliedName, MinItems: int(block.GetMinItems()), @@ -217,7 +218,7 @@ func decodeBlockListSpec(block *BlockList, impliedName string) (hcldec.Spec, hcl return spec, diags } -func decodeBlockSetSpec(block *BlockSet, impliedName string) (hcldec.Spec, hcl.Diagnostics) { +func decodeBlockSetSpec(block *hclspec.BlockSet, impliedName string) (hcldec.Spec, hcl.Diagnostics) { spec := &hcldec.BlockSetSpec{ TypeName: impliedName, MinItems: int(block.GetMinItems()), @@ -243,7 +244,7 @@ func decodeBlockSetSpec(block *BlockSet, impliedName string) (hcldec.Spec, hcl.D return spec, diags } -func decodeBlockMapSpec(block *BlockMap, impliedName string) (hcldec.Spec, hcl.Diagnostics) { +func decodeBlockMapSpec(block *hclspec.BlockMap, impliedName string) (hcldec.Spec, hcl.Diagnostics) { spec := &hcldec.BlockMapSpec{ TypeName: impliedName, LabelNames: block.GetLabels(), @@ -276,7 +277,7 @@ func decodeBlockMapSpec(block *BlockMap, impliedName string) (hcldec.Spec, hcl.D return spec, diags } -func decodeBlockNestedSpec(spec *Spec) (hcldec.Spec, hcl.Diagnostics) { +func decodeBlockNestedSpec(spec *hclspec.Spec) (hcldec.Spec, hcl.Diagnostics) { if spec == nil { return nil, hcl.Diagnostics([]*hcl.Diagnostic{ { @@ -289,7 +290,7 @@ func decodeBlockNestedSpec(spec *Spec) (hcldec.Spec, hcl.Diagnostics) { return decodeSpecBlock(spec, "") } -func decodeLiteralSpec(l *Literal) (hcldec.Spec, hcl.Diagnostics) { +func decodeLiteralSpec(l *hclspec.Literal) (hcldec.Spec, hcl.Diagnostics) { // Convert the string value to an hcl.Expression valueExpr, diags := hclsyntax.ParseExpression([]byte(l.GetValue()), "proto", emptyPos) if diags.HasErrors() { @@ -307,7 +308,7 @@ func decodeLiteralSpec(l *Literal) (hcldec.Spec, hcl.Diagnostics) { }, diags } -func decodeDefaultSpec(d *Default) (hcldec.Spec, hcl.Diagnostics) { +func decodeDefaultSpec(d *hclspec.Default) (hcldec.Spec, hcl.Diagnostics) { // Parse the primary primary, diags := decodeSpecBlock(d.GetPrimary(), "") if diags.HasErrors() { diff --git a/plugins/shared/hclspec/dec_test.go b/helper/pluginutils/hclspecutils/dec_test.go similarity index 70% rename from plugins/shared/hclspec/dec_test.go rename to helper/pluginutils/hclspecutils/dec_test.go index f3f730dea..588b8de17 100644 --- a/plugins/shared/hclspec/dec_test.go +++ b/helper/pluginutils/hclspecutils/dec_test.go @@ -1,16 +1,17 @@ -package hclspec +package hclspecutils import ( "testing" "github.com/hashicorp/hcl2/hcldec" + "github.com/hashicorp/nomad/plugins/shared/hclspec" "github.com/stretchr/testify/require" "github.com/zclconf/go-cty/cty" ) type testConversions struct { Name string - Input *Spec + Input *hclspec.Spec Expected hcldec.Spec ExpectedError string } @@ -42,29 +43,29 @@ func TestDec_Convert_Object(t *testing.T) { tests := []testConversions{ { Name: "Object w/ only attributes", - Input: &Spec{ - Block: &Spec_Object{ - &Object{ - Attributes: map[string]*Spec{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_Object{ + Object: &hclspec.Object{ + Attributes: map[string]*hclspec.Spec{ "foo": { - Block: &Spec_Attr{ - &Attr{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Type: "string", Required: false, }, }, }, "bar": { - Block: &Spec_Attr{ - &Attr{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Type: "number", Required: true, }, }, }, "baz": { - Block: &Spec_Attr{ - &Attr{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Type: "bool", }, }, @@ -102,13 +103,13 @@ func TestDec_Convert_Array(t *testing.T) { tests := []testConversions{ { Name: "array basic", - Input: &Spec{ - Block: &Spec_Array{ - Array: &Array{ - Values: []*Spec{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_Array{ + Array: &hclspec.Array{ + Values: []*hclspec.Spec{ { - Block: &Spec_Attr{ - &Attr{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Required: true, Type: "string", @@ -116,8 +117,8 @@ func TestDec_Convert_Array(t *testing.T) { }, }, { - Block: &Spec_Attr{ - &Attr{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "bar", Required: true, Type: "string", @@ -152,9 +153,9 @@ func TestDec_Convert_Attr(t *testing.T) { tests := []testConversions{ { Name: "attr basic type", - Input: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Required: true, Type: "string", @@ -169,9 +170,9 @@ func TestDec_Convert_Attr(t *testing.T) { }, { Name: "attr object type", - Input: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Required: true, Type: "object({name1 = string, name2 = bool})", @@ -189,9 +190,9 @@ func TestDec_Convert_Attr(t *testing.T) { }, { Name: "attr no name", - Input: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Required: true, Type: "string", }, @@ -210,14 +211,14 @@ func TestDec_Convert_Block(t *testing.T) { tests := []testConversions{ { Name: "block with attr", - Input: &Spec{ - Block: &Spec_BlockValue{ - BlockValue: &Block{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_BlockValue{ + BlockValue: &hclspec.Block{ Name: "test", Required: true, - Nested: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Nested: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Type: "string", }, @@ -238,19 +239,19 @@ func TestDec_Convert_Block(t *testing.T) { }, { Name: "block with nested block", - Input: &Spec{ - Block: &Spec_BlockValue{ - BlockValue: &Block{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_BlockValue{ + BlockValue: &hclspec.Block{ Name: "test", Required: true, - Nested: &Spec{ - Block: &Spec_BlockValue{ - BlockValue: &Block{ + Nested: &hclspec.Spec{ + Block: &hclspec.Spec_BlockValue{ + BlockValue: &hclspec.Block{ Name: "test", Required: true, - Nested: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Nested: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Type: "string", }, @@ -287,9 +288,9 @@ func TestDec_Convert_BlockAttrs(t *testing.T) { tests := []testConversions{ { Name: "block attr", - Input: &Spec{ - Block: &Spec_BlockAttrs{ - BlockAttrs: &BlockAttrs{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_BlockAttrs{ + BlockAttrs: &hclspec.BlockAttrs{ Name: "test", Type: "string", Required: true, @@ -304,9 +305,9 @@ func TestDec_Convert_BlockAttrs(t *testing.T) { }, { Name: "block list no name", - Input: &Spec{ - Block: &Spec_BlockAttrs{ - BlockAttrs: &BlockAttrs{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_BlockAttrs{ + BlockAttrs: &hclspec.BlockAttrs{ Type: "string", Required: true, }, @@ -325,15 +326,15 @@ func TestDec_Convert_BlockList(t *testing.T) { tests := []testConversions{ { Name: "block list with attr", - Input: &Spec{ - Block: &Spec_BlockList{ - BlockList: &BlockList{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_BlockList{ + BlockList: &hclspec.BlockList{ Name: "test", MinItems: 1, MaxItems: 3, - Nested: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Nested: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Type: "string", }, @@ -355,14 +356,14 @@ func TestDec_Convert_BlockList(t *testing.T) { }, { Name: "block list no name", - Input: &Spec{ - Block: &Spec_BlockList{ - BlockList: &BlockList{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_BlockList{ + BlockList: &hclspec.BlockList{ MinItems: 1, MaxItems: 3, - Nested: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Nested: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Type: "string", }, @@ -384,15 +385,15 @@ func TestDec_Convert_BlockSet(t *testing.T) { tests := []testConversions{ { Name: "block set with attr", - Input: &Spec{ - Block: &Spec_BlockSet{ - BlockSet: &BlockSet{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_BlockSet{ + BlockSet: &hclspec.BlockSet{ Name: "test", MinItems: 1, MaxItems: 3, - Nested: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Nested: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Type: "string", }, @@ -414,14 +415,14 @@ func TestDec_Convert_BlockSet(t *testing.T) { }, { Name: "block set missing name", - Input: &Spec{ - Block: &Spec_BlockSet{ - BlockSet: &BlockSet{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_BlockSet{ + BlockSet: &hclspec.BlockSet{ MinItems: 1, MaxItems: 3, - Nested: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Nested: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Type: "string", }, @@ -443,14 +444,14 @@ func TestDec_Convert_BlockMap(t *testing.T) { tests := []testConversions{ { Name: "block map with attr", - Input: &Spec{ - Block: &Spec_BlockMap{ - BlockMap: &BlockMap{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_BlockMap{ + BlockMap: &hclspec.BlockMap{ Name: "test", Labels: []string{"key1", "key2"}, - Nested: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Nested: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Type: "string", }, @@ -471,13 +472,13 @@ func TestDec_Convert_BlockMap(t *testing.T) { }, { Name: "block map missing name", - Input: &Spec{ - Block: &Spec_BlockMap{ - BlockMap: &BlockMap{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_BlockMap{ + BlockMap: &hclspec.BlockMap{ Labels: []string{"key1", "key2"}, - Nested: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Nested: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Type: "string", }, @@ -490,13 +491,13 @@ func TestDec_Convert_BlockMap(t *testing.T) { }, { Name: "block map missing labels", - Input: &Spec{ - Block: &Spec_BlockMap{ - BlockMap: &BlockMap{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_BlockMap{ + BlockMap: &hclspec.BlockMap{ Name: "foo", - Nested: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Nested: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Type: "string", }, @@ -518,21 +519,21 @@ func TestDec_Convert_Default(t *testing.T) { tests := []testConversions{ { Name: "default attr", - Input: &Spec{ - Block: &Spec_Default{ - Default: &Default{ - Primary: &Spec{ - Block: &Spec_Attr{ - &Attr{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_Default{ + Default: &hclspec.Default{ + Primary: &hclspec.Spec{ + Block: &hclspec.Spec_Attr{ + Attr: &hclspec.Attr{ Name: "foo", Type: "string", Required: true, }, }, }, - Default: &Spec{ - Block: &Spec_Literal{ - &Literal{ + Default: &hclspec.Spec{ + Block: &hclspec.Spec_Literal{ + Literal: &hclspec.Literal{ Value: "\"hi\"", }, }, @@ -562,9 +563,9 @@ func TestDec_Convert_Literal(t *testing.T) { tests := []testConversions{ { Name: "bool: true", - Input: &Spec{ - Block: &Spec_Literal{ - Literal: &Literal{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_Literal{ + Literal: &hclspec.Literal{ Value: "true", }, }, @@ -575,9 +576,9 @@ func TestDec_Convert_Literal(t *testing.T) { }, { Name: "bool: false", - Input: &Spec{ - Block: &Spec_Literal{ - Literal: &Literal{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_Literal{ + Literal: &hclspec.Literal{ Value: "false", }, }, @@ -588,9 +589,9 @@ func TestDec_Convert_Literal(t *testing.T) { }, { Name: "string", - Input: &Spec{ - Block: &Spec_Literal{ - Literal: &Literal{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_Literal{ + Literal: &hclspec.Literal{ Value: "\"hi\"", }, }, @@ -601,9 +602,9 @@ func TestDec_Convert_Literal(t *testing.T) { }, { Name: "string w/ func", - Input: &Spec{ - Block: &Spec_Literal{ - Literal: &Literal{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_Literal{ + Literal: &hclspec.Literal{ Value: "reverse(\"hi\")", }, }, @@ -614,9 +615,9 @@ func TestDec_Convert_Literal(t *testing.T) { }, { Name: "list string", - Input: &Spec{ - Block: &Spec_Literal{ - Literal: &Literal{ + Input: &hclspec.Spec{ + Block: &hclspec.Spec_Literal{ + Literal: &hclspec.Literal{ Value: "[\"hi\", \"bye\"]", }, }, diff --git a/plugins/shared/hclspec/spec_funcs.go b/helper/pluginutils/hclspecutils/spec_funcs.go similarity index 97% rename from plugins/shared/hclspec/spec_funcs.go rename to helper/pluginutils/hclspecutils/spec_funcs.go index c50c7d997..c5ab39cb5 100644 --- a/plugins/shared/hclspec/spec_funcs.go +++ b/helper/pluginutils/hclspecutils/spec_funcs.go @@ -1,4 +1,4 @@ -package hclspec +package hclspecutils import ( "github.com/zclconf/go-cty/cty/function" diff --git a/plugins/shared/hclspec/type_expr.go b/helper/pluginutils/hclspecutils/type_expr.go similarity index 99% rename from plugins/shared/hclspec/type_expr.go rename to helper/pluginutils/hclspecutils/type_expr.go index 5b8472b7c..1cd74ecdf 100644 --- a/plugins/shared/hclspec/type_expr.go +++ b/helper/pluginutils/hclspecutils/type_expr.go @@ -1,4 +1,4 @@ -package hclspec +package hclspecutils import ( "fmt" diff --git a/plugins/shared/hclutils/util.go b/helper/pluginutils/hclutils/util.go similarity index 100% rename from plugins/shared/hclutils/util.go rename to helper/pluginutils/hclutils/util.go diff --git a/plugins/shared/hclutils/util_test.go b/helper/pluginutils/hclutils/util_test.go similarity index 100% rename from plugins/shared/hclutils/util_test.go rename to helper/pluginutils/hclutils/util_test.go diff --git a/plugins/shared/loader/api_versions.go b/helper/pluginutils/loader/api_versions.go similarity index 100% rename from plugins/shared/loader/api_versions.go rename to helper/pluginutils/loader/api_versions.go diff --git a/plugins/shared/loader/filter_unix.go b/helper/pluginutils/loader/filter_unix.go similarity index 100% rename from plugins/shared/loader/filter_unix.go rename to helper/pluginutils/loader/filter_unix.go diff --git a/plugins/shared/loader/filter_windows.go b/helper/pluginutils/loader/filter_windows.go similarity index 100% rename from plugins/shared/loader/filter_windows.go rename to helper/pluginutils/loader/filter_windows.go diff --git a/plugins/shared/loader/init.go b/helper/pluginutils/loader/init.go similarity index 98% rename from plugins/shared/loader/init.go rename to helper/pluginutils/loader/init.go index 76ffd8854..774156c8d 100644 --- a/plugins/shared/loader/init.go +++ b/helper/pluginutils/loader/init.go @@ -11,10 +11,10 @@ import ( plugin "github.com/hashicorp/go-plugin" version "github.com/hashicorp/go-version" hcl2 "github.com/hashicorp/hcl2/hcl" + "github.com/hashicorp/nomad/helper/pluginutils/hclspecutils" + "github.com/hashicorp/nomad/helper/pluginutils/hclutils" "github.com/hashicorp/nomad/nomad/structs/config" "github.com/hashicorp/nomad/plugins/base" - "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/hclutils" "github.com/zclconf/go-cty/cty/msgpack" ) @@ -453,7 +453,7 @@ func (l *PluginLoader) validatePluginConfig(id PluginID, info *pluginInfo) error } // Convert the schema to hcl - spec, diag := hclspec.Convert(info.configSchema) + spec, diag := hclspecutils.Convert(info.configSchema) if diag.HasErrors() { multierror.Append(&mErr, diag.Errs()...) return multierror.Prefix(&mErr, "failed converting config schema:") diff --git a/plugins/shared/loader/instance.go b/helper/pluginutils/loader/instance.go similarity index 100% rename from plugins/shared/loader/instance.go rename to helper/pluginutils/loader/instance.go diff --git a/plugins/shared/loader/loader.go b/helper/pluginutils/loader/loader.go similarity index 99% rename from plugins/shared/loader/loader.go rename to helper/pluginutils/loader/loader.go index b07904832..ece1231d0 100644 --- a/plugins/shared/loader/loader.go +++ b/helper/pluginutils/loader/loader.go @@ -6,7 +6,7 @@ import ( log "github.com/hashicorp/go-hclog" plugin "github.com/hashicorp/go-plugin" - "github.com/hashicorp/go-version" + version "github.com/hashicorp/go-version" "github.com/hashicorp/nomad/nomad/structs/config" "github.com/hashicorp/nomad/plugins" "github.com/hashicorp/nomad/plugins/base" diff --git a/plugins/shared/loader/loader_test.go b/helper/pluginutils/loader/loader_test.go similarity index 100% rename from plugins/shared/loader/loader_test.go rename to helper/pluginutils/loader/loader_test.go diff --git a/plugins/shared/loader/plugin_test.go b/helper/pluginutils/loader/plugin_test.go similarity index 100% rename from plugins/shared/loader/plugin_test.go rename to helper/pluginutils/loader/plugin_test.go diff --git a/plugins/shared/loader/testing.go b/helper/pluginutils/loader/testing.go similarity index 100% rename from plugins/shared/loader/testing.go rename to helper/pluginutils/loader/testing.go diff --git a/plugins/shared/loader/util.go b/helper/pluginutils/loader/util.go similarity index 100% rename from plugins/shared/loader/util.go rename to helper/pluginutils/loader/util.go diff --git a/plugins/shared/singleton/future.go b/helper/pluginutils/singleton/future.go similarity index 95% rename from plugins/shared/singleton/future.go rename to helper/pluginutils/singleton/future.go index 10b8a7b65..6869f2763 100644 --- a/plugins/shared/singleton/future.go +++ b/helper/pluginutils/singleton/future.go @@ -1,8 +1,8 @@ package singleton import ( + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/helper/uuid" - "github.com/hashicorp/nomad/plugins/shared/loader" ) // future is a sharable future for retrieving a plugin instance or any error diff --git a/plugins/shared/singleton/singleton.go b/helper/pluginutils/singleton/singleton.go similarity index 98% rename from plugins/shared/singleton/singleton.go rename to helper/pluginutils/singleton/singleton.go index 260b092c5..2b90f549c 100644 --- a/plugins/shared/singleton/singleton.go +++ b/helper/pluginutils/singleton/singleton.go @@ -6,8 +6,8 @@ import ( log "github.com/hashicorp/go-hclog" plugin "github.com/hashicorp/go-plugin" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/plugins/base" - "github.com/hashicorp/nomad/plugins/shared/loader" ) var ( diff --git a/plugins/shared/singleton/singleton_test.go b/helper/pluginutils/singleton/singleton_test.go similarity index 99% rename from plugins/shared/singleton/singleton_test.go rename to helper/pluginutils/singleton/singleton_test.go index e1f122513..cfe067844 100644 --- a/plugins/shared/singleton/singleton_test.go +++ b/helper/pluginutils/singleton/singleton_test.go @@ -8,9 +8,9 @@ import ( log "github.com/hashicorp/go-hclog" plugin "github.com/hashicorp/go-plugin" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/plugins/base" - "github.com/hashicorp/nomad/plugins/shared/loader" "github.com/stretchr/testify/require" ) diff --git a/jobspec/parse.go b/jobspec/parse.go index c88df2d87..f1914a586 100644 --- a/jobspec/parse.go +++ b/jobspec/parse.go @@ -11,7 +11,7 @@ import ( "strings" "time" - "github.com/hashicorp/go-multierror" + multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/hcl" "github.com/hashicorp/hcl/hcl/ast" "github.com/hashicorp/nomad/api" diff --git a/main.go b/main.go index 45229139c..5f7169670 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "text/tabwriter" "github.com/hashicorp/nomad/command" + "github.com/hashicorp/nomad/drivers/docker/docklog" "github.com/hashicorp/nomad/version" "github.com/mitchellh/cli" "github.com/sean-/seed" @@ -36,6 +37,7 @@ var ( "server-join", "server-members", "syslog", + docklog.PluginName, } // aliases is the list of aliases we want users to be aware of. We hide diff --git a/nomad/alloc_endpoint.go b/nomad/alloc_endpoint.go index dd1dfcc96..643fa2bf8 100644 --- a/nomad/alloc_endpoint.go +++ b/nomad/alloc_endpoint.go @@ -4,11 +4,11 @@ import ( "fmt" "time" + metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" + memdb "github.com/hashicorp/go-memdb" multierror "github.com/hashicorp/go-multierror" - "github.com/armon/go-metrics" - "github.com/hashicorp/go-memdb" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/structs" diff --git a/nomad/alloc_endpoint_test.go b/nomad/alloc_endpoint_test.go index 5d309d7c3..b34dc7345 100644 --- a/nomad/alloc_endpoint_test.go +++ b/nomad/alloc_endpoint_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/hashicorp/net-rpc-msgpackrpc" + msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/helper/uuid" diff --git a/nomad/autopilot.go b/nomad/autopilot.go index 399b3458f..2cb5e2505 100644 --- a/nomad/autopilot.go +++ b/nomad/autopilot.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/armon/go-metrics" + metrics "github.com/armon/go-metrics" "github.com/hashicorp/consul/agent/consul/autopilot" "github.com/hashicorp/raft" "github.com/hashicorp/serf/serf" diff --git a/nomad/config.go b/nomad/config.go index d67241757..eab6267ff 100644 --- a/nomad/config.go +++ b/nomad/config.go @@ -11,10 +11,10 @@ import ( log "github.com/hashicorp/go-hclog" "github.com/hashicorp/memberlist" + "github.com/hashicorp/nomad/helper/pluginutils/loader" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/nomad/structs/config" - "github.com/hashicorp/nomad/plugins/shared/loader" "github.com/hashicorp/nomad/scheduler" "github.com/hashicorp/raft" "github.com/hashicorp/serf/serf" diff --git a/nomad/eval_endpoint.go b/nomad/eval_endpoint.go index da7520e71..ff30eaba8 100644 --- a/nomad/eval_endpoint.go +++ b/nomad/eval_endpoint.go @@ -4,11 +4,11 @@ import ( "fmt" "time" + metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" + memdb "github.com/hashicorp/go-memdb" multierror "github.com/hashicorp/go-multierror" - "github.com/armon/go-metrics" - "github.com/hashicorp/go-memdb" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/structs" diff --git a/nomad/eval_endpoint_test.go b/nomad/eval_endpoint_test.go index f5e144fa7..43662ed8c 100644 --- a/nomad/eval_endpoint_test.go +++ b/nomad/eval_endpoint_test.go @@ -8,7 +8,7 @@ import ( "time" memdb "github.com/hashicorp/go-memdb" - "github.com/hashicorp/net-rpc-msgpackrpc" + msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/mock" diff --git a/nomad/fsm.go b/nomad/fsm.go index c78b1fb51..3c91b8f5c 100644 --- a/nomad/fsm.go +++ b/nomad/fsm.go @@ -7,7 +7,7 @@ import ( "sync" "time" - "github.com/armon/go-metrics" + metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" memdb "github.com/hashicorp/go-memdb" "github.com/hashicorp/nomad/helper/uuid" diff --git a/nomad/heartbeat.go b/nomad/heartbeat.go index fe3b829ff..579d8d652 100644 --- a/nomad/heartbeat.go +++ b/nomad/heartbeat.go @@ -5,10 +5,10 @@ import ( "sync" "time" + metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" memdb "github.com/hashicorp/go-memdb" - "github.com/armon/go-metrics" "github.com/hashicorp/consul/lib" "github.com/hashicorp/nomad/nomad/structs" ) diff --git a/nomad/heartbeat_test.go b/nomad/heartbeat_test.go index 72a21377c..0e9e56ffb 100644 --- a/nomad/heartbeat_test.go +++ b/nomad/heartbeat_test.go @@ -6,7 +6,7 @@ import ( "time" memdb "github.com/hashicorp/go-memdb" - "github.com/hashicorp/net-rpc-msgpackrpc" + msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" diff --git a/nomad/job_endpoint.go b/nomad/job_endpoint.go index 94991c3f3..132c14f58 100644 --- a/nomad/job_endpoint.go +++ b/nomad/job_endpoint.go @@ -7,13 +7,13 @@ import ( "strings" "time" + metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" memdb "github.com/hashicorp/go-memdb" + multierror "github.com/hashicorp/go-multierror" - "github.com/armon/go-metrics" "github.com/golang/snappy" "github.com/hashicorp/consul/lib" - "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/helper/uuid" diff --git a/nomad/leader.go b/nomad/leader.go index f9aa35208..55bd2857e 100644 --- a/nomad/leader.go +++ b/nomad/leader.go @@ -13,10 +13,10 @@ import ( "strings" - "github.com/armon/go-metrics" + metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" memdb "github.com/hashicorp/go-memdb" - "github.com/hashicorp/go-version" + version "github.com/hashicorp/go-version" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/structs" diff --git a/nomad/mock/acl.go b/nomad/mock/acl.go index 01b65600b..3166db8cb 100644 --- a/nomad/mock/acl.go +++ b/nomad/mock/acl.go @@ -5,8 +5,9 @@ import ( "strconv" "strings" + testing "github.com/mitchellh/go-testing-interface" + "github.com/hashicorp/nomad/nomad/structs" - "github.com/mitchellh/go-testing-interface" "github.com/stretchr/testify/assert" ) diff --git a/nomad/node_endpoint.go b/nomad/node_endpoint.go index 84f51ee08..5e57406f8 100644 --- a/nomad/node_endpoint.go +++ b/nomad/node_endpoint.go @@ -9,12 +9,12 @@ import ( "golang.org/x/sync/errgroup" + metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" + memdb "github.com/hashicorp/go-memdb" + multierror "github.com/hashicorp/go-multierror" vapi "github.com/hashicorp/vault/api" - "github.com/armon/go-metrics" - "github.com/hashicorp/go-memdb" - "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/state" diff --git a/nomad/node_endpoint_test.go b/nomad/node_endpoint_test.go index 35eea7d85..70542392b 100644 --- a/nomad/node_endpoint_test.go +++ b/nomad/node_endpoint_test.go @@ -9,7 +9,7 @@ import ( "time" memdb "github.com/hashicorp/go-memdb" - "github.com/hashicorp/net-rpc-msgpackrpc" + msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/mock" diff --git a/nomad/operator_endpoint_test.go b/nomad/operator_endpoint_test.go index 957ce9e84..4f9d85345 100644 --- a/nomad/operator_endpoint_test.go +++ b/nomad/operator_endpoint_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/hashicorp/consul/lib/freeport" - "github.com/hashicorp/net-rpc-msgpackrpc" + msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" diff --git a/nomad/periodic_endpoint.go b/nomad/periodic_endpoint.go index ecac25654..4864fdd68 100644 --- a/nomad/periodic_endpoint.go +++ b/nomad/periodic_endpoint.go @@ -4,10 +4,10 @@ import ( "fmt" "time" + metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" memdb "github.com/hashicorp/go-memdb" - "github.com/armon/go-metrics" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/nomad/structs" ) diff --git a/nomad/plan_apply.go b/nomad/plan_apply.go index 28a2b14db..f40690d00 100644 --- a/nomad/plan_apply.go +++ b/nomad/plan_apply.go @@ -5,10 +5,10 @@ import ( "runtime" "time" - "github.com/armon/go-metrics" + metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" memdb "github.com/hashicorp/go-memdb" - "github.com/hashicorp/go-multierror" + multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/structs" diff --git a/nomad/plan_endpoint.go b/nomad/plan_endpoint.go index bacea404d..bf2c461fd 100644 --- a/nomad/plan_endpoint.go +++ b/nomad/plan_endpoint.go @@ -3,9 +3,9 @@ package nomad import ( "time" + metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" - "github.com/armon/go-metrics" "github.com/hashicorp/nomad/nomad/structs" ) diff --git a/nomad/plan_endpoint_test.go b/nomad/plan_endpoint_test.go index ed71ec417..7b9e1c38c 100644 --- a/nomad/plan_endpoint_test.go +++ b/nomad/plan_endpoint_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/hashicorp/net-rpc-msgpackrpc" + msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" diff --git a/nomad/plan_queue.go b/nomad/plan_queue.go index 4a7c93e0b..db031a3e2 100644 --- a/nomad/plan_queue.go +++ b/nomad/plan_queue.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/armon/go-metrics" + metrics "github.com/armon/go-metrics" "github.com/hashicorp/nomad/nomad/structs" ) diff --git a/nomad/regions_endpoint_test.go b/nomad/regions_endpoint_test.go index 8bd79d0bb..bf6d0e203 100644 --- a/nomad/regions_endpoint_test.go +++ b/nomad/regions_endpoint_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/hashicorp/net-rpc-msgpackrpc" + msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" ) diff --git a/nomad/state/autopilot.go b/nomad/state/autopilot.go index 83613817d..79447b2ce 100644 --- a/nomad/state/autopilot.go +++ b/nomad/state/autopilot.go @@ -3,7 +3,7 @@ package state import ( "fmt" - "github.com/hashicorp/go-memdb" + memdb "github.com/hashicorp/go-memdb" "github.com/hashicorp/nomad/nomad/structs" ) diff --git a/nomad/state/schema.go b/nomad/state/schema.go index 53df292dc..dc262977e 100644 --- a/nomad/state/schema.go +++ b/nomad/state/schema.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/hashicorp/go-memdb" + memdb "github.com/hashicorp/go-memdb" "github.com/hashicorp/nomad/nomad/structs" ) diff --git a/nomad/state/schema_test.go b/nomad/state/schema_test.go index 93c6d5872..1e1a17d82 100644 --- a/nomad/state/schema_test.go +++ b/nomad/state/schema_test.go @@ -3,7 +3,7 @@ package state import ( "testing" - "github.com/hashicorp/go-memdb" + memdb "github.com/hashicorp/go-memdb" ) func TestStateStoreSchema(t *testing.T) { diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 49626547b..84201cbaa 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -9,7 +9,7 @@ import ( "reflect" log "github.com/hashicorp/go-hclog" - "github.com/hashicorp/go-memdb" + memdb "github.com/hashicorp/go-memdb" multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/structs" diff --git a/nomad/state/testing.go b/nomad/state/testing.go index 5bf235016..bacb0470a 100644 --- a/nomad/state/testing.go +++ b/nomad/state/testing.go @@ -1,8 +1,9 @@ package state import ( + testing "github.com/mitchellh/go-testing-interface" + "github.com/hashicorp/nomad/helper/testlog" - "github.com/mitchellh/go-testing-interface" ) func TestStateStore(t testing.T) *StateStore { diff --git a/nomad/state/testing_oss.go b/nomad/state/testing_oss.go index ff9c3b23f..9c858d07e 100644 --- a/nomad/state/testing_oss.go +++ b/nomad/state/testing_oss.go @@ -3,7 +3,7 @@ package state import ( - "github.com/mitchellh/go-testing-interface" + testing "github.com/mitchellh/go-testing-interface" ) func TestInitState(t testing.T, state *StateStore) {} diff --git a/nomad/status_endpoint_test.go b/nomad/status_endpoint_test.go index eb968b673..7f3456124 100644 --- a/nomad/status_endpoint_test.go +++ b/nomad/status_endpoint_test.go @@ -3,7 +3,7 @@ package nomad import ( "testing" - "github.com/hashicorp/net-rpc-msgpackrpc" + msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/mock" diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index b735d6e37..775cf988f 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -7288,13 +7288,17 @@ func (a *Allocation) copyImpl(job bool) *Allocation { func (a *Allocation) TerminalStatus() bool { // First check the desired state and if that isn't terminal, check client // state. + return a.ServerTerminalStatus() || a.ClientTerminalStatus() +} + +// ServerTerminalStatus returns true if the desired state of the allocation is terminal +func (a *Allocation) ServerTerminalStatus() bool { switch a.DesiredStatus { case AllocDesiredStatusStop, AllocDesiredStatusEvict: return true default: + return false } - - return a.ClientTerminalStatus() } // ClientTerminalStatus returns if the client status is terminal and will no longer transition diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 2669f9399..9d2507669 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -9,7 +9,7 @@ import ( "time" "github.com/hashicorp/consul/api" - "github.com/hashicorp/go-multierror" + multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/helper/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/nomad/system_endpoint_test.go b/nomad/system_endpoint_test.go index ba9353e1e..4717dd537 100644 --- a/nomad/system_endpoint_test.go +++ b/nomad/system_endpoint_test.go @@ -6,7 +6,7 @@ import ( "testing" memdb "github.com/hashicorp/go-memdb" - "github.com/hashicorp/net-rpc-msgpackrpc" + msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" diff --git a/nomad/testing.go b/nomad/testing.go index 7d0f9fcd0..248644bc2 100644 --- a/nomad/testing.go +++ b/nomad/testing.go @@ -7,14 +7,15 @@ import ( "sync/atomic" "time" + testing "github.com/mitchellh/go-testing-interface" + "github.com/hashicorp/consul/lib/freeport" "github.com/hashicorp/nomad/command/agent/consul" + "github.com/hashicorp/nomad/helper/pluginutils/catalog" + "github.com/hashicorp/nomad/helper/pluginutils/singleton" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" - "github.com/hashicorp/nomad/plugins/shared/catalog" - "github.com/hashicorp/nomad/plugins/shared/singleton" - "github.com/mitchellh/go-testing-interface" ) var ( diff --git a/nomad/vault.go b/nomad/vault.go index ebf4bced2..e07142825 100644 --- a/nomad/vault.go +++ b/nomad/vault.go @@ -10,7 +10,7 @@ import ( "sync/atomic" "time" - "gopkg.in/tomb.v2" + tomb "gopkg.in/tomb.v2" metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" diff --git a/nomad/worker.go b/nomad/worker.go index 19442f47c..f0aefb62d 100644 --- a/nomad/worker.go +++ b/nomad/worker.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/armon/go-metrics" + metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" memdb "github.com/hashicorp/go-memdb" "github.com/hashicorp/nomad/nomad/structs" diff --git a/plugins/base/client.go b/plugins/base/client.go index 9dadaeed4..d7c4e9431 100644 --- a/plugins/base/client.go +++ b/plugins/base/client.go @@ -4,8 +4,8 @@ import ( "context" "fmt" + "github.com/hashicorp/nomad/helper/pluginutils/grpcutils" "github.com/hashicorp/nomad/plugins/base/proto" - "github.com/hashicorp/nomad/plugins/shared/grpcutils" "github.com/hashicorp/nomad/plugins/shared/hclspec" ) diff --git a/plugins/device/client.go b/plugins/device/client.go index 4dc187453..1538b2b80 100644 --- a/plugins/device/client.go +++ b/plugins/device/client.go @@ -7,9 +7,9 @@ import ( "github.com/LK4D4/joincontext" "github.com/golang/protobuf/ptypes" + "github.com/hashicorp/nomad/helper/pluginutils/grpcutils" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/device/proto" - "github.com/hashicorp/nomad/plugins/shared/grpcutils" ) // devicePluginClient implements the client side of a remote device plugin, using @@ -27,7 +27,7 @@ type devicePluginClient struct { // Fingerprint is used to retrieve the set of devices and their health from the // device plugin. An error may be immediately returned if the fingerprint call // could not be made or as part of the streaming response. If the context is -// cancelled, the error will be propogated. +// cancelled, the error will be propagated. func (d *devicePluginClient) Fingerprint(ctx context.Context) (<-chan *FingerprintResponse, error) { // Join the passed context and the shutdown context joinedCtx, _ := joincontext.Join(ctx, d.doneCtx) @@ -97,7 +97,7 @@ func (d *devicePluginClient) Reserve(deviceIDs []string) (*ContainerReservation, // Stats is used to retrieve device statistics from the device plugin. An error // may be immediately returned if the stats call could not be made or as part of // the streaming response. If the context is cancelled, the error will be -// propogated. +// propagated. func (d *devicePluginClient) Stats(ctx context.Context, interval time.Duration) (<-chan *StatsResponse, error) { // Join the passed context and the shutdown context joinedCtx, _ := joincontext.Join(ctx, d.doneCtx) diff --git a/plugins/drivers/client.go b/plugins/drivers/client.go index d5225e384..e8ce41c40 100644 --- a/plugins/drivers/client.go +++ b/plugins/drivers/client.go @@ -10,10 +10,10 @@ import ( "github.com/golang/protobuf/ptypes" hclog "github.com/hashicorp/go-hclog" cstructs "github.com/hashicorp/nomad/client/structs" + "github.com/hashicorp/nomad/helper/pluginutils/grpcutils" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers/proto" - "github.com/hashicorp/nomad/plugins/shared/grpcutils" "github.com/hashicorp/nomad/plugins/shared/hclspec" pstructs "github.com/hashicorp/nomad/plugins/shared/structs" sproto "github.com/hashicorp/nomad/plugins/shared/structs/proto" diff --git a/plugins/drivers/testutils/testing.go b/plugins/drivers/testutils/testing.go index a9756be2d..c363c593f 100644 --- a/plugins/drivers/testutils/testing.go +++ b/plugins/drivers/testutils/testing.go @@ -9,6 +9,8 @@ import ( "strings" "time" + testing "github.com/mitchellh/go-testing-interface" + hclog "github.com/hashicorp/go-hclog" plugin "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/allocdir" @@ -22,7 +24,6 @@ import ( "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/mitchellh/go-testing-interface" "github.com/stretchr/testify/require" ) diff --git a/plugins/shared/cmd/launcher/command/device.go b/plugins/shared/cmd/launcher/command/device.go index fc8b6b7af..5b5d4855c 100644 --- a/plugins/shared/cmd/launcher/command/device.go +++ b/plugins/shared/cmd/launcher/command/device.go @@ -16,10 +16,10 @@ import ( "github.com/hashicorp/hcl/hcl/ast" hcl2 "github.com/hashicorp/hcl2/hcl" "github.com/hashicorp/hcl2/hcldec" + "github.com/hashicorp/nomad/helper/pluginutils/hclspecutils" + "github.com/hashicorp/nomad/helper/pluginutils/hclutils" "github.com/hashicorp/nomad/plugins/base" "github.com/hashicorp/nomad/plugins/device" - "github.com/hashicorp/nomad/plugins/shared/hclspec" - "github.com/hashicorp/nomad/plugins/shared/hclutils" "github.com/kr/pretty" "github.com/mitchellh/cli" "github.com/zclconf/go-cty/cty/msgpack" @@ -176,7 +176,7 @@ func (c *Device) getSpec() (hcldec.Spec, error) { c.logger.Trace("device spec", "spec", hclog.Fmt("% #v", pretty.Formatter(spec))) // Convert the schema - schema, diag := hclspec.Convert(spec) + schema, diag := hclspecutils.Convert(spec) if diag.HasErrors() { errStr := "failed to convert HCL schema: " for _, err := range diag.Errs() { diff --git a/plugins/shared/plugin_reattach_config.go b/plugins/shared/structs/plugin_reattach_config.go similarity index 99% rename from plugins/shared/plugin_reattach_config.go rename to plugins/shared/structs/plugin_reattach_config.go index 1c4fd1e55..efac22e80 100644 --- a/plugins/shared/plugin_reattach_config.go +++ b/plugins/shared/structs/plugin_reattach_config.go @@ -1,4 +1,4 @@ -package shared +package structs import ( "fmt" diff --git a/scheduler/context.go b/scheduler/context.go index 0d83deab8..07cf9fdd6 100644 --- a/scheduler/context.go +++ b/scheduler/context.go @@ -5,7 +5,7 @@ import ( log "github.com/hashicorp/go-hclog" memdb "github.com/hashicorp/go-memdb" - "github.com/hashicorp/go-version" + version "github.com/hashicorp/go-version" "github.com/hashicorp/nomad/nomad/structs" ) diff --git a/scheduler/feasible.go b/scheduler/feasible.go index ce0f6d1ca..856b199b1 100644 --- a/scheduler/feasible.go +++ b/scheduler/feasible.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "github.com/hashicorp/go-version" + version "github.com/hashicorp/go-version" "github.com/hashicorp/nomad/nomad/structs" psstructs "github.com/hashicorp/nomad/plugins/shared/structs" ) diff --git a/scheduler/generic_sched.go b/scheduler/generic_sched.go index 93f982ede..e4b27b64e 100644 --- a/scheduler/generic_sched.go +++ b/scheduler/generic_sched.go @@ -6,7 +6,7 @@ import ( log "github.com/hashicorp/go-hclog" memdb "github.com/hashicorp/go-memdb" - "github.com/hashicorp/go-multierror" + multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/structs" ) diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index bd921a788..639b2b8cf 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -5,7 +5,7 @@ import ( log "github.com/hashicorp/go-hclog" - "github.com/hashicorp/go-memdb" + memdb "github.com/hashicorp/go-memdb" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/structs" ) diff --git a/scheduler/testing.go b/scheduler/testing.go index 31fc9ab91..f05010102 100644 --- a/scheduler/testing.go +++ b/scheduler/testing.go @@ -5,11 +5,12 @@ import ( "sync" "time" + testing "github.com/mitchellh/go-testing-interface" + memdb "github.com/hashicorp/go-memdb" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/structs" - "github.com/mitchellh/go-testing-interface" ) // RejectPlan is used to always reject the entire plan and force a state refresh diff --git a/scripts/test_check.sh b/scripts/test_check.sh index 4110f5c89..14ea78a9f 100755 --- a/scripts/test_check.sh +++ b/scripts/test_check.sh @@ -4,7 +4,7 @@ grep -A10 'panic: test timed out' test.log || true; grep -A1 -- '--- SKIP:' test.log || true; grep -A1 -- '--- FAIL:' test.log || true; grep '^FAIL' test.log || true; -exit_code=`cat exit-code` -echo $exit_code -if [ ${exit_code} == "0" ]; then echo "PASS" ; exit 0 ; else echo "TESTS FAILED"; exit 1 ; fi +exit_code=$(cat exit-code) +echo "$exit_code " +if [ "${exit_code}" == "0" ]; then echo "PASS" ; exit 0 ; else echo "TESTS FAILED"; exit 1 ; fi diff --git a/scripts/update_docker.sh b/scripts/update_docker.sh index 1f5f7a801..dc3972b80 100755 --- a/scripts/update_docker.sh +++ b/scripts/update_docker.sh @@ -6,7 +6,7 @@ DOCKER_VERSION="1.10.3" sudo stop docker sudo rm -rf /var/lib/docker -sudo rm -f "$(which docker)" +sudo rm -f "$(command -v docker)" sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list sudo apt-get update diff --git a/scripts/vagrant-linux-priv-protoc.sh b/scripts/vagrant-linux-priv-protoc.sh index 6e5ab7715..184fa049c 100755 --- a/scripts/vagrant-linux-priv-protoc.sh +++ b/scripts/vagrant-linux-priv-protoc.sh @@ -1,8 +1,8 @@ -# Make sure you grab the latest version #!/usr/bin/env bash set -o errexit +# Make sure you grab the latest version VERSION=3.6.1 DOWNLOAD=https://github.com/google/protobuf/releases/download/v${VERSION}/protoc-${VERSION}-linux-x86_64.zip diff --git a/testutil/wait.go b/testutil/wait.go index 7c947a3c6..c5bbf439c 100644 --- a/testutil/wait.go +++ b/testutil/wait.go @@ -6,7 +6,7 @@ import ( "time" "github.com/hashicorp/nomad/nomad/structs" - "github.com/mitchellh/go-testing-interface" + testing "github.com/mitchellh/go-testing-interface" "github.com/stretchr/testify/require" ) diff --git a/vendor/github.com/rkt/rkt/LICENSE b/vendor/github.com/rkt/rkt/LICENSE deleted file mode 100644 index 5c304d1a4..000000000 --- a/vendor/github.com/rkt/rkt/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/rkt/rkt/api/v1/json.go b/vendor/github.com/rkt/rkt/api/v1/json.go deleted file mode 100644 index 534c46f67..000000000 --- a/vendor/github.com/rkt/rkt/api/v1/json.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2016 The rkt Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v1 - -import "github.com/rkt/rkt/networking/netinfo" - -// AppState defines the state of the app. -type AppState string - -const ( - AppStateUnknown AppState = "unknown" - AppStateCreated AppState = "created" - AppStateRunning AppState = "running" - AppStateExited AppState = "exited" -) - -type ( - // Mount defines the mount point. - Mount struct { - // Name of the mount. - Name string `json:"name"` - // Container path of the mount. - ContainerPath string `json:"container_path"` - // Host path of the mount. - HostPath string `json:"host_path"` - // Whether the mount is read-only. - ReadOnly bool `json:"read_only"` - // TODO(yifan): What about 'SelinuxRelabel bool'? - } - - // App defines the app object. - App struct { - // Name of the app. - Name string `json:"name"` - // State of the app, can be created, running, exited, or unknown. - State AppState `json:"state"` - // Creation time of the container, nanoseconds since epoch. - CreatedAt *int64 `json:"created_at,omitempty"` - // Start time of the container, nanoseconds since epoch. - StartedAt *int64 `json:"started_at,omitempty"` - // Finish time of the container, nanoseconds since epoch. - FinishedAt *int64 `json:"finished_at,omitempty"` - // Exit code of the container. - ExitCode *int32 `json:"exit_code,omitempty"` - // Image ID of the container. - ImageID string `json:"image_id"` - // Mount points of the container. - Mounts []*Mount `json:"mounts,omitempty"` - // User annotations of the container. - UserAnnotations map[string]string `json:"user_annotations,omitempty"` - // User labels of the container. - UserLabels map[string]string `json:"user_labels,omitempty"` - } - - // Pod defines the pod object. - Pod struct { - // UUID of the pod. - UUID string `json:"name"` - // State of the pod, all valid values are defined in pkg/pod/pods.go. - State string `json:"state"` - // Networks are the information of the networks. - Networks []netinfo.NetInfo `json:"networks,omitempty"` - // AppNames are the names of the apps. - // Deprecated: use Apps instead. - AppNames []string `json:"app_names,omitempty"` - // Apps holds current information about each app. - Apps []*App `json:"apps,omitempty"` - // The start time of the pod. - StartedAt *int64 `json:"started_at,omitempty"` - // UserAnnotations are the pod user annotations. - UserAnnotations map[string]string `json:"user_annotations,omitempty"` - // UserLabels are the pod user labels. - UserLabels map[string]string `json:"user_labels,omitempty"` - } - - ImageListEntry struct { - // ID is the Image ID for this image - ID string `json:"id"` - // Name is the name of this image, such as example.com/some/image - Name string `json:"name"` - // ImportTime indicates when this image was imported in nanoseconds - // since the unix epoch - ImportTime int64 `json:"import_time"` - // LastUsedTime indicates when was last used in nanoseconds since the - // unix epoch - LastUsedTime int64 `json:"last_used_time"` - // Size is the size of this image in bytes - Size int64 `json:"size"` - } -) diff --git a/vendor/github.com/rkt/rkt/networking/netinfo/netinfo.go b/vendor/github.com/rkt/rkt/networking/netinfo/netinfo.go deleted file mode 100644 index 02d9f6f1d..000000000 --- a/vendor/github.com/rkt/rkt/networking/netinfo/netinfo.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2015 The rkt Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package netinfo - -import ( - "encoding/json" - "net" - "os" - "path/filepath" - "syscall" - - "github.com/containernetworking/cni/pkg/types" -) - -const filename = "net-info.json" - -// A type and some structure to represent rkt's view of a *runtime* -// network instance. -// -// Each instance represents a network configuration that has been enabled, -// along with runtime information from the network plugin. -// -// This information is also serialized in the pod's runtime directory so that -// `rkt list` and other stage0 programs can access the runtime state. -type NetInfo struct { - NetName string `json:"netName"` - ConfPath string `json:"netConf"` - PluginPath string `json:"pluginPath"` - IfName string `json:"ifName"` - IP net.IP `json:"ip"` - Args string `json:"args"` - Mask net.IP `json:"mask"` // we used IP instead of IPMask because support for json serialization (we don't need specific functionalities) - HostIP net.IP `json:"-"` - IP4 *types.IPConfig `json:"-"` - DNS types.DNS `json:"-"` -} - -func LoadAt(cdirfd int) ([]NetInfo, error) { - fd, err := syscall.Openat(cdirfd, filename, syscall.O_RDONLY, 0) - if err != nil { - return nil, err - } - - f := os.NewFile(uintptr(fd), filename) - - var info []NetInfo - err = json.NewDecoder(f).Decode(&info) - return info, err -} - -func Save(root string, info []NetInfo) error { - f, err := os.Create(filepath.Join(root, filename)) - if err != nil { - return err - } - defer f.Close() - - return json.NewEncoder(f).Encode(info) -} - -// MergeCNIResult will incorporate the result of a CNI plugin's execution -func (ni *NetInfo) MergeCNIResult(result types.Result) { - ni.IP = result.IP4.IP.IP - ni.Mask = net.IP(result.IP4.IP.Mask) - ni.HostIP = result.IP4.Gateway - ni.IP4 = result.IP4 - ni.DNS = result.DNS -} diff --git a/vendor/vendor.json b/vendor/vendor.json index 9294fdbb6..4ff3be734 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -334,8 +334,6 @@ {"path":"github.com/prometheus/common/model","checksumSHA1":"3VoqH7TFfzA6Ds0zFzIbKCUvBmw=","revision":"2f17f4a9d485bf34b4bfaccc273805040e4f86c8","revisionTime":"2017-09-08T16:18:22Z"}, {"path":"github.com/prometheus/procfs","checksumSHA1":"ihxJIjxtbEYdQKwA0D0nRipj95I=","revision":"e645f4e5aaa8506fc71d6edbc5c4ff02c04c46f2","revisionTime":"2017-07-03T10:12:42Z"}, {"path":"github.com/prometheus/procfs/xfs","checksumSHA1":"xCiFAAwVTrjsfZT1BIJQ3DgeNCY=","revision":"e645f4e5aaa8506fc71d6edbc5c4ff02c04c46f2","revisionTime":"2017-07-03T10:12:42Z"}, - {"path":"github.com/rkt/rkt/api/v1","checksumSHA1":"ge4Z0w3QJJYTBqJaK3S+a6MCxzQ=","revision":"3abde24bc284b7ded5784c56b4e8184c28999641","revisionTime":"2017-08-01T12:18:56Z","version":"v1.28.1","versionExact":"v1.28.1"}, - {"path":"github.com/rkt/rkt/networking/netinfo","checksumSHA1":"4QqLbh9MmajcN6gCx8Er1voiQys=","revision":"5e83d91aafef5f7a38fef62c045e8b57eeeb8bce","revisionTime":"2017-09-20T12:17:54Z"}, {"path":"github.com/rs/cors","checksumSHA1":"I778b2sbNN/yjwKSdb3y7hz2yUQ=","revision":"eabcc6af4bbe5ad3a949d36450326a2b0b9894b8","revisionTime":"2017-08-01T07:32:01Z"}, {"path":"github.com/ryanuber/columnize","checksumSHA1":"M57Rrfc8Z966p+IBtQ91QOcUtcg=","comment":"v2.0.1-8-g983d3a5","revision":"abc90934186a77966e2beeac62ed966aac0561d5","revisionTime":"2017-07-03T20:58:27Z"}, {"path":"github.com/ryanuber/go-glob","checksumSHA1":"6JP37UqrI0H80Gpk0Y2P+KXgn5M=","revision":"256dc444b735e061061cf46c809487313d5b0065","revisionTime":"2017-01-28T01:21:29Z"},