Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: purge use of old x/exp packages #20373

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .semgrep/imports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions api/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
package api

import (
"maps"
"slices"
"time"

"golang.org/x/exp/maps"
)

// Consul represents configuration related to consul.
Expand Down
1 change: 0 additions & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 0 additions & 2 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"errors"
"fmt"
"io"
"maps"
"net/url"
"sort"
"strconv"
"time"

"github.com/hashicorp/cronexpr"
"golang.org/x/exp/maps"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion client/allochealth/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package allochealth
import (
"context"
"fmt"
"maps"
"strings"
"sync"
"time"
Expand All @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion client/allocrunner/alloc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package allocrunner
import (
"context"
"fmt"
"maps"
"sync"
"time"

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/allocrunner/taskrunner/artifact_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package taskrunner
import (
"context"
"fmt"
"maps"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/allocrunner/taskrunner/logmon_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package taskrunner
import (
"context"
"encoding/json"
"maps"
"net"
"testing"

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion client/allocrunner/taskrunner/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package client
import (
"errors"
"fmt"
"maps"
"net"
"net/rpc"
"os"
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion client/meta_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion client/pluginmanager/csimanager/fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion client/serviceregistration/checks/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"io"
"maps"
"net"
"net/http"
"net/http/httptest"
Expand All @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion client/serviceregistration/checks/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion client/serviceregistration/service_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/state/db_mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package state

import (
"maps"
"sync"

"github.com/hashicorp/go-hclog"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion command/agent/consul/service_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package consul

import (
"fmt"
"maps"
"testing"
"time"

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion helper/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package helper

import (
"fmt"
"maps"
"reflect"
"sort"
"testing"

"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) {
Expand Down
3 changes: 2 additions & 1 deletion helper/opaque.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 2 additions & 4 deletions helper/pointer/pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions lib/lang/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion nomad/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"net"
"slices"
"strings"
"time"

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions nomad/job_endpoint_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion nomad/structs/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading
Loading