2019-03-19 17:06:46 +00:00
|
|
|
package structs
|
|
|
|
|
2019-03-27 23:52:38 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
2019-03-22 16:25:37 +00:00
|
|
|
|
2019-03-19 17:06:46 +00:00
|
|
|
const (
|
2019-03-19 22:56:17 +00:00
|
|
|
ServiceDefaults string = "service-defaults"
|
|
|
|
ProxyDefaults string = "proxy-defaults"
|
2019-03-22 16:25:37 +00:00
|
|
|
|
|
|
|
ProxyConfigGlobal string = "global"
|
2019-03-27 23:52:38 +00:00
|
|
|
|
|
|
|
DefaultServiceProtocol = "tcp"
|
2019-03-19 17:06:46 +00:00
|
|
|
)
|
|
|
|
|
2019-03-19 22:56:17 +00:00
|
|
|
// ConfigEntry is the
|
|
|
|
type ConfigEntry interface {
|
|
|
|
GetKind() string
|
2019-03-19 17:06:46 +00:00
|
|
|
GetName() string
|
2019-03-19 22:56:17 +00:00
|
|
|
|
2019-03-27 23:52:38 +00:00
|
|
|
// This is called in the RPC endpoint and can apply defaults or limits.
|
2019-03-19 22:56:17 +00:00
|
|
|
Normalize() error
|
2019-03-19 17:06:46 +00:00
|
|
|
Validate() error
|
2019-03-19 22:56:17 +00:00
|
|
|
|
|
|
|
GetRaftIndex() *RaftIndex
|
2019-03-19 17:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ServiceConfiguration is the top-level struct for the configuration of a service
|
|
|
|
// across the entire cluster.
|
2019-03-19 22:56:17 +00:00
|
|
|
type ServiceConfigEntry struct {
|
|
|
|
Kind string
|
2019-03-19 17:06:46 +00:00
|
|
|
Name string
|
|
|
|
Protocol string
|
|
|
|
Connect ConnectConfiguration
|
|
|
|
ServiceDefinitionDefaults ServiceDefinitionDefaults
|
|
|
|
|
|
|
|
RaftIndex
|
|
|
|
}
|
|
|
|
|
2019-03-20 23:13:13 +00:00
|
|
|
func (e *ServiceConfigEntry) GetKind() string {
|
2019-03-19 17:06:46 +00:00
|
|
|
return ServiceDefaults
|
|
|
|
}
|
|
|
|
|
2019-03-20 23:13:13 +00:00
|
|
|
func (e *ServiceConfigEntry) GetName() string {
|
2019-03-22 16:25:37 +00:00
|
|
|
if e == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2019-03-20 23:13:13 +00:00
|
|
|
return e.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *ServiceConfigEntry) Normalize() error {
|
2019-03-22 16:25:37 +00:00
|
|
|
if e == nil {
|
|
|
|
return fmt.Errorf("config entry is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
e.Kind = ServiceDefaults
|
2019-03-27 23:52:38 +00:00
|
|
|
if e.Protocol == "" {
|
|
|
|
e.Protocol = DefaultServiceProtocol
|
|
|
|
} else {
|
|
|
|
e.Protocol = strings.ToLower(e.Protocol)
|
|
|
|
}
|
2019-03-22 16:25:37 +00:00
|
|
|
|
2019-03-20 23:13:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *ServiceConfigEntry) Validate() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *ServiceConfigEntry) GetRaftIndex() *RaftIndex {
|
2019-03-22 16:25:37 +00:00
|
|
|
if e == nil {
|
|
|
|
return &RaftIndex{}
|
|
|
|
}
|
|
|
|
|
2019-03-20 23:13:13 +00:00
|
|
|
return &e.RaftIndex
|
|
|
|
}
|
|
|
|
|
2019-03-19 17:06:46 +00:00
|
|
|
type ConnectConfiguration struct {
|
|
|
|
SidecarProxy bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type ServiceDefinitionDefaults struct {
|
|
|
|
EnableTagOverride bool
|
|
|
|
|
|
|
|
// Non script/docker checks only
|
|
|
|
Check *HealthCheck
|
|
|
|
Checks HealthChecks
|
|
|
|
|
|
|
|
// Kind is allowed to accommodate non-sidecar proxies but it will be an error
|
|
|
|
// if they also set Connect.DestinationServiceID since sidecars are
|
|
|
|
// configured via their associated service's config.
|
|
|
|
Kind ServiceKind
|
|
|
|
|
|
|
|
// Only DestinationServiceName and Config are supported.
|
|
|
|
Proxy ConnectProxyConfig
|
|
|
|
|
|
|
|
Connect ServiceConnect
|
|
|
|
|
|
|
|
Weights Weights
|
|
|
|
}
|
|
|
|
|
2019-03-19 22:56:17 +00:00
|
|
|
// ProxyConfigEntry is the top-level struct for global proxy configuration defaults.
|
|
|
|
type ProxyConfigEntry struct {
|
2019-03-27 23:52:38 +00:00
|
|
|
Kind string
|
|
|
|
Name string
|
|
|
|
Config map[string]interface{}
|
2019-03-19 22:56:17 +00:00
|
|
|
|
|
|
|
RaftIndex
|
2019-03-19 17:06:46 +00:00
|
|
|
}
|
|
|
|
|
2019-03-20 23:13:13 +00:00
|
|
|
func (e *ProxyConfigEntry) GetKind() string {
|
2019-03-19 17:06:46 +00:00
|
|
|
return ProxyDefaults
|
|
|
|
}
|
2019-03-19 22:56:17 +00:00
|
|
|
|
2019-03-20 23:13:13 +00:00
|
|
|
func (e *ProxyConfigEntry) GetName() string {
|
2019-03-22 16:25:37 +00:00
|
|
|
if e == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2019-03-20 23:13:13 +00:00
|
|
|
return e.Name
|
2019-03-19 22:56:17 +00:00
|
|
|
}
|
|
|
|
|
2019-03-20 23:13:13 +00:00
|
|
|
func (e *ProxyConfigEntry) Normalize() error {
|
2019-03-22 16:25:37 +00:00
|
|
|
if e == nil {
|
|
|
|
return fmt.Errorf("config entry is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
e.Kind = ProxyDefaults
|
|
|
|
|
2019-03-19 22:56:17 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-20 23:13:13 +00:00
|
|
|
func (e *ProxyConfigEntry) Validate() error {
|
2019-03-22 16:25:37 +00:00
|
|
|
if e == nil {
|
|
|
|
return fmt.Errorf("config entry is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if e.Name != ProxyConfigGlobal {
|
|
|
|
return fmt.Errorf("invalid name (%q), only %q is supported", e.Name, ProxyConfigGlobal)
|
|
|
|
}
|
|
|
|
|
2019-03-19 22:56:17 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-20 23:13:13 +00:00
|
|
|
func (e *ProxyConfigEntry) GetRaftIndex() *RaftIndex {
|
2019-03-22 16:25:37 +00:00
|
|
|
if e == nil {
|
|
|
|
return &RaftIndex{}
|
|
|
|
}
|
|
|
|
|
2019-03-20 23:13:13 +00:00
|
|
|
return &e.RaftIndex
|
2019-03-19 22:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ConfigEntryOp string
|
|
|
|
|
|
|
|
const (
|
|
|
|
ConfigEntryUpsert ConfigEntryOp = "upsert"
|
|
|
|
ConfigEntryDelete ConfigEntryOp = "delete"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ConfigEntryRequest struct {
|
|
|
|
Op ConfigEntryOp
|
|
|
|
Entry ConfigEntry
|
|
|
|
}
|