diff --git a/.golangci.yml b/.golangci.yml index 4fb6f5e1f..6be0b4d43 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -65,9 +65,8 @@ linters-settings: - commentFormatting - deprecatedComment staticcheck: - # Only enable a single check to start. # I(jrasell) will work on enabling additional checks when possible. - checks: ["ST1020"] + checks: ["ST1020", "ST1016"] issues: exclude: diff --git a/client/allocdir/task_dir_nonlinux.go b/client/allocdir/task_dir_nonlinux.go index 87f813f7f..e69bab056 100644 --- a/client/allocdir/task_dir_nonlinux.go +++ b/client/allocdir/task_dir_nonlinux.go @@ -4,6 +4,6 @@ package allocdir // currently a noop on non-Linux platforms -func (d *TaskDir) unmountSpecialDirs() error { +func (t *TaskDir) unmountSpecialDirs() error { return nil } diff --git a/client/allocrunner/csi_hook.go b/client/allocrunner/csi_hook.go index da19bf657..6504b31cb 100644 --- a/client/allocrunner/csi_hook.go +++ b/client/allocrunner/csi_hook.go @@ -212,8 +212,8 @@ func newCSIHook(ar *allocRunner, logger hclog.Logger, alloc *structs.Allocation, } } -func (h *csiHook) shouldRun() bool { - tg := h.alloc.Job.LookupTaskGroup(h.alloc.TaskGroup) +func (c *csiHook) shouldRun() bool { + tg := c.alloc.Job.LookupTaskGroup(c.alloc.TaskGroup) for _, vol := range tg.Volumes { if vol.Type == structs.VolumeTypeCSI { return true diff --git a/client/allocrunner/state/state.go b/client/allocrunner/state/state.go index 6f15e0355..f1316cc57 100644 --- a/client/allocrunner/state/state.go +++ b/client/allocrunner/state/state.go @@ -65,8 +65,8 @@ func (s *State) Copy() *State { } // ClientTerminalStatus returns if the client status is terminal and will no longer transition -func (a *State) ClientTerminalStatus() bool { - switch a.ClientStatus { +func (s *State) ClientTerminalStatus() bool { + switch s.ClientStatus { case structs.AllocClientStatusComplete, structs.AllocClientStatusFailed, structs.AllocClientStatusLost: return true default: diff --git a/client/allocrunner/taskrunner/script_check_hook.go b/client/allocrunner/taskrunner/script_check_hook.go index 65232f708..332ec6673 100644 --- a/client/allocrunner/taskrunner/script_check_hook.go +++ b/client/allocrunner/taskrunner/script_check_hook.go @@ -399,9 +399,9 @@ const ( // updateTTL updates the state to Consul, performing an exponential backoff // in the case where the check isn't registered in Consul to avoid a race between // service registration and the first check. -func (s *scriptCheck) updateTTL(ctx context.Context, msg, state string) error { +func (sc *scriptCheck) updateTTL(ctx context.Context, msg, state string) error { for attempts := 0; ; attempts++ { - err := s.ttlUpdater.UpdateTTL(s.id, s.consulNamespace, msg, state) + err := sc.ttlUpdater.UpdateTTL(sc.id, sc.consulNamespace, msg, state) if err == nil { return nil } diff --git a/client/client.go b/client/client.go index 8b6d0ad75..1f5025cdc 100644 --- a/client/client.go +++ b/client/client.go @@ -3105,8 +3105,8 @@ func (g *group) Go(f func()) { }() } -func (c *group) AddCh(ch <-chan struct{}) { - c.Go(func() { +func (g *group) AddCh(ch <-chan struct{}) { + g.Go(func() { <-ch }) } diff --git a/client/fingerprint_manager.go b/client/fingerprint_manager.go index 7968b14c7..8a08a077a 100644 --- a/client/fingerprint_manager.go +++ b/client/fingerprint_manager.go @@ -68,16 +68,16 @@ func (fm *FingerprintManager) getNode() *structs.Node { // identifying allowlisted and denylisted fingerprints/drivers. Then, for // those which require periotic checking, it starts a periodic process for // each. -func (fp *FingerprintManager) Run() error { +func (fm *FingerprintManager) Run() error { // First, set up all fingerprints - cfg := fp.getConfig() + cfg := fm.getConfig() // COMPAT(1.0) using inclusive language, whitelist is kept for backward compatibility. allowlistFingerprints := cfg.ReadStringListToMap("fingerprint.allowlist", "fingerprint.whitelist") allowlistFingerprintsEnabled := len(allowlistFingerprints) > 0 // COMPAT(1.0) using inclusive language, blacklist is kept for backward compatibility. denylistFingerprints := cfg.ReadStringListToMap("fingerprint.denylist", "fingerprint.blacklist") - fp.logger.Debug("built-in fingerprints", "fingerprinters", fingerprint.BuiltinFingerprints()) + fm.logger.Debug("built-in fingerprints", "fingerprinters", fingerprint.BuiltinFingerprints()) var availableFingerprints []string var skippedFingerprints []string @@ -96,12 +96,12 @@ func (fp *FingerprintManager) Run() error { availableFingerprints = append(availableFingerprints, name) } - if err := fp.setupFingerprinters(availableFingerprints); err != nil { + if err := fm.setupFingerprinters(availableFingerprints); err != nil { return err } if len(skippedFingerprints) != 0 { - fp.logger.Debug("fingerprint modules skipped due to allow/denylist", + fm.logger.Debug("fingerprint modules skipped due to allow/denylist", "skipped_fingerprinters", skippedFingerprints) } diff --git a/command/agent/config.go b/command/agent/config.go index 2a18f0e2a..740da6cb6 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -737,8 +737,8 @@ type Telemetry struct { } // PrefixFilters parses the PrefixFilter field and returns a list of allowed and blocked filters -func (t *Telemetry) PrefixFilters() (allowed, blocked []string, err error) { - for _, rule := range t.PrefixFilter { +func (a *Telemetry) PrefixFilters() (allowed, blocked []string, err error) { + for _, rule := range a.PrefixFilter { if rule == "" { continue } @@ -1448,8 +1448,8 @@ func (a *ACLConfig) Merge(b *ACLConfig) *ACLConfig { } // Merge is used to merge two server configs together -func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig { - result := *a +func (s *ServerConfig) Merge(b *ServerConfig) *ServerConfig { + result := *s if b.Enabled { result.Enabled = true @@ -1583,13 +1583,13 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig { result.EnabledSchedulers = append(result.EnabledSchedulers, b.EnabledSchedulers...) // Copy the start join addresses - result.StartJoin = make([]string, 0, len(a.StartJoin)+len(b.StartJoin)) - result.StartJoin = append(result.StartJoin, a.StartJoin...) + result.StartJoin = make([]string, 0, len(s.StartJoin)+len(b.StartJoin)) + result.StartJoin = append(result.StartJoin, s.StartJoin...) result.StartJoin = append(result.StartJoin, b.StartJoin...) // Copy the retry join addresses - result.RetryJoin = make([]string, 0, len(a.RetryJoin)+len(b.RetryJoin)) - result.RetryJoin = append(result.RetryJoin, a.RetryJoin...) + result.RetryJoin = make([]string, 0, len(s.RetryJoin)+len(b.RetryJoin)) + result.RetryJoin = append(result.RetryJoin, s.RetryJoin...) result.RetryJoin = append(result.RetryJoin, b.RetryJoin...) return &result diff --git a/command/alloc_exec.go b/command/alloc_exec.go index 9555ee03d..cf72e033f 100644 --- a/command/alloc_exec.go +++ b/command/alloc_exec.go @@ -70,8 +70,8 @@ func (l *AllocExecCommand) Synopsis() string { return "Execute commands in task" } -func (c *AllocExecCommand) AutocompleteFlags() complete.Flags { - return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient), +func (l *AllocExecCommand) AutocompleteFlags() complete.Flags { + return mergeAutocompleteFlags(l.Meta.AutocompleteFlags(FlagSetClient), complete.Flags{ "--task": complete.PredictAnything, "-job": complete.PredictAnything, diff --git a/command/alloc_fs.go b/command/alloc_fs.go index 9afe28494..1912ebc1c 100644 --- a/command/alloc_fs.go +++ b/command/alloc_fs.go @@ -83,8 +83,8 @@ func (f *AllocFSCommand) Synopsis() string { return "Inspect the contents of an allocation directory" } -func (c *AllocFSCommand) AutocompleteFlags() complete.Flags { - return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient), +func (f *AllocFSCommand) AutocompleteFlags() complete.Flags { + return mergeAutocompleteFlags(f.Meta.AutocompleteFlags(FlagSetClient), complete.Flags{ "-H": complete.PredictNothing, "-verbose": complete.PredictNothing, diff --git a/command/alloc_logs.go b/command/alloc_logs.go index 935e7e265..24d8229b1 100644 --- a/command/alloc_logs.go +++ b/command/alloc_logs.go @@ -75,8 +75,8 @@ func (l *AllocLogsCommand) Synopsis() string { return "Streams the logs of a task." } -func (c *AllocLogsCommand) AutocompleteFlags() complete.Flags { - return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient), +func (l *AllocLogsCommand) AutocompleteFlags() complete.Flags { + return mergeAutocompleteFlags(l.Meta.AutocompleteFlags(FlagSetClient), complete.Flags{ "-stderr": complete.PredictNothing, "-verbose": complete.PredictNothing, diff --git a/command/alloc_restart.go b/command/alloc_restart.go index 3aea9538a..b06f5ccc8 100644 --- a/command/alloc_restart.go +++ b/command/alloc_restart.go @@ -13,7 +13,7 @@ type AllocRestartCommand struct { Meta } -func (a *AllocRestartCommand) Help() string { +func (c *AllocRestartCommand) Help() string { helpText := ` Usage: nomad alloc restart [options] @@ -153,7 +153,7 @@ func validateTaskExistsInAllocation(taskName string, alloc *api.Allocation) erro return fmt.Errorf("Could not find task named: %s, found:\n%s", taskName, formatList(foundTaskNames)) } -func (a *AllocRestartCommand) Synopsis() string { +func (c *AllocRestartCommand) Synopsis() string { return "Restart a running allocation" } diff --git a/command/alloc_signal.go b/command/alloc_signal.go index 70b949912..e4db386f9 100644 --- a/command/alloc_signal.go +++ b/command/alloc_signal.go @@ -13,7 +13,7 @@ type AllocSignalCommand struct { Meta } -func (a *AllocSignalCommand) Help() string { +func (c *AllocSignalCommand) Help() string { helpText := ` Usage: nomad alloc signal [options] @@ -141,7 +141,7 @@ func (c *AllocSignalCommand) Run(args []string) int { return 0 } -func (a *AllocSignalCommand) Synopsis() string { +func (c *AllocSignalCommand) Synopsis() string { return "Signal a running allocation" } diff --git a/command/alloc_stop.go b/command/alloc_stop.go index 3b1d10218..8a130cbaa 100644 --- a/command/alloc_stop.go +++ b/command/alloc_stop.go @@ -11,7 +11,7 @@ type AllocStopCommand struct { Meta } -func (a *AllocStopCommand) Help() string { +func (c *AllocStopCommand) Help() string { helpText := ` Usage: nomad alloc stop [options] Alias: nomad stop @@ -142,6 +142,6 @@ func (c *AllocStopCommand) Run(args []string) int { return mon.monitor(resp.EvalID) } -func (a *AllocStopCommand) Synopsis() string { +func (c *AllocStopCommand) Synopsis() string { return "Stop and reschedule a running allocation" } diff --git a/command/scaling_policy_info.go b/command/scaling_policy_info.go index d255816ae..4e8662055 100644 --- a/command/scaling_policy_info.go +++ b/command/scaling_policy_info.go @@ -61,9 +61,9 @@ func (s *ScalingPolicyInfoCommand) AutocompleteFlags() complete.Flags { }) } -func (c *ScalingPolicyInfoCommand) AutocompleteArgs() complete.Predictor { +func (s *ScalingPolicyInfoCommand) AutocompleteArgs() complete.Predictor { return complete.PredictFunc(func(a complete.Args) []string { - client, err := c.Meta.Client() + client, err := s.Meta.Client() if err != nil { return nil } diff --git a/command/status.go b/command/status.go index 54459577c..e48aefef4 100644 --- a/command/status.go +++ b/command/status.go @@ -16,7 +16,7 @@ type StatusCommand struct { verbose bool } -func (s *StatusCommand) Help() string { +func (c *StatusCommand) Help() string { helpText := ` Usage: nomad status [options] diff --git a/drivers/shared/executor/client.go b/drivers/shared/executor/client.go index 44f459e91..7ab2dbf6a 100644 --- a/drivers/shared/executor/client.go +++ b/drivers/shared/executor/client.go @@ -195,24 +195,24 @@ func (c *grpcExecutorClient) Exec(deadline time.Time, cmd string, args []string) return resp.Output, int(resp.ExitCode), nil } -func (d *grpcExecutorClient) ExecStreaming(ctx context.Context, +func (c *grpcExecutorClient) ExecStreaming(ctx context.Context, command []string, tty bool, execStream drivers.ExecTaskStream) error { - err := d.execStreaming(ctx, command, tty, execStream) + err := c.execStreaming(ctx, command, tty, execStream) if err != nil { - return grpcutils.HandleGrpcErr(err, d.doneCtx) + return grpcutils.HandleGrpcErr(err, c.doneCtx) } return nil } -func (d *grpcExecutorClient) execStreaming(ctx context.Context, +func (c *grpcExecutorClient) execStreaming(ctx context.Context, command []string, tty bool, execStream drivers.ExecTaskStream) error { - stream, err := d.client.ExecStreaming(ctx) + stream, err := c.client.ExecStreaming(ctx) if err != nil { return err } diff --git a/e2e/e2eutil/e2ejob.go b/e2e/e2eutil/e2ejob.go index 2befe146d..80ecdc1e7 100644 --- a/e2e/e2eutil/e2ejob.go +++ b/e2e/e2eutil/e2ejob.go @@ -28,8 +28,8 @@ type e2eJob struct { jobID string } -func (e *e2eJob) Name() string { - return filepath.Base(e.jobfile) +func (j *e2eJob) Name() string { + return filepath.Base(j.jobfile) } // Ensure cluster has leader and at least 1 client node diff --git a/lib/cpuset/cpuset.go b/lib/cpuset/cpuset.go index 7058e46df..e794d354c 100644 --- a/lib/cpuset/cpuset.go +++ b/lib/cpuset/cpuset.go @@ -102,8 +102,8 @@ func (c CPUSet) Difference(other CPUSet) CPUSet { } // IsSubsetOf returns true if all cpus of the this CPUSet are present in the other CPUSet. -func (s CPUSet) IsSubsetOf(other CPUSet) bool { - for cpu := range s.cpus { +func (c CPUSet) IsSubsetOf(other CPUSet) bool { + for cpu := range c.cpus { if _, ok := other.cpus[cpu]; !ok { return false } @@ -111,9 +111,9 @@ func (s CPUSet) IsSubsetOf(other CPUSet) bool { return true } -func (s CPUSet) IsSupersetOf(other CPUSet) bool { +func (c CPUSet) IsSupersetOf(other CPUSet) bool { for cpu := range other.cpus { - if _, ok := s.cpus[cpu]; !ok { + if _, ok := c.cpus[cpu]; !ok { return false } } @@ -121,9 +121,9 @@ func (s CPUSet) IsSupersetOf(other CPUSet) bool { } // ContainsAny returns true if any cpus in other CPUSet are present -func (s CPUSet) ContainsAny(other CPUSet) bool { +func (c CPUSet) ContainsAny(other CPUSet) bool { for cpu := range other.cpus { - if _, ok := s.cpus[cpu]; ok { + if _, ok := c.cpus[cpu]; ok { return true } } @@ -131,8 +131,8 @@ func (s CPUSet) ContainsAny(other CPUSet) bool { } // Equals tests the equality of the elements in the CPUSet -func (s CPUSet) Equals(other CPUSet) bool { - return reflect.DeepEqual(s.cpus, other.cpus) +func (c CPUSet) Equals(other CPUSet) bool { + return reflect.DeepEqual(c.cpus, other.cpus) } // Parse parses the Linux cpuset format into a CPUSet diff --git a/nomad/csi_endpoint.go b/nomad/csi_endpoint.go index eb6954eed..825abf4be 100644 --- a/nomad/csi_endpoint.go +++ b/nomad/csi_endpoint.go @@ -23,9 +23,9 @@ type CSIVolume struct { // QueryACLObj looks up the ACL token in the request and returns the acl.ACL object // - fallback to node secret ids -func (srv *Server) QueryACLObj(args *structs.QueryOptions, allowNodeAccess bool) (*acl.ACL, error) { +func (s *Server) QueryACLObj(args *structs.QueryOptions, allowNodeAccess bool) (*acl.ACL, error) { // Lookup the token - aclObj, err := srv.ResolveToken(args.AuthToken) + aclObj, err := s.ResolveToken(args.AuthToken) if err != nil { // If ResolveToken had an unexpected error return that if !structs.IsErrTokenNotFound(err) { @@ -41,7 +41,7 @@ func (srv *Server) QueryACLObj(args *structs.QueryOptions, allowNodeAccess bool) ws := memdb.NewWatchSet() // Attempt to lookup AuthToken as a Node.SecretID since nodes may call // call this endpoint and don't have an ACL token. - node, stateErr := srv.fsm.State().NodeBySecretID(ws, args.AuthToken) + node, stateErr := s.fsm.State().NodeBySecretID(ws, args.AuthToken) if stateErr != nil { // Return the original ResolveToken error with this err var merr multierror.Error @@ -60,13 +60,13 @@ func (srv *Server) QueryACLObj(args *structs.QueryOptions, allowNodeAccess bool) } // WriteACLObj calls QueryACLObj for a WriteRequest -func (srv *Server) WriteACLObj(args *structs.WriteRequest, allowNodeAccess bool) (*acl.ACL, error) { +func (s *Server) WriteACLObj(args *structs.WriteRequest, allowNodeAccess bool) (*acl.ACL, error) { opts := &structs.QueryOptions{ Region: args.RequestRegion(), Namespace: args.RequestNamespace(), AuthToken: args.AuthToken, } - return srv.QueryACLObj(opts, allowNodeAccess) + return s.QueryACLObj(opts, allowNodeAccess) } const ( @@ -75,17 +75,17 @@ const ( ) // replySetIndex sets the reply with the last index that modified the table -func (srv *Server) replySetIndex(table string, reply *structs.QueryMeta) error { - s := srv.fsm.State() +func (s *Server) replySetIndex(table string, reply *structs.QueryMeta) error { + fmsState := s.fsm.State() - index, err := s.Index(table) + index, err := fmsState.Index(table) if err != nil { return err } reply.Index = index // Set the query response - srv.setQueryMeta(reply) + s.setQueryMeta(reply) return nil } diff --git a/nomad/scaling_endpoint.go b/nomad/scaling_endpoint.go index bb87769a2..dd8c5fe11 100644 --- a/nomad/scaling_endpoint.go +++ b/nomad/scaling_endpoint.go @@ -137,9 +137,9 @@ func (p *Scaling) GetPolicy(args *structs.ScalingPolicySpecificRequest, return p.srv.blockingRPC(&opts) } -func (j *Scaling) listAllNamespaces(args *structs.ScalingPolicyListRequest, reply *structs.ScalingPolicyListResponse) error { +func (p *Scaling) listAllNamespaces(args *structs.ScalingPolicyListRequest, reply *structs.ScalingPolicyListResponse) error { // Check for list-job permissions - aclObj, err := j.srv.ResolveToken(args.AuthToken) + aclObj, err := p.srv.ResolveToken(args.AuthToken) if err != nil { return err } @@ -197,8 +197,8 @@ func (j *Scaling) listAllNamespaces(args *structs.ScalingPolicyListRequest, repl reply.Index = helper.Uint64Max(1, index) // Set the query response - j.srv.setQueryMeta(&reply.QueryMeta) + p.srv.setQueryMeta(&reply.QueryMeta) return nil }} - return j.srv.blockingRPC(&opts) + return p.srv.blockingRPC(&opts) } diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 81cbd7c63..93a7f27d6 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -6270,13 +6270,13 @@ type StateRestore struct { } // Abort is used to abort the restore operation -func (s *StateRestore) Abort() { - s.txn.Abort() +func (r *StateRestore) Abort() { + r.txn.Abort() } // Commit is used to commit the restore operation -func (s *StateRestore) Commit() error { - return s.txn.Commit() +func (r *StateRestore) Commit() error { + return r.txn.Commit() } // NodeRestore is used to restore a node diff --git a/nomad/structs/config/ui.go b/nomad/structs/config/ui.go index 7577fa6d9..1626544fb 100644 --- a/nomad/structs/config/ui.go +++ b/nomad/structs/config/ui.go @@ -60,8 +60,8 @@ func (old *UIConfig) Copy() *UIConfig { // Merge returns a new UI configuration by merging another UI // configuration into this one -func (this *UIConfig) Merge(other *UIConfig) *UIConfig { - result := this.Copy() +func (old *UIConfig) Merge(other *UIConfig) *UIConfig { + result := old.Copy() if other == nil { return result } @@ -86,8 +86,8 @@ func (old *ConsulUIConfig) Copy() *ConsulUIConfig { // Merge returns a new Consul UI configuration by merging another Consul UI // configuration into this one -func (this *ConsulUIConfig) Merge(other *ConsulUIConfig) *ConsulUIConfig { - result := this.Copy() +func (old *ConsulUIConfig) Merge(other *ConsulUIConfig) *ConsulUIConfig { + result := old.Copy() if result == nil { result = &ConsulUIConfig{} } @@ -114,8 +114,8 @@ func (old *VaultUIConfig) Copy() *VaultUIConfig { // Merge returns a new Vault UI configuration by merging another Vault UI // configuration into this one -func (this *VaultUIConfig) Merge(other *VaultUIConfig) *VaultUIConfig { - result := this.Copy() +func (old *VaultUIConfig) Merge(other *VaultUIConfig) *VaultUIConfig { + result := old.Copy() if result == nil { result = &VaultUIConfig{} } diff --git a/nomad/structs/config/vault.go b/nomad/structs/config/vault.go index 2c7921ea5..83a239a19 100644 --- a/nomad/structs/config/vault.go +++ b/nomad/structs/config/vault.go @@ -92,19 +92,19 @@ func DefaultVaultConfig() *VaultConfig { } // IsEnabled returns whether the config enables Vault integration -func (a *VaultConfig) IsEnabled() bool { - return a.Enabled != nil && *a.Enabled +func (c *VaultConfig) IsEnabled() bool { + return c.Enabled != nil && *c.Enabled } // AllowsUnauthenticated returns whether the config allows unauthenticated // access to Vault -func (a *VaultConfig) AllowsUnauthenticated() bool { - return a.AllowUnauthenticated != nil && *a.AllowUnauthenticated +func (c *VaultConfig) AllowsUnauthenticated() bool { + return c.AllowUnauthenticated != nil && *c.AllowUnauthenticated } // Merge merges two Vault configurations together. -func (a *VaultConfig) Merge(b *VaultConfig) *VaultConfig { - result := *a +func (c *VaultConfig) Merge(b *VaultConfig) *VaultConfig { + result := *c if b.Token != "" { result.Token = b.Token @@ -190,51 +190,51 @@ func (c *VaultConfig) Copy() *VaultConfig { // IsEqual compares two Vault configurations and returns a boolean indicating // if they are equal. -func (a *VaultConfig) IsEqual(b *VaultConfig) bool { - if a == nil && b != nil { +func (c *VaultConfig) IsEqual(b *VaultConfig) bool { + if c == nil && b != nil { return false } - if a != nil && b == nil { + if c != nil && b == nil { return false } - if a.Token != b.Token { + if c.Token != b.Token { return false } - if a.Role != b.Role { + if c.Role != b.Role { return false } - if a.TaskTokenTTL != b.TaskTokenTTL { + if c.TaskTokenTTL != b.TaskTokenTTL { return false } - if a.Addr != b.Addr { + if c.Addr != b.Addr { return false } - if a.ConnectionRetryIntv.Nanoseconds() != b.ConnectionRetryIntv.Nanoseconds() { + if c.ConnectionRetryIntv.Nanoseconds() != b.ConnectionRetryIntv.Nanoseconds() { return false } - if a.TLSCaFile != b.TLSCaFile { + if c.TLSCaFile != b.TLSCaFile { return false } - if a.TLSCaPath != b.TLSCaPath { + if c.TLSCaPath != b.TLSCaPath { return false } - if a.TLSCertFile != b.TLSCertFile { + if c.TLSCertFile != b.TLSCertFile { return false } - if a.TLSKeyFile != b.TLSKeyFile { + if c.TLSKeyFile != b.TLSKeyFile { return false } - if a.TLSServerName != b.TLSServerName { + if c.TLSServerName != b.TLSServerName { return false } - if a.AllowUnauthenticated != b.AllowUnauthenticated { + if c.AllowUnauthenticated != b.AllowUnauthenticated { return false } - if a.TLSSkipVerify != b.TLSSkipVerify { + if c.TLSSkipVerify != b.TLSSkipVerify { return false } - if a.Enabled != b.Enabled { + if c.Enabled != b.Enabled { return false } return true diff --git a/nomad/structs/csi.go b/nomad/structs/csi.go index 539501301..1ae51d87b 100644 --- a/nomad/structs/csi.go +++ b/nomad/structs/csi.go @@ -185,17 +185,17 @@ func (o *CSIMountOptions) Merge(p *CSIMountOptions) { var _ fmt.Stringer = &CSIMountOptions{} var _ fmt.GoStringer = &CSIMountOptions{} -func (v *CSIMountOptions) String() string { +func (o *CSIMountOptions) String() string { mountFlagsString := "nil" - if len(v.MountFlags) != 0 { + if len(o.MountFlags) != 0 { mountFlagsString = "[REDACTED]" } - return fmt.Sprintf("csi.CSIOptions(FSType: %s, MountFlags: %s)", v.FSType, mountFlagsString) + return fmt.Sprintf("csi.CSIOptions(FSType: %s, MountFlags: %s)", o.FSType, mountFlagsString) } -func (v *CSIMountOptions) GoString() string { - return v.String() +func (o *CSIMountOptions) GoString() string { + return o.String() } // CSISecrets contain optional additional configuration that can be used diff --git a/nomad/structs/diff.go b/nomad/structs/diff.go index d0f9e5bb2..fe8a00135 100644 --- a/nomad/structs/diff.go +++ b/nomad/structs/diff.go @@ -1901,24 +1901,24 @@ func (r *Resources) Diff(other *Resources, contextual bool) *ObjectDiff { // Diff returns a diff of two network resources. If contextual diff is enabled, // non-changed fields will still be returned. -func (r *NetworkResource) Diff(other *NetworkResource, contextual bool) *ObjectDiff { +func (n *NetworkResource) Diff(other *NetworkResource, contextual bool) *ObjectDiff { diff := &ObjectDiff{Type: DiffTypeNone, Name: "Network"} var oldPrimitiveFlat, newPrimitiveFlat map[string]string filter := []string{"Device", "CIDR", "IP"} - if reflect.DeepEqual(r, other) { + if reflect.DeepEqual(n, other) { return nil - } else if r == nil { - r = &NetworkResource{} + } else if n == nil { + n = &NetworkResource{} diff.Type = DiffTypeAdded newPrimitiveFlat = flatmap.Flatten(other, filter, true) } else if other == nil { other = &NetworkResource{} diff.Type = DiffTypeDeleted - oldPrimitiveFlat = flatmap.Flatten(r, filter, true) + oldPrimitiveFlat = flatmap.Flatten(n, filter, true) } else { diff.Type = DiffTypeEdited - oldPrimitiveFlat = flatmap.Flatten(r, filter, true) + oldPrimitiveFlat = flatmap.Flatten(n, filter, true) newPrimitiveFlat = flatmap.Flatten(other, filter, true) } @@ -1926,8 +1926,8 @@ func (r *NetworkResource) Diff(other *NetworkResource, contextual bool) *ObjectD diff.Fields = fieldDiffs(oldPrimitiveFlat, newPrimitiveFlat, contextual) // Port diffs - resPorts := portDiffs(r.ReservedPorts, other.ReservedPorts, false, contextual) - dynPorts := portDiffs(r.DynamicPorts, other.DynamicPorts, true, contextual) + resPorts := portDiffs(n.ReservedPorts, other.ReservedPorts, false, contextual) + dynPorts := portDiffs(n.DynamicPorts, other.DynamicPorts, true, contextual) if resPorts != nil { diff.Objects = append(diff.Objects, resPorts...) } @@ -1935,7 +1935,7 @@ func (r *NetworkResource) Diff(other *NetworkResource, contextual bool) *ObjectD diff.Objects = append(diff.Objects, dynPorts...) } - if dnsDiff := r.DNS.Diff(other.DNS, contextual); dnsDiff != nil { + if dnsDiff := n.DNS.Diff(other.DNS, contextual); dnsDiff != nil { diff.Objects = append(diff.Objects, dnsDiff) } @@ -1943,8 +1943,8 @@ func (r *NetworkResource) Diff(other *NetworkResource, contextual bool) *ObjectD } // Diff returns a diff of two DNSConfig structs -func (c *DNSConfig) Diff(other *DNSConfig, contextual bool) *ObjectDiff { - if reflect.DeepEqual(c, other) { +func (d *DNSConfig) Diff(other *DNSConfig, contextual bool) *ObjectDiff { + if reflect.DeepEqual(d, other) { return nil } @@ -1964,15 +1964,15 @@ func (c *DNSConfig) Diff(other *DNSConfig, contextual bool) *ObjectDiff { diff := &ObjectDiff{Type: DiffTypeNone, Name: "DNS"} var oldPrimitiveFlat, newPrimitiveFlat map[string]string - if c == nil { + if d == nil { diff.Type = DiffTypeAdded newPrimitiveFlat = flatten(other) } else if other == nil { diff.Type = DiffTypeDeleted - oldPrimitiveFlat = flatten(c) + oldPrimitiveFlat = flatten(d) } else { diff.Type = DiffTypeEdited - oldPrimitiveFlat = flatten(c) + oldPrimitiveFlat = flatten(d) newPrimitiveFlat = flatten(other) } diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 742fce06d..b856b9ddb 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2609,23 +2609,23 @@ type NetworkResource struct { DynamicPorts []Port // Host Dynamically assigned ports } -func (nr *NetworkResource) Hash() uint32 { +func (n *NetworkResource) Hash() uint32 { var data []byte - data = append(data, []byte(fmt.Sprintf("%s%s%s%s%s%d", nr.Mode, nr.Device, nr.CIDR, nr.IP, nr.Hostname, nr.MBits))...) + data = append(data, []byte(fmt.Sprintf("%s%s%s%s%s%d", n.Mode, n.Device, n.CIDR, n.IP, n.Hostname, n.MBits))...) - for i, port := range nr.ReservedPorts { + for i, port := range n.ReservedPorts { data = append(data, []byte(fmt.Sprintf("r%d%s%d%d", i, port.Label, port.Value, port.To))...) } - for i, port := range nr.DynamicPorts { + for i, port := range n.DynamicPorts { data = append(data, []byte(fmt.Sprintf("d%d%s%d%d", i, port.Label, port.Value, port.To))...) } return crc32.ChecksumIEEE(data) } -func (nr *NetworkResource) Equals(other *NetworkResource) bool { - return nr.Hash() == other.Hash() +func (n *NetworkResource) Equals(other *NetworkResource) bool { + return n.Hash() == other.Hash() } func (n *NetworkResource) Canonicalize() { @@ -3182,12 +3182,12 @@ type DeviceIdTuple struct { Name string } -func (d *DeviceIdTuple) String() string { - if d == nil { +func (id *DeviceIdTuple) String() string { + if id == nil { return "" } - return fmt.Sprintf("%s/%s/%s", d.Vendor, d.Type, d.Name) + return fmt.Sprintf("%s/%s/%s", id.Vendor, id.Type, id.Name) } // Matches returns if this Device ID is a superset of the passed ID. @@ -7852,98 +7852,98 @@ type TaskEvent struct { GenericSource string } -func (event *TaskEvent) PopulateEventDisplayMessage() { +func (e *TaskEvent) PopulateEventDisplayMessage() { // Build up the description based on the event type. - if event == nil { //TODO(preetha) needs investigation alloc_runner's Run method sends a nil event when sigterming nomad. Why? + if e == nil { //TODO(preetha) needs investigation alloc_runner's Run method sends a nil event when sigterming nomad. Why? return } - if event.DisplayMessage != "" { + if e.DisplayMessage != "" { return } var desc string - switch event.Type { + switch e.Type { case TaskSetup: - desc = event.Message + desc = e.Message case TaskStarted: desc = "Task started by client" case TaskReceived: desc = "Task received by client" case TaskFailedValidation: - if event.ValidationError != "" { - desc = event.ValidationError + if e.ValidationError != "" { + desc = e.ValidationError } else { desc = "Validation of task failed" } case TaskSetupFailure: - if event.SetupError != "" { - desc = event.SetupError + if e.SetupError != "" { + desc = e.SetupError } else { desc = "Task setup failed" } case TaskDriverFailure: - if event.DriverError != "" { - desc = event.DriverError + if e.DriverError != "" { + desc = e.DriverError } else { desc = "Failed to start task" } case TaskDownloadingArtifacts: desc = "Client is downloading artifacts" case TaskArtifactDownloadFailed: - if event.DownloadError != "" { - desc = event.DownloadError + if e.DownloadError != "" { + desc = e.DownloadError } else { desc = "Failed to download artifacts" } case TaskKilling: - if event.KillReason != "" { - desc = event.KillReason - } else if event.KillTimeout != 0 { - desc = fmt.Sprintf("Sent interrupt. Waiting %v before force killing", event.KillTimeout) + if e.KillReason != "" { + desc = e.KillReason + } else if e.KillTimeout != 0 { + desc = fmt.Sprintf("Sent interrupt. Waiting %v before force killing", e.KillTimeout) } else { desc = "Sent interrupt" } case TaskKilled: - if event.KillError != "" { - desc = event.KillError + if e.KillError != "" { + desc = e.KillError } else { desc = "Task successfully killed" } case TaskTerminated: var parts []string - parts = append(parts, fmt.Sprintf("Exit Code: %d", event.ExitCode)) + parts = append(parts, fmt.Sprintf("Exit Code: %d", e.ExitCode)) - if event.Signal != 0 { - parts = append(parts, fmt.Sprintf("Signal: %d", event.Signal)) + if e.Signal != 0 { + parts = append(parts, fmt.Sprintf("Signal: %d", e.Signal)) } - if event.Message != "" { - parts = append(parts, fmt.Sprintf("Exit Message: %q", event.Message)) + if e.Message != "" { + parts = append(parts, fmt.Sprintf("Exit Message: %q", e.Message)) } desc = strings.Join(parts, ", ") case TaskRestarting: - in := fmt.Sprintf("Task restarting in %v", time.Duration(event.StartDelay)) - if event.RestartReason != "" && event.RestartReason != ReasonWithinPolicy { - desc = fmt.Sprintf("%s - %s", event.RestartReason, in) + in := fmt.Sprintf("Task restarting in %v", time.Duration(e.StartDelay)) + if e.RestartReason != "" && e.RestartReason != ReasonWithinPolicy { + desc = fmt.Sprintf("%s - %s", e.RestartReason, in) } else { desc = in } case TaskNotRestarting: - if event.RestartReason != "" { - desc = event.RestartReason + if e.RestartReason != "" { + desc = e.RestartReason } else { desc = "Task exceeded restart policy" } case TaskSiblingFailed: - if event.FailedSibling != "" { - desc = fmt.Sprintf("Task's sibling %q failed", event.FailedSibling) + if e.FailedSibling != "" { + desc = fmt.Sprintf("Task's sibling %q failed", e.FailedSibling) } else { desc = "Task's sibling failed" } case TaskSignaling: - sig := event.TaskSignal - reason := event.TaskSignalReason + sig := e.TaskSignal + reason := e.TaskSignalReason if sig == "" && reason == "" { desc = "Task being sent a signal" @@ -7955,47 +7955,47 @@ func (event *TaskEvent) PopulateEventDisplayMessage() { desc = fmt.Sprintf("Task being sent signal %v: %v", sig, reason) } case TaskRestartSignal: - if event.RestartReason != "" { - desc = event.RestartReason + if e.RestartReason != "" { + desc = e.RestartReason } else { desc = "Task signaled to restart" } case TaskDriverMessage: - desc = event.DriverMessage + desc = e.DriverMessage case TaskLeaderDead: desc = "Leader Task in Group dead" case TaskMainDead: desc = "Main tasks in the group died" default: - desc = event.Message + desc = e.Message } - event.DisplayMessage = desc + e.DisplayMessage = desc } -func (te *TaskEvent) GoString() string { - return fmt.Sprintf("%v - %v", te.Time, te.Type) +func (e *TaskEvent) GoString() string { + return fmt.Sprintf("%v - %v", e.Time, e.Type) } // SetDisplayMessage sets the display message of TaskEvent -func (te *TaskEvent) SetDisplayMessage(msg string) *TaskEvent { - te.DisplayMessage = msg - return te +func (e *TaskEvent) SetDisplayMessage(msg string) *TaskEvent { + e.DisplayMessage = msg + return e } // SetMessage sets the message of TaskEvent -func (te *TaskEvent) SetMessage(msg string) *TaskEvent { - te.Message = msg - te.Details["message"] = msg - return te +func (e *TaskEvent) SetMessage(msg string) *TaskEvent { + e.Message = msg + e.Details["message"] = msg + return e } -func (te *TaskEvent) Copy() *TaskEvent { - if te == nil { +func (e *TaskEvent) Copy() *TaskEvent { + if e == nil { return nil } copy := new(TaskEvent) - *copy = *te + *copy = *e return copy } @@ -11095,7 +11095,7 @@ type ACLPolicy struct { } // SetHash is used to compute and set the hash of the ACL policy -func (c *ACLPolicy) SetHash() []byte { +func (a *ACLPolicy) SetHash() []byte { // Initialize a 256bit Blake2 hash (32 bytes) hash, err := blake2b.New256(nil) if err != nil { @@ -11103,15 +11103,15 @@ func (c *ACLPolicy) SetHash() []byte { } // Write all the user set fields - _, _ = hash.Write([]byte(c.Name)) - _, _ = hash.Write([]byte(c.Description)) - _, _ = hash.Write([]byte(c.Rules)) + _, _ = hash.Write([]byte(a.Name)) + _, _ = hash.Write([]byte(a.Description)) + _, _ = hash.Write([]byte(a.Rules)) // Finalize the hash hashVal := hash.Sum(nil) // Set and return the hash - c.Hash = hashVal + a.Hash = hashVal return hashVal } diff --git a/plugins/csi/testing/client.go b/plugins/csi/testing/client.go index 08168625b..dc180d058 100644 --- a/plugins/csi/testing/client.go +++ b/plugins/csi/testing/client.go @@ -63,18 +63,18 @@ func NewControllerClient() *ControllerClient { return &ControllerClient{} } -func (f *ControllerClient) Reset() { - f.NextErr = nil - f.NextCapabilitiesResponse = nil - f.NextPublishVolumeResponse = nil - f.NextUnpublishVolumeResponse = nil - f.NextValidateVolumeCapabilitiesResponse = nil - f.NextCreateVolumeResponse = nil - f.NextDeleteVolumeResponse = nil - f.NextListVolumesResponse = nil - f.NextCreateSnapshotResponse = nil - f.NextDeleteSnapshotResponse = nil - f.NextListSnapshotsResponse = nil +func (c *ControllerClient) Reset() { + c.NextErr = nil + c.NextCapabilitiesResponse = nil + c.NextPublishVolumeResponse = nil + c.NextUnpublishVolumeResponse = nil + c.NextValidateVolumeCapabilitiesResponse = nil + c.NextCreateVolumeResponse = nil + c.NextDeleteVolumeResponse = nil + c.NextListVolumesResponse = nil + c.NextCreateSnapshotResponse = nil + c.NextDeleteSnapshotResponse = nil + c.NextListSnapshotsResponse = nil } func (c *ControllerClient) ControllerGetCapabilities(ctx context.Context, in *csipbv1.ControllerGetCapabilitiesRequest, opts ...grpc.CallOption) (*csipbv1.ControllerGetCapabilitiesResponse, error) { @@ -144,14 +144,14 @@ func NewNodeClient() *NodeClient { return &NodeClient{} } -func (f *NodeClient) Reset() { - f.NextErr = nil - f.NextCapabilitiesResponse = nil - f.NextGetInfoResponse = nil - f.NextStageVolumeResponse = nil - f.NextUnstageVolumeResponse = nil - f.NextPublishVolumeResponse = nil - f.NextUnpublishVolumeResponse = nil +func (c *NodeClient) Reset() { + c.NextErr = nil + c.NextCapabilitiesResponse = nil + c.NextGetInfoResponse = nil + c.NextStageVolumeResponse = nil + c.NextUnstageVolumeResponse = nil + c.NextPublishVolumeResponse = nil + c.NextUnpublishVolumeResponse = nil } func (c *NodeClient) NodeGetCapabilities(ctx context.Context, in *csipbv1.NodeGetCapabilitiesRequest, opts ...grpc.CallOption) (*csipbv1.NodeGetCapabilitiesResponse, error) { diff --git a/plugins/drivers/testutils/testing.go b/plugins/drivers/testutils/testing.go index 32cc24477..d8fd2f75d 100644 --- a/plugins/drivers/testutils/testing.go +++ b/plugins/drivers/testutils/testing.go @@ -36,8 +36,8 @@ type DriverHarness struct { impl drivers.DriverPlugin } -func (d *DriverHarness) Impl() drivers.DriverPlugin { - return d.impl +func (h *DriverHarness) Impl() drivers.DriverPlugin { + return h.impl } func NewDriverHarness(t testing.T, d drivers.DriverPlugin) *DriverHarness { logger := testlog.HCLogger(t).Named("driver_harness") diff --git a/scheduler/reconcile_util.go b/scheduler/reconcile_util.go index 8ee080a0c..40ced8a86 100644 --- a/scheduler/reconcile_util.go +++ b/scheduler/reconcile_util.go @@ -394,9 +394,9 @@ func (a allocSet) filterByDeployment(id string) (match, nonmatch allocSet) { // delayByStopAfterClientDisconnect returns a delay for any lost allocation that's got a // stop_after_client_disconnect configured -func (as allocSet) delayByStopAfterClientDisconnect() (later []*delayedRescheduleInfo) { +func (a allocSet) delayByStopAfterClientDisconnect() (later []*delayedRescheduleInfo) { now := time.Now().UTC() - for _, a := range as { + for _, a := range a { if !a.ShouldClientStop() { continue }