consul

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const NodeHealthStatusHealthy = "passing"

NodeHealthStatusHealthy is the "healthy" status of a node.

Variables

This section is empty.

Functions

func ValidateConsulConfig

func ValidateConsulConfig(ctx context.Context, tr it.Transport, req *ValidateFileRequest) error

ValidateConsulConfig validates the consul config using the consul validate command.

func ValidateConsulLicense

func ValidateConsulLicense(ctx context.Context, tr it.Transport, req *ValidateFileRequest) error

ValidateConsulLicense validates the consul license using file path or env variable.

func Version

func Version(ctx context.Context, tr it.Transport, req *CLIRequest) (semver.Version, error)

Version takes a context, transport, and path to the consul binary on a remote machine and returns the version.

Types

type AgentHostRequest

type AgentHostRequest struct {
	FlightControlPath string
	ConsulAddr        string
}

AgentHostRequest is a consul /v1/agent/host request.

func NewAgentHostRequest

func NewAgentHostRequest(opts ...AgentHostRequestOpt) *AgentHostRequest

NewAgentHostRequest takes functional options and returns a new request.

func (*AgentHostRequest) String

func (r *AgentHostRequest) String() string

String returns the request as a string.

type AgentHostRequestOpt

type AgentHostRequestOpt func(*AgentHostRequest) *AgentHostRequest

AgentHostRequestOpt is a functional option agent host requests.

func WithAgentHostRequestConsulAddr

func WithAgentHostRequestConsulAddr(addr string) AgentHostRequestOpt

WithAgentHostRequestConsulAddr sets the consul bind address.

func WithAgentHostRequestFlightControlPath

func WithAgentHostRequestFlightControlPath(path string) AgentHostRequestOpt

WithAgentHostRequestFlightControlPath sets the path to flightcontrol.

type AgentHostResponse

type AgentHostResponse struct {
	Host *AgentHostResponseHost `json:"Host"`
}

AgentHostRequest is a consul /v1/agent/host response.

func GetAgentHost

func GetAgentHost(ctx context.Context, tr it.Transport, req *AgentHostRequest) (
	*AgentHostResponse,
	error,
)

GetAgentHost gets the agent host response.

func (*AgentHostResponse) Hostname

func (r *AgentHostResponse) Hostname() string

Hostname returns the hostname of the host.

type AgentHostResponseHost

type AgentHostResponseHost struct {
	Hostname string `json:"hostname"`
	ID       string `json:"hostId"`
}

AgentHostResponseHost is the Host section of the response.

type CLIRequest

type CLIRequest struct {
	BinPath string
}

CLIRequest are common things that we need when making a CLI request.

type CheckStater

type CheckStater func(s *State) error

CheckStater is a validate function that takes a state and checks that it has expected values.

func CheckStateClusterHasLeader

func CheckStateClusterHasLeader() CheckStater

CheckStateClusterHasLeader checks whether or not the consul cluster has a leader.

func CheckStateClusterHasMinNHealthyNodes

func CheckStateClusterHasMinNHealthyNodes(min uint) CheckStater

CheckStateClusterHasMinNHealthyNodes checks whether or not the cluster has a minimum of N healthy nodes.

func CheckStateClusterHasMinNVoters

func CheckStateClusterHasMinNVoters(min uint) CheckStater

CheckStateClusterHasMinNVoters checks whether or not the cluster has a minimum of N raft voters.

func CheckStateHasSystemdEnabledAndRunningProperties

func CheckStateHasSystemdEnabledAndRunningProperties() CheckStater

CheckStateHasSystemdEnabledAndRunningProperties checks that the consul systemd service has all of the properties and values we expect for a service to be running.

func CheckStateNodeIsHealthy

func CheckStateNodeIsHealthy() CheckStater

CheckStateNodeIsHealthy checks whether or not the consul node is healthy.

type HealthNodeRequest

type HealthNodeRequest struct {
	FlightControlPath string
	NodeName          string
	ConsulAddr        string
}

HealthNodeRequest is a consul /v1/health/node/:node request.

func NewHealthNodeRequest

func NewHealthNodeRequest(opts ...HealthNodeRequestOpt) *HealthNodeRequest

NewHealthNodeRequest takes functional options and returns a new request.

func (*HealthNodeRequest) String

func (r *HealthNodeRequest) String() string

String returns the request as a string.

type HealthNodeRequestOpt

type HealthNodeRequestOpt func(*HealthNodeRequest) *HealthNodeRequest

HealthNodeRequestOpt is a functional option agent host requests.

func WithHealthNodeRequestConsulAddr

func WithHealthNodeRequestConsulAddr(addr string) HealthNodeRequestOpt

WithHealthNodeRequestConsulAddr sets consul bind address.

func WithHealthNodeRequestFlightControlPath

func WithHealthNodeRequestFlightControlPath(path string) HealthNodeRequestOpt

WithHealthNodeRequestFlightControlPath sets the path to flightcontrol.

func WithHealthNodeRequestNodeName

func WithHealthNodeRequestNodeName(name string) HealthNodeRequestOpt

WithHealthNodeRequestNodeName sets the node name we're getting the health for.

type HealthNodeResponse

type HealthNodeResponse struct {
	Nodes []*NodeHealth `json:""`
}

HealthNodeResponse is a consul /v1/health/node/:node response.

func GetHealthNode

func GetHealthNode(ctx context.Context, tr it.Transport, req *HealthNodeRequest) (
	*HealthNodeResponse,
	error,
)

GetHealthNode gets the agent host response.

func (*HealthNodeResponse) String

func (n *HealthNodeResponse) String() string

String returns the NodeHealthResponse as a string.

type HealthStatePassingRequest

type HealthStatePassingRequest struct {
	FlightControlPath string
	ConsulAddr        string
}

HealthStatePassingRequest is a consul /v1/health/state/passing request.

func NewHealthStatePassingRequest

func NewHealthStatePassingRequest(opts ...HealthStatePassingRequestOpt) *HealthStatePassingRequest

NewHealthStatePassingRequest takes functional options and returns a new request.

func (*HealthStatePassingRequest) String

func (r *HealthStatePassingRequest) String() string

String returns the request as a string.

type HealthStatePassingRequestOpt

type HealthStatePassingRequestOpt func(*HealthStatePassingRequest) *HealthStatePassingRequest

HealthStatePassingRequestOpt is a functional option agent host requests.

func WithHealthStatePassingRequestConsulAddr

func WithHealthStatePassingRequestConsulAddr(addr string) HealthStatePassingRequestOpt

WithHealthStatePassingRequestConsulAddr sets the consul bind address.

func WithHealthStatePassingRequestFlightControlPath

func WithHealthStatePassingRequestFlightControlPath(path string) HealthStatePassingRequestOpt

WithHealthStatePassingRequestFlightControlPath sets the path to flightcontrol.

type HealthStatePassingResponse

type HealthStatePassingResponse struct {
	Nodes []*NodeHealth `json:""`
}

HealthStatePassingRequest is a consul /v1/health/state/passing response.

func GetHealthStatePassing

func GetHealthStatePassing(ctx context.Context, tr it.Transport, req *HealthStatePassingRequest) (
	*HealthStatePassingResponse,
	error,
)

GetHealthStatePassing gets the agent host response.

func (*HealthStatePassingResponse) String

func (n *HealthStatePassingResponse) String() string

String returns the NodeHealthResponse as a string.

type NodeHealth

type NodeHealth struct {
	Node   string `json:"Node"`
	Status string `json:"Status"`
	Output string `json:"Output"`
	Notes  string `json:"Notes"`
}

NodeHealth is the Node section of the response.

func (*NodeHealth) String

func (n *NodeHealth) String() string

String returns the NodeHealth as a string.

type RaftConfigurationRequest

type RaftConfigurationRequest struct {
	FlightControlPath string
	ConsulAddr        string
}

RaftConfigurationRequest is a consul /v1/operator/raft/configuration request.

func NewRaftConfigurationRequest

func NewRaftConfigurationRequest(opts ...RaftConfigurationRequestOpt) *RaftConfigurationRequest

NewRaftConfigurationRequest takes functional options and returns a new request.

func (*RaftConfigurationRequest) String

func (r *RaftConfigurationRequest) String() string

String returns the request as a string.

type RaftConfigurationRequestOpt

type RaftConfigurationRequestOpt func(*RaftConfigurationRequest) *RaftConfigurationRequest

RaftConfigurationRequestOpt is a functional option agent host requests.

func WithRaftConfigurationRequestConsulAddr

func WithRaftConfigurationRequestConsulAddr(addr string) RaftConfigurationRequestOpt

WithRaftConfigurationRequestConsulAddr sets the consul bind address.

func WithRaftConfigurationRequestFlightControlPath

func WithRaftConfigurationRequestFlightControlPath(path string) RaftConfigurationRequestOpt

WithRaftConfigurationRequestFlightControlPath sets the path to flightcontrol.

type RaftConfigurationResponse

type RaftConfigurationResponse struct {
	Servers []*RaftServer `json:"Servers"`
}

RaftConfigurationResponse is a consul /v1/operator/raft/configuration response.

func GetRaftConfiguration

func GetRaftConfiguration(ctx context.Context, tr it.Transport, req *RaftConfigurationRequest) (
	*RaftConfigurationResponse,
	error,
)

GetRaftConfiguration gets the agent host response.

func (*RaftConfigurationResponse) String

func (r *RaftConfigurationResponse) String() string

String returns the raft configuration response as a string.

type RaftServer

type RaftServer struct {
	ID              string      `json:"ID"`
	Node            string      `json:"Node"`
	Address         string      `json:"Address"`
	Leader          bool        `json:"Leader"`
	ProtocolVersion json.Number `json:"ProtocolVersion"`
	Voter           bool        `json:"Voter"`
}

RaftServer is raft server.

func (*RaftServer) String

func (s *RaftServer) String() string

String returns the RaftServer as a string.

type State

type State struct {
	*AgentHostResponse          // /v1/agent/host
	*HealthNodeResponse         // /v1/health/node/:node
	*HealthStatePassingResponse // /v1/health/state/passing
	*RaftConfigurationResponse  // /v1/operator/raft/configuration
	systemd.UnitProperties      // systemd unit properties for consul.service
}

State represents the state of a node in a consul cluster.

func GetState

func GetState(ctx context.Context, tr it.Transport, req *StateRequest) (*State, error)

GetState returns the consul cluster node state.

func NewState

func NewState() *State

NewState returns a new consul cluster node state.

func WaitForState

func WaitForState(ctx context.Context, tr it.Transport, req *StateRequest, checks ...CheckStater) (*State, error)

WaitForState waits until the consul cluster node state satisfies all of the provided checks.

func (*State) String

func (s *State) String() string

String returns our state as a string.

type StateRequest

type StateRequest struct {
	FlightControlPath       string // where enos-flight-control is installed
	FlightControlUseHomeDir bool   // install enos-flight-control into the $HOME directory
	SystemdUnitName         string // what the systemd unit name for the consul service is
	ConsulAddr              string // consul bind address
}

StateRequest is a consul status request.

func NewStateRequest

func NewStateRequest(opts ...StateRequestOpt) *StateRequest

NewStateRequest takes functional options and returns a new systemd unit request.

type StateRequestOpt

type StateRequestOpt func(*StateRequest) *StateRequest

StateRequestOpt is a functional option for a config create request.

func WithStateRequestConsulAddr

func WithStateRequestConsulAddr(addr string) StateRequestOpt

WithStateRequestConsulAddr sets the consul bind address.

func WithStateRequestFlightControlPath

func WithStateRequestFlightControlPath(path string) StateRequestOpt

WithStateRequestFlightControlPath sets the enos-flight-control binary path.

func WithStateRequestFlightControlUseHomeDir

func WithStateRequestFlightControlUseHomeDir() StateRequestOpt

WithStateRequestFlightControlUseHomeDir will use the $HOME directory for the enos-flight-control binary path.

func WithStateRequestSystemdUnitName

func WithStateRequestSystemdUnitName(name string) StateRequestOpt

WithStateRequestSystemdUnitName sets the flightcontrol binary path.

type ValidateFileRequest

type ValidateFileRequest struct {
	*CLIRequest
	FilePath string
	Username string
}

ValidateFileRequest is a Consul Config Validation request.

func NewValidateFileRequest

func NewValidateFileRequest(opts ...ValidateFileRequestOpt) *ValidateFileRequest

NewValidateFileRequest takes functional options and returns a new config validate request.

type ValidateFileRequestOpt

type ValidateFileRequestOpt func(*ValidateFileRequest) *ValidateFileRequest

ValidateFileRequestOpt is a functional option for a Consul validate command.

func WithValidateConfigBinPath

func WithValidateConfigBinPath(path string) ValidateFileRequestOpt

WithValidateConfigBinPath sets the Consul binary path.

func WithValidateFilePath

func WithValidateFilePath(path string) ValidateFileRequestOpt

WithValidateFilePath sets the Consul config path.

func WithValidateUsername

func WithValidateUsername(name string) ValidateFileRequestOpt

WithValidateUsername sets the username to sudo as for validation.

Jump to

Keyboard shortcuts

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