discovery

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 27 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAuth

func GetAuth(ctx context.Context, addr string, q AuthQuery) ([]byte, error)

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

func GetStunnerdStatus(ctx context.Context, addr string) (*stnrv2.StunnerStatus, error)

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.

func LeaderPod

func LeaderPod(holder string, pods []corev1.Pod) *corev1.Pod

LeaderPod selects the pod named by a Lease holder identity. The identity written by the operator's leader election is the leader pod's name followed by an underscore and a random suffix; pod names carry no underscore.

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

type AuthQuery struct {
	Namespace, Gateway, Username string
	TURNCredential               bool
}

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.

func (*PodConnector) PortFwd

func (d *PodConnector) PortFwd(ctx context.Context, pod *corev1.Pod, port int) (PodInfo, error)

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.

func (*PodInfo) String

func (p *PodInfo) String() string

Jump to

Keyboard shortcuts

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