tunnel

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: Apache-2.0 Imports: 17 Imported by: 1

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

View Source
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

func ApplyHTTP(ctx context.Context, cl client.Client, key client.ObjectKey) (*HTTP, error)

ApplyHTTP loads, configures, and persists any changes to an HTTP tunnel using the given client.

func ConfigureHTTP

func ConfigureHTTP(h *HTTP) *HTTP

ConfigureHTTP sets up the tunnel to receive connections. Use WithHTTPConnection to connect to the tunnel after persisting a configured tunnel.

func NewHTTP

func NewHTTP(key client.ObjectKey) *HTTP

NewHTTP creates a new, unconfigured HTTP-only tunnel service.

func (*HTTP) Delete

func (h *HTTP) Delete(ctx context.Context, cl client.Client, opts ...lifecycle.DeleteOption) (bool, error)

func (*HTTP) Load

func (h *HTTP) Load(ctx context.Context, cl client.Client) (bool, error)

func (*HTTP) Owned

func (h *HTTP) Owned(ctx context.Context, owner lifecycle.TypedObject) error

func (*HTTP) Persist

func (h *HTTP) Persist(ctx context.Context, cl client.Client) error

func (*HTTP) URL

func (h *HTTP) URL() string

URL returns the HTTP URL to the tunnel service.

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

func ApplyHTTPS(ctx context.Context, cl client.Client, key client.ObjectKey) (*HTTPS, error)

ApplyHTTPS loads, configures, and persists any changes to an HTTP tunnel with TLS reverse proxy using the given client.

func ConfigureHTTPS

func ConfigureHTTPS(h *HTTPS) (*HTTPS, error)

ConfigureHTTPS sets up the tunnel and TLS proxy.

func NewHTTPS

func NewHTTPS(key client.ObjectKey) *HTTPS

NewHTTPS creates an unconfigured tunnel and TLS proxy pair.

func (*HTTPS) CertificateAuthorityPEM

func (h *HTTPS) CertificateAuthorityPEM() ([]byte, error)

CertificateAuthorityPEM returns the PEM-encoded CA to use for validating connections to the tunnel from within the cluster.

func (*HTTPS) Delete

func (h *HTTPS) Delete(ctx context.Context, cl client.Client, opts ...lifecycle.DeleteOption) (bool, error)

func (*HTTPS) Load

func (h *HTTPS) Load(ctx context.Context, cl client.Client) (bool, error)

func (*HTTPS) Owned

func (h *HTTPS) Owned(ctx context.Context, owner lifecycle.TypedObject) error

func (*HTTPS) Persist

func (h *HTTPS) Persist(ctx context.Context, cl client.Client) error

func (*HTTPS) URL

func (h *HTTPS) URL() string

URL returns the HTTPS URL to the wrapped tunnel.

Jump to

Keyboard shortcuts

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