Documentation
¶
Index ¶
- Constants
- Variables
- func IsConfigDeleted(conf *stnrv1.StunnerConfig) bool
- func ParseConfig(c []byte) (*stnrv1.StunnerConfig, error)
- func ZeroConfig(id string) *stnrv1.StunnerConfig
- type AllConfigsAPI
- func (a *AllConfigsAPI) Endpoint() (string, string)
- func (a *AllConfigsAPI) Get(ctx context.Context) ([]*stnrv1.StunnerConfig, error)
- func (a *AllConfigsAPI) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
- func (a *AllConfigsAPI) Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
- type AuthConfigFlags
- type CDSClient
- type CDSConfigFlags
- type CdsApi
- func NewAllConfigsAPI(addr string, logger logging.LeveledLogger, opts ...ClientOption) (CdsApi, error)
- func NewConfigNamespaceNameAPI(addr, namespace, name, node string, logger logging.LeveledLogger, ...) (CdsApi, error)
- func NewConfigsNamespaceAPI(addr, namespace string, logger logging.LeveledLogger, opts ...ClientOption) (CdsApi, error)
- type Client
- type ClientOption
- type ConfigFileClient
- func (w *ConfigFileClient) Load() (*stnrv1.StunnerConfig, error)
- func (w *ConfigFileClient) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
- func (w *ConfigFileClient) String() string
- func (w *ConfigFileClient) Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
- type ConfigList
- type ConfigNamespaceNameAPI
- func (a *ConfigNamespaceNameAPI) Endpoint() (string, string)
- func (a *ConfigNamespaceNameAPI) Get(ctx context.Context) ([]*stnrv1.StunnerConfig, error)
- func (a *ConfigNamespaceNameAPI) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
- func (a *ConfigNamespaceNameAPI) Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
- type ConfigSkeleton
- type ConfigsNamespaceAPI
- func (a *ConfigsNamespaceAPI) Endpoint() (string, string)
- func (a *ConfigsNamespaceAPI) Get(ctx context.Context) ([]*stnrv1.StunnerConfig, error)
- func (a *ConfigsNamespaceAPI) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
- func (a *ConfigsNamespaceAPI) Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
- type HttpRequestDoer
- type JSONPathArg
- type LicenseStatusClient
- type PodConfigFlags
- type PodConnector
- type PodInfo
- func DiscoverK8sAuthServer(ctx context.Context, k8sFlags *cliopt.ConfigFlags, authFlags *AuthConfigFlags, ...) (PodInfo, error)
- func DiscoverK8sCDSServer(ctx context.Context, k8sFlags *cliopt.ConfigFlags, cdsFlags *CDSConfigFlags, ...) (PodInfo, error)
- func DiscoverK8sPod(ctx context.Context, k8sFlags *cliopt.ConfigFlags, ...) (PodInfo, error)
- func DiscoverK8sStunnerdPods(ctx context.Context, k8sFlags *cliopt.ConfigFlags, podFlags *PodConfigFlags, ...) ([]PodInfo, error)
- type Segment
- type SegmentType
Constants ¶
const ( ConfigNamespaceNameAPIEndpoint = "/api/v1/configs/%s/%s" ConfigsNamespaceAPIEndpoint = "/api/v1/configs/%s" AllConfigsAPIEndpoint = "/api/v1/configs" LicenseStatusEndpoint = "/api/v1/license" )
Variables ¶
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 (a *AllConfigsAPI) Get(ctx context.Context) ([]*stnrv1.StunnerConfig, error)
func (*AllConfigsAPI) Poll ¶ added in v0.16.2
func (a *AllConfigsAPI) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
func (*AllConfigsAPI) Watch ¶ added in v0.16.2
func (a *AllConfigsAPI) Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) 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.
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. If
// set, the suppressDelete instructs the API to ignore config delete updates from the
// server.
Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
// Poll creates a one-shot config watcher without the retry mechanincs of Watch.
Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) 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, node 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 listens to new configs from a config origin (config file or CDS server) and
// returns them on the given channel. The context cancels the watcher. If the origin is not
// available watch will retry. If set, the suppressDelete flag instructs the client to
// ignore delete config (essentially zero-configs) from the origin.
Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
// Poll creates a one-shot config watcher without the retry mechanincs of Watch.
Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) 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
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, node 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
func (w *ConfigFileClient) Load() (*stnrv1.StunnerConfig, error)
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, suppressDelete bool) 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, suppressDelete bool) 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 (a *ConfigNamespaceNameAPI) Get(ctx context.Context) ([]*stnrv1.StunnerConfig, error)
func (*ConfigNamespaceNameAPI) Poll ¶ added in v0.16.2
func (a *ConfigNamespaceNameAPI) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
func (*ConfigNamespaceNameAPI) Watch ¶ added in v0.16.2
func (a *ConfigNamespaceNameAPI) Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) 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 (a *ConfigsNamespaceAPI) Get(ctx context.Context) ([]*stnrv1.StunnerConfig, error)
func (*ConfigsNamespaceAPI) Poll ¶ added in v0.16.2
func (a *ConfigsNamespaceAPI) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
func (*ConfigsNamespaceAPI) Watch ¶ added in v0.16.2
func (a *ConfigsNamespaceAPI) Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig, suppressDelete bool) error
type HttpRequestDoer ¶ added in v0.17.6
type HttpRequestDoer = api.HttpRequestDoer
type JSONPathArg ¶ added in v1.1.0
type JSONPathArg interface {
Parse(arg string) (bool, error)
Evaluate(data interface{}) (string, error)
}
JSONPathArg parses a `-jsonpath="... {jsonpath} ..."` expression and knows how to evaluate the parsed JSONpath query/queries on any data.
func NewJSONPath ¶ added in v1.1.0
func NewJSONPath() JSONPathArg
NewJSONPath creates a new JSONPathArg instance
type LicenseStatusClient ¶ added in v1.1.0
type LicenseStatusClient interface {
LicenseStatus(ctx context.Context) (stnrv1.LicenseStatus, error)
}
func NewLicenseStatusClient ¶ added in v1.1.0
func NewLicenseStatusClient(addr string, logger logging.LeveledLogger, opts ...ClientOption) (LicenseStatusClient, error)
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 of the pod.
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 DiscoverK8sPod ¶ added in v1.1.0
func DiscoverK8sPod(ctx context.Context, k8sFlags *cliopt.ConfigFlags, namespace, labelSelector string, port int, log logging.LeveledLogger) (PodInfo, error)
DiscoverK8sPod discovers an arbitrary pod.
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.
type Segment ¶ added in v1.1.0
type Segment struct {
// String is the actual text of the segment (if any).
String string
// JSONQuery is the actual query in the segment.
JSONQuery *jsonpath.JSONPath
// Type indicates whether this is a regular string or an expression.
Type SegmentType
}
Segment represents a part of a JSONPath string
type SegmentType ¶ added in v1.1.0
type SegmentType int
SegmentType identifies the type of string segment in JSONPath.
const ( // String represents a plain text segment. String SegmentType = iota // Expression represents a segment enclosed in curly braces. Expression )