From aebd61f5c5155ffc4fd653372f34ced322c7c908 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 ++++---- .github/workflows/test-core.yaml | 2 +- .go-version | 2 +- contributing/README.md | 2 +- scripts/release/mac-remote-build | 2 +- scripts/vagrant-linux-priv-go.sh | 2 +- 7 files changed, 12 insertions(+), 9 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 d5da33a25ce..e22565d8c06 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -457,7 +457,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 @@ -470,7 +470,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 @@ -479,7 +479,7 @@ executors: environment: <<: *common_envs GOPATH: /Users/distiller/go - GOLANG_VERSION: 1.18.5 + GOLANG_VERSION: 1.19 go-windows: machine: @@ -491,7 +491,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/.github/workflows/test-core.yaml b/.github/workflows/test-core.yaml index 82ae3cb58f5..c71c256d362 100644 --- a/.github/workflows/test-core.yaml +++ b/.github/workflows/test-core.yaml @@ -21,7 +21,7 @@ on: - 'website/**' env: VERBOSE: 1 - GO_VERSION: 1.18.5 + GO_VERSION: 1.19 GOBIN: /usr/local/bin GOTESTARCH: amd64 CONSUL_VERSION: 1.11.3 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 0c62f445c3e4b8340d29f2f13e9e8e656d114f3b Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Tue, 16 Aug 2022 09:06:30 -0500 Subject: [PATCH 2/2] build: run gofmt on all go source files Go 1.19 will forecefully format all your doc strings. To get this out of the way, here is one big commit with all the changes gofmt wants to make. --- client/allocdir/alloc_dir_test.go | 5 +- client/allochealth/tracker.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 | 1 - command/agent/consul/namespaces_client.go | 3 +- command/agent/consul/self.go | 7 +- command/agent/consul/service_client.go | 24 +-- command/agent/fs_endpoint.go | 22 +- command/agent/job_endpoint_test.go | 1 + command/data_format.go | 2 +- drivers/docker/driver_windows.go | 2 +- drivers/qemu/driver_test.go | 3 +- 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 | 10 +- 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/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.go | 8 +- nomad/plan_apply.go | 1 - nomad/search_endpoint.go | 26 ++- nomad/state/paginator/tokenizer.go | 33 +-- nomad/stream/subscription_test.go | 2 +- nomad/structs/config/consul.go | 8 +- nomad/structs/config/tls_test.go | 2 +- nomad/structs/devices_test.go | 2 +- nomad/structs/node.go | 46 ++--- nomad/structs/node_class_test.go | 2 +- nomad/structs/search.go | 3 +- nomad/structs/structs_periodic_test.go | 2 +- nomad/vault.go | 21 +- plugins/csi/client.go | 46 ++--- 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 - 65 files changed, 349 insertions(+), 352 deletions(-) diff --git a/client/allocdir/alloc_dir_test.go b/client/allocdir/alloc_dir_test.go index b2467483ebb..e8871b4a672 100644 --- a/client/allocdir/alloc_dir_test.go +++ b/client/allocdir/alloc_dir_test.go @@ -82,8 +82,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/allochealth/tracker.go b/client/allochealth/tracker.go index 87820d9ed67..1de1cb12fc0 100644 --- a/client/allochealth/tracker.go +++ b/client/allochealth/tracker.go @@ -258,8 +258,9 @@ func (t *Tracker) setTaskHealth(healthy, terminal bool) { // returns true if health is propagated and no more health monitoring is needed // // todo: this is currently being shared by watchConsulEvents and watchNomadEvents, -// and must be split up if/when we support registering services (and thus checks) -// of different providers. +// +// and must be split up if/when we support registering services (and thus checks) +// of different providers. func (t *Tracker) setCheckHealth(healthy bool) bool { t.lock.Lock() defer t.lock.Unlock() diff --git a/client/allocrunner/taskrunner/envoy_bootstrap_hook.go b/client/allocrunner/taskrunner/envoy_bootstrap_hook.go index 144a4a1607e..3cc9e4fd4d1 100644 --- a/client/allocrunner/taskrunner/envoy_bootstrap_hook.go +++ b/client/allocrunner/taskrunner/envoy_bootstrap_hook.go @@ -152,8 +152,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 3501e27252a..ef958736d96 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 03e52e66b09..a21c632f8da 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 few things to a plugin task running inside Nomad. These are: -// * A mount to the `csi_plugin.mount_dir` where the plugin will create its csi.sock -// * A mount to `local/csi` that node plugins will use to stage 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 `csi_plugin.mount_dir` where the plugin will create its csi.sock +// - A mount to `local/csi` that node plugins will use to stage 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 @@ -247,13 +247,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 981998b4f32..de4fccfbc6a 100644 --- a/client/allocrunner/taskrunner/task_runner.go +++ b/client/allocrunner/taskrunner/task_runner.go @@ -1413,7 +1413,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 @@ -1445,7 +1445,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 27e6f19e6bf..9c10ff53530 100644 --- a/client/client.go +++ b/client/client.go @@ -136,7 +136,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 @@ -1252,8 +1252,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 65f8c355cbc..3059c1a2763 100644 --- a/client/dynamicplugins/registry.go +++ b/client/dynamicplugins/registry.go @@ -98,7 +98,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 31f8c3bef6d..b2a1394e114 100644 --- a/client/state/upgrade.go +++ b/client/state/upgrade.go @@ -82,15 +82,14 @@ func backupDB(bdb *bbolt.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 d40b52ab95c..7fb6a27cc2e 100644 --- a/client/taskenv/env.go +++ b/client/taskenv/env.go @@ -903,7 +903,6 @@ func (b *Builder) SetDriverNetwork(n *drivers.DriverNetwork) *Builder { // Handled by setAlloc -> otherPorts: // // Task: NOMAD_TASK_{IP,PORT,ADDR}__