Documentation ¶
Index ¶
- Constants
- func GetCloudMetadata(provider string) (*pb.CloudMetadata, error)
- func TestClientCredentials(c *C) credentials.TransportCredentials
- func TestServerCredentials(c *C) credentials.TransportCredentials
- type AgentGroup
- func (r *AgentGroup) Abort(ctx context.Context) error
- func (r *AgentGroup) Add(p Peer)
- func (r *AgentGroup) Close(ctx context.Context) error
- func (r *AgentGroup) GetPeers() []Peer
- func (r *AgentGroup) NumPeers() int
- func (r *AgentGroup) Remove(ctx context.Context, p Peer) error
- func (r *AgentGroup) Shutdown(ctx context.Context, req *pb.ShutdownRequest) error
- func (r *AgentGroup) Start()
- func (r AgentGroup) String() string
- func (r *AgentGroup) WatchChan() chan<- WatchEvent
- func (r *AgentGroup) With(addr string) client.Interface
- func (r *AgentGroup) WithContext(ctx context.Context, addr string) client.Interface
- type AgentGroupConfig
- type AgentServer
- func (srv *AgentServer) Abort(ctx context.Context, req *types.Empty) (resp *types.Empty, err error)
- func (srv *AgentServer) Addr() net.Addr
- func (srv *AgentServer) Command(req *pb.CommandArgs, stream pb.Agent_CommandServer) error
- func (srv *AgentServer) Done() <-chan struct{}
- func (srv *AgentServer) GetCurrentTime(ctx context.Context, _ *types.Empty) (*types.Timestamp, error)
- func (srv *AgentServer) GetRuntimeConfig(ctx context.Context, _ *types.Empty) (*pb.RuntimeConfig, error)
- func (srv *AgentServer) GetSystemInfo(ctx context.Context, _ *types.Empty) (*pb.SystemInfo, error)
- func (srv *AgentServer) GetVersion(ctx context.Context, _ *types.Empty) (*pb.Version, error)
- func (srv *AgentServer) PeerJoin(ctx context.Context, req *pb.PeerJoinRequest) (*types.Empty, error)
- func (srv *AgentServer) PeerLeave(ctx context.Context, req *pb.PeerLeaveRequest) (*types.Empty, error)
- func (srv *AgentServer) Serve() error
- func (srv *AgentServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (srv *AgentServer) Shutdown(ctx context.Context, req *pb.ShutdownRequest) (resp *types.Empty, err error)
- func (srv *AgentServer) Stop(ctx context.Context) error
- type Client
- type Config
- type Credentials
- type Peer
- type PeerConfig
- type PeerServer
- func (r *PeerServer) Close(ctx context.Context) error
- func (r *PeerServer) Done() <-chan struct{}
- func (r *PeerServer) Serve() error
- func (r *PeerServer) ServeWithToken(token string) error
- func (r *PeerServer) Stop(ctx context.Context) error
- func (r *PeerServer) ValidateConnection(ctx context.Context) error
- type PeerStore
- type ReconnectStrategy
- type Server
- type TestCommand
- type TestSystemInfo
- type WatchEvent
Constants ¶
const (
// ExitCodeUndefined specifies the value of the exit code when the real exit code is unknown
ExitCodeUndefined = -1
)
Variables ¶
This section is empty.
Functions ¶
func GetCloudMetadata ¶
func GetCloudMetadata(provider string) (*pb.CloudMetadata, error)
GetCloudMetadata fetches cloud metadata for the specified provider
func TestClientCredentials ¶
func TestClientCredentials(c *C) credentials.TransportCredentials
TestClientCredentials returns client credentials for tests
func TestServerCredentials ¶
func TestServerCredentials(c *C) credentials.TransportCredentials
TestServerCredentials returns server credentials for tests
Types ¶
type AgentGroup ¶
type AgentGroup struct { AgentGroupConfig // contains filtered or unexported fields }
AgentGroup manages a list of remote agents.
Group is initialized from an initial set of peers. As new peers appear, they can be added to the group with group.Add(peer). As part of its operation, the group will monitor health of the recorded set of peers and reestablish connections to those that failed the check.
func NewAgentGroup ¶
func NewAgentGroup(config AgentGroupConfig, from []Peer) (*AgentGroup, error)
NewAgentGroup creates a new agent group from the specified list of peers. Call Start on the resulting instance to start the health check loop
func (*AgentGroup) Abort ¶
func (r *AgentGroup) Abort(ctx context.Context) error
Abort requests agents to abort the operation and uninstall
func (*AgentGroup) Add ¶
func (r *AgentGroup) Add(p Peer)
Add adds a new peer to the set of peers to control and monitor. The connection to the peer will automatically be established in background.
func (*AgentGroup) Close ¶
func (r *AgentGroup) Close(ctx context.Context) error
Close closes all remote agent clients
func (*AgentGroup) GetPeers ¶
func (r *AgentGroup) GetPeers() []Peer
GetPeers returns the list of monitored peers
func (*AgentGroup) NumPeers ¶
func (r *AgentGroup) NumPeers() int
NumPeers returns the number of peers in this group
func (*AgentGroup) Remove ¶
func (r *AgentGroup) Remove(ctx context.Context, p Peer) error
Remove removes the specified peer from the group
func (*AgentGroup) Shutdown ¶
func (r *AgentGroup) Shutdown(ctx context.Context, req *pb.ShutdownRequest) error
Shutdown requests agents to shut down
func (*AgentGroup) Start ¶
func (r *AgentGroup) Start()
Start starts this group's internal goroutines
func (AgentGroup) String ¶
func (r AgentGroup) String() string
String returns textual representation of this group
func (*AgentGroup) WatchChan ¶
func (r *AgentGroup) WatchChan() chan<- WatchEvent
WatchChan returns the channel that receives peer updates
func (*AgentGroup) With ¶
func (r *AgentGroup) With(addr string) client.Interface
With returns a client for the peer specified with addr
func (*AgentGroup) WithContext ¶
WithContext returns a client for peer identified with addr. This is a blocking method that waits for a new client if there's a reconnect operation in progress. The specified context can be used to cancel the wait.
type AgentGroupConfig ¶
type AgentGroupConfig struct { log.FieldLogger // ReconnectStrategy configures the strategy for peer reconnects ReconnectStrategy // HealthCheckTimeout overrides timeout between health check attempts. // Defaults to defaults.AgentHealthCheckTimeout HealthCheckTimeout time.Duration // WatchCh is an optional channel that receives updates // when peers reconnect. WatchCh chan<- WatchEvent }
AgentGroupConfig defines agent group configuration
func (*AgentGroupConfig) CheckAndSetDefaults ¶
func (r *AgentGroupConfig) CheckAndSetDefaults() error
CheckAndSetDefaults validates this configuration object and sets defaults
type AgentServer ¶
type AgentServer struct {
// contains filtered or unexported fields
}
AgentServer implements a server in the agent cluster
func New ¶
func New(config Config) (*AgentServer, error)
New returns a new instance of the unstarted gRPC server
func (*AgentServer) Abort ¶
Abort aborts this server. Invokes an abort handler if one has been specified
func (*AgentServer) Addr ¶
func (srv *AgentServer) Addr() net.Addr
Addr returns address the server is listening on.
func (*AgentServer) Command ¶
func (srv *AgentServer) Command(req *pb.CommandArgs, stream pb.Agent_CommandServer) error
Command executes the command given with req and streams the output of the command as a result
func (*AgentServer) Done ¶
func (srv *AgentServer) Done() <-chan struct{}
Done returns a channel that's closed when agent shuts down
func (*AgentServer) GetCurrentTime ¶
func (srv *AgentServer) GetCurrentTime(ctx context.Context, _ *types.Empty) (*types.Timestamp, error)
GetCurrentTime queries the time on the remote node
func (*AgentServer) GetRuntimeConfig ¶
func (srv *AgentServer) GetRuntimeConfig(ctx context.Context, _ *types.Empty) (*pb.RuntimeConfig, error)
GetRuntimeConfig returns the agent's runtime configuration
func (*AgentServer) GetSystemInfo ¶
func (srv *AgentServer) GetSystemInfo(ctx context.Context, _ *types.Empty) (*pb.SystemInfo, error)
GetSystemInfo queries system information on the host the agent is running on
func (*AgentServer) GetVersion ¶
GetVersion queries the agent version information
func (*AgentServer) PeerJoin ¶
func (srv *AgentServer) PeerJoin(ctx context.Context, req *pb.PeerJoinRequest) (*types.Empty, error)
PeerJoin accepts a new peer
func (*AgentServer) PeerLeave ¶
func (srv *AgentServer) PeerLeave(ctx context.Context, req *pb.PeerLeaveRequest) (*types.Empty, error)
PeerLeave receives a "leave" request from a peer and initiates its shutdown
func (*AgentServer) Serve ¶
func (srv *AgentServer) Serve() error
Serve starts the server loop accepting connections
func (*AgentServer) ServeHTTP ¶
func (srv *AgentServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler
func (*AgentServer) Shutdown ¶
func (srv *AgentServer) Shutdown(ctx context.Context, req *pb.ShutdownRequest) (resp *types.Empty, err error)
Shutdown requests agent to shut down
type Client ¶
type Client interface { pb.AgentClient healthpb.HealthClient io.Closer // Client returns client.Client interface to this client Client() client.Interface }
Client defines the low-level agent client interface
type Config ¶
type Config struct { logrus.FieldLogger // Credentials specifies the connect credentials Credentials // PeerStore specifies the peer store. // The store is used to keep track of active peers. PeerStore // Listener specifies the listener for network connections net.Listener // RuntimeConfig specifies the runtime agent configuration pb.RuntimeConfig // ReconnectTimeout specifies the maximum timeout used to reconnect to a peer. // Defaults to defaults.RPCAgentBackoffThreshold ReconnectTimeout time.Duration // AbortHandler specifies an optional handler for aborting the operation. // The handler is invoked when serving the Abort API. // Note that the handler should avoid invoking blocking gRPC APIs - otherwise the // service shut down might block AbortHandler func(context.Context) error // StopHandler specifies an optional handler for when the agent is stopped. // completed indicates whether the agent is stopped after a successfully completed operation StopHandler func(ctx context.Context, completed bool) error // contains filtered or unexported fields }
Config defines RPC server configuration
func (*Config) CheckAndSetDefaults ¶
CheckAndSetDefaults validates this config and sets defaults
type Credentials ¶
type Credentials struct { // Client specifies client connect credentials Client credentials.TransportCredentials // Server specifies server connect credentials Server credentials.TransportCredentials }
Credentials specifies the connect credentials
func TestCredentials ¶
func TestCredentials(c *C) Credentials
TestCredentials returns credentials for tests
func (Credentials) IsEmpty ¶
func (r Credentials) IsEmpty() bool
IsEmpty determines if this Credentials is empty
type Peer ¶
type Peer interface { fmt.Stringer // Addr specifies the address of the peer Addr() string // Reconnect reestablishes a connection to this peer Reconnect(context.Context) (Client, error) // Disconnect requests a shutdown for this peer Disconnect(context.Context) error }
Peer defines a peer
type PeerConfig ¶
type PeerConfig struct { Config // ReconnectStrategy defines the strategy for reconnecting to server ReconnectStrategy // WatchCh is an optional channel that receives updates // when server reconnects. WatchCh chan<- WatchEvent // HealthCheckTimeout overrides timeout between server health check attempts. // Defaults to defaults.AgentHealthCheckTimeout HealthCheckTimeout time.Duration // contains filtered or unexported fields }
PeerConfig specifies the peer configuration
func (*PeerConfig) CheckAndSetDefaults ¶
func (r *PeerConfig) CheckAndSetDefaults() error
CheckAndSetDefaults validates this configuration object and sets defaults
type PeerServer ¶
type PeerServer struct { // PeerConfig is the peer configuration PeerConfig // contains filtered or unexported fields }
PeerServer represents a peer connected to a control server
func NewPeer ¶
func NewPeer(config PeerConfig, serverAddr string) (*PeerServer, error)
NewPeer returns a new instance of the gRPC server as a peer. To start the peer, invoke its Serve method. Once started, the peer connects to the control server to register its identity. The control server establishes reverse connection to execute remote commands.
func NewTestPeer ¶
func NewTestPeer(c *C, config PeerConfig, serverAddr string, cmd commandExecutor, sysinfo TestSystemInfo) *PeerServer
NewTestPeer creates a new peer instance for tests
func (*PeerServer) Close ¶
func (r *PeerServer) Close(ctx context.Context) error
Close stops this server and its internal goroutines
func (*PeerServer) Done ¶
func (r *PeerServer) Done() <-chan struct{}
Done returns a channel that's closed when agent shuts down
func (*PeerServer) ServeWithToken ¶
func (r *PeerServer) ServeWithToken(token string) error
ServeWithToken starts this peer using the specified token for authorization
func (*PeerServer) Stop ¶
func (r *PeerServer) Stop(ctx context.Context) error
Stop stops this server and its internal goroutines
func (*PeerServer) ValidateConnection ¶
func (r *PeerServer) ValidateConnection(ctx context.Context) error
ValidateConnection makes sure that connection to the control server can be established
type PeerStore ¶
type PeerStore interface { // NewPeer adds a new peer agent NewPeer(context.Context, pb.PeerJoinRequest, Peer) error // RemovePeer removes the specified peer from the store RemovePeer(context.Context, pb.PeerLeaveRequest, Peer) error }
PeerStore receives notifications about peers joining the cluster
type ReconnectStrategy ¶
type ReconnectStrategy struct { // Backoff defines the backoff for reconnects. // Defaults to exponential backoff w/o time limit if nil. Backoff func() backoff.BackOff `json:"-"` // ShouldReconnect makes a decision whether to continue reconnecting // or to abort based on the specified error. // To signal abort, should return an instance of *backoff.PermanentError. // The handler should return a valid error to continue reconnection attempts ShouldReconnect func(err error) error `json:"-"` }
ReconnectStrategy defines a reconnect strategy
type Server ¶
type Server interface { // Serve starts the server loop accepting connections Serve() error // ServeHTTP implements http.Handler ServeHTTP(http.ResponseWriter, *http.Request) // Stop requests the server to stop and clean up Stop(context.Context) error // Addr returns address the server is listening on Addr() net.Addr // Done returns a channel that's closed when agent shuts down Done() <-chan struct{} }
Server defines an RPC server
type TestCommand ¶
type TestCommand struct {
// contains filtered or unexported fields
}
func NewTestCommand ¶
func NewTestCommand(output string) TestCommand
NewTestCommand returns a new instance of command executor serving the specified output
type TestSystemInfo ¶
TestSystemInfo is an alias for system info for use in tests. Implements systemInfo
func NewTestSystemInfo ¶
func NewTestSystemInfo() TestSystemInfo
NewTestSystemInfo returns a new test system info
type WatchEvent ¶
type WatchEvent struct { // Peer specifies the peer after reconnect. Peer // Client specifies the client for peer. // Only set if Error == nil Client // Error specifies the last error encountered during reconnect Error error }
WatchEvent describes a peer update
func (WatchEvent) String ¶
func (r WatchEvent) String() string
String formats this event for logging