From 284a028a31f8ce5db65bd3292a8ebf4f05a7a4af Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Wed, 9 Aug 2023 19:27:03 +0000 Subject: [PATCH 1/5] build: update to go1.21 --- .go-version | 2 +- contributing/README.md | 2 +- scripts/linux-priv-go.sh | 2 +- scripts/release/mac-remote-build | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.go-version b/.go-version index e63679c7661b..3500250a4b05 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.20.6 +1.21.0 diff --git a/contributing/README.md b/contributing/README.md index a6dd9aa7fbf4..dd43d907cc53 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.20.6+](https://golang.org/) *(Note: `gcc-go` is not supported)* +1. Install [Go 1.21.0+](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/linux-priv-go.sh b/scripts/linux-priv-go.sh index c424b6194b1d..ae18fd852b70 100755 --- a/scripts/linux-priv-go.sh +++ b/scripts/linux-priv-go.sh @@ -21,7 +21,7 @@ case $(arch) in esac function install_go() { - local go_version="1.20.6" + local go_version="1.21.0" local download="https://storage.googleapis.com/golang/go${go_version}.linux-${ARCH}.tar.gz" if go version 2>&1 | grep -q "${go_version}"; then diff --git a/scripts/release/mac-remote-build b/scripts/release/mac-remote-build index b7bc0691a953..f738a5dc8a4a 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.20.6" + local go_version="1.21.0" local download= download="https://storage.googleapis.com/golang/go${go_version}.darwin-amd64.tar.gz" From 8d536378a356e7743ac5edde757c5c2aa188ccda Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Wed, 9 Aug 2023 19:48:29 +0000 Subject: [PATCH 2/5] go: eliminate helpers in favor of min/max --- .../allocrunner/taskrunner/driver_handle.go | 3 +- .../allocrunner/taskrunner/getter/params.go | 15 +++--- client/client.go | 2 +- command/job_restart.go | 3 +- go.mod | 2 +- helper/cluster_test.go | 2 +- helper/funcs.go | 17 ------- helper/funcs_test.go | 46 ------------------- nomad/blocked_evals.go | 6 +-- nomad/drainer/watch_jobs.go | 2 +- nomad/job_endpoint.go | 2 +- nomad/node_pool_endpoint.go | 10 ++-- nomad/scaling_endpoint.go | 6 +-- nomad/server.go | 4 +- nomad/state/state_store_variables.go | 6 +-- nomad/structs/structs.go | 2 +- scheduler/propertyset.go | 4 +- scheduler/reconcile.go | 16 +++---- 18 files changed, 37 insertions(+), 111 deletions(-) diff --git a/client/allocrunner/taskrunner/driver_handle.go b/client/allocrunner/taskrunner/driver_handle.go index 5b8872325207..aefd04bfb7f3 100644 --- a/client/allocrunner/taskrunner/driver_handle.go +++ b/client/allocrunner/taskrunner/driver_handle.go @@ -9,7 +9,6 @@ import ( "time" cstructs "github.com/hashicorp/nomad/client/structs" - "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/drivers" ) @@ -26,7 +25,7 @@ func NewDriverHandle( net: net, taskID: taskID, killSignal: task.KillSignal, - killTimeout: helper.Min(task.KillTimeout, maxKillTimeout), + killTimeout: min(task.KillTimeout, maxKillTimeout), } } diff --git a/client/allocrunner/taskrunner/getter/params.go b/client/allocrunner/taskrunner/getter/params.go index 98e225c8d6a5..3e8b6aed7204 100644 --- a/client/allocrunner/taskrunner/getter/params.go +++ b/client/allocrunner/taskrunner/getter/params.go @@ -13,7 +13,6 @@ import ( "github.com/hashicorp/go-cleanhttp" "github.com/hashicorp/go-getter" - "github.com/hashicorp/nomad/helper" "golang.org/x/exp/maps" "golang.org/x/exp/slices" ) @@ -65,13 +64,13 @@ func (p *parameters) read(r io.Reader) error { // terminated via signal. func (p *parameters) deadline() time.Duration { const minimum = 30 * time.Minute - max := minimum - max = helper.Max(max, p.HTTPReadTimeout) - max = helper.Max(max, p.GCSTimeout) - max = helper.Max(max, p.GitTimeout) - max = helper.Max(max, p.HgTimeout) - max = helper.Max(max, p.S3Timeout) - return max + 1*time.Minute + maximum := minimum + maximum = max(maximum, p.HTTPReadTimeout) + maximum = max(maximum, p.GCSTimeout) + maximum = max(maximum, p.GitTimeout) + maximum = max(maximum, p.HgTimeout) + maximum = max(maximum, p.S3Timeout) + return maximum + 1*time.Minute } // Equal returns whether p and o are the same. diff --git a/client/client.go b/client/client.go index b6e38544fdcf..359fa2ab65ed 100644 --- a/client/client.go +++ b/client/client.go @@ -3005,7 +3005,7 @@ func (c *Client) consulDiscoveryImpl() error { // datacenterQueryLimit, the next heartbeat will pick // a new set of servers so it's okay. shuffleStrings(dcs[1:]) - dcs = dcs[0:helper.Min(len(dcs), datacenterQueryLimit)] + dcs = dcs[0:min(len(dcs), datacenterQueryLimit)] } serviceName := c.GetConfig().ConsulConfig.ServerServiceName diff --git a/command/job_restart.go b/command/job_restart.go index 6f83bce3cc9b..d4c7f28fa238 100644 --- a/command/job_restart.go +++ b/command/job_restart.go @@ -21,7 +21,6 @@ import ( "github.com/hashicorp/go-set" "github.com/hashicorp/nomad/api" "github.com/hashicorp/nomad/api/contexts" - "github.com/hashicorp/nomad/helper" "github.com/posener/complete" ) @@ -370,7 +369,7 @@ func (c *JobRestartCommand) Run(args []string) int { "[bold]==> %s: Restarting %s batch of %d allocations[reset]", formatTime(time.Now()), humanize.Ordinal(batchNumber), - helper.Min(c.batchSize, remaining), + min(c.batchSize, remaining), ))) } diff --git a/go.mod b/go.mod index f70f288f04a6..8f90ed81c288 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/nomad -go 1.20 +go 1.21 // Pinned dependencies are noted in github.com/hashicorp/nomad/issues/11826 replace ( diff --git a/helper/cluster_test.go b/helper/cluster_test.go index 04ae9d3be53c..b3bbfbdb5527 100644 --- a/helper/cluster_test.go +++ b/helper/cluster_test.go @@ -21,7 +21,7 @@ func TestCluster_RandomStagger(t *testing.T) { } abs := func(d time.Duration) time.Duration { - return Max(d, -d) + return max(d, -d) } for _, tc := range cases { diff --git a/helper/funcs.go b/helper/funcs.go index e405ae5346d5..5094cbe84e53 100644 --- a/helper/funcs.go +++ b/helper/funcs.go @@ -18,7 +18,6 @@ import ( multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-set" "github.com/hashicorp/hcl/hcl/ast" - "golang.org/x/exp/constraints" "golang.org/x/exp/maps" "golang.org/x/exp/slices" ) @@ -82,22 +81,6 @@ func HashUUID(input string) (output string, hashed bool) { return output, true } -// Min returns the minimum of a and b. -func Min[T constraints.Ordered](a, b T) T { - if a < b { - return a - } - return b -} - -// Max returns the maximum of a and b. -func Max[T constraints.Ordered](a, b T) T { - if a > b { - return a - } - return b -} - // UniqueMapSliceValues returns the union of values from each slice in a map[K][]V. func UniqueMapSliceValues[K, V comparable](m map[K][]V) []V { s := set.New[V](0) diff --git a/helper/funcs_test.go b/helper/funcs_test.go index ed7245bd4eae..80c259d2f491 100644 --- a/helper/funcs_test.go +++ b/helper/funcs_test.go @@ -15,52 +15,6 @@ import ( "golang.org/x/exp/maps" ) -func Test_Min(t *testing.T) { - t.Run("int", func(t *testing.T) { - a := 1 - b := 2 - must.Eq(t, 1, Min(a, b)) - must.Eq(t, 1, Min(b, a)) - }) - - t.Run("float64", func(t *testing.T) { - a := 1.1 - b := 2.2 - must.Eq(t, 1.1, Min(a, b)) - must.Eq(t, 1.1, Min(b, a)) - }) - - t.Run("string", func(t *testing.T) { - a := "cat" - b := "dog" - must.Eq(t, "cat", Min(a, b)) - must.Eq(t, "cat", Min(b, a)) - }) -} - -func Test_Max(t *testing.T) { - t.Run("int", func(t *testing.T) { - a := 1 - b := 2 - must.Eq(t, 2, Max(a, b)) - must.Eq(t, 2, Max(b, a)) - }) - - t.Run("float64", func(t *testing.T) { - a := 1.1 - b := 2.2 - must.Eq(t, 2.2, Max(a, b)) - must.Eq(t, 2.2, Max(b, a)) - }) - - t.Run("string", func(t *testing.T) { - a := "cat" - b := "dog" - must.Eq(t, "dog", Max(a, b)) - must.Eq(t, "dog", Max(b, a)) - }) -} - func TestIsSubset(t *testing.T) { l := []string{"a", "b", "c"} s := []string{"d"} diff --git a/nomad/blocked_evals.go b/nomad/blocked_evals.go index 8ecccab80e76..1ec1beee4a38 100644 --- a/nomad/blocked_evals.go +++ b/nomad/blocked_evals.go @@ -293,7 +293,7 @@ func latestEvalIndex(eval *structs.Evaluation) uint64 { return 0 } - return helper.Max(eval.CreateIndex, eval.SnapshotIndex) + return max(eval.CreateIndex, eval.SnapshotIndex) } // missedUnblock returns whether an evaluation missed an unblock while it was in @@ -545,9 +545,9 @@ func (b *BlockedEvals) unblock(computedClass, quota string, index uint64) { // Every eval that has escaped computed node class has to be unblocked // because any node could potentially be feasible. - numEscaped := len(b.escaped) numQuotaLimit := 0 - unblocked := make(map[*structs.Evaluation]string, helper.Max(numEscaped, 4)) + numEscaped := len(b.escaped) + unblocked := make(map[*structs.Evaluation]string, max(uint64(numEscaped), 4)) if numEscaped != 0 && computedClass != "" { for id, wrapped := range b.escaped { diff --git a/nomad/drainer/watch_jobs.go b/nomad/drainer/watch_jobs.go index e2c456bef664..523a198dd491 100644 --- a/nomad/drainer/watch_jobs.go +++ b/nomad/drainer/watch_jobs.go @@ -414,7 +414,7 @@ func handleTaskGroup(snap *state.StateSnapshot, batch bool, tg *structs.TaskGrou // Determine how many we can drain thresholdCount := tg.Count - tg.Migrate.MaxParallel numToDrain := healthy - thresholdCount - numToDrain = helper.Min(len(drainable), numToDrain) + numToDrain = min(len(drainable), numToDrain) if numToDrain <= 0 { return nil } diff --git a/nomad/job_endpoint.go b/nomad/job_endpoint.go index c17cc28585e0..274000cabcaa 100644 --- a/nomad/job_endpoint.go +++ b/nomad/job_endpoint.go @@ -1502,7 +1502,7 @@ func (j *Job) List(args *structs.JobListRequest, reply *structs.JobListResponse) if err != nil { return err } - reply.Index = helper.Max(jindex, sindex) + reply.Index = max(jindex, sindex) // Set the query response j.srv.setQueryMeta(&reply.QueryMeta) diff --git a/nomad/node_pool_endpoint.go b/nomad/node_pool_endpoint.go index c0de8b1e57d5..ac71ba721023 100644 --- a/nomad/node_pool_endpoint.go +++ b/nomad/node_pool_endpoint.go @@ -12,9 +12,7 @@ import ( metrics "github.com/armon/go-metrics" "github.com/hashicorp/go-memdb" multierror "github.com/hashicorp/go-multierror" - "github.com/hashicorp/nomad/acl" - "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/state/paginator" "github.com/hashicorp/nomad/nomad/structs" @@ -106,7 +104,7 @@ func (n *NodePool) List(args *structs.NodePoolListRequest, reply *structs.NodePo if err != nil { return err } - reply.Index = helper.Max(1, index) + reply.Index = max(1, index) // Set the query response. n.srv.setQueryMeta(&reply.QueryMeta) @@ -161,7 +159,7 @@ func (n *NodePool) GetNodePool(args *structs.NodePoolSpecificRequest, reply *str if err != nil { return err } - reply.Index = helper.Max(1, index) + reply.Index = max(1, index) } return nil }} @@ -503,7 +501,7 @@ func (n *NodePool) ListJobs(args *structs.NodePoolJobsRequest, reply *structs.No if err != nil { return err } - reply.Index = helper.Max(jindex, sindex) + reply.Index = max(jindex, sindex) // Set the query response n.srv.setQueryMeta(&reply.QueryMeta) @@ -593,7 +591,7 @@ func (n *NodePool) ListNodes(args *structs.NodePoolNodesRequest, reply *structs. if err != nil { return err } - reply.Index = helper.Max(1, index) + reply.Index = max(1, index) // Set the query response. n.srv.setQueryMeta(&reply.QueryMeta) diff --git a/nomad/scaling_endpoint.go b/nomad/scaling_endpoint.go index 3a7b0ecbf62d..1a9f2544df77 100644 --- a/nomad/scaling_endpoint.go +++ b/nomad/scaling_endpoint.go @@ -10,9 +10,7 @@ import ( "github.com/armon/go-metrics" "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-memdb" - "github.com/hashicorp/nomad/acl" - "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/structs" ) @@ -148,7 +146,7 @@ func (p *Scaling) GetPolicy(args *structs.ScalingPolicySpecificRequest, if err != nil { return err } - reply.Index = helper.Max(1, index) + reply.Index = max(1, index) } return nil }} @@ -212,7 +210,7 @@ func (p *Scaling) listAllNamespaces(args *structs.ScalingPolicyListRequest, repl if err != nil { return err } - reply.Index = helper.Max(1, index) + reply.Index = max(1, index) // Set the query response p.srv.setQueryMeta(&reply.QueryMeta) diff --git a/nomad/server.go b/nomad/server.go index 12f25a646e8f..82f96999bf6e 100644 --- a/nomad/server.go +++ b/nomad/server.go @@ -977,7 +977,7 @@ func (s *Server) setupBootstrapHandler() error { // walk all datacenter until it finds enough hosts to // form a quorum. shuffleStrings(dcs[1:]) - dcs = dcs[0:helper.Min(len(dcs), datacenterQueryLimit)] + dcs = dcs[0:min(len(dcs), datacenterQueryLimit)] } nomadServerServiceName := s.config.ConsulConfig.ServerServiceName @@ -2010,7 +2010,7 @@ func (s *Server) setReplyQueryMeta(stateStore *state.StateStore, table string, r if err != nil { return err } - reply.Index = helper.Max(1, index) + reply.Index = max(1, index) // Set the query response. s.setQueryMeta(reply) diff --git a/nomad/state/state_store_variables.go b/nomad/state/state_store_variables.go index d39d6fa6c638..83311d8912dc 100644 --- a/nomad/state/state_store_variables.go +++ b/nomad/state/state_store_variables.go @@ -8,8 +8,6 @@ import ( "math" "github.com/hashicorp/go-memdb" - - "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/structs" ) @@ -251,7 +249,7 @@ func (s *StateStore) varSetTxn(tx WriteTxn, idx uint64, req *structs.VarApplySta if quotaChange > 0 { quotaUsed.Size += quotaChange } else if quotaChange < 0 { - quotaUsed.Size -= helper.Min(quotaUsed.Size, -quotaChange) + quotaUsed.Size -= min(quotaUsed.Size, -quotaChange) } err = s.enforceVariablesQuota(idx, tx, sv.Namespace, quotaChange) @@ -392,7 +390,7 @@ func (s *StateStore) svDeleteTxn(tx WriteTxn, idx uint64, req *structs.VarApplyS if existingQuota != nil { quotaUsed := existingQuota.(*structs.VariablesQuota) quotaUsed = quotaUsed.Copy() - quotaUsed.Size -= helper.Min(quotaUsed.Size, int64(len(sv.Data))) + quotaUsed.Size -= min(quotaUsed.Size, int64(len(sv.Data))) quotaUsed.ModifyIndex = idx if err := tx.Insert(TableVariablesQuotas, quotaUsed); err != nil { return req.ErrorResponse(idx, fmt.Errorf("variable quota insert failed: %v", err)) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 68943f871dad..949d35c6b4ac 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -9105,7 +9105,7 @@ func (e *TaskEvent) SetValidationError(err error) *TaskEvent { } func (e *TaskEvent) SetKillTimeout(timeout, maxTimeout time.Duration) *TaskEvent { - actual := helper.Min(timeout, maxTimeout) + actual := min(timeout, maxTimeout) e.KillTimeout = actual e.Details["kill_timeout"] = actual.String() return e diff --git a/scheduler/propertyset.go b/scheduler/propertyset.go index 48d46ea82c30..ea53678d3158 100644 --- a/scheduler/propertyset.go +++ b/scheduler/propertyset.go @@ -10,8 +10,6 @@ import ( log "github.com/hashicorp/go-hclog" memdb "github.com/hashicorp/go-memdb" "github.com/hashicorp/go-set" - - "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/structs" ) @@ -263,7 +261,7 @@ func (p *propertySet) UsedCount(option *structs.Node, _ string) (string, string, // existing and proposed allocations. It also takes into account any stopped // allocations func (p *propertySet) GetCombinedUseMap() map[string]uint64 { - combinedUse := make(map[string]uint64, helper.Max(len(p.existingValues), len(p.proposedValues))) + combinedUse := make(map[string]uint64, max(len(p.existingValues), len(p.proposedValues))) for _, usedValues := range []map[string]uint64{p.existingValues, p.proposedValues} { for propertyValue, usedCount := range usedValues { targetPropertyValue := p.targetedPropertyValue(propertyValue) diff --git a/scheduler/reconcile.go b/scheduler/reconcile.go index a170e6c681c2..db0ecda4b5f2 100644 --- a/scheduler/reconcile.go +++ b/scheduler/reconcile.go @@ -816,8 +816,8 @@ func (a *allocReconciler) computeReplacements(deploymentPlaceReady bool, desired a.markStop(failed, "", allocRescheduled) desiredChanges.Stop += uint64(len(failed)) - min := helper.Min(len(place), underProvisionedBy) - underProvisionedBy -= min + minimum := min(len(place), underProvisionedBy) + underProvisionedBy -= minimum return underProvisionedBy } @@ -828,7 +828,7 @@ func (a *allocReconciler) computeReplacements(deploymentPlaceReady bool, desired // If allocs have been lost, determine the number of replacements that are needed // and add placements to the result for the lost allocs. if len(lost) != 0 { - allowed := helper.Min(len(lost), len(place)) + allowed := min(len(lost), len(place)) desiredChanges.Place += uint64(allowed) a.result.place = append(a.result.place, place[:allowed]...) } @@ -869,10 +869,10 @@ func (a *allocReconciler) computeDestructiveUpdates(destructive allocSet, underP desiredChanges *structs.DesiredUpdates, tg *structs.TaskGroup) { // Do all destructive updates - min := helper.Min(len(destructive), underProvisionedBy) - desiredChanges.DestructiveUpdate += uint64(min) - desiredChanges.Ignore += uint64(len(destructive) - min) - for _, alloc := range destructive.nameOrder()[:min] { + minimum := min(len(destructive), underProvisionedBy) + desiredChanges.DestructiveUpdate += uint64(minimum) + desiredChanges.Ignore += uint64(len(destructive) - minimum) + for _, alloc := range destructive.nameOrder()[:minimum] { a.result.destructiveUpdate = append(a.result.destructiveUpdate, allocDestructiveResult{ placeName: alloc.Name, placeTaskGroup: tg, @@ -948,7 +948,7 @@ func (a *allocReconciler) isDeploymentComplete(groupName string, destructive, in // Final check to see if the deployment is complete is to ensure everything is healthy if dstate, ok := a.deployment.TaskGroups[groupName]; ok { - if dstate.HealthyAllocs < helper.Max(dstate.DesiredTotal, dstate.DesiredCanaries) || // Make sure we have enough healthy allocs + if dstate.HealthyAllocs < max(dstate.DesiredTotal, dstate.DesiredCanaries) || // Make sure we have enough healthy allocs (dstate.DesiredCanaries > 0 && !dstate.Promoted) { // Make sure we are promoted if we have canaries complete = false } From 187205d72c41a8461d9588af237049aaa26b58c5 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Wed, 9 Aug 2023 20:10:36 +0000 Subject: [PATCH 3/5] build: run go mod tidy --- go.sum | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/go.sum b/go.sum index 9ddfe7efd44f..9d7c0e89dd74 100644 --- a/go.sum +++ b/go.sum @@ -117,6 +117,7 @@ cloud.google.com/go/language v1.6.0/go.mod h1:6dJ8t3B+lUYfStgls25GusK04NLh3eDLQn cloud.google.com/go/lifesciences v0.5.0/go.mod h1:3oIKy8ycWGPUyZDR/8RNnTOYevhaMLqh5vLUXs9zvT8= cloud.google.com/go/lifesciences v0.6.0/go.mod h1:ddj6tSX/7BOnhxCSd3ZcETvtNr8NZ6t/iPhY2Tyfu08= cloud.google.com/go/longrunning v0.3.0 h1:NjljC+FYPV3uh5/OwWT6pVU+doBqMg2x/rZlE+CamDs= +cloud.google.com/go/longrunning v0.3.0/go.mod h1:qth9Y41RRSUE69rDcOn6DdK3HfQfsUI0YSmW3iIlLJc= cloud.google.com/go/mediatranslation v0.5.0/go.mod h1:jGPUhGTybqsPQn91pNXw0xVHfuJ3leR1wj37oU3y1f4= cloud.google.com/go/mediatranslation v0.6.0/go.mod h1:hHdBCTYNigsBxshbznuIMFNe5QXEowAuNmmC7h8pu5w= cloud.google.com/go/memcache v1.4.0/go.mod h1:rTOfiGZtJX1AaFUrOgsMHX5kAzaTQ8azHiuDoTPzNsE= @@ -261,6 +262,7 @@ github.com/Microsoft/hcsshim v0.8.15/go.mod h1:x38A4YbHbdxJtc0sF6oIz+RG0npwSCAvn github.com/Microsoft/hcsshim v0.8.16/go.mod h1:o5/SZqmR7x9JNKsW3pu+nqHm0MF8vbA+VxGOoXdC600= github.com/Microsoft/hcsshim v0.8.23/go.mod h1:4zegtUJth7lAvFyc6cH2gGQ5B3OFQim01nnU2M8jKDg= github.com/Microsoft/hcsshim v0.9.6 h1:VwnDOgLeoi2du6dAznfmspNqTiwczvjv4K7NxuY9jsY= +github.com/Microsoft/hcsshim v0.9.6/go.mod h1:7pLA8lDk46WKDWlVsENo92gC0XFa8rbKfyFRBqxEbCc= github.com/Microsoft/hcsshim/test v0.0.0-20201218223536-d3e5debf77da/go.mod h1:5hlzMzRKMLyo42nCZ9oml8AdTlq/0cvIaBv6tK1RehU= github.com/Microsoft/hcsshim/test v0.0.0-20210227013316-43a75bb4edd3/go.mod h1:mw7qgWloBUl75W/gVH3cQszUg1+gUITj7D6NY7ywVnY= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= @@ -418,6 +420,7 @@ github.com/containerd/continuity v0.0.0-20201208142359-180525291bb7/go.mod h1:kR github.com/containerd/continuity v0.0.0-20210208174643-50096c924a4e/go.mod h1:EXlVlkqNba9rJe3j7w3Xa924itAMLgZH4UD/Q4PExuQ= github.com/containerd/continuity v0.1.0/go.mod h1:ICJu0PwR54nI0yPEnJ6jcS+J7CZAUXrLh8lPo2knzsM= github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg= +github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM= github.com/containerd/fifo v0.0.0-20180307165137-3d5202aec260/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= github.com/containerd/fifo v0.0.0-20200410184934-f15a3290365b/go.mod h1:jPQ2IAeZRCYxpS/Cm1495vGFww6ecHmMk1YJH2Q5ln0= @@ -585,6 +588,7 @@ github.com/frankban/quicktest v1.10.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= github.com/frankban/quicktest v1.13.0/go.mod h1:qLE0fzW0VuyUAJgPU19zByoIr0HtCHN/r/VLSOOIySU= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -822,6 +826,7 @@ github.com/hashicorp/go-discover v0.0.0-20220621183603-a413e131e836/go.mod h1:1x github.com/hashicorp/go-envparse v0.0.0-20180119215841-310ca1881b22 h1:HTmDIaSN95gbdMyrsbNiXSdW4fbGctGQwEqv0H7OhDQ= github.com/hashicorp/go-envparse v0.0.0-20180119215841-310ca1881b22/go.mod h1:/NlxCzN2D4C4L2uDE6ux/h6jM+n98VFQM14nnCIfHJU= github.com/hashicorp/go-gatedio v0.5.0 h1:Jm1X5yP4yCqqWj5L1TgW7iZwCVPGtVc+mro5r/XX7Tg= +github.com/hashicorp/go-gatedio v0.5.0/go.mod h1:Lr3t8L6IyxD3DAeaUxGcgl2JnRUpWMCsmBl4Omu/2t4= github.com/hashicorp/go-getter v1.7.0 h1:bzrYP+qu/gMrL1au7/aDvkoOVGUJpeKBgbqRHACAFDY= github.com/hashicorp/go-getter v1.7.0/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744= github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= @@ -1150,6 +1155,7 @@ github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.1.3 h1:e/3Cwtogj0HA+25nMP1jCMDIf8RtRYbGwGGuBIFztkc= github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= @@ -1160,6 +1166,7 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.24.2 h1:J/tulyYK6JwBldPViHJReihxxZ+22FHs0piGjQAvoUE= +github.com/onsi/gomega v1.24.2/go.mod h1:gs3J10IS7Z7r7eXRoNJIrNqU4ToQukCJhFtKrWgHWnk= github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= @@ -2104,6 +2111,7 @@ gopkg.in/check.v1 v1.0.0-20141024133853-64131543e789/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= From 1941f46cdabab80f5d64f395615d38259ceb281d Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Wed, 9 Aug 2023 20:26:12 +0000 Subject: [PATCH 4/5] build: swap depguard for semgrep --- .golangci.yml | 8 -------- .semgrep/imports.yml | 18 ++++++++++++++++++ GNUmakefile | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 .semgrep/imports.yml diff --git a/.golangci.yml b/.golangci.yml index f0901f1c6795..413de5a48672 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -59,13 +59,6 @@ linters-settings: gofmt: # simplify code: gofmt with `-s` option, true by default simplify: true - depguard: - # disallow packages from being used - list-type: blacklist - packages: - - github.com/boltdb/bolt - - github.com/hashicorp/consul/command/flags - - github.com/pkg/errors gocritic: disabled-checks: - commentFormatting @@ -92,7 +85,6 @@ linters: - unconvert - gofmt - gosimple - - depguard - staticcheck - asasalint - asciicheck diff --git a/.semgrep/imports.yml b/.semgrep/imports.yml new file mode 100644 index 000000000000..3afb901dd621 --- /dev/null +++ b/.semgrep/imports.yml @@ -0,0 +1,18 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +rules: + - id: "disallow-imports" + patterns: + - pattern: '"github.com/boltdb/bolt"' + - pattern: '"github.com/pkg/errors"' + - pattern: '"github.com/hashicorp/consul"' + - pattern: '"github.com/hashicorp/consul/command/flags"' + - pattern: '"github.com/hashicorp/consul/sdk"' + message: "Import of this package has been disallowed" + languages: + - "generic" + severity: "ERROR" + paths: + include: + - "*.go" diff --git a/GNUmakefile b/GNUmakefile index 33a6757c527a..23faae6ff659 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -143,7 +143,7 @@ deps: ## Install build and development dependencies .PHONY: lint-deps lint-deps: ## Install linter dependencies @echo "==> Updating linter dependencies..." - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.0 go install github.com/client9/misspell/cmd/misspell@v0.3.4 go install github.com/hashicorp/go-hclog/hclogvet@v0.1.6 From 6ceec1bbdd96e98cf096d260685ba92ceaae7758 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Mon, 14 Aug 2023 13:12:09 +0000 Subject: [PATCH 5/5] command: fixup broken tls error check on go1.21 --- command/agent/http_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/command/agent/http_test.go b/command/agent/http_test.go index 41e851a16d31..1008ba3a9c6e 100644 --- a/command/agent/http_test.go +++ b/command/agent/http_test.go @@ -16,6 +16,7 @@ import ( "net/http/httptest" "net/url" "os" + "slices" "strconv" "strings" "testing" @@ -914,8 +915,10 @@ func TestHTTP_VerifyHTTPSClient(t *testing.T) { if !ok { t.Fatalf("expected a *net.OpErr but received: %T -> %v", urlErr.Err, urlErr.Err) } - const badCertificate = "tls: bad certificate" // from crypto/tls/alert.go:52 and RFC 5246 § A.3 - if opErr.Err.Error() != badCertificate { + + // from crypto/tls/alert.go:52 and RFC 5246 § A.3 + possibleBadCertErr := []string{"tls: bad certificate", "tls: certificate required"} + if !slices.Contains(possibleBadCertErr, opErr.Err.Error()) { t.Fatalf("expected tls.alert bad_certificate but received: %q", opErr.Err.Error()) }