Documentation
¶
Overview ¶
Package lifecyclehooks runs the file and HTTP actions a container's settings ask for at points in its checkpoint and restore lifecycle: the checkpoint readiness probe and the post-restore action. It performs the actions and single probe checks; when to run them, how often, and how to count the results is the caller's.
Index ¶
- func CheckWritePath(pod *corev1.Pod, container, filePath string) error
- func CreateMarker(ctx context.Context, e Execer, containerID, filePath string, ...) error
- func FileExists(ctx context.Context, e Execer, containerID, filePath string, ...) (bool, error)
- func HTTPGet(ctx context.Context, client *http.Client, u *url.URL, timeout time.Duration) error
- func HTTPPost(ctx context.Context, client *http.Client, u *url.URL, timeout time.Duration) error
- func HTTPTarget(pod *corev1.Pod) (string, error)
- func NewHTTPClient() *http.Client
- func RequestURL(podIP string, port int, path string) (*url.URL, error)
- func ResolvePort(pod *corev1.Pod, container string, port intstr.IntOrString) (int, error)
- type Execer
- type FilePostRestore
- type FileProbe
- type HTTPPostRestore
- type HTTPProbe
- type PostRestoreTarget
- type ReadyCondition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckWritePath ¶
CheckWritePath refuses a file action that would create one of the files Snapshot itself writes in the container's snapshot-control volume. Any other path is the application's to choose: the action runs as the container's user, so it can only write where that user could.
Reads need no check, so a probe may watch ready-for-snapshot.
func CreateMarker ¶
func CreateMarker(ctx context.Context, e Execer, containerID, filePath string, timeout time.Duration) error
CreateMarker creates an empty regular file at filePath in the container, as the container's user. The parent directory must exist. A regular file that is already there is left alone, and the error matches fs.ErrExist; the caller decides whether that file is its own.
func FileExists ¶
func FileExists(ctx context.Context, e Execer, containerID, filePath string, timeout time.Duration) (bool, error)
FileExists reports whether a regular file exists at filePath in the container. A missing file is false. Anything else at the path is an error, so a caller never reads it as either answer.
func HTTPPost ¶
HTTPPost sends a notification's POST, with an empty body. It succeeds on a 2xx status, the probe's rule. Kubelet's own lifecycle hooks accept any response; this one must confirm that the application accepted the notification.
func HTTPTarget ¶
HTTPTarget returns the address hook requests go to: the Pod IP. Like kubelet's probes, it takes the Pod IP of a Pod on the host network too, which is the node's IP: creating such a Pod already takes the privilege to listen there.
func NewHTTPClient ¶
NewHTTPClient returns the client hook requests go through. Like kubelet's prober, it ignores the agent's proxy environment, which would send Pod traffic elsewhere, and it opens a new connection for every request.
Unlike kubelet, which follows redirects to the same host, it follows none: the 3xx response is the result, and it fails. A redirect could otherwise send the agent somewhere the Pod chose, and Go would turn a redirected POST into a GET, so a notification could pass without the application getting it. The path in the spec must be the final one.
func RequestURL ¶
RequestURL builds a hook request's URL the way kubelet builds an httpGet probe's: the path as parsed, with the scheme and host set to http and the Pod IP and port. Setting the host replaces any host the path names, so the request goes to the Pod.
Unlike kubelet, which sends a path that doesn't parse as it is, it fails: kubelet keeps old probes working, and this API has none.
func ResolvePort ¶
ResolvePort returns the port number an action's port names: the number itself, or the containerPort of the container's port with that name. Like kubelet's ResolveContainerPort, it returns -1 with the error when the port is not a valid port number.
Types ¶
type Execer ¶
type Execer interface {
ExecSync(ctx context.Context, containerID string, cmd []string, timeout time.Duration) (stdout, stderr []byte, err error)
}
Execer runs a command in a container the way kubelet runs an exec probe: as the container's user, with its capabilities, seccomp and LSM profile, inside its mounts. runtime.Runtime implements it through CRI ExecSync.
File actions go through it so that they do only what the application's own user could do. The agent never touches the files as root.
type FilePostRestore ¶
FilePostRestore creates a file in the restored container, as the container's user. Timeout bounds each attempt.
func (*FilePostRestore) Check ¶
func (h *FilePostRestore) Check(pod *corev1.Pod, container string) error
Check refuses one of Snapshot's own control files.
func (*FilePostRestore) Notify ¶
func (h *FilePostRestore) Notify(ctx context.Context, target PostRestoreTarget) error
Notify counts an existing file as the notification. Usually an earlier attempt created it: one whose reply was lost, or one before the agent restarted. Nothing checks the file before the release, to keep the restore fast, so a file that was there before the restore, such as one the restored files brought back, counts too: the workload contract forbids such a file, and the application then gets no notification. A file that can't be created fails each attempt with the reason, until the restore deadline.
type FileProbe ¶
FileProbe succeeds when a regular file exists at Path in the container. It reads as the container's user, so any path is allowed.
type HTTPPostRestore ¶
type HTTPPostRestore struct {
Client *http.Client
Action *snapshotv1alpha1.HTTPPostAction
Timeout time.Duration
}
HTTPPostRestore sends a POST to the restored Pod's IP. Timeout bounds each attempt.
func (*HTTPPostRestore) Check ¶
func (h *HTTPPostRestore) Check(pod *corev1.Pod, container string) error
Check refuses a path that doesn't parse and a port name the container doesn't have. A named port resolves against the restored container, which runs the restored application.
func (*HTTPPostRestore) Notify ¶
func (h *HTTPPostRestore) Notify(ctx context.Context, target PostRestoreTarget) error
type HTTPProbe ¶
type HTTPProbe struct {
Client *http.Client
Action *snapshotv1alpha1.HTTPGetAction
}
HTTPProbe succeeds when a GET to the Pod's IP returns a 2xx status.
type PostRestoreTarget ¶
type PostRestoreTarget struct {
Pod *corev1.Pod
Container string
ContainerID string
// PodIP returns the Pod's IP, reading the Pod again when the copy above
// doesn't have one yet.
PodIP func(ctx context.Context) (string, error)
}
PostRestoreTarget is the restored container a post-restore action notifies.
type ReadyCondition ¶
type ReadyCondition struct{}
ReadyCondition is the probe for a container without a checkpointReadinessProbe: the container's Ready condition.