Skip to content

Commit

Permalink
kubelet: Pass context down to long running methods (2/5)
Browse files Browse the repository at this point in the history
In preparation for allowing `sync*Pod` methods to be cancelled when
the pod transitions to terminating, pass context to the appropriate
methods in the Kubelet that might need to be cancelled within a
deadline or due to user input. Does not change the behavior of those
functions.

Propagate core long running methods (CRI, GC, streaming) up out of
methods towards the top-level. Methods with context imply remote
invocations of CRI and so the context is propagated up until it
hits either a method carrying a context (such as HTTP servers,
or `sync*Pod` which will perform cancellation), a top level wait
loop, or a boundary with a subsystem that does not clearly deserve
a context propagation.  Top level loops get context.Background()
and the rest get context.TODO(). This commits contains all such
transitions, and subsequent PRs are propagating context only.
  • Loading branch information
smarterclayton committed Feb 1, 2022
1 parent 3eefaae commit c5822d6
Show file tree
Hide file tree
Showing 30 changed files with 47 additions and 42 deletions.
4 changes: 2 additions & 2 deletions pkg/kubelet/cm/container_manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,13 +788,13 @@ func (cm *containerManagerImpl) SystemCgroupsLimit() v1.ResourceList {

func buildContainerMapFromRuntime(runtimeService internalapi.RuntimeService) (containermap.ContainerMap, error) {
podSandboxMap := make(map[string]string)
podSandboxList, _ := runtimeService.ListPodSandbox(nil)
podSandboxList, _ := runtimeService.ListPodSandbox(context.Background(), nil)
for _, p := range podSandboxList {
podSandboxMap[p.Id] = p.Metadata.Uid
}

containerMap := containermap.NewContainerMap()
containerList, _ := runtimeService.ListContainers(nil)
containerList, _ := runtimeService.ListContainers(context.Background(), nil)
for _, c := range containerList {
if _, exists := podSandboxMap[c.PodSandboxId]; !exists {
return nil, fmt.Errorf("no PodsandBox found with Id '%s'", c.PodSandboxId)
Expand Down
1 change: 1 addition & 0 deletions pkg/kubelet/cm/cpumanager/cpu_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ func (m *manager) updateContainerCPUSet(containerID string, cpus cpuset.CPUSet)
// It would be better to pass the full container resources here instead of
// this patch-like partial resources.
return m.containerRuntime.UpdateContainerResources(
context.TODO(),
containerID,
&runtimeapi.LinuxContainerResources{
CpusetCpus: cpus.String(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/container/runtime_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ func (r *runtimeCache) updateCache() error {
func (r *runtimeCache) getPodsWithTimestamp() ([]*Pod, time.Time, error) {
// Always record the timestamp before getting the pods to avoid stale pods.
timestamp := time.Now()
pods, err := r.getter.GetPods(false)
pods, err := r.getter.GetPods(context.Background(), false)
return pods, timestamp, err
}
2 changes: 1 addition & 1 deletion pkg/kubelet/container/testing/fake_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewFakeCache(runtime container.Runtime) container.Cache {
}

func (c *fakeCache) Get(id types.UID) (*container.PodStatus, error) {
return c.runtime.GetPodStatus(id, "", "")
return c.runtime.GetPodStatus(context.TODO(), id, "", "")
}

func (c *fakeCache) GetNewerThan(id types.UID, minTime time.Time) (*container.PodStatus, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/container/testing/fake_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewFakeRuntimeCache(getter podsGetter) kubecontainer.RuntimeCache {
}

func (f *FakeRuntimeCache) GetPods() ([]*kubecontainer.Pod, error) {
return f.getter.GetPods(false)
return f.getter.GetPods(context.Background(), false)
}

func (f *FakeRuntimeCache) ForceUpdateIfOlder(time.Time) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/cri/streaming/portforward/httpstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (h *httpStreamHandler) portForward(p *httpStreamPair) {
port, _ := strconv.ParseInt(portString, 10, 32)

klog.V(5).InfoS("Connection request invoking forwarder.PortForward for port", "connection", h.conn, "request", p.requestID, "port", portString)
err := h.forwarder.PortForward(h.pod, h.uid, int32(port), p.dataStream)
err := h.forwarder.PortForward(context.Background(), h.pod, h.uid, int32(port), p.dataStream)
klog.V(5).InfoS("Connection request done invoking forwarder.PortForward for port", "connection", h.conn, "request", p.requestID, "port", portString)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/cri/streaming/portforward/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (h *websocketStreamHandler) portForward(p *websocketStreamPair) {
defer p.errorStream.Close()

klog.V(5).InfoS("Connection invoking forwarder.PortForward for port", "connection", h.conn, "port", p.port)
err := h.forwarder.PortForward(h.pod, h.uid, p.port, p.dataStream)
err := h.forwarder.PortForward(context.Background(), h.pod, h.uid, p.port, p.dataStream)
klog.V(5).InfoS("Connection done invoking forwarder.PortForward for port", "connection", h.conn, "port", p.port)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/cri/streaming/remotecommand/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ServeAttach(w http.ResponseWriter, req *http.Request, attacher Attacher, po
}
defer ctx.conn.Close()

err := attacher.AttachContainer(podName, uid, container, ctx.stdinStream, ctx.stdoutStream, ctx.stderrStream, ctx.tty, ctx.resizeChan)
err := attacher.AttachContainer(req.Context(), podName, uid, container, ctx.stdinStream, ctx.stdoutStream, ctx.stderrStream, ctx.tty, ctx.resizeChan)
if err != nil {
err = fmt.Errorf("error attaching to container: %v", err)
runtime.HandleError(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/cri/streaming/remotecommand/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func ServeExec(w http.ResponseWriter, req *http.Request, executor Executor, podN
}
defer ctx.conn.Close()

err := executor.ExecInContainer(podName, uid, container, cmd, ctx.stdinStream, ctx.stdoutStream, ctx.stderrStream, ctx.tty, ctx.resizeChan, 0)
err := executor.ExecInContainer(req.Context(), podName, uid, container, cmd, ctx.stdinStream, ctx.stdoutStream, ctx.stderrStream, ctx.tty, ctx.resizeChan, 0)
if err != nil {
if exitErr, ok := err.(utilexec.ExitError); ok && exitErr.Exited() {
rc := exitErr.ExitStatus()
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/eviction/eviction_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (m *managerImpl) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAd
func (m *managerImpl) Start(diskInfoProvider DiskInfoProvider, podFunc ActivePodsFunc, podCleanedUpFunc PodCleanedUpFunc, monitoringInterval time.Duration) {
thresholdHandler := func(message string) {
klog.InfoS(message)
m.synchronize(diskInfoProvider, podFunc)
m.synchronize(context.Background(), diskInfoProvider, podFunc)
}
if m.config.KernelMemcgNotification {
for _, threshold := range m.config.Thresholds {
Expand All @@ -194,7 +194,7 @@ func (m *managerImpl) Start(diskInfoProvider DiskInfoProvider, podFunc ActivePod
// start the eviction manager monitoring
go func() {
for {
if evictedPods := m.synchronize(diskInfoProvider, podFunc); evictedPods != nil {
if evictedPods := m.synchronize(context.Background(), diskInfoProvider, podFunc); evictedPods != nil {
klog.InfoS("Eviction manager: pods evicted, waiting for pod to be cleaned up", "pods", klog.KObjs(evictedPods))
m.waitForPodsCleanup(podCleanedUpFunc, evictedPods)
} else {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/images/image_gc_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (im *realImageGCManager) Start() {
if im.initialized {
ts = time.Now()
}
_, err := im.detectImages(ts)
_, err := im.detectImages(context.Background(), ts)
if err != nil {
klog.InfoS("Failed to monitor images", "err", err)
} else {
Expand All @@ -194,7 +194,7 @@ func (im *realImageGCManager) Start() {

// Start a goroutine periodically updates image cache.
go wait.Until(func() {
images, err := im.runtime.ListImages()
images, err := im.runtime.ListImages(context.Background())
if err != nil {
klog.InfoS("Failed to update image list", "err", err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/images/image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (m *imageManager) EnsureImageExists(pod *v1.Pod, container *v1.Container, p
Image: image,
Annotations: podAnnotations,
}
imageRef, err := m.imageService.GetImageRef(spec)
imageRef, err := m.imageService.GetImageRef(context.Background(), spec)
if err != nil {
msg := fmt.Sprintf("Failed to inspect image %q: %v", container.Image, err)
m.logIt(ref, v1.EventTypeWarning, events.FailedToInspectImage, logPrefix, msg, klog.Warning)
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/images/puller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newParallelImagePuller(imageService kubecontainer.ImageService) imagePuller

func (pip *parallelImagePuller) pullImage(spec kubecontainer.ImageSpec, pullSecrets []v1.Secret, pullChan chan<- pullResult, podSandboxConfig *runtimeapi.PodSandboxConfig) {
go func() {
imageRef, err := pip.imageService.PullImage(spec, pullSecrets, podSandboxConfig)
imageRef, err := pip.imageService.PullImage(context.Background(), spec, pullSecrets, podSandboxConfig)
pullChan <- pullResult{
imageRef: imageRef,
err: err,
Expand Down Expand Up @@ -86,7 +86,7 @@ func (sip *serialImagePuller) pullImage(spec kubecontainer.ImageSpec, pullSecret

func (sip *serialImagePuller) processImagePullRequests() {
for pullRequest := range sip.pullRequests {
imageRef, err := sip.imageService.PullImage(pullRequest.spec, pullRequest.pullSecrets, pullRequest.podSandboxConfig)
imageRef, err := sip.imageService.PullImage(context.Background(), pullRequest.spec, pullRequest.pullSecrets, pullRequest.podSandboxConfig)
pullRequest.pullChan <- pullResult{
imageRef: imageRef,
err: err,
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ func (kl *Kubelet) setupDataDirs() error {
func (kl *Kubelet) StartGarbageCollection() {
loggedContainerGCFailure := false
go wait.Until(func() {
if err := kl.containerGC.GarbageCollect(); err != nil {
if err := kl.containerGC.GarbageCollect(context.Background()); err != nil {
klog.ErrorS(err, "Container garbage collection failed")
kl.recorder.Eventf(kl.nodeRef, v1.EventTypeWarning, events.ContainerGCFailed, err.Error())
loggedContainerGCFailure = true
Expand All @@ -1358,7 +1358,7 @@ func (kl *Kubelet) StartGarbageCollection() {

prevImageGCFailed := false
go wait.Until(func() {
if err := kl.imageManager.GarbageCollect(); err != nil {
if err := kl.imageManager.GarbageCollect(context.Background()); err != nil {
if prevImageGCFailed {
klog.ErrorS(err, "Image garbage collection failed multiple times in a row")
// Only create an event for repeated failures
Expand Down Expand Up @@ -2354,7 +2354,7 @@ func (kl *Kubelet) updateRuntimeUp() {
kl.updateRuntimeMux.Lock()
defer kl.updateRuntimeMux.Unlock()

s, err := kl.containerRuntime.Status()
s, err := kl.containerRuntime.Status(context.Background())
if err != nil {
klog.ErrorS(err, "Container runtime sanity check failed")
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/kubelet_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (kl *Kubelet) updatePodCIDR(cidr string) (bool, error) {

// kubelet -> generic runtime -> runtime shim -> network plugin
// docker/non-cri implementations have a passthrough UpdatePodCIDR
if err := kl.getRuntime().UpdatePodCIDR(cidr); err != nil {
if err := kl.getRuntime().UpdatePodCIDR(context.Background(), cidr); err != nil {
// If updatePodCIDR would fail, theoretically pod CIDR could not change.
// But it is better to be on the safe side to still return true here.
return true, fmt.Errorf("failed to update pod CIDR: %v", err)
Expand Down
4 changes: 3 additions & 1 deletion pkg/kubelet/kubelet_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,8 @@ func (kl *Kubelet) deleteOrphanedMirrorPods() {
// NOTE: This function is executed by the main sync loop, so it
// should not contain any blocking calls.
func (kl *Kubelet) HandlePodCleanups() error {
ctx := context.Background()

// The kubelet lacks checkpointing, so we need to introspect the set of pods
// in the cgroup tree prior to inspecting the set of pods in our pod manager.
// this ensures our view of the cgroup tree does not mistakenly observe pods
Expand Down Expand Up @@ -1145,7 +1147,7 @@ func (kl *Kubelet) HandlePodCleanups() error {
// in the cache. We need to bypass the cache to get the latest set of
// running pods to clean up the volumes.
// TODO: Evaluate the performance impact of bypassing the runtime cache.
runningRuntimePods, err = kl.containerRuntime.GetPods(false)
runningRuntimePods, err = kl.containerRuntime.GetPods(ctx, false)
if err != nil {
klog.ErrorS(err, "Error listing containers")
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/kuberuntime/fake_kuberuntime_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func newFakeKubeRuntimeManager(runtimeService internalapi.RuntimeService, imageS
memoryThrottlingFactor: 0.8,
}

typedVersion, err := runtimeService.Version(kubeRuntimeAPIVersion)
typedVersion, err := runtimeService.Version(context.Background(), kubeRuntimeAPIVersion)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/kuberuntime/kuberuntime_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func NewKubeGenericRuntimeManager(
memoryThrottlingFactor: memoryThrottlingFactor,
}

typedVersion, err := kubeRuntimeManager.getTypedVersion()
typedVersion, err := kubeRuntimeManager.getTypedVersion(context.Background())
if err != nil {
klog.ErrorS(err, "Get runtime version failed")
return nil, err
Expand Down Expand Up @@ -285,7 +285,7 @@ func NewKubeGenericRuntimeManager(

kubeRuntimeManager.versionCache = cache.NewObjectCache(
func() (interface{}, error) {
return kubeRuntimeManager.getTypedVersion()
return kubeRuntimeManager.getTypedVersion(context.Background())
},
versionCacheTTL,
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/logs/container_log_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func NewContainerLogManager(runtimeService internalapi.RuntimeService, osInterfa
func (c *containerLogManager) Start() {
// Start a goroutine periodically does container log rotation.
go wait.Forever(func() {
if err := c.rotateLogs(); err != nil {
if err := c.rotateLogs(context.TODO()); err != nil {
klog.ErrorS(err, "Failed to rotate container logs")
}
}, logMonitorPeriod)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/metrics/collectors/log_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *logMetricsCollector) DescribeWithStability(ch chan<- *metrics.Desc) {

// CollectWithStability implements the metrics.StableCollector interface.
func (c *logMetricsCollector) CollectWithStability(ch chan<- metrics.Metric) {
podStats, err := c.podStats()
podStats, err := c.podStats(context.Background())
if err != nil {
klog.ErrorS(err, "Failed to get pod stats")
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/metrics/collectors/resource_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (rc *resourceMetricsCollector) CollectWithStability(ch chan<- metrics.Metri
defer func() {
ch <- metrics.NewLazyConstMetric(resourceScrapeResultDesc, metrics.GaugeValue, errorCount)
}()
statsSummary, err := rc.provider.GetCPUAndMemoryStats()
statsSummary, err := rc.provider.GetCPUAndMemoryStats(context.Background())
if err != nil {
errorCount = 1
klog.ErrorS(err, "Error getting summary for resourceMetric prometheus endpoint")
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/metrics/collectors/volume_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (collector *volumeStatsCollector) DescribeWithStability(ch chan<- *metrics.

// CollectWithStability implements the metrics.StableCollector interface.
func (collector *volumeStatsCollector) CollectWithStability(ch chan<- metrics.Metric) {
podStats, err := collector.statsProvider.ListPodStats()
podStats, err := collector.statsProvider.ListPodStats(context.Background())
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/nodestatus/setters.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func VersionInfo(versionInfoFunc func() (*cadvisorapiv1.VersionInfo, error), //
node.Status.NodeInfo.OSImage = verinfo.ContainerOsVersion

runtimeVersion := "Unknown"
if runtimeVer, err := runtimeVersionFunc(); err == nil {
if runtimeVer, err := runtimeVersionFunc(context.Background()); err == nil {
runtimeVersion = runtimeVer.String()
}
node.Status.NodeInfo.ContainerRuntimeVersion = fmt.Sprintf("%s://%s", runtimeTypeFunc(), runtimeVersion)
Expand Down Expand Up @@ -452,7 +452,7 @@ func Images(nodeStatusMaxImages int32,
return func(node *v1.Node) error {
// Update image list of this node
var imagesOnNode []v1.ContainerImage
containerImages, err := imageListFunc()
containerImages, err := imageListFunc(context.Background())
if err != nil {
node.Status.Images = imagesOnNode
return fmt.Errorf("error getting image list: %v", err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubelet/pleg/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package pleg

import (
"context"
"fmt"
"sync/atomic"
"time"
Expand Down Expand Up @@ -128,7 +129,7 @@ func (g *GenericPLEG) Watch() chan *PodLifecycleEvent {

// Start spawns a goroutine to relist periodically.
func (g *GenericPLEG) Start() {
go wait.Until(g.relist, g.relistPeriod, wait.NeverStop)
go wait.UntilWithContext(context.Background(), g.relist, g.relistPeriod)
}

// Healthy check if PLEG work properly.
Expand Down Expand Up @@ -404,7 +405,7 @@ func (g *GenericPLEG) updateCache(pod *kubecontainer.Pod, pid types.UID) error {
// TODO: Consider adding a new runtime method
// GetPodStatus(pod *kubecontainer.Pod) so that Docker can avoid listing
// all containers again.
status, err := g.runtime.GetPodStatus(pod.ID, pod.Name, pod.Namespace)
status, err := g.runtime.GetPodStatus(context.Background(), pod.ID, pod.Name, pod.Namespace)
if klog.V(6).Enabled() {
klog.V(6).ErrorS(err, "PLEG: Write status", "pod", klog.KRef(pod.Namespace, pod.Name), "podStatus", status)
} else {
Expand Down
3 changes: 2 additions & 1 deletion pkg/kubelet/pod_container_deletor.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ func (a containerStatusbyCreatedList) Less(i, j int) bool {
func newPodContainerDeletor(runtime kubecontainer.Runtime, containersToKeep int) *podContainerDeletor {
buffer := make(chan kubecontainer.ContainerID, containerDeletorBufferLimit)
go wait.Until(func() {
ctx := context.Background()
for {
id := <-buffer
if err := runtime.DeleteContainer(id); err != nil {
if err := runtime.DeleteContainer(ctx, id); err != nil {
klog.InfoS("DeleteContainer returned error", "containerID", id, "err", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/prober/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (w *worker) doProbe() (keepGoing bool) {
// TODO: in order for exec probes to correctly handle downward API env, we must be able to reconstruct
// the full container environment here, OR we must make a call to the CRI in order to get those environment
// values from the running container.
result, err := w.probeManager.prober.probe(w.probeType, w.pod, status, w.container, w.containerID)
result, err := w.probeManager.prober.probe(context.TODO(), w.probeType, w.pod, status, w.container, w.containerID)
if err != nil {
// Prober error, throw away the result.
return true
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/runonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (kl *Kubelet) RunOnce(updates <-chan kubetypes.PodUpdate) ([]RunPodResult,
select {
case u := <-updates:
klog.InfoS("Processing manifest with pods", "numPods", len(u.Pods))
result, err := kl.runOnce(u.Pods, runOnceRetryDelay)
result, err := kl.runOnce(context.Background(), u.Pods, runOnceRetryDelay)
klog.InfoS("Finished processing pods", "numPods", len(u.Pods))
return result, err
case <-time.After(runOnceManifestDelay):
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubelet/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ func (s *Server) getAttach(request *restful.Request, response *restful.Response)
}

podFullName := kubecontainer.GetPodFullName(pod)
url, err := s.host.GetAttach(podFullName, params.podUID, params.containerName, *streamOpts)
url, err := s.host.GetAttach(request.Request.Context(), podFullName, params.podUID, params.containerName, *streamOpts)
if err != nil {
streaming.WriteError(err, response.ResponseWriter)
return
Expand All @@ -808,7 +808,7 @@ func (s *Server) getExec(request *restful.Request, response *restful.Response) {
}

podFullName := kubecontainer.GetPodFullName(pod)
url, err := s.host.GetExec(podFullName, params.podUID, params.containerName, params.cmd, *streamOpts)
url, err := s.host.GetExec(request.Request.Context(), podFullName, params.podUID, params.containerName, params.cmd, *streamOpts)
if err != nil {
streaming.WriteError(err, response.ResponseWriter)
return
Expand All @@ -827,7 +827,7 @@ func (s *Server) getRun(request *restful.Request, response *restful.Response) {

// For legacy reasons, run uses different query param than exec.
params.cmd = strings.Split(request.QueryParameter("cmd"), " ")
data, err := s.host.RunInContainer(kubecontainer.GetPodFullName(pod), params.podUID, params.containerName, params.cmd)
data, err := s.host.RunInContainer(request.Request.Context(), kubecontainer.GetPodFullName(pod), params.podUID, params.containerName, params.cmd)
if err != nil {
response.WriteError(http.StatusInternalServerError, err)
return
Expand Down Expand Up @@ -870,7 +870,7 @@ func (s *Server) getPortForward(request *restful.Request, response *restful.Resp
return
}

url, err := s.host.GetPortForward(pod.Name, pod.Namespace, pod.UID, *portForwardOptions)
url, err := s.host.GetPortForward(request.Request.Context(), pod.Name, pod.Namespace, pod.UID, *portForwardOptions)
if err != nil {
streaming.WriteError(err, response.ResponseWriter)
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/server/stats/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ func (h *handler) handleSummary(request *restful.Request, response *restful.Resp
}
var summary *statsapi.Summary
if onlyCPUAndMemory {
summary, err = h.summaryProvider.GetCPUAndMemoryStats()
summary, err = h.summaryProvider.GetCPUAndMemoryStats(request.Request.Context())
} else {
// external calls to the summary API use cached stats
forceStatsUpdate := false
summary, err = h.summaryProvider.Get(forceStatsUpdate)
summary, err = h.summaryProvider.Get(request.Request.Context(), forceStatsUpdate)
}
if err != nil {
handleError(response, "/stats/summary", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/stats/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (p *Provider) GetRawContainerInfo(containerName string, req *cadvisorapiv1.

// HasDedicatedImageFs returns true if a dedicated image filesystem exists for storing images.
func (p *Provider) HasDedicatedImageFs() (bool, error) {
device, err := p.containerStatsProvider.ImageFsDevice()
device, err := p.containerStatsProvider.ImageFsDevice(context.TODO())
if err != nil {
return false, err
}
Expand Down

0 comments on commit c5822d6

Please sign in to comment.