Documentation ¶
Overview ¶
Package k8s implements Kubernetes-specific code.
Index ¶
- Constants
- type GcOptions
- type K8s
- func (k8s *K8s) Apply(ctx context.Context, resourcesPath string, labelSelector string) error
- func (k8s *K8s) Gc(ctx context.Context, cfg *config.Config, name names.Name, options *GcOptions) error
- func (k8s *K8s) KubectlCommandContext(ctx context.Context, args ...string) (*exec.Cmd, error)
- func (k8s *K8s) KubectlLikeCommandContext(ctx context.Context, command string, args ...string) (*exec.Cmd, error)
- func (k8s *K8s) ServiceName(ctx context.Context, service ServiceSpec) (string, error)
- func (k8s *K8s) Tail(ctx context.Context, cfg *config.Config, name names.Name) error
- func (k8s *K8s) WaitForAllPodsRunning(ctx context.Context, k8sNamespace string, labelSelector string) error
- func (k8s *K8s) WaitForEndpoints(ctx context.Context, k8sNamespace string, name names.Name) error
- func (k8s *K8s) WaitForOnePodPerService(ctx context.Context, k8sNamespace string, name names.Name) error
- func (k8s *K8s) WaitForOnePodRunning(ctx context.Context, k8sNamespace string, labelSelector string) error
- type Labels
- type Ports
- func (ports *Ports) CancelForwarding()
- func (ports *Ports) PodPortForward(namespace, name string, localPortSpec, exposedTCPPort int) (int, error)
- func (ports *Ports) Port(service ServiceSpec, exposedTCPPort int) (int, error)
- func (ports *Ports) ServicePortForward(service ServiceSpec, localPortSpec, exposedTCPPort int) (localPort int, err error)
- type ServiceSpec
Constants ¶
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 (*K8s) Apply ¶
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 ¶
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
ServiceName returns the name of a service matching a spec.
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 ¶
WaitForEndpoints waits for all the services to have at least one ready endpoint.
type Labels ¶
Labels maps labels to values. Combining Labels with the String function gives a convenient way to specify 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