Documentation
¶
Overview ¶
Package discovery finds STUNner's components in a Kubernetes cluster, the config discovery server of the gateway operator, the stunnerd pods of a Gateway and the auth service, and opens port-forwards to them. It is the toolbox behind stunnerctl and the k8s config origin of stunnerd.
Index ¶
- func GetAuth(ctx context.Context, addr string, q AuthQuery) ([]byte, error)
- func GetStunnerdStatus(ctx context.Context, addr string) (*stnrv2.StunnerStatus, error)
- func LeaderPod(holder string, pods []corev1.Pod) *corev1.Pod
- type AuthConfigFlags
- type AuthQuery
- type CDSConfigFlags
- 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)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAuth ¶
GetAuth queries the auth service served at addr (host:port), typically the local end of a port-forward opened by DiscoverK8sAuthServer, and returns its response: a JSON ICE server configuration or TURN credential.
func GetStunnerdStatus ¶
GetStunnerdStatus fetches the runtime status of the stunnerd instance whose health-check endpoint is served at addr (host:port), typically the local end of a port-forward opened by DiscoverK8sStunnerdPods.
Types ¶
type AuthConfigFlags ¶
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 ¶
func NewAuthConfigFlags() *AuthConfigFlags
NewAuthConfigFlags returns auth service discovery flags with default values set.
func (*AuthConfigFlags) AddFlags ¶
func (f *AuthConfigFlags) AddFlags(flags *pflag.FlagSet)
AddFlags binds pod discovery configuration flags to a given flagset.
type AuthQuery ¶
AuthQuery is a request to the auth service: the ICE server configuration, or with TURNCredential a TURN credential in the format of the REST API for TURN, of the Gateways of a namespace or of one Gateway, optionally for a user. Empty fields are left out of the query.
type CDSConfigFlags ¶
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 ¶
func NewCDSConfigFlags() *CDSConfigFlags
NewCDSConfigFlags returns CDS service discovery flags with default values set.
func (*CDSConfigFlags) AddFlags ¶
func (f *CDSConfigFlags) AddFlags(flags *pflag.FlagSet)
AddFlags binds pod discovery configuration flags to a given flagset.
type PodConfigFlags ¶
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 ¶
func NewPodConfigFlags() *PodConfigFlags
NewPodConfigFlags returns Stunnerd service discovery flags with default values set.
func (*PodConfigFlags) AddFlags ¶
func (f *PodConfigFlags) AddFlags(flags *pflag.FlagSet)
AddFlags binds pod discovery configuration flags to a given flagset.
type PodConnector ¶
type PodConnector struct {
// contains filtered or unexported fields
}
PodConnector is a helper for discovering and connecting to pods in a Kubernetes cluster.
func NewK8sDiscoverer ¶
func NewK8sDiscoverer(k8sFlags *cliopt.ConfigFlags, log logging.LeveledLogger) (*PodConnector, error)
NewK8sDiscoverer returns a new Kubernetes CDS discovery client.
type PodInfo ¶
type PodInfo struct {
// Name of the pod.
Name string
// Namespace is the Kubernetes namespace of the pod.
Namespace string
// Addr is the address 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 ¶
func DiscoverK8sAuthServer(ctx context.Context, k8sFlags *cliopt.ConfigFlags, authFlags *AuthConfigFlags, log logging.LeveledLogger) (PodInfo, error)
DiscoverK8sAuthServer discovers the cluster authentication service.
func DiscoverK8sCDSServer ¶
func DiscoverK8sCDSServer(ctx context.Context, k8sFlags *cliopt.ConfigFlags, cdsFlags *CDSConfigFlags, log logging.LeveledLogger) (PodInfo, error)
DiscoverK8sCDSServer discovers the serving CDS server of the gateway operator in a Kubernetes cluster and returns an address that a CDS client can use. If necessary, opens a port-forward connection to a remote cluster. The operator may run multiple replicas that each carry the config discovery label, but only the leader serves config discovery. Policy for looking up the leader pod:
- find the operator's Lease and parse the leader pod's name from the holder identity,
- when the Lease is unavailable, (no permission, a custom Lease name, or a holder that is not among the pods), probe replicas and use the first one that answers.
func DiscoverK8sPod ¶
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 ¶
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.