Documentation
¶
Index ¶
- Constants
- func ContainerMatching(pod *v1.Pod, ref reference.Named) (v1.ContainerStatus, error)
- func ContainerSpecOf(pod *v1.Pod, status v1.ContainerStatus) v1.Container
- func ExtractPods(obj interface{}) ([]*v1.PodSpec, error)
- func FakePodSpec(image reference.NamedTagged) v1.PodSpec
- func FakePodStatus(image reference.NamedTagged, phase string) v1.PodStatus
- func IsContainerExited(pod v1.PodStatus, container v1.ContainerStatus) bool
- func IsUnschedulable(pod v1.PodStatus) (bool, string)
- func MustParseNamed(s string) reference.Named
- func MustParseNamedTagged(s string) reference.NamedTagged
- func OpenService(ctx context.Context, client Client, lbSpec LoadBalancerSpec) error
- func ParseNamedTagged(s string) (reference.NamedTagged, error)
- func PodContainsRef(pod *v1.PodSpec, ref reference.Named) (bool, error)
- func ProvideCoreInterface(cfg *rest.Config) (apiv1.CoreV1Interface, error)
- func ProvideRESTClient(cfg *rest.Config) (apiv1.CoreV1Interface, error)
- func ProvideRESTConfig() (*rest.Config, error)
- func SerializeYAML(decoded []K8sEntity) (string, error)
- func ServiceURL(service *v1.Service) (*url.URL, error)
- func WaitForContainerReady(ctx context.Context, client Client, pod *v1.Pod, ref reference.Named) (v1.ContainerStatus, error)
- type BufferCloser
- type Client
- type ContainerID
- type ContainerName
- type Env
- type FakeK8sClient
- func (c *FakeK8sClient) ContainerLogs(ctx context.Context, pID PodID, cName ContainerName, n Namespace) (io.ReadCloser, error)
- func (c *FakeK8sClient) Delete(ctx context.Context, entities []K8sEntity) error
- func (c *FakeK8sClient) FindAppByNode(ctx context.Context, nodeID NodeID, appName string, ...) (PodID, error)
- func (c *FakeK8sClient) ForwardPort(ctx context.Context, namespace Namespace, podID PodID, ...) (int, func(), error)
- func (c *FakeK8sClient) GetNodeForPod(ctx context.Context, podID PodID) (NodeID, error)
- func (c *FakeK8sClient) PodByID(ctx context.Context, pID PodID, n Namespace) (*v1.Pod, error)
- func (c *FakeK8sClient) PodsWithImage(ctx context.Context, image reference.NamedTagged, n Namespace, ...) ([]v1.Pod, error)
- func (c *FakeK8sClient) PollForPodsWithImage(ctx context.Context, image reference.NamedTagged, n Namespace, ...) ([]v1.Pod, error)
- func (c *FakeK8sClient) ResolveLoadBalancer(ctx context.Context, lb LoadBalancerSpec) (LoadBalancer, error)
- func (c *FakeK8sClient) SetPodsWithImageResp(pID PodID)
- func (c *FakeK8sClient) SetPollForPodsWithImageDelay(dur time.Duration)
- func (c *FakeK8sClient) Upsert(ctx context.Context, entities []K8sEntity) error
- func (c *FakeK8sClient) WatchPod(ctx context.Context, pod *v1.Pod) (watch.Interface, error)
- func (c *FakeK8sClient) WatchPods(ctx context.Context, lps []LabelPair) (<-chan *v1.Pod, error)
- func (c *FakeK8sClient) WatchServices(ctx context.Context, lps []LabelPair) (<-chan *v1.Service, error)
- type FindAppByNodeOptions
- type K8sClient
- func (k K8sClient) ContainerLogs(ctx context.Context, pID PodID, cName ContainerName, n Namespace) (io.ReadCloser, error)
- func (k K8sClient) Delete(ctx context.Context, entities []K8sEntity) error
- func (k K8sClient) FindAppByNode(ctx context.Context, nodeID NodeID, appName string, ...) (PodID, error)
- func (k K8sClient) ForwardPort(ctx context.Context, namespace Namespace, podID PodID, ...) (localPort int, closer func(), err error)
- func (k K8sClient) GetNodeForPod(ctx context.Context, podID PodID) (NodeID, error)
- func (k K8sClient) PodByID(ctx context.Context, pID PodID, n Namespace) (*v1.Pod, error)
- func (k K8sClient) PodsWithImage(ctx context.Context, image reference.NamedTagged, n Namespace, ...) ([]v1.Pod, error)
- func (k K8sClient) PollForPodsWithImage(ctx context.Context, image reference.NamedTagged, n Namespace, ...) ([]v1.Pod, error)
- func (k K8sClient) ResolveLoadBalancer(ctx context.Context, lb LoadBalancerSpec) (LoadBalancer, error)
- func (k K8sClient) Upsert(ctx context.Context, entities []K8sEntity) error
- func (k K8sClient) WatchPod(ctx context.Context, pod *v1.Pod) (watch.Interface, error)
- func (kCli K8sClient) WatchPods(ctx context.Context, lps []LabelPair) (<-chan *v1.Pod, error)
- func (kCli K8sClient) WatchServices(ctx context.Context, lps []LabelPair) (<-chan *v1.Service, error)
- type K8sEntity
- func ImmutableEntities(entities []K8sEntity) []K8sEntity
- func InjectImageDigest(entity K8sEntity, injectRef reference.Named, policy v1.PullPolicy) (K8sEntity, bool, error)
- func InjectImagePullPolicy(entity K8sEntity, policy v1.PullPolicy) (K8sEntity, error)
- func InjectLabels(entity K8sEntity, labels []LabelPair) (K8sEntity, error)
- func MutableEntities(entities []K8sEntity) []K8sEntity
- func ParseYAML(k8sYaml io.Reader) ([]K8sEntity, error)
- func ParseYAMLFromString(yaml string) ([]K8sEntity, error)
- type LabelPair
- type LoadBalancer
- type LoadBalancerSpec
- type MultipleAppsFoundError
- type Namespace
- type NodeID
- type PodID
- type PortForwarder
- type ServiceName
Constants ¶
const ( EnvUnknown Env = "unknown" EnvGKE = "gke" EnvMinikube = "minikube" EnvDockerDesktop = "docker-for-desktop" )
const ContainerIDPrefix = "docker://"
const DefaultNamespace = Namespace("default")
const MagicTestContainerID = "tilt-testcontainer"
A magic constant. If the docker client returns this constant, we always match even if the container doesn't have the correct image name.
Variables ¶
This section is empty.
Functions ¶
func ContainerMatching ¶
func ContainerSpecOf ¶
func ExtractPods ¶
func FakePodSpec ¶
func FakePodSpec(image reference.NamedTagged) v1.PodSpec
func FakePodStatus ¶
func FakePodStatus(image reference.NamedTagged, phase string) v1.PodStatus
func IsContainerExited ¶
func IsContainerExited(pod v1.PodStatus, container v1.ContainerStatus) bool
If true, this means the container is gone and will never recover.
func IsUnschedulable ¶
Returns the error message if the pod is unschedulable
func MustParseNamed ¶
func MustParseNamedTagged ¶
func MustParseNamedTagged(s string) reference.NamedTagged
func OpenService ¶
func OpenService(ctx context.Context, client Client, lbSpec LoadBalancerSpec) error
func ParseNamedTagged ¶
func ParseNamedTagged(s string) (reference.NamedTagged, error)
func ProvideCoreInterface ¶
func ProvideCoreInterface(cfg *rest.Config) (apiv1.CoreV1Interface, error)
func ProvideRESTClient ¶
func ProvideRESTClient(cfg *rest.Config) (apiv1.CoreV1Interface, error)
func ProvideRESTConfig ¶
func SerializeYAML ¶
Types ¶
type BufferCloser ¶
func (BufferCloser) Close ¶
func (b BufferCloser) Close() error
type Client ¶
type Client interface { // Updates the entities, creating them if necessary. // // Tries to update them in-place if possible. But for certain resource types, // we might need to fallback to deleting and re-creating them. Upsert(ctx context.Context, entities []K8sEntity) error // Deletes all given entities Delete(ctx context.Context, entities []K8sEntity) error // Find all the pods that match the given image, namespace, and labels. PodsWithImage(ctx context.Context, image reference.NamedTagged, n Namespace, labels []LabelPair) ([]v1.Pod, error) // Find all the pods matching the given parameters, stopping on timeout or // when we have at least one pod. PollForPodsWithImage(ctx context.Context, image reference.NamedTagged, n Namespace, labels []LabelPair, timeout time.Duration) ([]v1.Pod, error) PodByID(ctx context.Context, podID PodID, n Namespace) (*v1.Pod, error) // Creates a channel where all changes to the pod are brodcast. // Takes a pod as input, to indicate the version of the pod where we start watching. WatchPod(ctx context.Context, pod *v1.Pod) (watch.Interface, error) // Streams the container logs ContainerLogs(ctx context.Context, podID PodID, cName ContainerName, n Namespace) (io.ReadCloser, error) // Gets the ID for the Node on which the specified Pod is running GetNodeForPod(ctx context.Context, podID PodID) (NodeID, error) // Finds the PodID for the instance of appName running on the same node as podID FindAppByNode(ctx context.Context, nodeID NodeID, appName string, options FindAppByNodeOptions) (PodID, error) // Waits for the LoadBalancerSpec to get a publicly available URL. ResolveLoadBalancer(ctx context.Context, lb LoadBalancerSpec) (LoadBalancer, error) // Opens a tunnel to the specified pod+port. Returns the tunnel's local port and a function that closes the tunnel ForwardPort(ctx context.Context, namespace Namespace, podID PodID, optionalLocalPort, remotePort int) (localPort int, closer func(), err error) WatchPods(ctx context.Context, lps []LabelPair) (<-chan *v1.Pod, error) WatchServices(ctx context.Context, lps []LabelPair) (<-chan *v1.Service, error) }
type ContainerID ¶
type ContainerID string
func ContainerIDFromContainerStatus ¶
func ContainerIDFromContainerStatus(status v1.ContainerStatus) (ContainerID, error)
func (ContainerID) Empty ¶
func (cID ContainerID) Empty() bool
func (ContainerID) ShortStr ¶
func (cID ContainerID) ShortStr() string
func (ContainerID) String ¶
func (cID ContainerID) String() string
type ContainerName ¶
type ContainerName string
func ContainerNameFromContainerStatus ¶
func ContainerNameFromContainerStatus(status v1.ContainerStatus) ContainerName
func (ContainerName) String ¶
func (n ContainerName) String() string
type FakeK8sClient ¶
type FakeK8sClient struct { Yaml string DeletedYaml string Lb LoadBalancerSpec PodsWithImageResp PodID PodsWithImageError error PollForPodsWithImageDelay time.Duration LastPodQueryNamespace Namespace LastPodQueryImage reference.NamedTagged PodLogs string ContainerLogsError error LastForwardPortPodID PodID LastForwardPortRemotePort int }
func NewFakeK8sClient ¶
func NewFakeK8sClient() *FakeK8sClient
func (*FakeK8sClient) ContainerLogs ¶
func (c *FakeK8sClient) ContainerLogs(ctx context.Context, pID PodID, cName ContainerName, n Namespace) (io.ReadCloser, error)
func (*FakeK8sClient) Delete ¶
func (c *FakeK8sClient) Delete(ctx context.Context, entities []K8sEntity) error
func (*FakeK8sClient) FindAppByNode ¶
func (c *FakeK8sClient) FindAppByNode(ctx context.Context, nodeID NodeID, appName string, options FindAppByNodeOptions) (PodID, error)
func (*FakeK8sClient) ForwardPort ¶
func (*FakeK8sClient) GetNodeForPod ¶
func (*FakeK8sClient) PodsWithImage ¶
func (c *FakeK8sClient) PodsWithImage(ctx context.Context, image reference.NamedTagged, n Namespace, labels []LabelPair) ([]v1.Pod, error)
func (*FakeK8sClient) PollForPodsWithImage ¶
func (*FakeK8sClient) ResolveLoadBalancer ¶
func (c *FakeK8sClient) ResolveLoadBalancer(ctx context.Context, lb LoadBalancerSpec) (LoadBalancer, error)
func (*FakeK8sClient) SetPodsWithImageResp ¶
func (c *FakeK8sClient) SetPodsWithImageResp(pID PodID)
func (*FakeK8sClient) SetPollForPodsWithImageDelay ¶
func (c *FakeK8sClient) SetPollForPodsWithImageDelay(dur time.Duration)
func (*FakeK8sClient) Upsert ¶
func (c *FakeK8sClient) Upsert(ctx context.Context, entities []K8sEntity) error
func (*FakeK8sClient) WatchServices ¶
type FindAppByNodeOptions ¶
type K8sClient ¶
type K8sClient struct {
// contains filtered or unexported fields
}
func NewK8sClient ¶
func NewK8sClient( ctx context.Context, env Env, core apiv1.CoreV1Interface, restConfig *rest.Config, pf PortForwarder) K8sClient
func (K8sClient) ContainerLogs ¶
func (k K8sClient) ContainerLogs(ctx context.Context, pID PodID, cName ContainerName, n Namespace) (io.ReadCloser, error)
func (K8sClient) FindAppByNode ¶
func (K8sClient) ForwardPort ¶
func (K8sClient) GetNodeForPod ¶
func (K8sClient) PodsWithImage ¶
func (k K8sClient) PodsWithImage(ctx context.Context, image reference.NamedTagged, n Namespace, labels []LabelPair) ([]v1.Pod, error)
PodsWithImage returns the ID of the pod running the given image. If too many matches, throw an error. If no matches, return nil -- nothing is wrong, we just didn't find a result.
func (K8sClient) PollForPodsWithImage ¶
func (K8sClient) ResolveLoadBalancer ¶
func (k K8sClient) ResolveLoadBalancer(ctx context.Context, lb LoadBalancerSpec) (LoadBalancer, error)
type K8sEntity ¶
type K8sEntity struct { Obj runtime.Object Kind *schema.GroupVersionKind }
func ImmutableEntities ¶
func InjectImageDigest ¶
func InjectImageDigest(entity K8sEntity, injectRef reference.Named, policy v1.PullPolicy) (K8sEntity, bool, error)
Iterate through the fields of a k8s entity and replace a image name with its digest.
policy: The pull policy to set on the replaced image.
When working with a local k8s cluster, we want to set this to Never, to ensure that k8s fails hard if the image is missing from docker.
Returns: the new entity, whether the image was replaced, and an error.
func InjectImagePullPolicy ¶
func InjectImagePullPolicy(entity K8sEntity, policy v1.PullPolicy) (K8sEntity, error)
Iterate through the fields of a k8s entity and replace the image pull policy on all images.
func MutableEntities ¶
func ParseYAMLFromString ¶
func (K8sEntity) ImmutableOnceCreated ¶
Most entities can be updated once running, but a few cannot.
func (K8sEntity) Meta ¶
func (e K8sEntity) Meta() metav1.ObjectMeta
type LoadBalancer ¶
type LoadBalancer struct { Spec LoadBalancerSpec URL *url.URL }
type LoadBalancerSpec ¶
func ToLoadBalancerSpec ¶
func ToLoadBalancerSpec(entity K8sEntity) (LoadBalancerSpec, bool)
Try to convert the current entity to a LoadBalancerSpec service
func ToLoadBalancerSpecs ¶
func ToLoadBalancerSpecs(entities []K8sEntity) []LoadBalancerSpec
type MultipleAppsFoundError ¶
type MultipleAppsFoundError struct {
// contains filtered or unexported fields
}
func (MultipleAppsFoundError) Error ¶
func (m MultipleAppsFoundError) Error() string
type PortForwarder ¶
type PortForwarder func(ctx context.Context, restConfig *rest.Config, core apiv1.CoreV1Interface, namespace string, podID PodID, localPort int, remotePort int) (closer func(), err error)
func ProvidePortForwarder ¶
func ProvidePortForwarder() PortForwarder
type ServiceName ¶
type ServiceName string