client

package
v1.4.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2022 License: MPL-2.0 Imports: 80 Imported by: 126

Documentation

Index

Constants

View Source
const (

	// OriginStart and OriginEnd are the available parameters for the origin
	// argument when streaming a file. They respectively offset from the start
	// and end of a file.
	OriginStart = "start"
	OriginEnd   = "end"
)
View Source
const (
	// CSIPluginRequestTimeout is the timeout that should be used when making reqs
	// against CSI Plugins. It is copied from Kubernetes as an initial seed value.
	// https://github.com/kubernetes/kubernetes/blob/e680ad7156f263a6d8129cc0117fda58602e50ad/pkg/volume/csi/csi_plugin.go#L52
	CSIPluginRequestTimeout = 2 * time.Minute
)
View Source
const (
	// MB is a constant which converts values in bytes to MB
	MB = 1024 * 1024
)

Variables

View Source
var (
	ErrPluginTypeError = errors.New("CSI Plugin loaded incorrectly")
)

Functions

This section is empty.

Types

type Agent added in v0.10.2

type Agent struct {
	// contains filtered or unexported fields
}

func NewAgentEndpoint added in v0.10.2

func NewAgentEndpoint(c *Client) *Agent

func (*Agent) Host added in v0.12.0

func (a *Agent) Host(args *structs.HostDataRequest, reply *structs.HostDataResponse) error

Host collects data about the host evironment running the agent

func (*Agent) Profile added in v0.10.4

func (a *Agent) Profile(args *structs.AgentPprofRequest, reply *structs.AgentPprofResponse) error

type AllocCounter added in v0.6.0

type AllocCounter interface {
	NumAllocs() int
}

AllocCounter is used by AllocGarbageCollector to discover how many un-GC'd allocations a client has and is generally fulfilled by the Client.

type AllocGarbageCollector added in v0.5.2

type AllocGarbageCollector struct {
	// contains filtered or unexported fields
}

AllocGarbageCollector garbage collects terminated allocations on a node

func NewAllocGarbageCollector added in v0.5.2

func NewAllocGarbageCollector(logger hclog.Logger, statsCollector stats.NodeStatsCollector, ac AllocCounter, config *GCConfig) *AllocGarbageCollector

NewAllocGarbageCollector returns a garbage collector for terminated allocations on a node. Must call Run() in a goroutine enable periodic garbage collection.

func (*AllocGarbageCollector) Collect added in v0.5.2

func (a *AllocGarbageCollector) Collect(allocID string) bool

Collect garbage collects a single allocation on a node. Returns true if alloc was found and garbage collected; otherwise false.

func (*AllocGarbageCollector) CollectAll added in v0.5.2

func (a *AllocGarbageCollector) CollectAll()

CollectAll garbage collects all terminated allocations on a node

func (*AllocGarbageCollector) MakeRoomFor added in v0.5.2

func (a *AllocGarbageCollector) MakeRoomFor(allocations []*structs.Allocation) error

MakeRoomFor garbage collects enough number of allocations in the terminal state to make room for new allocations

func (*AllocGarbageCollector) MarkForCollection added in v0.5.2

func (a *AllocGarbageCollector) MarkForCollection(allocID string, ar AllocRunner)

MarkForCollection starts tracking an allocation for Garbage Collection

func (*AllocGarbageCollector) Run added in v0.6.0

func (a *AllocGarbageCollector) Run()

Run the periodic garbage collector.

func (*AllocGarbageCollector) Stop added in v0.5.2

func (a *AllocGarbageCollector) Stop()

func (*AllocGarbageCollector) Trigger added in v0.7.1

func (a *AllocGarbageCollector) Trigger()

Trigger forces the garbage collector to run.

type AllocRunner

type AllocRunner interface {
	Alloc() *structs.Allocation
	AllocState() *arstate.State
	Destroy()
	Shutdown()
	GetAllocDir() *allocdir.AllocDir
	IsDestroyed() bool
	IsMigrating() bool
	IsWaiting() bool
	Listener() *cstructs.AllocListener
	Restore() error
	Run()
	StatsReporter() interfaces.AllocStatsReporter
	Update(*structs.Allocation)
	WaitCh() <-chan struct{}
	DestroyCh() <-chan struct{}
	ShutdownCh() <-chan struct{}
	Signal(taskName, signal string) error
	GetTaskEventHandler(taskName string) drivermanager.EventHandler
	PersistState() error

	RestartTask(taskName string, taskEvent *structs.TaskEvent) error
	RestartRunning(taskEvent *structs.TaskEvent) error
	RestartAll(taskEvent *structs.TaskEvent) error
	Reconnect(update *structs.Allocation) error

	GetTaskExecHandler(taskName string) drivermanager.TaskExecHandler
	GetTaskDriverCapabilities(taskName string) (*drivers.Capabilities, error)
}

AllocRunner is the interface implemented by the core alloc runner. TODO Create via factory to allow testing Client with mock AllocRunners.

type Allocations added in v0.8.0

type Allocations struct {
	// contains filtered or unexported fields
}

Allocations endpoint is used for interacting with client allocations

func NewAllocationsEndpoint added in v0.9.2

func NewAllocationsEndpoint(c *Client) *Allocations

func (*Allocations) Checks added in v1.4.0

Checks is used to retrieve nomad service discovery check status information.

func (*Allocations) GarbageCollect added in v0.8.0

func (a *Allocations) GarbageCollect(args *nstructs.AllocSpecificRequest, reply *nstructs.GenericResponse) error

GarbageCollect is used to garbage collect an allocation on a client.

func (*Allocations) GarbageCollectAll added in v0.8.0

func (a *Allocations) GarbageCollectAll(args *nstructs.NodeSpecificRequest, reply *nstructs.GenericResponse) error

GarbageCollectAll is used to garbage collect all allocations on a client.

func (*Allocations) Restart added in v0.9.2

Restart is used to trigger a restart of an allocation or a subtask on a client.

func (*Allocations) Signal added in v0.9.2

Signal is used to send a signal to an allocation's tasks on a client.

func (*Allocations) Stats added in v0.8.0

Stats is used to collect allocation statistics

type CSI added in v0.11.0

type CSI struct {
	// contains filtered or unexported fields
}

CSI endpoint is used for interacting with CSI plugins on a client. TODO: Submit metrics with labels to allow debugging per plugin perf problems.

func (*CSI) ControllerAttachVolume added in v0.11.0

ControllerAttachVolume is used to attach a volume from a CSI Cluster to the storage node provided in the request.

The controller attachment flow currently works as follows: 1. Validate the volume request 2. Call ControllerPublishVolume on the CSI Plugin to trigger a remote attachment

In the future this may be expanded to request dynamic secrets for attachment.

func (*CSI) ControllerCreateVolume added in v1.1.0

func (*CSI) ControllerDeleteVolume added in v1.1.0

func (*CSI) ControllerDetachVolume added in v0.11.0

ControllerDetachVolume is used to detach a volume from a CSI Cluster from the storage node provided in the request.

func (*CSI) ControllerListSnapshots added in v1.1.0

func (*CSI) ControllerListVolumes added in v1.1.0

func (*CSI) ControllerValidateVolume added in v0.11.0

ControllerValidateVolume is used during volume registration to validate that a volume exists and that the capabilities it was registered with are supported by the CSI Plugin and external volume configuration.

func (*CSI) NodeDetachVolume added in v0.11.0

NodeDetachVolume is used to detach a volume from a CSI Cluster from the storage node provided in the request.

type Client

type Client struct {

	// EnterpriseClient is used to set and check enterprise features for clients
	EnterpriseClient *EnterpriseClient
	// contains filtered or unexported fields
}

Client is used to implement the client interaction with Nomad. Clients are expected to register as a schedule-able node to the servers, and to run allocations as determined by the servers.

func NewClient

func NewClient(cfg *config.Config, consulCatalog consul.CatalogAPI, consulProxies consulApi.SupportedProxiesAPI, consulService serviceregistration.Handler, rpcs map[string]interface{}) (*Client, error)

NewClient is used to create a new client from the given configuration. `rpcs` is a map of RPC names to RPC structs that, if non-nil, will be registered via https://golang.org/pkg/net/rpc/#Server.RegisterName in place of the client's normal RPC handlers. This allows server tests to override the behavior of the client.

func TestClient added in v0.8.0

func TestClient(t testing.T, cb func(c *config.Config)) (*Client, func() error)

TestClient creates an in-memory client for testing purposes and returns a cleanup func to shutdown the client and remove the alloc and state dirs.

There is no need to override the AllocDir or StateDir as they are randomized and removed in the returned cleanup function. If they are overridden in the callback then the caller still must run the returned cleanup func.

func TestClientWithRPCs added in v1.1.0

func TestClientWithRPCs(t testing.T, cb func(c *config.Config), rpcs map[string]interface{}) (*Client, func() error)

func TestRPCOnlyClient added in v1.1.0

func TestRPCOnlyClient(t testing.T, srvAddr net.Addr, rpcs map[string]interface{}) (*Client, func() error, error)

TestRPCOnlyClient is a client that only pings to establish a connection with the server and then returns mock RPC responses for those interfaces passed in the `rpcs` parameter. Useful for testing client RPCs from the server. Returns the Client, a shutdown function, and any error.

func (*Client) AllocStateUpdated added in v0.9.0

func (c *Client) AllocStateUpdated(alloc *structs.Allocation)

AllocStateUpdated asynchronously updates the server with the current state of an allocations and its tasks.

func (*Client) ClientRPC added in v0.8.0

func (c *Client) ClientRPC(method string, args interface{}, reply interface{}) error

ClientRPC is used to make a local, client only RPC call

func (*Client) CollectAllAllocs added in v0.5.2

func (c *Client) CollectAllAllocs()

CollectAllAllocs garbage collects all allocations on a node in the terminal state

func (*Client) CollectAllocation added in v0.5.2

func (c *Client) CollectAllocation(allocID string) bool

CollectAllocation garbage collects a single allocation on a node. Returns true if alloc was found and garbage collected; otherwise false.

func (*Client) Datacenter added in v0.4.0

func (c *Client) Datacenter() string

Datacenter returns the datacenter for the given client

func (*Client) GetAlloc added in v0.9.6

func (c *Client) GetAlloc(allocID string) (*structs.Allocation, error)

GetAlloc returns an allocation or an error.

func (*Client) GetAllocFS added in v0.3.0

func (c *Client) GetAllocFS(allocID string) (allocdir.AllocDirFS, error)

GetAllocFS returns the AllocFS interface for the alloc dir of an allocation

func (*Client) GetAllocState added in v0.9.0

func (c *Client) GetAllocState(allocID string) (*arstate.State, error)

GetAllocState returns a copy of an allocation's state on this client. It returns either an AllocState or an unknown allocation error.

func (*Client) GetAllocStats added in v0.4.0

func (c *Client) GetAllocStats(allocID string) (interfaces.AllocStatsReporter, error)

func (*Client) GetConfig added in v0.7.1

func (c *Client) GetConfig() *config.Config

GetConfig returns the config of the client. Do *not* mutate without first calling Copy().

func (*Client) GetServers added in v0.5.0

func (c *Client) GetServers() []string

GetServers returns the list of nomad servers this client is aware of.

func (*Client) GetTaskEventHandler added in v0.9.0

func (c *Client) GetTaskEventHandler(allocID, taskName string) drivermanager.EventHandler

GetTaskEventHandler returns an event handler for the given allocID and task name

func (*Client) LatestDeviceResourceStats added in v0.9.0

func (c *Client) LatestDeviceResourceStats(devices []*structs.AllocatedDeviceResource) []*device.DeviceGroupStats

func (*Client) LatestHostStats added in v0.4.0

func (c *Client) LatestHostStats() *stats.HostStats

LatestHostStats returns all the stats related to a Nomad client.

func (*Client) Leave

func (c *Client) Leave() error

Leave is used to prepare the client to leave the cluster

func (*Client) Node

func (c *Client) Node() *structs.Node

Node returns the locally registered node

func (*Client) NodeID added in v0.7.0

func (c *Client) NodeID() string

NodeID returns the node ID for the given client

func (*Client) NumAllocs added in v0.6.0

func (c *Client) NumAllocs() int

NumAllocs returns the number of un-GC'd allocs this client has. Used to fulfill the AllocCounter interface for the GC.

func (*Client) Ping added in v0.8.0

func (c *Client) Ping(srv net.Addr) error

Ping is used to ping a particular server and returns whether it is healthy or a potential error.

func (*Client) PutAllocation added in v1.3.0

func (c *Client) PutAllocation(alloc *structs.Allocation) error

PutAllocation stores an allocation or returns an error if it could not be stored.

func (*Client) RPC

func (c *Client) RPC(method string, args interface{}, reply interface{}) error

RPC is used to forward an RPC call to a nomad server, or fail if no servers.

func (*Client) Ready added in v0.9.0

func (c *Client) Ready() <-chan struct{}

Ready returns a chan that is closed when the client is fully initialized

func (*Client) Region added in v0.4.0

func (c *Client) Region() string

Region returns the region for the given client

func (*Client) Reload added in v0.8.0

func (c *Client) Reload(newConfig *config.Config) error

Reload allows a client to reload its configuration on the fly

func (*Client) RemoteStreamingRpcHandler added in v0.8.0

func (c *Client) RemoteStreamingRpcHandler(method string) (structs.StreamingRpcHandler, error)

RemoteStreamingRpcHandler is used to make a streaming RPC call to a remote server.

func (*Client) ResolveSecretToken added in v0.11.0

func (c *Client) ResolveSecretToken(secretID string) (*structs.ACLToken, error)

func (*Client) ResolveToken added in v0.7.0

func (c *Client) ResolveToken(secretID string) (*acl.ACL, error)

ResolveToken is used to translate an ACL Token Secret ID into an ACL object, nil if ACLs are disabled, or an error.

func (*Client) RestartAllocation added in v0.9.2

func (c *Client) RestartAllocation(allocID, taskName string, allTasks bool) error

func (*Client) SetServers

func (c *Client) SetServers(in []string) (int, error)

SetServers sets a new list of nomad servers to connect to. As long as one server is resolvable no error is returned.

func (*Client) Shutdown

func (c *Client) Shutdown() error

Shutdown is used to tear down the client

func (*Client) SignalAllocation added in v0.9.2

func (c *Client) SignalAllocation(allocID, task, signal string) error

SignalAllocation sends a signal to the tasks within an allocation. If the provided task is empty, then every allocation will be signalled. If a task is provided, then only an exactly matching task will be signalled.

func (*Client) Stats

func (c *Client) Stats() map[string]map[string]string

Stats is used to return statistics for debugging and insight for various sub-systems

func (*Client) StatsReporter added in v0.4.0

func (c *Client) StatsReporter() ClientStatsReporter

StatsReporter exposes the various APIs related resource usage of a Nomad client

func (*Client) StreamingRpcHandler added in v0.8.0

func (c *Client) StreamingRpcHandler(method string) (structs.StreamingRpcHandler, error)

StreamingRpcHandler is used to make a local, client only streaming RPC call.

func (*Client) UpdateConfig added in v1.2.13

func (c *Client) UpdateConfig(cb func(*config.Config)) *config.Config

UpdateConfig allows mutating the configuration. The updated configuration is returned.

func (*Client) ValidateMigrateToken added in v0.7.0

func (c *Client) ValidateMigrateToken(allocID, migrateToken string) bool

ValidateMigrateToken verifies that a token is for a specific client and allocation, and has been created by a trusted party that has privileged knowledge of the client's secret identifier

type ClientStats added in v0.8.0

type ClientStats struct {
	// contains filtered or unexported fields
}

ClientStats endpoint is used for retrieving stats about a client

func (*ClientStats) Stats added in v0.8.0

Stats is used to retrieve the Clients stats.

type ClientStatsReporter added in v0.4.0

type ClientStatsReporter interface {
	// GetAllocStats returns the AllocStatsReporter for the passed allocation.
	// If it does not exist an error is reported.
	GetAllocStats(allocID string) (interfaces.AllocStatsReporter, error)

	// LatestHostStats returns the latest resource usage stats for the host
	LatestHostStats() *stats.HostStats
}

ClientStatsReporter exposes all the APIs related to resource usage of a Nomad Client

type EnterpriseClient added in v0.12.0

type EnterpriseClient struct{}

EnterpriseClient holds information and methods for enterprise functionality

func (*EnterpriseClient) SetFeatures added in v0.12.0

func (ec *EnterpriseClient) SetFeatures(features uint64)

SetFeatures is used for enterprise builds to configure enterprise features

type FileSystem added in v0.8.0

type FileSystem struct {
	// contains filtered or unexported fields
}

FileSystem endpoint is used for accessing the logs and filesystem of allocations.

func NewFileSystemEndpoint added in v0.8.0

func NewFileSystemEndpoint(c *Client) *FileSystem

func (*FileSystem) List added in v0.8.0

List is used to list the contents of an allocation's directory.

func (*FileSystem) Stat added in v0.8.0

Stat is used to stat a file in the allocation's directory.

type FingerprintManager added in v0.8.0

type FingerprintManager struct {
	// contains filtered or unexported fields
}

FingerprintManager runs a client fingerprinters on a continuous basis, and updates the client when the node has changed

func NewFingerprintManager added in v0.8.0

func NewFingerprintManager(
	singletonLoader loader.PluginCatalog,
	getConfig func() *config.Config,
	node *structs.Node,
	shutdownCh chan struct{},
	updateNodeAttributes func(*fingerprint.FingerprintResponse) *structs.Node,
	logger log.Logger) *FingerprintManager

NewFingerprintManager is a constructor that creates and returns an instance of FingerprintManager

func (*FingerprintManager) Reload added in v0.12.0

func (fm *FingerprintManager) Reload()

Reload will reload any registered ReloadableFingerprinters and immediately call Fingerprint

func (*FingerprintManager) Run added in v0.8.0

func (fm *FingerprintManager) Run() error

Run starts the process of fingerprinting the node. It does an initial pass, identifying allowlisted and denylisted fingerprints/drivers. Then, for those which require periotic checking, it starts a periodic process for each.

type GCAlloc added in v0.5.2

type GCAlloc struct {
	// contains filtered or unexported fields
}

GCAlloc wraps an allocation runner and an index enabling it to be used within a PQ

type GCAllocPQImpl added in v0.5.2

type GCAllocPQImpl []*GCAlloc

func (GCAllocPQImpl) Len added in v0.5.2

func (pq GCAllocPQImpl) Len() int

func (GCAllocPQImpl) Less added in v0.5.2

func (pq GCAllocPQImpl) Less(i, j int) bool

func (*GCAllocPQImpl) Pop added in v0.5.2

func (pq *GCAllocPQImpl) Pop() interface{}

func (*GCAllocPQImpl) Push added in v0.5.2

func (pq *GCAllocPQImpl) Push(x interface{})

func (GCAllocPQImpl) Swap added in v0.5.2

func (pq GCAllocPQImpl) Swap(i, j int)

type GCConfig added in v0.5.4

type GCConfig struct {
	// MaxAllocs is the maximum number of allocations to track before a GC
	// is triggered.
	MaxAllocs           int
	DiskUsageThreshold  float64
	InodeUsageThreshold float64
	Interval            time.Duration
	ReservedDiskMB      int
	ParallelDestroys    int
}

GCConfig allows changing the behaviour of the garbage collector

type IndexedGCAllocPQ added in v0.5.2

type IndexedGCAllocPQ struct {
	// contains filtered or unexported fields
}

IndexedGCAllocPQ is an indexed PQ which maintains a list of allocation runner based on their termination time.

func NewIndexedGCAllocPQ added in v0.5.2

func NewIndexedGCAllocPQ() *IndexedGCAllocPQ

func (*IndexedGCAllocPQ) Length added in v0.5.2

func (i *IndexedGCAllocPQ) Length() int

func (*IndexedGCAllocPQ) Pop added in v0.5.2

func (i *IndexedGCAllocPQ) Pop() *GCAlloc

func (*IndexedGCAllocPQ) Push added in v0.5.2

func (i *IndexedGCAllocPQ) Push(allocID string, ar AllocRunner) bool

Push an alloc runner into the GC queue. Returns true if alloc was added, false if the alloc already existed.

func (*IndexedGCAllocPQ) Remove added in v0.5.2

func (i *IndexedGCAllocPQ) Remove(allocID string) *GCAlloc

Remove alloc from GC. Returns nil if alloc doesn't exist.

Directories

Path Synopsis
tasklifecycle
Package tasklifecycle manages the execution order of tasks based on their lifecycle configuration.
Package tasklifecycle manages the execution order of tasks based on their lifecycle configuration.
Package allocwatcher allows blocking until another allocation - whether running locally or remotely - completes and migrates the allocation directory if necessary.
Package allocwatcher allows blocking until another allocation - whether running locally or remotely - completes and migrates the allocation directory if necessary.
Package devicemanager is used to manage device plugins
Package devicemanager is used to manage device plugins
dynamicplugins is a package that manages dynamic plugins in Nomad.
dynamicplugins is a package that manages dynamic plugins in Nomad.
lib
fifo
Package fifo implements functions to create and open a fifo for inter-process communication in an OS agnostic way.
Package fifo implements functions to create and open a fifo for inter-process communication in an OS agnostic way.
csimanager
* csimanager manages locally running CSI Plugins on a Nomad host, and provides a few different interfaces.
* csimanager manages locally running CSI Plugins on a Nomad host, and provides a few different interfaces.
Package servers provides an interface for choosing Servers to communicate with from a Nomad Client perspective.
Package servers provides an interface for choosing Servers to communicate with from a Nomad Client perspective.
nsd
Package nsd provides Nomad service registration and therefore discovery capabilities for Nomad clients.
Package nsd provides Nomad service registration and therefore discovery capabilities for Nomad clients.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL