Skip to content

Commit

Permalink
deps: update to go-set/v3 and refactor to use custom iterators (#23971)
Browse files Browse the repository at this point in the history
* deps: update to go-set/v3

* deps: use custom set iterators for looping
  • Loading branch information
shoenig authored Sep 16, 2024
1 parent 212a72b commit 51215bf
Show file tree
Hide file tree
Showing 66 changed files with 108 additions and 113 deletions.
2 changes: 1 addition & 1 deletion client/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/armon/go-metrics"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/acl"
"github.com/hashicorp/nomad/nomad/structs"
)
Expand Down
2 changes: 1 addition & 1 deletion client/allocdir/task_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/helper/users/dynamic"
"github.com/hashicorp/nomad/plugins/drivers/fsisolation"
)
Expand Down
8 changes: 3 additions & 5 deletions client/allocrunner/consul_grpc_sock_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/hashicorp/go-hclog"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down Expand Up @@ -72,8 +72,7 @@ func newConsulGRPCSocketHook(
}
proxies := map[string]*grpcSocketProxy{}

clusterNames.ForEach(func(clusterName string) bool {

for clusterName := range clusterNames.Items() {
// Attempt to find the gRPC port via the node attributes, otherwise use
// the default fallback.
attrName := "consul.grpc"
Expand All @@ -91,8 +90,7 @@ func newConsulGRPCSocketHook(
configs[clusterName],
consulGRPCPort,
)
return true
})
}

return &consulGRPCSocketHook{
alloc: alloc,
Expand Down
7 changes: 3 additions & 4 deletions client/allocrunner/consul_http_sock_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/hashicorp/go-hclog"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down Expand Up @@ -59,14 +59,13 @@ func newConsulHTTPSocketHook(
}
proxies := map[string]*httpSocketProxy{}

clusterNames.ForEach(func(clusterName string) bool {
for clusterName := range clusterNames.Items() {
proxies[clusterName] = newHTTPSocketProxy(
logger,
allocDir,
configs[clusterName],
)
return true
})
}

return &consulHTTPSockHook{
alloc: alloc,
Expand Down
2 changes: 1 addition & 1 deletion client/allocrunner/networking_cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
cnilibrary "github.com/containernetworking/cni/libcni"
consulIPTables "github.com/hashicorp/consul/sdk/iptables"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/helper/envoy"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down
7 changes: 3 additions & 4 deletions client/lib/cgroupslib/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strconv"
"strings"

"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -176,10 +176,9 @@ func (l *lifeCG1) Kill() error {
}

signal := unix.SignalNum("SIGKILL")
pids.ForEach(func(pid int) bool {
for pid := range pids.Items() {
_ = unix.Kill(pid, signal)
return true
})
}

return l.thaw()
}
Expand Down
2 changes: 1 addition & 1 deletion client/lib/cgroupslib/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"
"syscall"

"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
)

// detect tries to detect which cgroups version we have by looking at the mount
Expand Down
4 changes: 2 additions & 2 deletions client/lib/idset/idset.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strconv"
"strings"

"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
)

// An ID is representative of a non-negative identifier of something like
Expand Down Expand Up @@ -184,7 +184,7 @@ func (s *Set[T]) String() string {
// ForEach iterates the elements in the set and applies f. Iteration stops
// if the result of f is a non-nil error.
func (s *Set[T]) ForEach(f func(id T) error) error {
for _, id := range s.items.Slice() {
for id := range s.items.Items() {
if err := f(id); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion client/serviceregistration/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/nomad/structs"
)
Expand Down
2 changes: 1 addition & 1 deletion command/acl_token_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/helper"
"github.com/posener/complete"
Expand Down
9 changes: 4 additions & 5 deletions command/agent/consul/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/armon/go-metrics"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/client/serviceregistration"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/helper/envoy"
Expand Down Expand Up @@ -1824,8 +1824,7 @@ func (c *ServiceClient) Shutdown() error {

// Always attempt to deregister Nomad agent Consul entries, even if
// deadline was reached
for _, id := range c.agentServices.Slice() {

for id := range c.agentServices.Items() {
opts := &api.QueryOptions{
Token: c.getServiceToken(id),
}
Expand Down Expand Up @@ -1860,7 +1859,7 @@ func (c *ServiceClient) Shutdown() error {
return false
}

for _, id := range c.agentChecks.Slice() {
for id := range c.agentChecks.Items() {
// if we couldn't populate remainingChecks it is unlikely that CheckDeregister will work, but try anyway
// if we could list the remaining checks, verify that the check we store still exists before removing it.
if remainingChecks == nil || checkRemains(id) {
Expand Down Expand Up @@ -1932,7 +1931,7 @@ func (c *ServiceClient) setServiceTokens(tokens map[string]string) {
func (c *ServiceClient) gcDeregisteredServiceTokens() {
c.serviceTokensLock.Lock()
defer c.serviceTokensLock.Unlock()
for _, serviceID := range c.explicitlyDeregisteredServices.Slice() {
for serviceID := range c.explicitlyDeregisteredServices.Items() {
delete(c.serviceTokens, serviceID)
}
}
Expand Down
6 changes: 3 additions & 3 deletions command/job_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
humanize "github.com/dustin/go-humanize"
"github.com/dustin/go-humanize/english"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/api/contexts"
"github.com/posener/complete"
Expand Down Expand Up @@ -674,7 +674,7 @@ func (c *JobRestartCommand) filterAllocs(stubs []AllocationListStubWithJob) []Al
// Skip allocations that don't have any of the requested tasks.
if c.tasks.Size() > 0 {
hasTask := false
for _, taskName := range c.tasks.Slice() {
for taskName := range c.tasks.Items() {
if stub.HasTask(taskName) {
hasTask = true
break
Expand Down Expand Up @@ -910,7 +910,7 @@ func (c *JobRestartCommand) restartAlloc(alloc AllocationListStubWithJob) error

// Run restarts concurrently when specific tasks were requested.
var restarts multierror.Group
for _, task := range c.tasks.Slice() {
for task := range c.tasks.Items() {
if !alloc.HasTask(task) {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion command/job_restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"time"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/ci"
"github.com/hashicorp/nomad/command/agent"
Expand Down
2 changes: 1 addition & 1 deletion command/node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"strings"

"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/api/contexts"
"github.com/mitchellh/cli"
Expand Down
2 changes: 1 addition & 1 deletion command/node_pool_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"strings"

"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/api"
"github.com/posener/complete"
)
Expand Down
2 changes: 1 addition & 1 deletion command/node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"regexp"
"testing"

"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/ci"
"github.com/mitchellh/cli"
Expand Down
8 changes: 4 additions & 4 deletions command/var_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"strings"

multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/hcl"
"github.com/hashicorp/hcl/hcl/ast"
"github.com/hashicorp/nomad/api"
Expand Down Expand Up @@ -588,11 +588,11 @@ func formatInvalidVarKeyChars(invalid []string) string {

// Sort the characters for output
charList := make([]string, 0, chars.Size())
chars.ForEach(func(k string) bool {

for k := range chars.Items() {
// Use %s instead of %q to avoid escaping characters.
charList = append(charList, fmt.Sprintf(`"%s"`, k))
return true
})
}

slices.Sort(charList)

Expand Down
2 changes: 1 addition & 1 deletion drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
hclog "github.com/hashicorp/go-hclog"
multierror "github.com/hashicorp/go-multierror"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/client/lib/cgroupslib"
"github.com/hashicorp/nomad/client/lib/cpustats"
"github.com/hashicorp/nomad/client/taskenv"
Expand Down
4 changes: 2 additions & 2 deletions drivers/docker/reconcile_dangling.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

docker "github.com/fsouza/go-dockerclient"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
)

// containerReconciler detects and kills unexpectedly running containers.
Expand Down Expand Up @@ -114,7 +114,7 @@ func (r *containerReconciler) removeDanglingContainersIteration() error {
return err
}

for _, id := range untracked.Slice() {
for id := range untracked.Items() {
ctx, cancel := r.dockerAPIQueryContext()
err := dockerClient.RemoveContainer(docker.RemoveContainerOptions{
Context: ctx,
Expand Down
2 changes: 1 addition & 1 deletion drivers/docker/reconcile_dangling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

docker "github.com/fsouza/go-dockerclient"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/shoenig/test/must"
"github.com/shoenig/test/wait"

Expand Down
2 changes: 1 addition & 1 deletion drivers/docker/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package docker
import (
"sync"

"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
)

type taskStore struct {
Expand Down
2 changes: 1 addition & 1 deletion drivers/shared/executor/executor_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os/exec"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/client/lib/cpustats"
"github.com/hashicorp/nomad/drivers/shared/executor/procstats"
"github.com/hashicorp/nomad/plugins/drivers"
Expand Down
2 changes: 1 addition & 1 deletion drivers/shared/executor/executor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/armon/circbuf"
"github.com/hashicorp/consul-template/signals"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/lib/cgroupslib"
"github.com/hashicorp/nomad/client/lib/cpustats"
Expand Down
2 changes: 1 addition & 1 deletion drivers/shared/executor/executor_universal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strconv"
"syscall"

"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/client/lib/cgroupslib"
"github.com/hashicorp/nomad/client/lib/nsutil"
"github.com/hashicorp/nomad/drivers/shared/executor/procstats"
Expand Down
2 changes: 1 addition & 1 deletion drivers/shared/executor/procstats/getstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (lps *linuxProcStats) scanPIDs() {
}

// insert trackers for new pids not yet present
for _, pid := range currentPIDs.Slice() {
for pid := range currentPIDs.Items() {
if _, exists := lps.latest[pid]; !exists {
lps.latest[pid] = &stats{
TotalCPU: cpustats.New(lps.compute),
Expand Down
2 changes: 1 addition & 1 deletion drivers/shared/executor/procstats/list_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"context"
"time"

"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/lib/lang"
"github.com/shirou/gopsutil/v3/process"
)
Expand Down
2 changes: 1 addition & 1 deletion drivers/shared/executor/procstats/list_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package procstats

import (
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/client/lib/cgroupslib"
)

Expand Down
2 changes: 1 addition & 1 deletion drivers/shared/executor/procstats/list_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package procstats

import (
"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/mitchellh/go-ps"
)

Expand Down
2 changes: 1 addition & 1 deletion drivers/shared/executor/procstats/procstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package procstats
import (
"time"

"github.com/hashicorp/go-set/v2"
"github.com/hashicorp/go-set/v3"
"github.com/hashicorp/nomad/client/lib/cpustats"
"github.com/hashicorp/nomad/plugins/drivers"
)
Expand Down
Loading

0 comments on commit 51215bf

Please sign in to comment.