From 5bfdb408d5246a80dbec536e110577439c6c572f Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Tue, 16 Aug 2022 08:39:09 -0500 Subject: [PATCH 1/2] build: update to go1.19 --- .changelog/14132.txt | 3 +++ .circleci/config.yml | 8 ++++---- .go-version | 2 +- contributing/README.md | 2 +- scripts/release/mac-remote-build | 2 +- scripts/vagrant-linux-priv-go.sh | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 .changelog/14132.txt diff --git a/.changelog/14132.txt b/.changelog/14132.txt new file mode 100644 index 00000000000..a93b804ce49 --- /dev/null +++ b/.changelog/14132.txt @@ -0,0 +1,3 @@ +```release-note:improvement +build: update to go1.19 +``` diff --git a/.circleci/config.yml b/.circleci/config.yml index fc8a6b5b16a..049c9204d86 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -456,7 +456,7 @@ executors: go: working_directory: /go/src/github.com/hashicorp/nomad docker: - - image: docker.mirror.hashicorp.services/golang:1.18.5 + - image: docker.mirror.hashicorp.services/golang:1.19 resource_class: medium environment: <<: *common_envs @@ -469,7 +469,7 @@ executors: resource_class: large environment: &machine_env <<: *common_envs - GOLANG_VERSION: 1.18.5 + GOLANG_VERSION: 1.19 go-macos: working_directory: ~/go/src/github.com/hashicorp/nomad @@ -478,7 +478,7 @@ executors: environment: <<: *common_envs GOPATH: /Users/distiller/go - GOLANG_VERSION: 1.18.5 + GOLANG_VERSION: 1.19 go-windows: machine: @@ -490,7 +490,7 @@ executors: GOPATH: c:\gopath GOBIN: c:\gopath\bin GOTESTSUM_PATH: c:\tmp\test-reports - GOLANG_VERSION: 1.18.5 + GOLANG_VERSION: 1.19 GOTESTSUM_VERSION: 1.7.0 VAULT_VERSION: 1.4.1 diff --git a/.go-version b/.go-version index 8e8b0a9335a..bc4493477ae 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.18.5 +1.19 diff --git a/contributing/README.md b/contributing/README.md index fa7ea221dac..fdc7e10c2f8 100644 --- a/contributing/README.md +++ b/contributing/README.md @@ -30,7 +30,7 @@ A development environment is supplied via Vagrant to make getting started easier Developing without Vagrant --- -1. Install [Go 1.18.5+](https://golang.org/) *(Note: `gcc-go` is not supported)* +1. Install [Go 1.19+](https://golang.org/) *(Note: `gcc-go` is not supported)* 1. Clone this repo ```sh $ git clone https://github.com/hashicorp/nomad.git diff --git a/scripts/release/mac-remote-build b/scripts/release/mac-remote-build index 65f4b9dde9d..3b91ca3aef6 100755 --- a/scripts/release/mac-remote-build +++ b/scripts/release/mac-remote-build @@ -56,7 +56,7 @@ REPO_PATH="${TMP_WORKSPACE}/gopath/src/github.com/hashicorp/nomad" mkdir -p "${TMP_WORKSPACE}/tmp" install_go() { - local go_version="1.18.5" + local go_version="1.19" local download= download="https://storage.googleapis.com/golang/go${go_version}.darwin-amd64.tar.gz" diff --git a/scripts/vagrant-linux-priv-go.sh b/scripts/vagrant-linux-priv-go.sh index df44b60dd8c..10eb60eebe5 100755 --- a/scripts/vagrant-linux-priv-go.sh +++ b/scripts/vagrant-linux-priv-go.sh @@ -3,7 +3,7 @@ set -o errexit function install_go() { - local go_version="1.18.5" + local go_version="1.19" local download="https://storage.googleapis.com/golang/go${go_version}.linux-amd64.tar.gz" if go version 2>&1 | grep -q "${go_version}"; then From 53a9aecca0559b27fe85d9d6db51b85826c43191 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Tue, 16 Aug 2022 12:08:10 -0500 Subject: [PATCH 2/2] build: run gofmt on all the files --- client/allocdir/alloc_dir_test.go | 5 +- .../taskrunner/envoy_bootstrap_hook.go | 4 +- .../taskrunner/envoy_version_hook.go | 6 +- .../taskrunner/plugin_supervisor_hook.go | 24 +-- .../allocrunner/taskrunner/remotetask_hook.go | 8 +- .../taskrunner/restarts/restarts.go | 10 +- client/allocrunner/taskrunner/task_runner.go | 4 +- client/client.go | 6 +- client/dynamicplugins/registry.go | 3 +- client/pluginmanager/csimanager/doc.go | 19 +- client/state/08types.go | 1 - client/state/upgrade.go | 17 +- client/taskenv/env.go | 1 - command/agent/config.go | 6 +- command/agent/config_test.go | 2 +- command/agent/consul/check_watcher_test.go | 2 +- command/agent/consul/namespaces_client.go | 3 +- command/agent/consul/self.go | 7 +- command/agent/consul/service_client.go | 24 +-- command/agent/consul/unit_test.go | 2 +- command/agent/fs_endpoint.go | 22 +- command/agent/job_endpoint_test.go | 1 + command/data_format.go | 2 +- drivers/docker/config_test.go | 2 +- drivers/docker/driver_windows.go | 2 +- drivers/qemu/driver_test.go | 5 +- drivers/shared/capabilities/defaults.go | 5 +- e2e/consultemplate/consultemplate.go | 2 +- e2e/framework/doc.go | 7 +- helper/escapingio/reader.go | 6 +- helper/pluginutils/hclutils/testing.go | 4 +- jobspec2/functions.go | 1 - jobspec2/hcl_conversions.go | 8 +- jobspec2/hclutil/blockattrs.go | 16 +- jobspec2/parse_test.go | 2 +- jobspec2/types.variables.go | 1 - lib/circbufwriter/writer_test.go | 2 +- lib/cpuset/cpuset_test.go | 2 +- lib/delayheap/delay_heap_test.go | 2 +- nomad/consul_policy_test.go | 2 +- nomad/drainer/draining_node_test.go | 2 +- nomad/drainer/watch_jobs_test.go | 2 +- nomad/eval_broker.go | 6 +- nomad/job_endpoint_hook_expose_check.go | 6 +- nomad/job_endpoint_hook_expose_check_test.go | 2 +- nomad/job_endpoint_test.go | 1 - nomad/leader_test.go | 2 +- nomad/plan_apply.go | 1 - nomad/search_endpoint.go | 26 ++- nomad/stream/subscription_test.go | 2 +- nomad/structs/config/consul.go | 8 +- nomad/structs/config/tls_test.go | 2 +- nomad/structs/config/vault_test.go | 2 +- nomad/structs/devices_test.go | 2 +- nomad/structs/funcs_test.go | 2 +- nomad/structs/node.go | 46 ++--- nomad/structs/node_class_test.go | 2 +- nomad/structs/search.go | 3 +- nomad/structs/structs.go | 2 +- nomad/structs/structs_periodic_test.go | 2 +- nomad/structs/structs_test.go | 2 +- nomad/vault.go | 21 +- plugins/csi/client.go | 46 ++--- plugins/csi/client_test.go | 2 +- plugins/csi/fake/client.go | 2 +- plugins/drivers/proto/driver.pb.go | 20 +- plugins/shared/hclspec/hcl_spec.pb.go | 191 +++++++++--------- plugins/shared/structs/proto/attribute.pb.go | 1 + scheduler/annotate.go | 9 +- scheduler/benchmarks/benchmarks_test.go | 6 +- scheduler/context_test.go | 1 - scheduler/reconcile_util_test.go | 2 +- 72 files changed, 337 insertions(+), 335 deletions(-) diff --git a/client/allocdir/alloc_dir_test.go b/client/allocdir/alloc_dir_test.go index f0764f26e92..ad1c10bb314 100644 --- a/client/allocdir/alloc_dir_test.go +++ b/client/allocdir/alloc_dir_test.go @@ -87,8 +87,9 @@ func TestAllocDir_BuildAlloc(t *testing.T) { } // HACK: This function is copy/pasted from client.testutil to prevent a test -// import cycle, due to testutil transitively importing allocdir. This -// should be fixed after DriverManager is implemented. +// +// import cycle, due to testutil transitively importing allocdir. This +// should be fixed after DriverManager is implemented. func MountCompatible(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("Windows does not support mount") diff --git a/client/allocrunner/taskrunner/envoy_bootstrap_hook.go b/client/allocrunner/taskrunner/envoy_bootstrap_hook.go index fa9c63a4313..02d2c6edce6 100644 --- a/client/allocrunner/taskrunner/envoy_bootstrap_hook.go +++ b/client/allocrunner/taskrunner/envoy_bootstrap_hook.go @@ -150,8 +150,8 @@ func newEnvoyBootstrapHook(c *envoyBootstrapHookConfig) *envoyBootstrapHook { } // getConsulNamespace will resolve the Consul namespace, choosing between -// - agent config (low precedence) -// - task group config (high precedence) +// - agent config (low precedence) +// - task group config (high precedence) func (h *envoyBootstrapHook) getConsulNamespace() string { var namespace string if h.consulConfig.Namespace != "" { diff --git a/client/allocrunner/taskrunner/envoy_version_hook.go b/client/allocrunner/taskrunner/envoy_version_hook.go index 8bd83154941..55b114eae02 100644 --- a/client/allocrunner/taskrunner/envoy_version_hook.go +++ b/client/allocrunner/taskrunner/envoy_version_hook.go @@ -181,9 +181,9 @@ func (h *envoyVersionHook) tweakImage(configured string, supported map[string][] // semver sanitizes the envoy version string coming from Consul into the format // used by the Envoy project when publishing images (i.e. proper semver). This // resulting string value does NOT contain the 'v' prefix for 2 reasons: -// 1) the version library does not include the 'v' -// 2) its plausible unofficial images use the 3 numbers without the prefix for -// tagging their own images +// 1. the version library does not include the 'v' +// 2. its plausible unofficial images use the 3 numbers without the prefix for +// tagging their own images func semver(chosen string) (string, error) { v, err := version.NewVersion(chosen) if err != nil { diff --git a/client/allocrunner/taskrunner/plugin_supervisor_hook.go b/client/allocrunner/taskrunner/plugin_supervisor_hook.go index a1ace67b632..4ab9e684164 100644 --- a/client/allocrunner/taskrunner/plugin_supervisor_hook.go +++ b/client/allocrunner/taskrunner/plugin_supervisor_hook.go @@ -22,11 +22,11 @@ import ( // to their requisite plugin manager. // // It provides a couple of things to a task running inside Nomad. These are: -// * A mount to the `plugin_mount_dir`, that will then be used by Nomad -// to connect to the nested plugin and handle volume mounts. -// * When the task has started, it starts a loop of attempting to connect to the -// plugin, to perform initial fingerprinting of the plugins capabilities before -// notifying the plugin manager of the plugin. +// - A mount to the `plugin_mount_dir`, that will then be used by Nomad +// to connect to the nested plugin and handle volume mounts. +// - When the task has started, it starts a loop of attempting to connect to the +// plugin, to perform initial fingerprinting of the plugins capabilities before +// notifying the plugin manager of the plugin. type csiPluginSupervisorHook struct { logger hclog.Logger alloc *structs.Allocation @@ -202,13 +202,13 @@ func (h *csiPluginSupervisorHook) Poststart(_ context.Context, _ *interfaces.Tas // the passed in context is terminated. // // The supervisor works by: -// - Initially waiting for the plugin to become available. This loop is expensive -// and may do things like create new gRPC Clients on every iteration. -// - After receiving an initial healthy status, it will inform the plugin catalog -// of the plugin, registering it with the plugins fingerprinted capabilities. -// - We then perform a more lightweight check, simply probing the plugin on a less -// frequent interval to ensure it is still alive, emitting task events when this -// status changes. +// - Initially waiting for the plugin to become available. This loop is expensive +// and may do things like create new gRPC Clients on every iteration. +// - After receiving an initial healthy status, it will inform the plugin catalog +// of the plugin, registering it with the plugins fingerprinted capabilities. +// - We then perform a more lightweight check, simply probing the plugin on a less +// frequent interval to ensure it is still alive, emitting task events when this +// status changes. // // Deeper fingerprinting of the plugin is implemented by the csimanager. func (h *csiPluginSupervisorHook) ensureSupervisorLoop(ctx context.Context) { diff --git a/client/allocrunner/taskrunner/remotetask_hook.go b/client/allocrunner/taskrunner/remotetask_hook.go index 5a8ac03d12a..4fd9a63769b 100644 --- a/client/allocrunner/taskrunner/remotetask_hook.go +++ b/client/allocrunner/taskrunner/remotetask_hook.go @@ -32,10 +32,10 @@ func (h *remoteTaskHook) Name() string { } // Prestart performs 2 remote task driver related tasks: -// 1. If there is no local handle, see if there is a handle propagated from a -// previous alloc to be restored. -// 2. If the alloc is lost make sure the task signal is set to detach instead -// of kill. +// 1. If there is no local handle, see if there is a handle propagated from a +// previous alloc to be restored. +// 2. If the alloc is lost make sure the task signal is set to detach instead +// of kill. func (h *remoteTaskHook) Prestart(ctx context.Context, req *interfaces.TaskPrestartRequest, resp *interfaces.TaskPrestartResponse) error { if h.tr.getDriverHandle() != nil { // Driver handle already exists so don't try to load remote diff --git a/client/allocrunner/taskrunner/restarts/restarts.go b/client/allocrunner/taskrunner/restarts/restarts.go index a117e8d49d1..0e39e471524 100644 --- a/client/allocrunner/taskrunner/restarts/restarts.go +++ b/client/allocrunner/taskrunner/restarts/restarts.go @@ -139,11 +139,11 @@ func (r *RestartTracker) GetCount() int { // GetState returns the tasks next state given the set exit code and start // error. One of the following states are returned: -// * TaskRestarting - Task should be restarted -// * TaskNotRestarting - Task should not be restarted and has exceeded its -// restart policy. -// * TaskTerminated - Task has terminated successfully and does not need a -// restart. +// - TaskRestarting - Task should be restarted +// - TaskNotRestarting - Task should not be restarted and has exceeded its +// restart policy. +// - TaskTerminated - Task has terminated successfully and does not need a +// restart. // // If TaskRestarting is returned, the duration is how long to wait until // starting the task again. diff --git a/client/allocrunner/taskrunner/task_runner.go b/client/allocrunner/taskrunner/task_runner.go index cc6dd387a03..debe51cf6c4 100644 --- a/client/allocrunner/taskrunner/task_runner.go +++ b/client/allocrunner/taskrunner/task_runner.go @@ -1396,7 +1396,7 @@ func (tr *TaskRunner) UpdateStats(ru *cstructs.TaskResourceUsage) { } } -//TODO Remove Backwardscompat or use tr.Alloc()? +// TODO Remove Backwardscompat or use tr.Alloc()? func (tr *TaskRunner) setGaugeForMemory(ru *cstructs.TaskResourceUsage) { alloc := tr.Alloc() var allocatedMem float32 @@ -1428,7 +1428,7 @@ func (tr *TaskRunner) setGaugeForMemory(ru *cstructs.TaskResourceUsage) { } } -//TODO Remove Backwardscompat or use tr.Alloc()? +// TODO Remove Backwardscompat or use tr.Alloc()? func (tr *TaskRunner) setGaugeForCPU(ru *cstructs.TaskResourceUsage) { alloc := tr.Alloc() var allocatedCPU float32 diff --git a/client/client.go b/client/client.go index e699e0d9736..1b78140548a 100644 --- a/client/client.go +++ b/client/client.go @@ -134,7 +134,7 @@ type ClientStatsReporter interface { } // AllocRunner is the interface implemented by the core alloc runner. -//TODO Create via factory to allow testing Client with mock AllocRunners. +// TODO Create via factory to allow testing Client with mock AllocRunners. type AllocRunner interface { Alloc() *structs.Allocation AllocState() *arstate.State @@ -1221,8 +1221,8 @@ func (c *Client) restoreState() error { // wait until it gets allocs from server to launch them. // // See: -// * https://github.com/hashicorp/nomad/pull/6207 -// * https://github.com/hashicorp/nomad/issues/5984 +// - https://github.com/hashicorp/nomad/pull/6207 +// - https://github.com/hashicorp/nomad/issues/5984 // // COMPAT(0.12): remove once upgrading from 0.9.5 is no longer supported func (c *Client) hasLocalState(alloc *structs.Allocation) bool { diff --git a/client/dynamicplugins/registry.go b/client/dynamicplugins/registry.go index ed1710ee568..65a6529b0ce 100644 --- a/client/dynamicplugins/registry.go +++ b/client/dynamicplugins/registry.go @@ -95,7 +95,8 @@ type PluginInfo struct { // PluginConnectionInfo is the data required to connect to the plugin. // note: We currently only support Unix Domain Sockets, but this may be expanded -// to support other connection modes in the future. +// +// to support other connection modes in the future. type PluginConnectionInfo struct { // SocketPath is the path to the plugins api socket. SocketPath string diff --git a/client/pluginmanager/csimanager/doc.go b/client/pluginmanager/csimanager/doc.go index 42400a09241..298bf18bf7a 100644 --- a/client/pluginmanager/csimanager/doc.go +++ b/client/pluginmanager/csimanager/doc.go @@ -1,15 +1,16 @@ -/** +/* +* csimanager manages locally running CSI Plugins on a Nomad host, and provides a few different interfaces. It provides: -- a pluginmanager.PluginManager implementation that is used to fingerprint and - heartbeat local node plugins -- (TODO) a csimanager.AttachmentWaiter implementation that can be used to wait for an - external CSIVolume to be attached to the node before returning -- (TODO) a csimanager.NodeController implementation that is used to manage the node-local - portions of the CSI specification, and encompassess volume staging/publishing -- (TODO) a csimanager.VolumeChecker implementation that can be used by hooks to ensure - their volumes are healthy(ish) + - a pluginmanager.PluginManager implementation that is used to fingerprint and + heartbeat local node plugins + - (TODO) a csimanager.AttachmentWaiter implementation that can be used to wait for an + external CSIVolume to be attached to the node before returning + - (TODO) a csimanager.NodeController implementation that is used to manage the node-local + portions of the CSI specification, and encompassess volume staging/publishing + - (TODO) a csimanager.VolumeChecker implementation that can be used by hooks to ensure + their volumes are healthy(ish) */ package csimanager diff --git a/client/state/08types.go b/client/state/08types.go index a10d537f0af..b4cc54bf702 100644 --- a/client/state/08types.go +++ b/client/state/08types.go @@ -16,7 +16,6 @@ import ( // changed over the life-cycle of the alloc_runner in Nomad 0.8. // // https://github.com/hashicorp/nomad/blob/v0.8.6/client/alloc_runner.go#L146-L153 -// type allocRunnerMutableState08 struct { // AllocClientStatus does not need to be upgraded as it is computed // from task states. diff --git a/client/state/upgrade.go b/client/state/upgrade.go index 5942105d50d..f2319149c4c 100644 --- a/client/state/upgrade.go +++ b/client/state/upgrade.go @@ -75,15 +75,14 @@ func backupDB(bdb *bolt.DB, dst string) error { // UpgradeAllocs upgrades the boltdb schema. Example 0.8 schema: // -// * allocations -// * 15d83e8a-74a2-b4da-3f17-ed5c12895ea8 -// * echo -// - simple-all (342 bytes) -// - alloc (2827 bytes) -// - alloc-dir (166 bytes) -// - immutable (15 bytes) -// - mutable (1294 bytes) -// +// - allocations +// - 15d83e8a-74a2-b4da-3f17-ed5c12895ea8 +// - echo +// - simple-all (342 bytes) +// - alloc (2827 bytes) +// - alloc-dir (166 bytes) +// - immutable (15 bytes) +// - mutable (1294 bytes) func UpgradeAllocs(logger hclog.Logger, tx *boltdd.Tx) error { btx := tx.BoltTx() allocationsBucket := btx.Bucket(allocationsBucketName) diff --git a/client/taskenv/env.go b/client/taskenv/env.go index 06341cada30..906a5ca8d46 100644 --- a/client/taskenv/env.go +++ b/client/taskenv/env.go @@ -881,7 +881,6 @@ func (b *Builder) SetDriverNetwork(n *drivers.DriverNetwork) *Builder { // Handled by setAlloc -> otherPorts: // // Task: NOMAD_TASK_{IP,PORT,ADDR}__