2023-01-11 21:34:27 +00:00
|
|
|
package cluster
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/testcontainers/testcontainers-go"
|
|
|
|
|
2023-01-20 22:02:44 +00:00
|
|
|
"github.com/hashicorp/consul/api"
|
|
|
|
|
2023-01-11 21:34:27 +00:00
|
|
|
"github.com/hashicorp/consul/test/integration/consul-container/libs/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Agent represent a Consul agent abstraction
|
|
|
|
type Agent interface {
|
|
|
|
GetIP() string
|
|
|
|
GetClient() *api.Client
|
2023-02-07 19:13:19 +00:00
|
|
|
NewClient(string, bool) (*api.Client, error)
|
2023-01-11 21:34:27 +00:00
|
|
|
GetName() string
|
2023-02-07 19:13:19 +00:00
|
|
|
GetAgentName() string
|
2023-01-11 21:34:27 +00:00
|
|
|
GetPod() testcontainers.Container
|
2023-01-27 15:19:10 +00:00
|
|
|
ClaimAdminPort() (int, error)
|
2023-01-11 21:34:27 +00:00
|
|
|
GetConfig() Config
|
|
|
|
GetInfo() AgentInfo
|
|
|
|
GetDatacenter() string
|
2023-02-24 20:57:44 +00:00
|
|
|
GetNetwork() string
|
2023-01-11 21:34:27 +00:00
|
|
|
IsServer() bool
|
|
|
|
RegisterTermination(func() error)
|
|
|
|
Terminate() error
|
2023-01-30 14:49:52 +00:00
|
|
|
TerminateAndRetainPod(bool) error
|
2023-01-11 21:34:27 +00:00
|
|
|
Upgrade(ctx context.Context, config Config) error
|
2023-02-07 19:13:19 +00:00
|
|
|
Exec(ctx context.Context, cmd []string) (string, error)
|
2023-01-11 21:34:27 +00:00
|
|
|
DataDir() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config is a set of configurations required to create a Agent
|
|
|
|
//
|
|
|
|
// Constructed by (Builder).ToAgentConfig()
|
|
|
|
type Config struct {
|
|
|
|
ScratchDir string
|
|
|
|
CertVolume string
|
|
|
|
CACert string
|
|
|
|
JSON string
|
|
|
|
ConfigBuilder *ConfigBuilder
|
|
|
|
Image string
|
|
|
|
Version string
|
|
|
|
Cmd []string
|
2023-01-19 15:43:33 +00:00
|
|
|
LogConsumer testcontainers.LogConsumer
|
2023-01-11 21:34:27 +00:00
|
|
|
|
|
|
|
// service defaults
|
|
|
|
UseAPIWithTLS bool // TODO
|
|
|
|
UseGRPCWithTLS bool
|
2023-02-07 19:13:19 +00:00
|
|
|
|
|
|
|
ACLEnabled bool
|
2023-01-11 21:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) DockerImage() string {
|
|
|
|
return utils.DockerImage(c.Image, c.Version)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clone copies everything. It is the caller's job to replace fields that
|
|
|
|
// should be unique.
|
|
|
|
func (c Config) Clone() Config {
|
|
|
|
c2 := c
|
|
|
|
if c.Cmd != nil {
|
|
|
|
c2.Cmd = make([]string, len(c.Cmd))
|
|
|
|
for i, v := range c.Cmd {
|
|
|
|
c2.Cmd[i] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c2
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: refactor away
|
|
|
|
type AgentInfo struct {
|
|
|
|
CACertFile string
|
|
|
|
UseTLSForAPI bool
|
|
|
|
UseTLSForGRPC bool
|
|
|
|
}
|