Skip to content

Commit

Permalink
build: run gofmt on all go source files
Browse files Browse the repository at this point in the history
Go 1.19 will forecefully format all your doc strings. To get this
out of the way, here is one big commit with all the changes gofmt
wants to make.
  • Loading branch information
shoenig committed Aug 16, 2022
1 parent aebd61f commit 12659f8
Show file tree
Hide file tree
Showing 62 changed files with 242 additions and 234 deletions.
5 changes: 3 additions & 2 deletions client/allocdir/alloc_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ func TestAllocDir_BuildAlloc(t *testing.T) {
}

// HACK: This function is copy/pasted from client.testutil to prevent a test
// import cycle, due to testutil transitively importing allocdir. This
// should be fixed after DriverManager is implemented.
//
// import cycle, due to testutil transitively importing allocdir. This
// should be fixed after DriverManager is implemented.
func MountCompatible(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Windows does not support mount")
Expand Down
5 changes: 3 additions & 2 deletions client/allochealth/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,9 @@ func (t *Tracker) setTaskHealth(healthy, terminal bool) {
// returns true if health is propagated and no more health monitoring is needed
//
// todo: this is currently being shared by watchConsulEvents and watchNomadEvents,
// and must be split up if/when we support registering services (and thus checks)
// of different providers.
//
// and must be split up if/when we support registering services (and thus checks)
// of different providers.
func (t *Tracker) setCheckHealth(healthy bool) bool {
t.lock.Lock()
defer t.lock.Unlock()
Expand Down
4 changes: 2 additions & 2 deletions client/allocrunner/taskrunner/envoy_bootstrap_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func newEnvoyBootstrapHook(c *envoyBootstrapHookConfig) *envoyBootstrapHook {
}

// getConsulNamespace will resolve the Consul namespace, choosing between
// - agent config (low precedence)
// - task group config (high precedence)
// - agent config (low precedence)
// - task group config (high precedence)
func (h *envoyBootstrapHook) getConsulNamespace() string {
var namespace string
if h.consulConfig.Namespace != "" {
Expand Down
6 changes: 3 additions & 3 deletions client/allocrunner/taskrunner/envoy_version_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ func (h *envoyVersionHook) tweakImage(configured string, supported map[string][]
// semver sanitizes the envoy version string coming from Consul into the format
// used by the Envoy project when publishing images (i.e. proper semver). This
// resulting string value does NOT contain the 'v' prefix for 2 reasons:
// 1) the version library does not include the 'v'
// 2) its plausible unofficial images use the 3 numbers without the prefix for
// tagging their own images
// 1. the version library does not include the 'v'
// 2. its plausible unofficial images use the 3 numbers without the prefix for
// tagging their own images
func semver(chosen string) (string, error) {
v, err := version.NewVersion(chosen)
if err != nil {
Expand Down
24 changes: 12 additions & 12 deletions client/allocrunner/taskrunner/plugin_supervisor_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
// to their requisite plugin manager.
//
// It provides a few things to a plugin task running inside Nomad. These are:
// * A mount to the `csi_plugin.mount_dir` where the plugin will create its csi.sock
// * A mount to `local/csi` that node plugins will use to stage volume mounts.
// * When the task has started, it starts a loop of attempting to connect to the
// plugin, to perform initial fingerprinting of the plugins capabilities before
// notifying the plugin manager of the plugin.
// - A mount to the `csi_plugin.mount_dir` where the plugin will create its csi.sock
// - A mount to `local/csi` that node plugins will use to stage volume mounts.
// - When the task has started, it starts a loop of attempting to connect to the
// plugin, to perform initial fingerprinting of the plugins capabilities before
// notifying the plugin manager of the plugin.
type csiPluginSupervisorHook struct {
logger hclog.Logger
alloc *structs.Allocation
Expand Down Expand Up @@ -247,13 +247,13 @@ func (h *csiPluginSupervisorHook) Poststart(_ context.Context, _ *interfaces.Tas
// the passed in context is terminated.
//
// The supervisor works by:
// - Initially waiting for the plugin to become available. This loop is expensive
// and may do things like create new gRPC Clients on every iteration.
// - After receiving an initial healthy status, it will inform the plugin catalog
// of the plugin, registering it with the plugins fingerprinted capabilities.
// - We then perform a more lightweight check, simply probing the plugin on a less
// frequent interval to ensure it is still alive, emitting task events when this
// status changes.
// - Initially waiting for the plugin to become available. This loop is expensive
// and may do things like create new gRPC Clients on every iteration.
// - After receiving an initial healthy status, it will inform the plugin catalog
// of the plugin, registering it with the plugins fingerprinted capabilities.
// - We then perform a more lightweight check, simply probing the plugin on a less
// frequent interval to ensure it is still alive, emitting task events when this
// status changes.
//
// Deeper fingerprinting of the plugin is implemented by the csimanager.
func (h *csiPluginSupervisorHook) ensureSupervisorLoop(ctx context.Context) {
Expand Down
8 changes: 4 additions & 4 deletions client/allocrunner/taskrunner/remotetask_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func (h *remoteTaskHook) Name() string {
}

// Prestart performs 2 remote task driver related tasks:
// 1. If there is no local handle, see if there is a handle propagated from a
// previous alloc to be restored.
// 2. If the alloc is lost make sure the task signal is set to detach instead
// of kill.
// 1. If there is no local handle, see if there is a handle propagated from a
// previous alloc to be restored.
// 2. If the alloc is lost make sure the task signal is set to detach instead
// of kill.
func (h *remoteTaskHook) Prestart(ctx context.Context, req *interfaces.TaskPrestartRequest, resp *interfaces.TaskPrestartResponse) error {
if h.tr.getDriverHandle() != nil {
// Driver handle already exists so don't try to load remote
Expand Down
10 changes: 5 additions & 5 deletions client/allocrunner/taskrunner/restarts/restarts.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ func (r *RestartTracker) GetCount() int {

// GetState returns the tasks next state given the set exit code and start
// error. One of the following states are returned:
// * TaskRestarting - Task should be restarted
// * TaskNotRestarting - Task should not be restarted and has exceeded its
// restart policy.
// * TaskTerminated - Task has terminated successfully and does not need a
// restart.
// - TaskRestarting - Task should be restarted
// - TaskNotRestarting - Task should not be restarted and has exceeded its
// restart policy.
// - TaskTerminated - Task has terminated successfully and does not need a
// restart.
//
// If TaskRestarting is returned, the duration is how long to wait until
// starting the task again.
Expand Down
4 changes: 2 additions & 2 deletions client/allocrunner/taskrunner/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ func (tr *TaskRunner) UpdateStats(ru *cstructs.TaskResourceUsage) {
}
}

//TODO Remove Backwardscompat or use tr.Alloc()?
// TODO Remove Backwardscompat or use tr.Alloc()?
func (tr *TaskRunner) setGaugeForMemory(ru *cstructs.TaskResourceUsage) {
alloc := tr.Alloc()
var allocatedMem float32
Expand Down Expand Up @@ -1445,7 +1445,7 @@ func (tr *TaskRunner) setGaugeForMemory(ru *cstructs.TaskResourceUsage) {
}
}

//TODO Remove Backwardscompat or use tr.Alloc()?
// TODO Remove Backwardscompat or use tr.Alloc()?
func (tr *TaskRunner) setGaugeForCPU(ru *cstructs.TaskResourceUsage) {
alloc := tr.Alloc()
var allocatedCPU float32
Expand Down
6 changes: 3 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ type ClientStatsReporter interface {
}

// AllocRunner is the interface implemented by the core alloc runner.
//TODO Create via factory to allow testing Client with mock AllocRunners.
// TODO Create via factory to allow testing Client with mock AllocRunners.
type AllocRunner interface {
Alloc() *structs.Allocation
AllocState() *arstate.State
Expand Down Expand Up @@ -1252,8 +1252,8 @@ func (c *Client) restoreState() error {
// wait until it gets allocs from server to launch them.
//
// See:
// * https://github.com/hashicorp/nomad/pull/6207
// * https://github.com/hashicorp/nomad/issues/5984
// - https://github.com/hashicorp/nomad/pull/6207
// - https://github.com/hashicorp/nomad/issues/5984
//
// COMPAT(0.12): remove once upgrading from 0.9.5 is no longer supported
func (c *Client) hasLocalState(alloc *structs.Allocation) bool {
Expand Down
3 changes: 2 additions & 1 deletion client/dynamicplugins/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ type PluginInfo struct {

// PluginConnectionInfo is the data required to connect to the plugin.
// note: We currently only support Unix Domain Sockets, but this may be expanded
// to support other connection modes in the future.
//
// to support other connection modes in the future.
type PluginConnectionInfo struct {
// SocketPath is the path to the plugins api socket.
SocketPath string
Expand Down
19 changes: 10 additions & 9 deletions client/pluginmanager/csimanager/doc.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/**
/*
*
csimanager manages locally running CSI Plugins on a Nomad host, and provides a
few different interfaces.
It provides:
- a pluginmanager.PluginManager implementation that is used to fingerprint and
heartbeat local node plugins
- (TODO) a csimanager.AttachmentWaiter implementation that can be used to wait for an
external CSIVolume to be attached to the node before returning
- (TODO) a csimanager.NodeController implementation that is used to manage the node-local
portions of the CSI specification, and encompassess volume staging/publishing
- (TODO) a csimanager.VolumeChecker implementation that can be used by hooks to ensure
their volumes are healthy(ish)
- a pluginmanager.PluginManager implementation that is used to fingerprint and
heartbeat local node plugins
- (TODO) a csimanager.AttachmentWaiter implementation that can be used to wait for an
external CSIVolume to be attached to the node before returning
- (TODO) a csimanager.NodeController implementation that is used to manage the node-local
portions of the CSI specification, and encompassess volume staging/publishing
- (TODO) a csimanager.VolumeChecker implementation that can be used by hooks to ensure
their volumes are healthy(ish)
*/
package csimanager
1 change: 0 additions & 1 deletion client/state/08types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
// changed over the life-cycle of the alloc_runner in Nomad 0.8.
//
// https://github.com/hashicorp/nomad/blob/v0.8.6/client/alloc_runner.go#L146-L153
//
type allocRunnerMutableState08 struct {
// AllocClientStatus does not need to be upgraded as it is computed
// from task states.
Expand Down
17 changes: 8 additions & 9 deletions client/state/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,14 @@ func backupDB(bdb *bbolt.DB, dst string) error {

// UpgradeAllocs upgrades the boltdb schema. Example 0.8 schema:
//
// * allocations
// * 15d83e8a-74a2-b4da-3f17-ed5c12895ea8
// * echo
// - simple-all (342 bytes)
// - alloc (2827 bytes)
// - alloc-dir (166 bytes)
// - immutable (15 bytes)
// - mutable (1294 bytes)
//
// - allocations
// - 15d83e8a-74a2-b4da-3f17-ed5c12895ea8
// - echo
// - simple-all (342 bytes)
// - alloc (2827 bytes)
// - alloc-dir (166 bytes)
// - immutable (15 bytes)
// - mutable (1294 bytes)
func UpgradeAllocs(logger hclog.Logger, tx *boltdd.Tx) error {
btx := tx.BoltTx()
allocationsBucket := btx.Bucket(allocationsBucketName)
Expand Down
1 change: 0 additions & 1 deletion client/taskenv/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,6 @@ func (b *Builder) SetDriverNetwork(n *drivers.DriverNetwork) *Builder {
// Handled by setAlloc -> otherPorts:
//
// Task: NOMAD_TASK_{IP,PORT,ADDR}_<task>_<label> # Always host values
//
func buildNetworkEnv(envMap map[string]string, nets structs.Networks, driverNet *drivers.DriverNetwork) {
for _, n := range nets {
for _, p := range n.ReservedPorts {
Expand Down
6 changes: 3 additions & 3 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
// Config is the configuration for the Nomad agent.
//
// time.Duration values have two parts:
// - a string field tagged with an hcl:"foo" and json:"-"
// - a time.Duration field in the same struct and a call to duration
// in config_parse.go ParseConfigFile
// - a string field tagged with an hcl:"foo" and json:"-"
// - a time.Duration field in the same struct and a call to duration
// in config_parse.go ParseConfigFile
//
// All config structs should have an ExtraKeysHCL field to check for
// unexpected keys
Expand Down
2 changes: 1 addition & 1 deletion command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ func TestConfig_templateNetworkInterface(t *testing.T) {
{
name: "insignificant whitespace",
clientConfig: &ClientConfig{
Enabled: true,
Enabled: true,
NetworkInterface: ` {{GetAllInterfaces | attr "name" }}`,
},
expectedInterface: iface.Name,
Expand Down
2 changes: 1 addition & 1 deletion command/agent/consul/check_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newFakeCheckRestarter(w *checkWatcher, allocID, taskName, checkName string,
// watching and is normally fulfilled by a TaskRunner.
//
// Restarts are recorded in the []restarts field and re-Watch the check.
//func (c *fakeCheckRestarter) Restart(source, reason string, failure bool) {
// func (c *fakeCheckRestarter) Restart(source, reason string, failure bool) {
func (c *fakeCheckRestarter) Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error {
c.mu.Lock()
defer c.mu.Unlock()
Expand Down
3 changes: 2 additions & 1 deletion command/agent/consul/namespaces_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func (ns *NamespacesClient) allowable(now time.Time) bool {
// List returns a list of Consul Namespaces.
//
// TODO(shoenig): return empty string instead of "default" when namespaces are not
// enabled. (Coming in followup PR).
//
// enabled. (Coming in followup PR).
func (ns *NamespacesClient) List() ([]string, error) {
if !ns.allowable(time.Now()) {
// TODO(shoenig): lets return the empty string instead, that way we do not
Expand Down
7 changes: 4 additions & 3 deletions command/agent/consul/self.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ func Namespaces(info Self) bool {
// feature returns whether the indicated feature is enabled by Consul and the
// associated License.
// possible values as of v1.9.5+ent:
// Automated Backups, Automated Upgrades, Enhanced Read Scalability,
// Network Segments, Redundancy Zone, Advanced Network Federation,
// Namespaces, SSO, Audit Logging
//
// Automated Backups, Automated Upgrades, Enhanced Read Scalability,
// Network Segments, Redundancy Zone, Advanced Network Federation,
// Namespaces, SSO, Audit Logging
func feature(name string, info Self) bool {
lic, licOK := info["Stats"]["license"].(map[string]interface{})
if !licOK {
Expand Down
24 changes: 10 additions & 14 deletions command/agent/consul/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ type ACLsAPI interface {
// of a service definition are different from the existing service definition as
// known by Consul.
//
// reason - The syncReason that triggered this synchronization with the consul
// agent API.
// wanted - Nomad's view of what the service definition is intended to be.
// Not nil.
// existing - Consul's view (agent, not catalog) of the actual service definition.
// Not nil.
// sidecar - Consul's view (agent, not catalog) of the service definition of the sidecar
// associated with existing that may or may not exist.
// May be nil.
// reason - The syncReason that triggered this synchronization with the consul
// agent API.
// wanted - Nomad's view of what the service definition is intended to be.
// Not nil.
// existing - Consul's view (agent, not catalog) of the actual service definition.
// Not nil.
// sidecar - Consul's view (agent, not catalog) of the service definition of the sidecar
// associated with existing that may or may not exist.
// May be nil.
func agentServiceUpdateRequired(reason syncReason, wanted *api.AgentServiceRegistration, existing *api.AgentService, sidecar *api.AgentService) bool {
switch reason {
case syncPeriodic:
Expand Down Expand Up @@ -1499,14 +1499,13 @@ func (c *ServiceClient) removeRegistration(allocID, taskName string) {
// {nomadServicePrefix}-{ROLE}-b32(sha1({Service.Name}-{Service.Tags...})
// Example Server ID: _nomad-server-fbbk265qn4tmt25nd4ep42tjvmyj3hr4
// Example Client ID: _nomad-client-ggnjpgl7yn7rgmvxzilmpvrzzvrszc7l
//
func makeAgentServiceID(role string, service *structs.Service) string {
return fmt.Sprintf("%s-%s-%s", nomadServicePrefix, role, service.Hash(role, "", false))
}

// MakeCheckID creates a unique ID for a check.
//
// Example Check ID: _nomad-check-434ae42f9a57c5705344974ac38de2aee0ee089d
// Example Check ID: _nomad-check-434ae42f9a57c5705344974ac38de2aee0ee089d
func MakeCheckID(serviceID string, check *structs.ServiceCheck) string {
return fmt.Sprintf("%s%s", nomadCheckPrefix, check.Hash(serviceID))
}
Expand Down Expand Up @@ -1597,7 +1596,6 @@ func isNomadService(id string) bool {
//
// {nomadServicePrefix}-executor-{ALLOC_ID}-{Service.Name}-{Service.Tags...}
// Example Service ID: _nomad-executor-1234-echo-http-tag1-tag2-tag3
//
func isOldNomadService(id string) bool {
const prefix = nomadServicePrefix + "-executor"
return strings.HasPrefix(id, prefix)
Expand All @@ -1615,15 +1613,13 @@ const (
// It is important not to reference the parent service, which may or may not still
// be tracked by Nomad internally.
//
//
// For example if you have a Connect enabled service with the ID:
//
// _nomad-task-5229c7f8-376b-3ccc-edd9-981e238f7033-cache-redis-cache-db
//
// Consul will create a service for the sidecar proxy with the ID:
//
// _nomad-task-5229c7f8-376b-3ccc-edd9-981e238f7033-cache-redis-cache-db-sidecar-proxy
//
func maybeConnectSidecar(id string) bool {
return strings.HasSuffix(id, sidecarSuffix)
}
Expand Down
22 changes: 11 additions & 11 deletions command/agent/fs_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ func (s *HTTPServer) FileCatRequest(resp http.ResponseWriter, req *http.Request)

// Stream streams the content of a file blocking on EOF.
// The parameters are:
// * path: path to file to stream.
// * follow: A boolean of whether to follow the file, defaults to true.
// * offset: The offset to start streaming data at, defaults to zero.
// * origin: Either "start" or "end" and defines from where the offset is
// applied. Defaults to "start".
// - path: path to file to stream.
// - follow: A boolean of whether to follow the file, defaults to true.
// - offset: The offset to start streaming data at, defaults to zero.
// - origin: Either "start" or "end" and defines from where the offset is
// applied. Defaults to "start".
func (s *HTTPServer) Stream(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
var allocID, path string
var err error
Expand Down Expand Up @@ -255,12 +255,12 @@ func (s *HTTPServer) Stream(resp http.ResponseWriter, req *http.Request) (interf
}

// Logs streams the content of a log blocking on EOF. The parameters are:
// * task: task name to stream logs for.
// * type: stdout/stderr to stream.
// * follow: A boolean of whether to follow the logs.
// * offset: The offset to start streaming data at, defaults to zero.
// * origin: Either "start" or "end" and defines from where the offset is
// applied. Defaults to "start".
// - task: task name to stream logs for.
// - type: stdout/stderr to stream.
// - follow: A boolean of whether to follow the logs.
// - offset: The offset to start streaming data at, defaults to zero.
// - origin: Either "start" or "end" and defines from where the offset is
// applied. Defaults to "start".
func (s *HTTPServer) Logs(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
var allocID, task, logType string
var plain, follow bool
Expand Down
1 change: 1 addition & 0 deletions command/agent/job_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3486,6 +3486,7 @@ func TestJobs_ApiJobToStructsJobUpdate(t *testing.T) {
}

// TestJobs_Matching_Resources asserts:
//
// api.{Default,Min}Resources == structs.{Default,Min}Resources
//
// While this is an odd place to test that, this is where both are imported,
Expand Down
Loading

0 comments on commit 12659f8

Please sign in to comment.