client

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 31 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ConfigNamespaceNameAPIEndpoint = "/api/v1/configs/%s/%s"
	ConfigsNamespaceAPIEndpoint    = "/api/v1/configs/%s"
	AllConfigsAPIEndpoint          = "/api/v1/configs"
)

Variables

View Source
var (
	// Send pings to the CDS server with this period. Must be less than PongWait.
	PingPeriod = 5 * time.Second

	// Time allowed to read the next pong message from the CDS server.
	PongWait = 8 * time.Second

	// Time allowed to write a message to the CDS server.
	WriteWait = 2 * time.Second

	// Period for retrying failed CDS connections.
	RetryPeriod = 1 * time.Second
)

Functions

func IsConfigDeleted added in v0.17.10

func IsConfigDeleted(conf *stnrv1.StunnerConfig) bool

IsConfigDeleted is a helper that allows to decide whether a config is being deleted. When a config is being removed (say, because the corresponding Gateway is deleted), the CDS server sends a validated zero-config for the client. This function is a quick helper to decide whether the config received is such a zero-config.

func ParseConfig

func ParseConfig(c []byte) (*stnrv1.StunnerConfig, error)

ParseConfig parses a raw buffer holding a configuration, substituting environment variables for placeholders in the configuration. Returns the new configuration or error if parsing fails.

func ZeroConfig

func ZeroConfig(id string) *stnrv1.StunnerConfig

ZeroConfig builds a zero configuration useful for bootstrapping STUNner. The minimal config defaults to static authentication with a dummy username and password and opens no listeners or clusters.

Types

type AllConfigsAPI added in v0.16.2

type AllConfigsAPI struct {
	logging.LeveledLogger
	// contains filtered or unexported fields
}

AllConfigsAPI is the API for listing all configs in a namespace.

func (*AllConfigsAPI) Endpoint added in v0.16.2

func (a *AllConfigsAPI) Endpoint() (string, string)

func (*AllConfigsAPI) Get added in v0.16.2

func (*AllConfigsAPI) Poll added in v0.16.2

func (a *AllConfigsAPI) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error

func (*AllConfigsAPI) Watch added in v0.16.2

func (a *AllConfigsAPI) Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error

type AuthConfigFlags added in v0.17.13

type AuthConfigFlags struct {
	// Addr is an explicit IP address for the server.
	Addr string
	// Namespace is the namespace of the server pod.
	Namespace string
	// Port is the port of the server pod.
	Port int
	// Enforce turn credential.
	TurnAuth bool
}

AuthConfigFlags composes a set of flags for authentication service discovery.

func NewAuthConfigFlags added in v0.17.13

func NewAuthConfigFlags() *AuthConfigFlags

NewAuthConfigFlags returns auth service discovery flags with default values set.

func (*AuthConfigFlags) AddFlags added in v0.17.13

func (f *AuthConfigFlags) AddFlags(flags *pflag.FlagSet)

AddFlags binds pod discovery configuration flags to a given flagset.

type CDSClient added in v0.16.2

type CDSClient struct {
	CdsApi
	// contains filtered or unexported fields
}

CDSClient is a client for the config discovery service that knows how to poll configs for a specific gateway. Use the CDSAPI to access the general CDS client set.

func (*CDSClient) Load added in v0.16.2

func (p *CDSClient) Load() (*stnrv1.StunnerConfig, error)

Load grabs a new configuration from the config doscovery server.

func (*CDSClient) String added in v0.16.2

func (p *CDSClient) String() string

String outputs the status of the client.

type CDSConfigFlags added in v0.17.6

type CDSConfigFlags struct {
	// Addr is an explicit IP address for the CDS server.
	Addr string
	// Namespace is the namespace of the CDS server pod.
	Namespace string
	// Port is the port of the CDS server pod.
	Port int
}

CDSConfigFlags composes a set of flags for CDS server discovery.

func NewCDSConfigFlags added in v0.17.6

func NewCDSConfigFlags() *CDSConfigFlags

NewCDSConfigFlags returns CDS service discovery flags with default values set.

func (*CDSConfigFlags) AddFlags added in v0.17.6

func (f *CDSConfigFlags) AddFlags(flags *pflag.FlagSet)

AddFlags binds pod discovery configuration flags to a given flagset.

type CdsApi added in v0.17.1

type CdsApi interface {
	// Endpoint returns the address of the server plus the WebSocket API endpoint.
	Endpoint() (string, string)
	// Get loads the config(s) from the API endpoint.
	Get(ctx context.Context) ([]*stnrv1.StunnerConfig, error)
	// Watch watches config(s) from the API endpoint of a CDS server. If the server is not
	// available watch will retry, and if the connection goes away it will create a new one.
	Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error
	// Poll creates a one-shot config watcher without the retry mechanincs of Watch.
	Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error
	logging.LeveledLogger
}

func NewAllConfigsAPI added in v0.16.2

func NewAllConfigsAPI(addr string, logger logging.LeveledLogger, opts ...ClientOption) (CdsApi, error)

func NewConfigNamespaceNameAPI added in v0.16.2

func NewConfigNamespaceNameAPI(addr, namespace, name string, logger logging.LeveledLogger, opts ...ClientOption) (CdsApi, error)

func NewConfigsNamespaceAPI added in v0.16.2

func NewConfigsNamespaceAPI(addr, namespace string, logger logging.LeveledLogger, opts ...ClientOption) (CdsApi, error)

type Client

type Client interface {
	// Load grabs a new configuration from the config client.
	Load() (*stnrv1.StunnerConfig, error)
	// Watch grabs new configs from a config origin (config file or CDS server) and returns
	// them on the channel. The context cancels the watcher. If the origin is not available
	// watch will retry.
	Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error
	// Poll creates a one-shot config watcher without the retry mechanincs of Watch.
	Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error
	fmt.Stringer
}

Client represents a generic config client. Currently supported config providers: http, ws, or file. Configuration obtained through the client are not validated, make sure to validate on the receiver side.

func New added in v0.16.2

func New(origin string, id string, logger logging.LoggerFactory) (Client, error)

New creates a generic config client. Origin is either a network address in the form "<IP>:<port>" or a proper HTTP/WS URI, in which case a CDS client is returned, or a proper file URL "file://<path>/<filename>" in which case a config file watcher is returned.

func NewCDSClient added in v0.16.2

func NewCDSClient(addr, id string, logger logging.LeveledLogger) (Client, error)

NewCDSClient creates a config discovery service client that can be used to load or watch STUNner configurations from a CDS remote server.

func NewConfigFileClient added in v0.16.2

func NewConfigFileClient(origin, id string, logger logging.LeveledLogger) (Client, error)

NewConfigFileClient creates a client that load or watch STUNner configurations from a local file.

type ClientOption added in v0.17.6

type ClientOption = api.ClientOption

func WithHTTPClient added in v0.17.6

func WithHTTPClient(doer HttpRequestDoer) ClientOption

type ConfigFileClient added in v0.16.2

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

ConfigFileClient is the implementation of the Client interface for config files.

func (*ConfigFileClient) Load added in v0.16.2

Load grabs a new configuration from a config file.

func (*ConfigFileClient) Poll added in v0.16.2

func (w *ConfigFileClient) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error

Poll watches the config file and emits new configs on the specified channel. Returns an error if further action is needed (tryWatchConfig is to be started) or nil on normal exit.

func (*ConfigFileClient) String added in v0.16.2

func (w *ConfigFileClient) String() string

String outputs the status of the client.

func (*ConfigFileClient) Watch added in v0.16.2

func (w *ConfigFileClient) Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error

Watch watches a configuration file for changes. If no file exists at the given path, it will periodically retry until the file appears.

type ConfigList added in v0.16.2

type ConfigList struct {
	Version string                  `json:"version"`
	Items   []*stnrv1.StunnerConfig `json:"items"`
}

type ConfigNamespaceNameAPI added in v0.16.2

type ConfigNamespaceNameAPI struct {
	logging.LeveledLogger
	// contains filtered or unexported fields
}

func (*ConfigNamespaceNameAPI) Endpoint added in v0.16.2

func (a *ConfigNamespaceNameAPI) Endpoint() (string, string)

func (*ConfigNamespaceNameAPI) Get added in v0.16.2

func (*ConfigNamespaceNameAPI) Poll added in v0.16.2

func (*ConfigNamespaceNameAPI) Watch added in v0.16.2

func (a *ConfigNamespaceNameAPI) Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error

type ConfigSkeleton added in v0.16.1

type ConfigSkeleton struct {
	ApiVersion string `json:"version"`
}

type ConfigsNamespaceAPI added in v0.16.2

type ConfigsNamespaceAPI struct {
	logging.LeveledLogger
	// contains filtered or unexported fields
}

ConfigsNamespaceAPI is the API for listing all configs in a namespace.

func (*ConfigsNamespaceAPI) Endpoint added in v0.16.2

func (a *ConfigsNamespaceAPI) Endpoint() (string, string)

func (*ConfigsNamespaceAPI) Get added in v0.16.2

func (*ConfigsNamespaceAPI) Poll added in v0.16.2

func (a *ConfigsNamespaceAPI) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error

func (*ConfigsNamespaceAPI) Watch added in v0.16.2

func (a *ConfigsNamespaceAPI) Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error

type HttpRequestDoer added in v0.17.6

type HttpRequestDoer = api.HttpRequestDoer

type PodConfigFlags added in v0.17.12

type PodConfigFlags struct {
	// Addr is an explicit IP address for the pod.
	Addr string
	// Name is the name of the pod.
	Name string
	// Port is the port to use.
	Port int
}

PodConfigFlags composes a set of flags for pod discovery.

func NewPodConfigFlags added in v0.17.12

func NewPodConfigFlags() *PodConfigFlags

NewPodConfigFlags returns Stunnerd service discovery flags with default values set.

func (*PodConfigFlags) AddFlags added in v0.17.12

func (f *PodConfigFlags) AddFlags(flags *pflag.FlagSet)

AddFlags binds pod discovery configuration flags to a given flagset.

type PodConnector added in v0.17.12

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

PodConnector is a helper for discovering and connecting to pods in a Kubernetes cluster.

func NewK8sDiscoverer added in v0.17.12

func NewK8sDiscoverer(k8sFlags *cliopt.ConfigFlags, log logging.LeveledLogger) (*PodConnector, error)

NewK8sDiscoverer returns a new Kubernetes CDS discovery client.

type PodInfo added in v0.17.12

type PodInfo struct {
	// Name is the name of the pod. Only valid
	Name string
	// Namespace is the Kubernetes namespace of the pod.
	Namespace string
	// Addr is the Kubernetes namespace of the pod.
	Addr string
	// Proxy is a boolean telling whether the connection is proxied over a port-forwarder.
	Proxy bool
}

PodInfo allows to return a full pod descriptor to callers.

func DiscoverK8sAuthServer added in v0.17.13

func DiscoverK8sAuthServer(ctx context.Context, k8sFlags *cliopt.ConfigFlags, authFlags *AuthConfigFlags, log logging.LeveledLogger) (PodInfo, error)

DiscoverK8sAuthServer discovers the cluster authentication service.

func DiscoverK8sCDSServer added in v0.17.6

func DiscoverK8sCDSServer(ctx context.Context, k8sFlags *cliopt.ConfigFlags, cdsFlags *CDSConfigFlags, log logging.LeveledLogger) (PodInfo, error)

DiscoverK8sCDSServer discovers a CDS Server located in a Kubernetes cluster and returns an address that a CDS client can be opened to for reaching that CDS server. If necessary, opens a port-forward connection to the remote cluster.

func DiscoverK8sStunnerdPods added in v0.17.12

func DiscoverK8sStunnerdPods(ctx context.Context, k8sFlags *cliopt.ConfigFlags, podFlags *PodConfigFlags, gwNs, gw string, log logging.LeveledLogger) ([]PodInfo, error)

DiscoverK8sStunnerdPods discovers the stunnerd pods in a Kubernetes cluster, opens a port-forwarded connection to each, and returns a local address that can be used to connect to each pod. If gateway is empty, return all stunnerd pods in a namespace. If no namespace is given (using the -n CLI flag), query all stunnerd pods in the cluster.

func (*PodInfo) String added in v0.17.12

func (p *PodInfo) String() string

Directories

Path Synopsis
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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