From ae6c4c8e3f9a4955b98cfbcd12521684a68065bb Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Fri, 12 Apr 2024 08:29:00 -0500 Subject: [PATCH] deps: purge use of old x/exp packages (#20373) --- .semgrep/imports.yml | 1 + api/consul.go | 3 +-- api/go.mod | 1 - api/go.sum | 2 -- api/jobs.go | 2 +- client/allochealth/tracker.go | 2 +- client/allocrunner/alloc_runner.go | 2 +- .../taskrunner/artifact_hook_test.go | 2 +- .../allocrunner/taskrunner/logmon_hook_test.go | 2 +- client/allocrunner/taskrunner/state/state.go | 3 ++- client/client.go | 5 +++-- client/meta_endpoint.go | 2 +- client/pluginmanager/csimanager/fingerprint.go | 2 +- .../serviceregistration/checks/client_test.go | 2 +- client/serviceregistration/checks/result.go | 2 +- .../service_registration.go | 2 +- client/state/db_mem.go | 2 +- command/agent/consul/service_client_test.go | 2 +- go.mod | 2 +- helper/funcs_test.go | 2 +- helper/opaque.go | 3 ++- helper/pointer/pointer.go | 6 ++---- lib/lang/maps.go | 18 ++++++++++++++++++ nomad/auth/auth.go | 2 +- nomad/job_endpoint_hooks.go | 4 ++-- nomad/structs/node.go | 2 +- nomad/structs/node_pool.go | 2 +- plugins/csi/client.go | 2 +- plugins/drivers/driver.go | 2 +- scheduler/feasible.go | 4 ++-- scheduler/reconcile_util.go | 2 +- 31 files changed, 53 insertions(+), 37 deletions(-) diff --git a/.semgrep/imports.yml b/.semgrep/imports.yml index ccfc5d470..4c1bae943 100644 --- a/.semgrep/imports.yml +++ b/.semgrep/imports.yml @@ -12,6 +12,7 @@ rules: - pattern: '"github.com/hashicorp/go-set"' - pattern: '"golang.org/x/exp/slices"' - pattern: '"golang.org/x/exp/maps"' + - pattern: '"golang.org/x/exp/constraints"' message: "Import of this package has been disallowed" languages: - "generic" diff --git a/api/consul.go b/api/consul.go index 93b2dc622..3f1678a07 100644 --- a/api/consul.go +++ b/api/consul.go @@ -4,10 +4,9 @@ package api import ( + "maps" "slices" "time" - - "golang.org/x/exp/maps" ) // Consul represents configuration related to consul. diff --git a/api/go.mod b/api/go.mod index 017cd4d93..e373700ae 100644 --- a/api/go.mod +++ b/api/go.mod @@ -13,7 +13,6 @@ require ( github.com/mitchellh/go-testing-interface v1.14.1 github.com/mitchellh/mapstructure v1.5.0 github.com/shoenig/test v1.7.1 - golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 ) require ( diff --git a/api/go.sum b/api/go.sum index 92a42b04c..4f27bc8e4 100644 --- a/api/go.sum +++ b/api/go.sum @@ -36,8 +36,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 h1:/yRP+0AN7mf5DkD3BAI6TOFnd51gEoDEb8o35jIFtgw= -golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/api/jobs.go b/api/jobs.go index 89117468b..3bd60c4ef 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -8,13 +8,13 @@ import ( "errors" "fmt" "io" + "maps" "net/url" "sort" "strconv" "time" "github.com/hashicorp/cronexpr" - "golang.org/x/exp/maps" ) const ( diff --git a/client/allochealth/tracker.go b/client/allochealth/tracker.go index 4ccf6b578..3273a1562 100644 --- a/client/allochealth/tracker.go +++ b/client/allochealth/tracker.go @@ -6,6 +6,7 @@ package allochealth import ( "context" "fmt" + "maps" "strings" "sync" "time" @@ -18,7 +19,6 @@ import ( "github.com/hashicorp/nomad/client/taskenv" "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/structs" - "golang.org/x/exp/maps" ) const ( diff --git a/client/allocrunner/alloc_runner.go b/client/allocrunner/alloc_runner.go index 169c0c2f5..c56d46e78 100644 --- a/client/allocrunner/alloc_runner.go +++ b/client/allocrunner/alloc_runner.go @@ -6,6 +6,7 @@ package allocrunner import ( "context" "fmt" + "maps" "sync" "time" @@ -39,7 +40,6 @@ import ( "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/device" "github.com/hashicorp/nomad/plugins/drivers" - "golang.org/x/exp/maps" ) // allocRunner is used to run all the tasks in a given allocation diff --git a/client/allocrunner/taskrunner/artifact_hook_test.go b/client/allocrunner/taskrunner/artifact_hook_test.go index 944bd17bd..3e2ee1891 100644 --- a/client/allocrunner/taskrunner/artifact_hook_test.go +++ b/client/allocrunner/taskrunner/artifact_hook_test.go @@ -6,6 +6,7 @@ package taskrunner import ( "context" "fmt" + "maps" "net/http" "net/http/httptest" "os" @@ -23,7 +24,6 @@ import ( "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/structs" "github.com/stretchr/testify/require" - "golang.org/x/exp/maps" ) // Statically assert the artifact hook implements the expected interface diff --git a/client/allocrunner/taskrunner/logmon_hook_test.go b/client/allocrunner/taskrunner/logmon_hook_test.go index c27a17549..716f7677f 100644 --- a/client/allocrunner/taskrunner/logmon_hook_test.go +++ b/client/allocrunner/taskrunner/logmon_hook_test.go @@ -6,6 +6,7 @@ package taskrunner import ( "context" "encoding/json" + "maps" "net" "testing" @@ -17,7 +18,6 @@ import ( pstructs "github.com/hashicorp/nomad/plugins/shared/structs" "github.com/shoenig/test/must" "github.com/stretchr/testify/require" - "golang.org/x/exp/maps" ) // Statically assert the logmon hook implements the expected interfaces diff --git a/client/allocrunner/taskrunner/state/state.go b/client/allocrunner/taskrunner/state/state.go index 09d3a99a3..32d21951c 100644 --- a/client/allocrunner/taskrunner/state/state.go +++ b/client/allocrunner/taskrunner/state/state.go @@ -4,8 +4,9 @@ package state import ( + "maps" + "github.com/hashicorp/nomad/plugins/drivers" - "golang.org/x/exp/maps" ) // LocalState is Task state which is persisted for use when restarting Nomad diff --git a/client/client.go b/client/client.go index 3b991f4bc..88df8d7d9 100644 --- a/client/client.go +++ b/client/client.go @@ -6,6 +6,7 @@ package client import ( "errors" "fmt" + "maps" "net" "net/rpc" "os" @@ -58,13 +59,13 @@ import ( "github.com/hashicorp/nomad/helper/tlsutil" "github.com/hashicorp/nomad/helper/users/dynamic" "github.com/hashicorp/nomad/helper/uuid" + "github.com/hashicorp/nomad/lib/lang" "github.com/hashicorp/nomad/nomad/structs" nconfig "github.com/hashicorp/nomad/nomad/structs/config" "github.com/hashicorp/nomad/plugins/csi" "github.com/hashicorp/nomad/plugins/device" vaultapi "github.com/hashicorp/vault/api" "github.com/shirou/gopsutil/v3/host" - "golang.org/x/exp/maps" ) const ( @@ -3474,7 +3475,7 @@ func (p *pendingClientUpdates) nextBatch(c *Client, updateTicks int) []*structs. // Clear here so that allocrunners can queue up the next set of updates // while we're waiting to hear from the server - maps.Clear(p.updates) + lang.MapClear(p.updates) return toSync diff --git a/client/meta_endpoint.go b/client/meta_endpoint.go index bfffc074c..85b4dfa10 100644 --- a/client/meta_endpoint.go +++ b/client/meta_endpoint.go @@ -4,12 +4,12 @@ package client import ( + "maps" "net/http" "time" "github.com/armon/go-metrics" "github.com/hashicorp/nomad/nomad/structs" - "golang.org/x/exp/maps" ) type NodeMeta struct { diff --git a/client/pluginmanager/csimanager/fingerprint.go b/client/pluginmanager/csimanager/fingerprint.go index 6b0f70039..dae851971 100644 --- a/client/pluginmanager/csimanager/fingerprint.go +++ b/client/pluginmanager/csimanager/fingerprint.go @@ -6,12 +6,12 @@ package csimanager import ( "context" "fmt" + "maps" "github.com/hashicorp/go-hclog" "github.com/hashicorp/nomad/client/dynamicplugins" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/csi" - "golang.org/x/exp/maps" ) type pluginFingerprinter struct { diff --git a/client/serviceregistration/checks/client_test.go b/client/serviceregistration/checks/client_test.go index f601305cc..ca69fbf64 100644 --- a/client/serviceregistration/checks/client_test.go +++ b/client/serviceregistration/checks/client_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "io" + "maps" "net" "net/http" "net/http/httptest" @@ -20,7 +21,6 @@ import ( "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" "github.com/shoenig/test/must" - "golang.org/x/exp/maps" "oss.indeed.com/go/libtime/libtimetest" ) diff --git a/client/serviceregistration/checks/result.go b/client/serviceregistration/checks/result.go index f8fc58599..22de135a4 100644 --- a/client/serviceregistration/checks/result.go +++ b/client/serviceregistration/checks/result.go @@ -4,11 +4,11 @@ package checks import ( + "maps" "net/http" "time" "github.com/hashicorp/nomad/nomad/structs" - "golang.org/x/exp/maps" ) // GetCheckQuery extracts the needed info from c to actually execute the check. diff --git a/client/serviceregistration/service_registration.go b/client/serviceregistration/service_registration.go index 9866fea39..22124ac0b 100644 --- a/client/serviceregistration/service_registration.go +++ b/client/serviceregistration/service_registration.go @@ -5,10 +5,10 @@ package serviceregistration import ( "context" + "maps" "github.com/hashicorp/consul/api" "github.com/hashicorp/nomad/nomad/structs" - "golang.org/x/exp/maps" ) // Handler is the interface the Nomad Client uses to register, update and diff --git a/client/state/db_mem.go b/client/state/db_mem.go index 10037999e..91e6481b4 100644 --- a/client/state/db_mem.go +++ b/client/state/db_mem.go @@ -4,6 +4,7 @@ package state import ( + "maps" "sync" "github.com/hashicorp/go-hclog" @@ -15,7 +16,6 @@ import ( "github.com/hashicorp/nomad/client/serviceregistration/checks" cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/nomad/structs" - "golang.org/x/exp/maps" ) // MemDB implements a StateDB that stores data in memory and should only be diff --git a/command/agent/consul/service_client_test.go b/command/agent/consul/service_client_test.go index 7d7aaf985..9a991f5d0 100644 --- a/command/agent/consul/service_client_test.go +++ b/command/agent/consul/service_client_test.go @@ -5,6 +5,7 @@ package consul import ( "fmt" + "maps" "testing" "time" @@ -16,7 +17,6 @@ import ( "github.com/hashicorp/nomad/nomad/structs" "github.com/shoenig/test/must" "github.com/stretchr/testify/require" - "golang.org/x/exp/maps" ) func TestSyncLogic_maybeTweakTaggedAddresses(t *testing.T) { diff --git a/go.mod b/go.mod index f27543852..3a15727cf 100644 --- a/go.mod +++ b/go.mod @@ -126,7 +126,6 @@ require ( go.etcd.io/bbolt v1.3.9 go.uber.org/goleak v1.2.1 golang.org/x/crypto v0.19.0 - golang.org/x/exp v0.0.0-20231006140011-7918f672742d golang.org/x/sync v0.6.0 golang.org/x/sys v0.18.0 golang.org/x/time v0.3.0 @@ -275,6 +274,7 @@ require ( github.com/vmware/govmomi v0.18.0 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect go.opencensus.io v0.24.0 // indirect + golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/mod v0.13.0 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/oauth2 v0.12.0 // indirect diff --git a/helper/funcs_test.go b/helper/funcs_test.go index fc08ff87a..f6c9b3e24 100644 --- a/helper/funcs_test.go +++ b/helper/funcs_test.go @@ -5,6 +5,7 @@ package helper import ( "fmt" + "maps" "reflect" "sort" "testing" @@ -12,7 +13,6 @@ import ( "github.com/hashicorp/go-set/v2" "github.com/shoenig/test/must" "github.com/stretchr/testify/require" - "golang.org/x/exp/maps" ) func TestIsSubset(t *testing.T) { diff --git a/helper/opaque.go b/helper/opaque.go index d6110f8c6..b59736f1f 100644 --- a/helper/opaque.go +++ b/helper/opaque.go @@ -4,9 +4,10 @@ package helper import ( + "maps" + "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "golang.org/x/exp/maps" ) var ( diff --git a/helper/pointer/pointer.go b/helper/pointer/pointer.go index f9f1a3da2..3aacde937 100644 --- a/helper/pointer/pointer.go +++ b/helper/pointer/pointer.go @@ -4,14 +4,12 @@ // Package pointer provides helper functions related to Go pointers. package pointer -import ( - "golang.org/x/exp/constraints" -) +import "cmp" // Primitive represents basic types that are safe to do basic comparisons by // pointer dereference (checking nullity first). type Primitive interface { - constraints.Ordered | bool + cmp.Ordered | bool } // Of returns a pointer to a. diff --git a/lib/lang/maps.go b/lib/lang/maps.go index 17b62323f..8d7feb627 100644 --- a/lib/lang/maps.go +++ b/lib/lang/maps.go @@ -6,8 +6,26 @@ package lang import ( "cmp" "slices" + + "github.com/hashicorp/nomad/helper/pointer" ) +// MapKeys will return a slice of keys of m in no particular order. +func MapKeys[M ~map[K]V, K pointer.Primitive, V any](m M) []K { + result := make([]K, 0, len(m)) + for key := range m { + result = append(result, key) + } + return result +} + +// MapClear will delete all elements out of m. +func MapClear[M ~map[K]V, K pointer.Primitive, V any](m M) { + for key := range m { + delete(m, key) + } +} + // WalkMap will call f for every k/v in m, iterating the keyset of m in the // cmp.Ordered order. If f returns false the iteration is halted early. func WalkMap[K cmp.Ordered, V any](m map[K]V, f func(K, V) bool) { diff --git a/nomad/auth/auth.go b/nomad/auth/auth.go index fa79385f7..940d17583 100644 --- a/nomad/auth/auth.go +++ b/nomad/auth/auth.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "net" + "slices" "strings" "time" @@ -17,7 +18,6 @@ import ( "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/structs" - "golang.org/x/exp/slices" ) // aclCacheSize is the number of ACL objects to keep cached. ACLs have a parsing diff --git a/nomad/job_endpoint_hooks.go b/nomad/job_endpoint_hooks.go index dba4c9438..7e1d3b59f 100644 --- a/nomad/job_endpoint_hooks.go +++ b/nomad/job_endpoint_hooks.go @@ -11,8 +11,8 @@ import ( "github.com/dustin/go-humanize" "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/helper" + "github.com/hashicorp/nomad/lib/lang" "github.com/hashicorp/nomad/nomad/structs" - "golang.org/x/exp/maps" ) // Node attributes acquired via fingerprinting. @@ -276,7 +276,7 @@ func (jobImpliedConstraints) Mutate(j *structs.Job) (*structs.Job, []error, erro // this single loop, with a new constraintMatcher if needed. for _, tg := range j.TaskGroups { // If the task group utilises Vault, run the mutator. - vaultTasks := maps.Keys(vaultBlocks[tg.Name]) + vaultTasks := lang.MapKeys(vaultBlocks[tg.Name]) sort.Strings(vaultTasks) for _, vaultTask := range vaultTasks { vaultBlock := vaultBlocks[tg.Name][vaultTask] diff --git a/nomad/structs/node.go b/nomad/structs/node.go index d4751752a..bc15ddaba 100644 --- a/nomad/structs/node.go +++ b/nomad/structs/node.go @@ -5,12 +5,12 @@ package structs import ( "fmt" + "maps" "reflect" "strings" "time" "github.com/hashicorp/hcl/v2/hclsyntax" - "golang.org/x/exp/maps" ) // CSITopology is a map of topological domains to topological segments. diff --git a/nomad/structs/node_pool.go b/nomad/structs/node_pool.go index 4805bd509..ada2a8d57 100644 --- a/nomad/structs/node_pool.go +++ b/nomad/structs/node_pool.go @@ -5,13 +5,13 @@ package structs import ( "fmt" + "maps" "regexp" "sort" "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/helper/pointer" "golang.org/x/crypto/blake2b" - "golang.org/x/exp/maps" ) const ( diff --git a/plugins/csi/client.go b/plugins/csi/client.go index 736289e9c..059321ebd 100644 --- a/plugins/csi/client.go +++ b/plugins/csi/client.go @@ -6,6 +6,7 @@ package csi import ( "context" "fmt" + "maps" "math" "net" "os" @@ -14,7 +15,6 @@ import ( csipbv1 "github.com/container-storage-interface/spec/lib/go/csi" "github.com/hashicorp/go-hclog" multierror "github.com/hashicorp/go-multierror" - "golang.org/x/exp/maps" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" diff --git a/plugins/drivers/driver.go b/plugins/drivers/driver.go index cbbf3a4cb..c41289209 100644 --- a/plugins/drivers/driver.go +++ b/plugins/drivers/driver.go @@ -8,6 +8,7 @@ import ( "crypto/md5" "fmt" "io" + "maps" "path/filepath" "sort" "strconv" @@ -23,7 +24,6 @@ import ( pstructs "github.com/hashicorp/nomad/plugins/shared/structs" "github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty/msgpack" - "golang.org/x/exp/maps" ) const ( diff --git a/scheduler/feasible.go b/scheduler/feasible.go index 69562e53a..9ff3878ba 100644 --- a/scheduler/feasible.go +++ b/scheduler/feasible.go @@ -4,6 +4,7 @@ package scheduler import ( + "cmp" "fmt" "reflect" "regexp" @@ -15,7 +16,6 @@ import ( "github.com/hashicorp/nomad/helper/constraints/semver" "github.com/hashicorp/nomad/nomad/structs" psstructs "github.com/hashicorp/nomad/plugins/shared/structs" - "golang.org/x/exp/constraints" ) const ( @@ -926,7 +926,7 @@ func checkLexicalOrder(op string, lVal, rVal string) bool { } // compareOrder returns the result of the expression (left op right) -func compareOrder[T constraints.Ordered](op string, left, right T) bool { +func compareOrder[T cmp.Ordered](op string, left, right T) bool { switch op { case "<": return left < right diff --git a/scheduler/reconcile_util.go b/scheduler/reconcile_util.go index 25c7f5431..21bf608f1 100644 --- a/scheduler/reconcile_util.go +++ b/scheduler/reconcile_util.go @@ -11,12 +11,12 @@ package scheduler import ( "errors" "fmt" + "slices" "sort" "strings" "time" "github.com/hashicorp/nomad/nomad/structs" - "golang.org/x/exp/slices" ) // placementResult is an allocation that must be placed. It potentially has a