k8s

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package k8s implements Kubernetes-specific code.

Index

Constants

View Source
const (
	// StackLabel is a label put on all the Kubernetes resources a stack.  This label
	// indicates ownership, and can be used for resource pruning (kubectl --prune)
	// and deletion, when the stack is removed.
	StackLabel = "warp.stack"

	// ServiceLabel is a label put on a Service resource to identify it.  Typically,
	// the service name (coming from metadata.name) contains some stack-specific
	// prefix, which makes it difficult to refer to a service by its name.
	ServiceLabel = "warp.service"

	// NameLabel is a label put on any resource to identify it.  Typically,
	// the resource name (coming from metadata.name) contains some stack-specific
	// prefix, which makes it difficult to refer to a resource by its name.
	NameLabel = "warp.name"

	// RunIDLabel is a label put on any resource to tie it to a specific run of
	// "warp".  Having such a label ensures that the resource is recreated every
	// time warp runs.
	RunIDLabel = "warp.runID"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GcOptions added in v0.1.0

type GcOptions struct {
	// PreservePersistentVolumeClaims indicates whether to preserve
	// the persistent volume claims instead of garbage-collecting them.
	PreservePersistentVolumeClaims bool
}

GcOptions are options for the Gc function.

type K8s

type K8s struct {
	Clientset *kubernetes.Clientset
	DynClient dynamic.Interface

	Ports *Ports
	// contains filtered or unexported fields
}

K8s wraps a Kubernetes client.

func New

func New(cfg *config.Config) (*K8s, error)

New creates a new Kubernetes client wrapper.

func (*K8s) Apply

func (k8s *K8s) Apply(ctx context.Context, resourcesPath string, labelSelector string) error

Apply executes "kubectl apply". The resources matching the label selector are pruned.

func (*K8s) Gc

func (k8s *K8s) Gc(ctx context.Context, cfg *config.Config, name names.Name, options *GcOptions) error

Gc garbage-collects resources that pertain to a given stack.

func (*K8s) KubectlCommandContext

func (k8s *K8s) KubectlCommandContext(ctx context.Context, args ...string) (*exec.Cmd, error)

KubectlCommandContext returns a command object to call the kubectl command.

func (*K8s) KubectlLikeCommandContext

func (k8s *K8s) KubectlLikeCommandContext(ctx context.Context, command string, args ...string) (*exec.Cmd, error)

KubectlLikeCommandContext returns a command object to call the kubectl command, or a command that behave similarly concerning the "--context" option and the "KUBECONFIG" environment variable.

func (*K8s) ServiceName added in v0.1.0

func (k8s *K8s) ServiceName(ctx context.Context, service ServiceSpec) (string, error)

ServiceName returns the name of a service matching a spec.

func (*K8s) Tail

func (k8s *K8s) Tail(ctx context.Context, cfg *config.Config, name names.Name) error

Tail pipes the stdout/stderr outputs of all the services of a stack.

func (*K8s) WaitForAllPodsRunning added in v0.1.0

func (k8s *K8s) WaitForAllPodsRunning(
	ctx context.Context,
	k8sNamespace string,
	labelSelector string,
) error

WaitForAllPodsRunning waits for all the pods to be running.

func (*K8s) WaitForEndpoints

func (k8s *K8s) WaitForEndpoints(ctx context.Context, k8sNamespace string, name names.Name) error

WaitForEndpoints waits for all the services to have at least one ready endpoint.

func (*K8s) WaitForOnePodPerService added in v0.1.0

func (k8s *K8s) WaitForOnePodPerService(ctx context.Context, k8sNamespace string, name names.Name) error

WaitForOnePodPerService waits for all the services to have at least one ready endpoint.

func (*K8s) WaitForOnePodRunning added in v0.1.0

func (k8s *K8s) WaitForOnePodRunning(
	ctx context.Context,
	k8sNamespace string,
	labelSelector string,
) error

WaitForOnePodRunning waits for at least one pod to be running.

type Labels

type Labels map[string]string

Labels maps labels to values. Combining Labels with the String function gives a convenient way to specify a Kubernetes selector.

func (Labels) String

func (lbls Labels) String() string

String converts a Labels map to a Kubernetes selector.

type Ports

type Ports struct {
	// contains filtered or unexported fields
}

Ports is a "singleton" to pass around port forwarding information. This singleton keeps track of all the port forwarding to 1) avoid forwarding ports in duplicate, 2) provide a single function to cancel all the port forwarding.

func (*Ports) CancelForwarding

func (ports *Ports) CancelForwarding()

CancelForwarding cancels all the port forwarding.

func (*Ports) PodPortForward

func (ports *Ports) PodPortForward(namespace, name string, localPortSpec, exposedTCPPort int) (int, error)

PodPortForward forwards a remote port to a fixed local port.

func (*Ports) Port

func (ports *Ports) Port(service ServiceSpec, exposedTCPPort int) (int, error)

Port gives a random local port to which a remote port is forwarded. The remote port comes from the first pod that matches a service spec.

PodPortForward can be used instead to fix the local port.

func (*Ports) ServicePortForward added in v0.1.0

func (ports *Ports) ServicePortForward(service ServiceSpec, localPortSpec, exposedTCPPort int) (localPort int, err error)

ServicePortForward forwards a remote port to a fixed local port. The remote port comes from the first pod that matches a service spec.

type ServiceSpec

type ServiceSpec struct {
	// Namespace is the Kubernetes namespace to which the service belongs.
	Namespace string

	// Labels is a Kubernetes selector.
	Labels string
}

ServiceSpec specifies a Kubernetes service to forward from.

func (ServiceSpec) String

func (s ServiceSpec) String() string

Jump to

Keyboard shortcuts

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