Documentation ¶
Overview ¶
Package tunnel provides a bidirectional HTTP stream between a cluster service and a locally-accessible web server.
This package is useful for testing. For example, you may want to start a server using net/http/httptest and make that server available to a test Kubernetes cluster. To do so, simply create a tunnel:
tun, err := ApplyHTTP(ctx, cl, key)
Then connect to it using the server URL.
srv := httptest.NewServer(handler) err := WithHTTPConnection(ctx, cfg, tun, srv.URL, func(ctx context.Context) { // The server is now available in your cluster at tun.URL(). })
If you need to wrap the server with TLS, you can use ApplyHTTPS instead, which combines the HTTP tunnel with a TLS reverse proxy from the controller/app/tlsproxy package.
Index ¶
- Constants
- func WithHTTPConnection(ctx context.Context, cfg *rest.Config, h *HTTP, targetURL string, ...) error
- type HTTP
- func (h *HTTP) Delete(ctx context.Context, cl client.Client, opts ...lifecycle.DeleteOption) (bool, error)
- func (h *HTTP) Load(ctx context.Context, cl client.Client) (bool, error)
- func (h *HTTP) Owned(ctx context.Context, owner lifecycle.TypedObject) error
- func (h *HTTP) Persist(ctx context.Context, cl client.Client) error
- func (h *HTTP) URL() string
- type HTTPS
- func (h *HTTPS) CertificateAuthorityPEM() ([]byte, error)
- func (h *HTTPS) Delete(ctx context.Context, cl client.Client, opts ...lifecycle.DeleteOption) (bool, error)
- func (h *HTTPS) Load(ctx context.Context, cl client.Client) (bool, error)
- func (h *HTTPS) Owned(ctx context.Context, owner lifecycle.TypedObject) error
- func (h *HTTPS) Persist(ctx context.Context, cl client.Client) error
- func (h *HTTPS) URL() string
Constants ¶
const HTTPImage = "ghcr.io/puppetlabs/inlets:latest"
HTTPImage is the Inlets Docker image to use for tunneling.
Variables ¶
This section is empty.
Functions ¶
func WithHTTPConnection ¶
func WithHTTPConnection(ctx context.Context, cfg *rest.Config, h *HTTP, targetURL string, fn func(ctx context.Context)) error
WithHTTPConnection forwards the service provided by the given HTTP tunnel to the target URL accessible from the caller of this function.
It invokes the given callback function when the connection is established. When the callback completes, the connection is torn down.
Types ¶
type HTTP ¶
type HTTP struct { Key client.ObjectKey OwnerConfigMap *corev1obj.ConfigMap Service *corev1obj.Service Pod *corev1obj.Pod }
HTTP represents the resources required to maintain a tunnel.
func ApplyHTTP ¶
ApplyHTTP loads, configures, and persists any changes to an HTTP tunnel using the given client.
func ConfigureHTTP ¶
ConfigureHTTP sets up the tunnel to receive connections. Use WithHTTPConnection to connect to the tunnel after persisting a configured tunnel.
type HTTPS ¶
type HTTPS struct { Key client.ObjectKey OwnerConfigMap *corev1obj.ConfigMap HTTP *HTTP TLSProxy *tlsproxy.TLSProxy }
HTTPS is a helper that manages the combination of an HTTP tunnel with a TLS proxy.
func ApplyHTTPS ¶
ApplyHTTPS loads, configures, and persists any changes to an HTTP tunnel with TLS reverse proxy using the given client.
func ConfigureHTTPS ¶
ConfigureHTTPS sets up the tunnel and TLS proxy.
func (*HTTPS) CertificateAuthorityPEM ¶
CertificateAuthorityPEM returns the PEM-encoded CA to use for validating connections to the tunnel from within the cluster.