svcdiscovery

package
v0.0.0-...-0c1943d Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//IsServiceDiscoveryEnabled whether Consul service discovery should be enabled
	IsServiceDiscoveryEnabled bool

	//MeshEnabled whether Consul service mesh is enabled or not
	MeshEnabled bool

	//MeshCACert a CA cert of Consul Mesh
	MeshCACert string
	//MeshServiceCert public cert of Router
	MeshServiceCert string
	//MeshServiceKey private key of Router
	MeshServiceKey string
	//MeshUpdateSignal send a signal to notify that a cert update should be propagated to envoy
	MeshUpdateSignal chan bool

	//ConsulClientInstance instance for consul client
	ConsulClientInstance ConsulClient
	//ClusterConsulKeyMap Cluster Name -> consul syntax key
	ClusterConsulKeyMap map[string]string
	//ClusterConsulResultMap Cluster Name -> Upstream
	//saves the last result with respected to a cluster
	ClusterConsulResultMap map[string][]Upstream
	//ClusterConsulDoneChanMap Cluster Name -> doneChan for respective go routine
	//when the cluster is removed we can stop the respective go routine to stop polling and release resources
	ClusterConsulDoneChanMap map[string]chan bool
	//ServiceConsulMeshMap Service -> whether in Mesh
	ServiceConsulMeshMap map[string]bool
)

Functions

func CreateUpstreamTLSContext

func CreateUpstreamTLSContext(upstreamCACert, privateKey, publicKey string) *tlsv3.UpstreamTlsContext

CreateUpstreamTLSContext create a new TLS context using CA, private key and public key

func InitConsul

func InitConsul()

InitConsul loads certs and initialize a ConsulClient lazy loading

func IsDiscoveryServiceEndpoint

func IsDiscoveryServiceEndpoint(str string) bool

IsDiscoveryServiceEndpoint checks whether an endpoint string is a consul syntax string

func ParseConsulSyntax

func ParseConsulSyntax(str string) (string, string, error)

ParseConsulSyntax breaks the syntax string into query string and default host string

func SetClusterConsulResultMap

func SetClusterConsulResultMap(key string, value []Upstream)

SetClusterConsulResultMap avoid concurrent map writes when writing to ClusterConsulResultMap

Types

type ConsulClient

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

ConsulClient wraps the HTTP API

func NewConsulClient

func NewConsulClient(api http.Client, longPollClient http.Client, scheme string, host string, aclToken string) ConsulClient

NewConsulClient constructor for ConsulClient

func (ConsulClient) LongPollRootCert

func (c ConsulClient) LongPollRootCert(signal chan bool)

LongPollRootCert starts long polling root certificate

func (ConsulClient) LongPollServiceCertAndKey

func (c ConsulClient) LongPollServiceCertAndKey(signal chan bool)

LongPollServiceCertAndKey starts long polling for service cert and key

func (ConsulClient) Poll

func (c ConsulClient) Poll(query Query, doneChan <-chan bool) <-chan []Upstream

Poll periodically poll consul for updates using getUpstreams() func. doneChan is there to release resources closing the doneChan will stop polling

type DefaultHost

type DefaultHost struct {
	Host string
	Port string
}

DefaultHost host and port of the default host Clusters are initialized with default host at the time of initialization of an api project

type Proxy

type Proxy struct {
	DestinationServiceID string
	LocalServiceAddress  string
	LocalServicePort     int
}

Proxy side car proxy information

type Query

type Query struct {
	Datacenters []string
	ServiceName string
	Namespace   string
	Tags        []string
}

Query query structure for a consul string syntax

func ParseQueryString

func ParseQueryString(query string) (Query, error)

ParseQueryString parses the string into a Query struct

type Root

type Root struct {
	RootCert          string
	IntermediateCerts []string
	Active            bool
}

Root contains root certificates

type RootCertResp

type RootCertResp struct {
	Roots []Root
}

RootCertResp structure of a response to a request to get the root certificates

type ServiceCertResp

type ServiceCertResp struct {
	CertPEM       string
	PrivateKeyPEM string
}

ServiceCertResp structure of a response to get a service's certificate and private key

type Upstream

type Upstream struct {
	Address     string
	ServicePort int
	ID          string
	InMesh      bool
}

Upstream Data for a service instance

func GetClusterConsulResultMap

func GetClusterConsulResultMap(key string) []Upstream

GetClusterConsulResultMap avoid concurrent map reads/writes when reading from ClusterConsulResultMap

Jump to

Keyboard shortcuts

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