kubelet: add CheckpointContainer in remote runtime

This is the first step to implement checkpointing and restoring of
container and containers starting from the lowest layer in the kubelet.

Signed-off-by: Adrian Reber <areber@redhat.com>
This commit is contained in:
Adrian Reber 2021-09-08 12:28:39 +00:00
parent 564f0e9a25
commit 1ac7d78296
No known key found for this signature in database
GPG Key ID: 82C9378ED3C4906A

View File

@ -1149,3 +1149,58 @@ func (r *remoteRuntimeService) ReopenContainerLog(containerID string) (err error
klog.V(10).InfoS("[RemoteRuntimeService] ReopenContainerLog Response", "containerID", containerID)
return nil
}
// CheckpointContainer triggers a checkpoint of the given CheckpointContainerRequest
func (r *remoteRuntimeService) CheckpointContainer(options *runtimeapi.CheckpointContainerRequest) error {
klog.V(10).InfoS(
"[RemoteRuntimeService] CheckpointContainer",
"options",
options,
)
if options == nil {
return errors.New("CheckpointContainer requires non-nil CheckpointRestoreOptions parameter")
}
if !r.useV1API() {
return errors.New("CheckpointContainer is only supported in the CRI v1 runtime API")
}
if options.Timeout < 0 {
return errors.New("CheckpointContainer requires the timeout value to be > 0")
}
ctx, cancel := func() (context.Context, context.CancelFunc) {
defaultTimeout := int64(r.timeout / time.Second)
if options.Timeout > defaultTimeout {
// The user requested a specific timeout, let's use that if it
// is larger than the CRI default.
return getContextWithTimeout(time.Duration(options.Timeout) * time.Second)
}
// If the user requested a timeout less than the
// CRI default, let's use the CRI default.
options.Timeout = defaultTimeout
return getContextWithTimeout(r.timeout)
}()
defer cancel()
_, err := r.runtimeClient.CheckpointContainer(
ctx,
options,
)
if err != nil {
klog.ErrorS(
err,
"CheckpointContainer from runtime service failed",
"containerID",
options.ContainerId,
)
return err
}
klog.V(10).InfoS(
"[RemoteRuntimeService] CheckpointContainer Response",
"containerID",
options.ContainerId,
)
return nil
}