Merge pull request #1221 from jterry75/log_g
Switch to containerd/log package
This commit is contained in:
commit
8ea0cc90aa
@ -25,10 +25,10 @@ import (
|
|||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/mount"
|
"github.com/containerd/containerd/mount"
|
||||||
"github.com/containerd/continuity/fs"
|
"github.com/containerd/continuity/fs"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// WithNewSnapshot wraps `containerd.WithNewSnapshot` so that if creating the
|
// WithNewSnapshot wraps `containerd.WithNewSnapshot` so that if creating the
|
||||||
@ -80,7 +80,7 @@ func WithVolumes(volumeMounts map[string]string) containerd.NewContainerOpts {
|
|||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if uerr := mount.Unmount(root, 0); uerr != nil {
|
if uerr := mount.Unmount(root, 0); uerr != nil {
|
||||||
logrus.WithError(uerr).Errorf("Failed to unmount snapshot %q", c.SnapshotKey)
|
log.G(ctx).WithError(uerr).Errorf("Failed to unmount snapshot %q", c.SnapshotKey)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = uerr
|
err = uerr
|
||||||
}
|
}
|
||||||
|
@ -27,18 +27,20 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/mount"
|
"github.com/containerd/containerd/mount"
|
||||||
"github.com/containerd/containerd/oci"
|
"github.com/containerd/containerd/oci"
|
||||||
osinterface "github.com/containerd/cri/pkg/os"
|
|
||||||
"github.com/containerd/cri/pkg/util"
|
|
||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/opencontainers/runc/libcontainer/devices"
|
"github.com/opencontainers/runc/libcontainer/devices"
|
||||||
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/opencontainers/selinux/go-selinux/label"
|
"github.com/opencontainers/selinux/go-selinux/label"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
|
|
||||||
|
osinterface "github.com/containerd/cri/pkg/os"
|
||||||
|
"github.com/containerd/cri/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -250,7 +252,7 @@ func WithMounts(osi osinterface.OS, config *runtime.ContainerConfig, extra []*ru
|
|||||||
s.Linux.RootfsPropagation = "rslave"
|
s.Linux.RootfsPropagation = "rslave"
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
logrus.Warnf("Unknown propagation mode for hostPath %q", mount.HostPath)
|
log.G(ctx).Warnf("Unknown propagation mode for hostPath %q", mount.HostPath)
|
||||||
options = append(options, "rprivate")
|
options = append(options, "rprivate")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2018 The Containerd Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package log
|
|
||||||
|
|
||||||
import "github.com/containerd/containerd/log"
|
|
||||||
|
|
||||||
// Trace logs a message at level Trace on the standard logger.
|
|
||||||
func Trace(args ...interface{}) {
|
|
||||||
log.Trace(log.L, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tracef logs a message at level Trace on the standard logger.
|
|
||||||
func Tracef(format string, args ...interface{}) {
|
|
||||||
log.Tracef(log.L, format, args...)
|
|
||||||
}
|
|
@ -20,8 +20,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"k8s.io/client-go/tools/remotecommand"
|
"k8s.io/client-go/tools/remotecommand"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
@ -62,7 +62,7 @@ func (c *criService) attachContainer(ctx context.Context, id string, stdin io.Re
|
|||||||
}
|
}
|
||||||
handleResizing(resize, func(size remotecommand.TerminalSize) {
|
handleResizing(resize, func(size remotecommand.TerminalSize) {
|
||||||
if err := task.Resize(ctx, uint32(size.Width), uint32(size.Height)); err != nil {
|
if err := task.Resize(ctx, uint32(size.Width), uint32(size.Height)); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to resize task %q console", id)
|
log.G(ctx).WithError(err).Errorf("Failed to resize task %q console", id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -26,13 +26,13 @@ import (
|
|||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
"github.com/containerd/containerd/contrib/apparmor"
|
"github.com/containerd/containerd/contrib/apparmor"
|
||||||
"github.com/containerd/containerd/contrib/seccomp"
|
"github.com/containerd/containerd/contrib/seccomp"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/oci"
|
"github.com/containerd/containerd/oci"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ func init() {
|
|||||||
// CreateContainer creates a new container in the given PodSandbox.
|
// CreateContainer creates a new container in the given PodSandbox.
|
||||||
func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateContainerRequest) (_ *runtime.CreateContainerResponse, retErr error) {
|
func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateContainerRequest) (_ *runtime.CreateContainerResponse, retErr error) {
|
||||||
config := r.GetConfig()
|
config := r.GetConfig()
|
||||||
logrus.Debugf("Container config %+v", config)
|
log.G(ctx).Debugf("Container config %+v", config)
|
||||||
sandboxConfig := r.GetSandboxConfig()
|
sandboxConfig := r.GetSandboxConfig()
|
||||||
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
|
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -89,7 +89,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
return nil, errors.New("container config must include metadata")
|
return nil, errors.New("container config must include metadata")
|
||||||
}
|
}
|
||||||
name := makeContainerName(metadata, sandboxConfig.GetMetadata())
|
name := makeContainerName(metadata, sandboxConfig.GetMetadata())
|
||||||
logrus.Debugf("Generated id %q for container %q", id, name)
|
log.G(ctx).Debugf("Generated id %q for container %q", id, name)
|
||||||
if err = c.containerNameIndex.Reserve(name, id); err != nil {
|
if err = c.containerNameIndex.Reserve(name, id); err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to reserve container name %q", name)
|
return nil, errors.Wrapf(err, "failed to reserve container name %q", name)
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
// Cleanup the container root directory.
|
// Cleanup the container root directory.
|
||||||
if err = c.os.RemoveAll(containerRootDir); err != nil {
|
if err = c.os.RemoveAll(containerRootDir); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to remove container root directory %q",
|
log.G(ctx).WithError(err).Errorf("Failed to remove container root directory %q",
|
||||||
containerRootDir)
|
containerRootDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
// Cleanup the volatile container root directory.
|
// Cleanup the volatile container root directory.
|
||||||
if err = c.os.RemoveAll(volatileContainerRootDir); err != nil {
|
if err = c.os.RemoveAll(volatileContainerRootDir); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to remove volatile container root directory %q",
|
log.G(ctx).WithError(err).Errorf("Failed to remove volatile container root directory %q",
|
||||||
volatileContainerRootDir)
|
volatileContainerRootDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to get sandbox runtime")
|
return nil, errors.Wrap(err, "failed to get sandbox runtime")
|
||||||
}
|
}
|
||||||
logrus.Debugf("Use OCI runtime %+v for sandbox %q and container %q", ociRuntime, sandboxID, id)
|
log.G(ctx).Debugf("Use OCI runtime %+v for sandbox %q and container %q", ociRuntime, sandboxID, id)
|
||||||
|
|
||||||
spec, err := c.generateContainerSpec(id, sandboxID, sandboxPid, config, sandboxConfig,
|
spec, err := c.generateContainerSpec(id, sandboxID, sandboxPid, config, sandboxConfig,
|
||||||
&image.ImageSpec.Config, append(mounts, volumeMounts...), ociRuntime.PodAnnotations)
|
&image.ImageSpec.Config, append(mounts, volumeMounts...), ociRuntime.PodAnnotations)
|
||||||
@ -173,7 +173,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
return nil, errors.Wrapf(err, "failed to generate container %q spec", id)
|
return nil, errors.Wrapf(err, "failed to generate container %q spec", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf("Container %q spec: %#+v", id, spew.NewFormatter(spec))
|
log.G(ctx).Debugf("Container %q spec: %#+v", id, spew.NewFormatter(spec))
|
||||||
|
|
||||||
// Set snapshotter before any other options.
|
// Set snapshotter before any other options.
|
||||||
opts := []containerd.NewContainerOpts{
|
opts := []containerd.NewContainerOpts{
|
||||||
@ -199,10 +199,10 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
// Validate log paths and compose full container log path.
|
// Validate log paths and compose full container log path.
|
||||||
if sandboxConfig.GetLogDirectory() != "" && config.GetLogPath() != "" {
|
if sandboxConfig.GetLogDirectory() != "" && config.GetLogPath() != "" {
|
||||||
meta.LogPath = filepath.Join(sandboxConfig.GetLogDirectory(), config.GetLogPath())
|
meta.LogPath = filepath.Join(sandboxConfig.GetLogDirectory(), config.GetLogPath())
|
||||||
logrus.Debugf("Composed container full log path %q using sandbox log dir %q and container log path %q",
|
log.G(ctx).Debugf("Composed container full log path %q using sandbox log dir %q and container log path %q",
|
||||||
meta.LogPath, sandboxConfig.GetLogDirectory(), config.GetLogPath())
|
meta.LogPath, sandboxConfig.GetLogDirectory(), config.GetLogPath())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("Logging will be disabled due to empty log paths for sandbox (%q) or container (%q)",
|
log.G(ctx).Infof("Logging will be disabled due to empty log paths for sandbox (%q) or container (%q)",
|
||||||
sandboxConfig.GetLogDirectory(), config.GetLogPath())
|
sandboxConfig.GetLogDirectory(), config.GetLogPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
defer func() {
|
defer func() {
|
||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
if err := containerIO.Close(); err != nil {
|
if err := containerIO.Close(); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to close container io %q", id)
|
log.G(ctx).WithError(err).Errorf("Failed to close container io %q", id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -286,7 +286,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
if err := cntr.Delete(deferCtx, containerd.WithSnapshotCleanup); err != nil {
|
if err := cntr.Delete(deferCtx, containerd.WithSnapshotCleanup); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to delete containerd container %q", id)
|
log.G(ctx).WithError(err).Errorf("Failed to delete containerd container %q", id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -304,7 +304,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
|||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
// Cleanup container checkpoint on error.
|
// Cleanup container checkpoint on error.
|
||||||
if err := container.Delete(); err != nil {
|
if err := container.Delete(); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to cleanup container checkpoint for %q", id)
|
log.G(ctx).WithError(err).Errorf("Failed to cleanup container checkpoint for %q", id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -532,7 +533,7 @@ func TestContainerSpecCommand(t *testing.T) {
|
|||||||
imageConfig.Cmd = test.imageArgs
|
imageConfig.Cmd = test.imageArgs
|
||||||
|
|
||||||
var spec runtimespec.Spec
|
var spec runtimespec.Spec
|
||||||
err := opts.WithProcessArgs(config, imageConfig)(nil, nil, nil, &spec)
|
err := opts.WithProcessArgs(config, imageConfig)(context.Background(), nil, nil, &spec)
|
||||||
if test.expectErr {
|
if test.expectErr {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
continue
|
continue
|
||||||
@ -902,7 +903,7 @@ func TestMountPropagation(t *testing.T) {
|
|||||||
var spec runtimespec.Spec
|
var spec runtimespec.Spec
|
||||||
spec.Linux = &runtimespec.Linux{}
|
spec.Linux = &runtimespec.Linux{}
|
||||||
|
|
||||||
err := opts.WithMounts(c.os, config, []*runtime.Mount{test.criMount}, "")(nil, nil, nil, &spec)
|
err := opts.WithMounts(c.os, config, []*runtime.Mount{test.criMount}, "")(context.Background(), nil, nil, &spec)
|
||||||
if test.expectErr {
|
if test.expectErr {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,9 +25,9 @@ import (
|
|||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
containerdio "github.com/containerd/containerd/cio"
|
containerdio "github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/oci"
|
"github.com/containerd/containerd/oci"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"k8s.io/client-go/tools/remotecommand"
|
"k8s.io/client-go/tools/remotecommand"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
@ -104,7 +104,7 @@ func (c *criService) execInContainer(ctx context.Context, id string, opts execOp
|
|||||||
|
|
||||||
pspec.Terminal = opts.tty
|
pspec.Terminal = opts.tty
|
||||||
if opts.tty {
|
if opts.tty {
|
||||||
if err := oci.WithEnv([]string{"TERM=xterm"})(nil, nil, nil, spec); err != nil {
|
if err := oci.WithEnv([]string{"TERM=xterm"})(ctx, nil, nil, spec); err != nil {
|
||||||
return nil, errors.Wrap(err, "add TERM env var to spec")
|
return nil, errors.Wrap(err, "add TERM env var to spec")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ func (c *criService) execInContainer(ctx context.Context, id string, opts execOp
|
|||||||
opts.stderr = cio.NewDiscardLogger()
|
opts.stderr = cio.NewDiscardLogger()
|
||||||
}
|
}
|
||||||
execID := util.GenerateID()
|
execID := util.GenerateID()
|
||||||
logrus.Debugf("Generated exec id %q for container %q", execID, id)
|
log.G(ctx).Debugf("Generated exec id %q for container %q", execID, id)
|
||||||
volatileRootDir := c.getVolatileContainerRootDir(id)
|
volatileRootDir := c.getVolatileContainerRootDir(id)
|
||||||
var execIO *cio.ExecIO
|
var execIO *cio.ExecIO
|
||||||
process, err := task.Exec(ctx, execID, pspec,
|
process, err := task.Exec(ctx, execID, pspec,
|
||||||
@ -135,7 +135,7 @@ func (c *criService) execInContainer(ctx context.Context, id string, opts execOp
|
|||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
if _, err := process.Delete(deferCtx, containerd.WithProcessKill); err != nil {
|
if _, err := process.Delete(deferCtx, containerd.WithProcessKill); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to delete exec process %q for container %q", execID, id)
|
log.G(ctx).WithError(err).Errorf("Failed to delete exec process %q for container %q", execID, id)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ func (c *criService) execInContainer(ctx context.Context, id string, opts execOp
|
|||||||
|
|
||||||
handleResizing(opts.resize, func(size remotecommand.TerminalSize) {
|
handleResizing(opts.resize, func(size remotecommand.TerminalSize) {
|
||||||
if err := process.Resize(ctx, uint32(size.Width), uint32(size.Height)); err != nil {
|
if err := process.Resize(ctx, uint32(size.Width), uint32(size.Height)); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to resize process %q console for container %q", execID, id)
|
log.G(ctx).WithError(err).Errorf("Failed to resize process %q console for container %q", execID, id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -179,19 +179,19 @@ func (c *criService) execInContainer(ctx context.Context, id string, opts execOp
|
|||||||
}
|
}
|
||||||
// Wait for the process to be killed.
|
// Wait for the process to be killed.
|
||||||
exitRes := <-exitCh
|
exitRes := <-exitCh
|
||||||
logrus.Infof("Timeout received while waiting for exec process kill %q code %d and error %v",
|
log.G(ctx).Infof("Timeout received while waiting for exec process kill %q code %d and error %v",
|
||||||
execID, exitRes.ExitCode(), exitRes.Error())
|
execID, exitRes.ExitCode(), exitRes.Error())
|
||||||
<-attachDone
|
<-attachDone
|
||||||
logrus.Debugf("Stream pipe for exec process %q done", execID)
|
log.G(ctx).Debugf("Stream pipe for exec process %q done", execID)
|
||||||
return nil, errors.Wrapf(execCtx.Err(), "timeout %v exceeded", opts.timeout)
|
return nil, errors.Wrapf(execCtx.Err(), "timeout %v exceeded", opts.timeout)
|
||||||
case exitRes := <-exitCh:
|
case exitRes := <-exitCh:
|
||||||
code, _, err := exitRes.Result()
|
code, _, err := exitRes.Result()
|
||||||
logrus.Infof("Exec process %q exits with exit code %d and error %v", execID, code, err)
|
log.G(ctx).Infof("Exec process %q exits with exit code %d and error %v", execID, code, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed while waiting for exec %q", execID)
|
return nil, errors.Wrapf(err, "failed while waiting for exec %q", execID)
|
||||||
}
|
}
|
||||||
<-attachDone
|
<-attachDone
|
||||||
logrus.Debugf("Stream pipe for exec process %q done", execID)
|
log.G(ctx).Debugf("Stream pipe for exec process %q done", execID)
|
||||||
return &code, nil
|
return &code, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,12 @@ package server
|
|||||||
import (
|
import (
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
|
|
||||||
"github.com/containerd/cri/pkg/log"
|
|
||||||
"github.com/containerd/cri/pkg/store"
|
"github.com/containerd/cri/pkg/store"
|
||||||
containerstore "github.com/containerd/cri/pkg/store/container"
|
containerstore "github.com/containerd/cri/pkg/store/container"
|
||||||
)
|
)
|
||||||
@ -39,7 +38,7 @@ func (c *criService) RemoveContainer(ctx context.Context, r *runtime.RemoveConta
|
|||||||
return nil, errors.Wrapf(err, "an error occurred when try to find container %q", r.GetContainerId())
|
return nil, errors.Wrapf(err, "an error occurred when try to find container %q", r.GetContainerId())
|
||||||
}
|
}
|
||||||
// Do not return error if container metadata doesn't exist.
|
// Do not return error if container metadata doesn't exist.
|
||||||
log.Tracef("RemoveContainer called for container %q that does not exist", r.GetContainerId())
|
log.G(ctx).Tracef("RemoveContainer called for container %q that does not exist", r.GetContainerId())
|
||||||
return &runtime.RemoveContainerResponse{}, nil
|
return &runtime.RemoveContainerResponse{}, nil
|
||||||
}
|
}
|
||||||
id := container.ID
|
id := container.ID
|
||||||
@ -53,7 +52,7 @@ func (c *criService) RemoveContainer(ctx context.Context, r *runtime.RemoveConta
|
|||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
// Reset removing if remove failed.
|
// Reset removing if remove failed.
|
||||||
if err := resetContainerRemoving(container); err != nil {
|
if err := resetContainerRemoving(container); err != nil {
|
||||||
logrus.WithError(err).Errorf("failed to reset removing state for container %q", id)
|
log.G(ctx).WithError(err).Errorf("failed to reset removing state for container %q", id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -68,7 +67,7 @@ func (c *criService) RemoveContainer(ctx context.Context, r *runtime.RemoveConta
|
|||||||
if !errdefs.IsNotFound(err) {
|
if !errdefs.IsNotFound(err) {
|
||||||
return nil, errors.Wrapf(err, "failed to delete containerd container %q", id)
|
return nil, errors.Wrapf(err, "failed to delete containerd container %q", id)
|
||||||
}
|
}
|
||||||
log.Tracef("Remove called for containerd container %q that does not exist", id)
|
log.G(ctx).Tracef("Remove called for containerd container %q that does not exist", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete container checkpoint.
|
// Delete container checkpoint.
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
containerdio "github.com/containerd/containerd/cio"
|
containerdio "github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -65,11 +66,11 @@ func (c *criService) StartContainer(ctx context.Context, r *runtime.StartContain
|
|||||||
status.Message = retErr.Error()
|
status.Message = retErr.Error()
|
||||||
return status, nil
|
return status, nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
logrus.WithError(err).Errorf("failed to set start failure state for container %q", id)
|
log.G(ctx).WithError(err).Errorf("failed to set start failure state for container %q", id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := resetContainerStarting(cntr); err != nil {
|
if err := resetContainerStarting(cntr); err != nil {
|
||||||
logrus.WithError(err).Errorf("failed to reset starting state for container %q", id)
|
log.G(ctx).WithError(err).Errorf("failed to reset starting state for container %q", id)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -113,7 +114,7 @@ func (c *criService) StartContainer(ctx context.Context, r *runtime.StartContain
|
|||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
// It's possible that task is deleted by event monitor.
|
// It's possible that task is deleted by event monitor.
|
||||||
if _, err := task.Delete(deferCtx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {
|
if _, err := task.Delete(deferCtx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {
|
||||||
logrus.WithError(err).Errorf("Failed to delete containerd task %q", id)
|
log.G(ctx).WithError(err).Errorf("Failed to delete containerd task %q", id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -23,8 +23,8 @@ import (
|
|||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
eventtypes "github.com/containerd/containerd/api/events"
|
eventtypes "github.com/containerd/containerd/api/events"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ func (c *criService) stopContainer(ctx context.Context, container containerstore
|
|||||||
state := container.Status.Get().State()
|
state := container.Status.Get().State()
|
||||||
if state != runtime.ContainerState_CONTAINER_RUNNING &&
|
if state != runtime.ContainerState_CONTAINER_RUNNING &&
|
||||||
state != runtime.ContainerState_CONTAINER_UNKNOWN {
|
state != runtime.ContainerState_CONTAINER_UNKNOWN {
|
||||||
logrus.Infof("Container to stop %q must be in running or unknown state, current state %q",
|
log.G(ctx).Infof("Container to stop %q must be in running or unknown state, current state %q",
|
||||||
id, criContainerStateToString(state))
|
id, criContainerStateToString(state))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ func (c *criService) stopContainer(ctx context.Context, container containerstore
|
|||||||
if err != store.ErrNotExist {
|
if err != store.ErrNotExist {
|
||||||
return errors.Wrapf(err, "failed to get image %q", container.ImageRef)
|
return errors.Wrapf(err, "failed to get image %q", container.ImageRef)
|
||||||
}
|
}
|
||||||
logrus.Warningf("Image %q not found, stop container with signal %q", container.ImageRef, stopSignal)
|
log.G(ctx).Warningf("Image %q not found, stop container with signal %q", container.ImageRef, stopSignal)
|
||||||
} else {
|
} else {
|
||||||
if image.ImageSpec.Config.StopSignal != "" {
|
if image.ImageSpec.Config.StopSignal != "" {
|
||||||
stopSignal = image.ImageSpec.Config.StopSignal
|
stopSignal = image.ImageSpec.Config.StopSignal
|
||||||
@ -129,7 +129,7 @@ func (c *criService) stopContainer(ctx context.Context, container containerstore
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to parse stop signal %q", stopSignal)
|
return errors.Wrapf(err, "failed to parse stop signal %q", stopSignal)
|
||||||
}
|
}
|
||||||
logrus.Infof("Stop container %q with signal %v", id, sig)
|
log.G(ctx).Infof("Stop container %q with signal %v", id, sig)
|
||||||
if err = task.Kill(ctx, sig); err != nil && !errdefs.IsNotFound(err) {
|
if err = task.Kill(ctx, sig); err != nil && !errdefs.IsNotFound(err) {
|
||||||
return errors.Wrapf(err, "failed to stop container %q", id)
|
return errors.Wrapf(err, "failed to stop container %q", id)
|
||||||
}
|
}
|
||||||
@ -146,10 +146,10 @@ func (c *criService) stopContainer(ctx context.Context, container containerstore
|
|||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
// sigTermCtx was exceeded. Send SIGKILL
|
// sigTermCtx was exceeded. Send SIGKILL
|
||||||
logrus.Debugf("Stop container %q with signal %v timed out", id, sig)
|
log.G(ctx).Debugf("Stop container %q with signal %v timed out", id, sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("Kill container %q", id)
|
log.G(ctx).Infof("Kill container %q", id)
|
||||||
if err = task.Kill(ctx, syscall.SIGKILL); err != nil && !errdefs.IsNotFound(err) {
|
if err = task.Kill(ctx, syscall.SIGKILL); err != nil && !errdefs.IsNotFound(err) {
|
||||||
return errors.Wrapf(err, "failed to kill container %q", id)
|
return errors.Wrapf(err, "failed to kill container %q", id)
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,10 @@ import (
|
|||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ func (c *criService) updateContainerResources(ctx context.Context,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to get container spec")
|
return errors.Wrap(err, "failed to get container spec")
|
||||||
}
|
}
|
||||||
newSpec, err := updateOCILinuxResource(oldSpec, resources)
|
newSpec, err := updateOCILinuxResource(ctx, oldSpec, resources)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to update resource in spec")
|
return errors.Wrap(err, "failed to update resource in spec")
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ func (c *criService) updateContainerResources(ctx context.Context,
|
|||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
// Reset spec on error.
|
// Reset spec on error.
|
||||||
if err := updateContainerSpec(deferCtx, cntr.Container, oldSpec); err != nil {
|
if err := updateContainerSpec(deferCtx, cntr.Container, oldSpec); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to update spec %+v for container %q", oldSpec, id)
|
log.G(ctx).WithError(err).Errorf("Failed to update spec %+v for container %q", oldSpec, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -130,7 +130,7 @@ func updateContainerSpec(ctx context.Context, cntr containerd.Container, spec *r
|
|||||||
}
|
}
|
||||||
|
|
||||||
// updateOCILinuxResource updates container resource limit.
|
// updateOCILinuxResource updates container resource limit.
|
||||||
func updateOCILinuxResource(spec *runtimespec.Spec, new *runtime.LinuxContainerResources) (*runtimespec.Spec, error) {
|
func updateOCILinuxResource(ctx context.Context, spec *runtimespec.Spec, new *runtime.LinuxContainerResources) (*runtimespec.Spec, error) {
|
||||||
// Copy to make sure old spec is not changed.
|
// Copy to make sure old spec is not changed.
|
||||||
var cloned runtimespec.Spec
|
var cloned runtimespec.Spec
|
||||||
if err := util.DeepCopy(&cloned, spec); err != nil {
|
if err := util.DeepCopy(&cloned, spec); err != nil {
|
||||||
@ -139,7 +139,7 @@ func updateOCILinuxResource(spec *runtimespec.Spec, new *runtime.LinuxContainerR
|
|||||||
if cloned.Linux == nil {
|
if cloned.Linux == nil {
|
||||||
cloned.Linux = &runtimespec.Linux{}
|
cloned.Linux = &runtimespec.Linux{}
|
||||||
}
|
}
|
||||||
if err := opts.WithResources(new)(nil, nil, nil, &cloned); err != nil {
|
if err := opts.WithResources(new)(ctx, nil, nil, &cloned); err != nil {
|
||||||
return nil, errors.Wrap(err, "unable to set linux container resources")
|
return nil, errors.Wrap(err, "unable to set linux container resources")
|
||||||
}
|
}
|
||||||
return &cloned, nil
|
return &cloned, nil
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
@ -150,7 +151,7 @@ func TestUpdateOCILinuxResource(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
got, err := updateOCILinuxResource(test.spec, test.resources)
|
got, err := updateOCILinuxResource(context.Background(), test.spec, test.resources)
|
||||||
if test.expectErr {
|
if test.expectErr {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
@ -385,7 +386,7 @@ func TestEnvDeduplication(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, kv := range test.kv {
|
for _, kv := range test.kv {
|
||||||
oci.WithEnv([]string{kv[0] + "=" + kv[1]})(nil, nil, nil, &spec)
|
oci.WithEnv([]string{kv[0] + "=" + kv[1]})(context.Background(), nil, nil, &spec)
|
||||||
}
|
}
|
||||||
assert.Equal(t, test.expected, spec.Process.Env)
|
assert.Equal(t, test.expected, spec.Process.Env)
|
||||||
}
|
}
|
||||||
|
@ -30,16 +30,17 @@ import (
|
|||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
containerdimages "github.com/containerd/containerd/images"
|
containerdimages "github.com/containerd/containerd/images"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/reference"
|
"github.com/containerd/containerd/reference"
|
||||||
"github.com/containerd/containerd/remotes"
|
"github.com/containerd/containerd/remotes"
|
||||||
"github.com/containerd/containerd/remotes/docker"
|
"github.com/containerd/containerd/remotes/docker"
|
||||||
"github.com/containerd/cri/pkg/config"
|
|
||||||
distribution "github.com/docker/distribution/reference"
|
distribution "github.com/docker/distribution/reference"
|
||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
|
|
||||||
|
"github.com/containerd/cri/pkg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// For image management:
|
// For image management:
|
||||||
@ -92,7 +93,7 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
|
|||||||
}
|
}
|
||||||
ref := namedRef.String()
|
ref := namedRef.String()
|
||||||
if ref != imageRef {
|
if ref != imageRef {
|
||||||
logrus.Debugf("PullImage using normalized image ref: %q", ref)
|
log.G(ctx).Debugf("PullImage using normalized image ref: %q", ref)
|
||||||
}
|
}
|
||||||
resolver, desc, err := c.getResolver(ctx, ref, c.credentials(r.GetAuth()))
|
resolver, desc, err := c.getResolver(ctx, ref, c.credentials(r.GetAuth()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -136,7 +137,7 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf("Pulled image %q with image id %q, repo tag %q, repo digest %q", imageRef, imageID,
|
log.G(ctx).Debugf("Pulled image %q with image id %q, repo tag %q, repo digest %q", imageRef, imageID,
|
||||||
repoTag, repoDigest)
|
repoTag, repoDigest)
|
||||||
// NOTE(random-liu): the actual state in containerd is the source of truth, even we maintain
|
// NOTE(random-liu): the actual state in containerd is the source of truth, even we maintain
|
||||||
// in-memory image store, it's only for in-memory indexing. The image could be removed
|
// in-memory image store, it's only for in-memory indexing. The image could be removed
|
||||||
@ -317,7 +318,7 @@ func (c *criService) getResolver(ctx context.Context, ref string, cred func(stri
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return resolver, desc, nil
|
return resolver, desc, nil
|
||||||
}
|
}
|
||||||
logrus.WithError(err).Debugf("Tried registry mirror %q but failed", e)
|
log.G(ctx).WithError(err).Debugf("Tried registry mirror %q but failed", e)
|
||||||
// Continue to try next endpoint
|
// Continue to try next endpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,14 +19,14 @@ package server
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
|
|
||||||
"github.com/containerd/cri/pkg/store"
|
"github.com/containerd/cri/pkg/store"
|
||||||
imagestore "github.com/containerd/cri/pkg/store/image"
|
imagestore "github.com/containerd/cri/pkg/store/image"
|
||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImageStatus returns the status of the image, returns nil if the image isn't present.
|
// ImageStatus returns the status of the image, returns nil if the image isn't present.
|
||||||
@ -97,7 +97,7 @@ func (c *criService) toCRIImageInfo(ctx context.Context, image *imagestore.Image
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
info["info"] = string(m)
|
info["info"] = string(m)
|
||||||
} else {
|
} else {
|
||||||
logrus.WithError(err).Errorf("failed to marshal info %v", imi)
|
log.G(ctx).WithError(err).Errorf("failed to marshal info %v", imi)
|
||||||
info["info"] = err.Error()
|
info["info"] = err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,13 +19,12 @@ package server
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
|
|
||||||
"github.com/containerd/containerd/errdefs"
|
|
||||||
ctrdutil "github.com/containerd/cri/pkg/containerd/util"
|
ctrdutil "github.com/containerd/cri/pkg/containerd/util"
|
||||||
"github.com/containerd/cri/pkg/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// instrumentedService wraps service with containerd namespace and logs.
|
// instrumentedService wraps service with containerd namespace and logs.
|
||||||
@ -52,12 +51,12 @@ func (in *instrumentedService) RunPodSandbox(ctx context.Context, r *runtime.Run
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("RunPodsandbox for %+v", r.GetConfig().GetMetadata())
|
log.G(ctx).Infof("RunPodsandbox for %+v", r.GetConfig().GetMetadata())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("RunPodSandbox for %+v failed, error", r.GetConfig().GetMetadata())
|
log.G(ctx).WithError(err).Errorf("RunPodSandbox for %+v failed, error", r.GetConfig().GetMetadata())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("RunPodSandbox for %+v returns sandbox id %q", r.GetConfig().GetMetadata(), res.GetPodSandboxId())
|
log.G(ctx).Infof("RunPodSandbox for %+v returns sandbox id %q", r.GetConfig().GetMetadata(), res.GetPodSandboxId())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.RunPodSandbox(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.RunPodSandbox(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -68,12 +67,12 @@ func (in *instrumentedService) ListPodSandbox(ctx context.Context, r *runtime.Li
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Tracef("ListPodSandbox with filter %+v", r.GetFilter())
|
log.G(ctx).Tracef("ListPodSandbox with filter %+v", r.GetFilter())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("ListPodSandbox failed")
|
log.G(ctx).WithError(err).Error("ListPodSandbox failed")
|
||||||
} else {
|
} else {
|
||||||
log.Tracef("ListPodSandbox returns pod sandboxes %+v", res.GetItems())
|
log.G(ctx).Tracef("ListPodSandbox returns pod sandboxes %+v", res.GetItems())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.ListPodSandbox(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.ListPodSandbox(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -84,12 +83,12 @@ func (in *instrumentedService) PodSandboxStatus(ctx context.Context, r *runtime.
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Tracef("PodSandboxStatus for %q", r.GetPodSandboxId())
|
log.G(ctx).Tracef("PodSandboxStatus for %q", r.GetPodSandboxId())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("PodSandboxStatus for %q failed", r.GetPodSandboxId())
|
log.G(ctx).WithError(err).Errorf("PodSandboxStatus for %q failed", r.GetPodSandboxId())
|
||||||
} else {
|
} else {
|
||||||
log.Tracef("PodSandboxStatus for %q returns status %+v", r.GetPodSandboxId(), res.GetStatus())
|
log.G(ctx).Tracef("PodSandboxStatus for %q returns status %+v", r.GetPodSandboxId(), res.GetStatus())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.PodSandboxStatus(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.PodSandboxStatus(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -100,12 +99,12 @@ func (in *instrumentedService) StopPodSandbox(ctx context.Context, r *runtime.St
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("StopPodSandbox for %q", r.GetPodSandboxId())
|
log.G(ctx).Infof("StopPodSandbox for %q", r.GetPodSandboxId())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("StopPodSandbox for %q failed", r.GetPodSandboxId())
|
log.G(ctx).WithError(err).Errorf("StopPodSandbox for %q failed", r.GetPodSandboxId())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("StopPodSandbox for %q returns successfully", r.GetPodSandboxId())
|
log.G(ctx).Infof("StopPodSandbox for %q returns successfully", r.GetPodSandboxId())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err := in.c.StopPodSandbox(ctrdutil.WithNamespace(ctx), r)
|
res, err := in.c.StopPodSandbox(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -116,12 +115,12 @@ func (in *instrumentedService) RemovePodSandbox(ctx context.Context, r *runtime.
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("RemovePodSandbox for %q", r.GetPodSandboxId())
|
log.G(ctx).Infof("RemovePodSandbox for %q", r.GetPodSandboxId())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("RemovePodSandbox for %q failed", r.GetPodSandboxId())
|
log.G(ctx).WithError(err).Errorf("RemovePodSandbox for %q failed", r.GetPodSandboxId())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("RemovePodSandbox %q returns successfully", r.GetPodSandboxId())
|
log.G(ctx).Infof("RemovePodSandbox %q returns successfully", r.GetPodSandboxId())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err := in.c.RemovePodSandbox(ctrdutil.WithNamespace(ctx), r)
|
res, err := in.c.RemovePodSandbox(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -132,12 +131,12 @@ func (in *instrumentedService) PortForward(ctx context.Context, r *runtime.PortF
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("Portforward for %q port %v", r.GetPodSandboxId(), r.GetPort())
|
log.G(ctx).Infof("Portforward for %q port %v", r.GetPodSandboxId(), r.GetPort())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Portforward for %q failed", r.GetPodSandboxId())
|
log.G(ctx).WithError(err).Errorf("Portforward for %q failed", r.GetPodSandboxId())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("Portforward for %q returns URL %q", r.GetPodSandboxId(), res.GetUrl())
|
log.G(ctx).Infof("Portforward for %q returns URL %q", r.GetPodSandboxId(), res.GetUrl())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.PortForward(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.PortForward(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -148,14 +147,14 @@ func (in *instrumentedService) CreateContainer(ctx context.Context, r *runtime.C
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("CreateContainer within sandbox %q for container %+v",
|
log.G(ctx).Infof("CreateContainer within sandbox %q for container %+v",
|
||||||
r.GetPodSandboxId(), r.GetConfig().GetMetadata())
|
r.GetPodSandboxId(), r.GetConfig().GetMetadata())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("CreateContainer within sandbox %q for %+v failed",
|
log.G(ctx).WithError(err).Errorf("CreateContainer within sandbox %q for %+v failed",
|
||||||
r.GetPodSandboxId(), r.GetConfig().GetMetadata())
|
r.GetPodSandboxId(), r.GetConfig().GetMetadata())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("CreateContainer within sandbox %q for %+v returns container id %q",
|
log.G(ctx).Infof("CreateContainer within sandbox %q for %+v returns container id %q",
|
||||||
r.GetPodSandboxId(), r.GetConfig().GetMetadata(), res.GetContainerId())
|
r.GetPodSandboxId(), r.GetConfig().GetMetadata(), res.GetContainerId())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -167,12 +166,12 @@ func (in *instrumentedService) StartContainer(ctx context.Context, r *runtime.St
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("StartContainer for %q", r.GetContainerId())
|
log.G(ctx).Infof("StartContainer for %q", r.GetContainerId())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("StartContainer for %q failed", r.GetContainerId())
|
log.G(ctx).WithError(err).Errorf("StartContainer for %q failed", r.GetContainerId())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("StartContainer for %q returns successfully", r.GetContainerId())
|
log.G(ctx).Infof("StartContainer for %q returns successfully", r.GetContainerId())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err := in.c.StartContainer(ctrdutil.WithNamespace(ctx), r)
|
res, err := in.c.StartContainer(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -183,12 +182,12 @@ func (in *instrumentedService) ListContainers(ctx context.Context, r *runtime.Li
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Tracef("ListContainers with filter %+v", r.GetFilter())
|
log.G(ctx).Tracef("ListContainers with filter %+v", r.GetFilter())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("ListContainers with filter %+v failed", r.GetFilter())
|
log.G(ctx).WithError(err).Errorf("ListContainers with filter %+v failed", r.GetFilter())
|
||||||
} else {
|
} else {
|
||||||
log.Tracef("ListContainers with filter %+v returns containers %+v",
|
log.G(ctx).Tracef("ListContainers with filter %+v returns containers %+v",
|
||||||
r.GetFilter(), res.GetContainers())
|
r.GetFilter(), res.GetContainers())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -200,12 +199,12 @@ func (in *instrumentedService) ContainerStatus(ctx context.Context, r *runtime.C
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Tracef("ContainerStatus for %q", r.GetContainerId())
|
log.G(ctx).Tracef("ContainerStatus for %q", r.GetContainerId())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("ContainerStatus for %q failed", r.GetContainerId())
|
log.G(ctx).WithError(err).Errorf("ContainerStatus for %q failed", r.GetContainerId())
|
||||||
} else {
|
} else {
|
||||||
log.Tracef("ContainerStatus for %q returns status %+v", r.GetContainerId(), res.GetStatus())
|
log.G(ctx).Tracef("ContainerStatus for %q returns status %+v", r.GetContainerId(), res.GetStatus())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.ContainerStatus(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.ContainerStatus(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -216,12 +215,12 @@ func (in *instrumentedService) StopContainer(ctx context.Context, r *runtime.Sto
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("StopContainer for %q with timeout %d (s)", r.GetContainerId(), r.GetTimeout())
|
log.G(ctx).Infof("StopContainer for %q with timeout %d (s)", r.GetContainerId(), r.GetTimeout())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("StopContainer for %q failed", r.GetContainerId())
|
log.G(ctx).WithError(err).Errorf("StopContainer for %q failed", r.GetContainerId())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("StopContainer for %q returns successfully", r.GetContainerId())
|
log.G(ctx).Infof("StopContainer for %q returns successfully", r.GetContainerId())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.StopContainer(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.StopContainer(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -232,12 +231,12 @@ func (in *instrumentedService) RemoveContainer(ctx context.Context, r *runtime.R
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("RemoveContainer for %q", r.GetContainerId())
|
log.G(ctx).Infof("RemoveContainer for %q", r.GetContainerId())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("RemoveContainer for %q failed", r.GetContainerId())
|
log.G(ctx).WithError(err).Errorf("RemoveContainer for %q failed", r.GetContainerId())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("RemoveContainer for %q returns successfully", r.GetContainerId())
|
log.G(ctx).Infof("RemoveContainer for %q returns successfully", r.GetContainerId())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.RemoveContainer(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.RemoveContainer(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -248,13 +247,13 @@ func (in *instrumentedService) ExecSync(ctx context.Context, r *runtime.ExecSync
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("ExecSync for %q with command %+v and timeout %d (s)", r.GetContainerId(), r.GetCmd(), r.GetTimeout())
|
log.G(ctx).Infof("ExecSync for %q with command %+v and timeout %d (s)", r.GetContainerId(), r.GetCmd(), r.GetTimeout())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("ExecSync for %q failed", r.GetContainerId())
|
log.G(ctx).WithError(err).Errorf("ExecSync for %q failed", r.GetContainerId())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("ExecSync for %q returns with exit code %d", r.GetContainerId(), res.GetExitCode())
|
log.G(ctx).Infof("ExecSync for %q returns with exit code %d", r.GetContainerId(), res.GetExitCode())
|
||||||
logrus.Debugf("ExecSync for %q outputs - stdout: %q, stderr: %q", r.GetContainerId(),
|
log.G(ctx).Debugf("ExecSync for %q outputs - stdout: %q, stderr: %q", r.GetContainerId(),
|
||||||
res.GetStdout(), res.GetStderr())
|
res.GetStdout(), res.GetStderr())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -266,13 +265,13 @@ func (in *instrumentedService) Exec(ctx context.Context, r *runtime.ExecRequest)
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("Exec for %q with command %+v, tty %v and stdin %v",
|
log.G(ctx).Infof("Exec for %q with command %+v, tty %v and stdin %v",
|
||||||
r.GetContainerId(), r.GetCmd(), r.GetTty(), r.GetStdin())
|
r.GetContainerId(), r.GetCmd(), r.GetTty(), r.GetStdin())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Exec for %q failed", r.GetContainerId())
|
log.G(ctx).WithError(err).Errorf("Exec for %q failed", r.GetContainerId())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("Exec for %q returns URL %q", r.GetContainerId(), res.GetUrl())
|
log.G(ctx).Infof("Exec for %q returns URL %q", r.GetContainerId(), res.GetUrl())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.Exec(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.Exec(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -283,12 +282,12 @@ func (in *instrumentedService) Attach(ctx context.Context, r *runtime.AttachRequ
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("Attach for %q with tty %v and stdin %v", r.GetContainerId(), r.GetTty(), r.GetStdin())
|
log.G(ctx).Infof("Attach for %q with tty %v and stdin %v", r.GetContainerId(), r.GetTty(), r.GetStdin())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Attach for %q failed", r.GetContainerId())
|
log.G(ctx).WithError(err).Errorf("Attach for %q failed", r.GetContainerId())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("Attach for %q returns URL %q", r.GetContainerId(), res.Url)
|
log.G(ctx).Infof("Attach for %q returns URL %q", r.GetContainerId(), res.Url)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.Attach(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.Attach(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -299,12 +298,12 @@ func (in *instrumentedService) UpdateContainerResources(ctx context.Context, r *
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("UpdateContainerResources for %q with %+v", r.GetContainerId(), r.GetLinux())
|
log.G(ctx).Infof("UpdateContainerResources for %q with %+v", r.GetContainerId(), r.GetLinux())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("UpdateContainerResources for %q failed", r.GetContainerId())
|
log.G(ctx).WithError(err).Errorf("UpdateContainerResources for %q failed", r.GetContainerId())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("UpdateContainerResources for %q returns successfully", r.GetContainerId())
|
log.G(ctx).Infof("UpdateContainerResources for %q returns successfully", r.GetContainerId())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.UpdateContainerResources(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.UpdateContainerResources(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -315,12 +314,12 @@ func (in *instrumentedService) PullImage(ctx context.Context, r *runtime.PullIma
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("PullImage %q", r.GetImage().GetImage())
|
log.G(ctx).Infof("PullImage %q", r.GetImage().GetImage())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("PullImage %q failed", r.GetImage().GetImage())
|
log.G(ctx).WithError(err).Errorf("PullImage %q failed", r.GetImage().GetImage())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("PullImage %q returns image reference %q",
|
log.G(ctx).Infof("PullImage %q returns image reference %q",
|
||||||
r.GetImage().GetImage(), res.GetImageRef())
|
r.GetImage().GetImage(), res.GetImageRef())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -332,12 +331,12 @@ func (in *instrumentedService) ListImages(ctx context.Context, r *runtime.ListIm
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Tracef("ListImages with filter %+v", r.GetFilter())
|
log.G(ctx).Tracef("ListImages with filter %+v", r.GetFilter())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("ListImages with filter %+v failed", r.GetFilter())
|
log.G(ctx).WithError(err).Errorf("ListImages with filter %+v failed", r.GetFilter())
|
||||||
} else {
|
} else {
|
||||||
log.Tracef("ListImages with filter %+v returns image list %+v",
|
log.G(ctx).Tracef("ListImages with filter %+v returns image list %+v",
|
||||||
r.GetFilter(), res.GetImages())
|
r.GetFilter(), res.GetImages())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -349,12 +348,12 @@ func (in *instrumentedService) ImageStatus(ctx context.Context, r *runtime.Image
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Tracef("ImageStatus for %q", r.GetImage().GetImage())
|
log.G(ctx).Tracef("ImageStatus for %q", r.GetImage().GetImage())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("ImageStatus for %q failed", r.GetImage().GetImage())
|
log.G(ctx).WithError(err).Errorf("ImageStatus for %q failed", r.GetImage().GetImage())
|
||||||
} else {
|
} else {
|
||||||
log.Tracef("ImageStatus for %q returns image status %+v",
|
log.G(ctx).Tracef("ImageStatus for %q returns image status %+v",
|
||||||
r.GetImage().GetImage(), res.GetImage())
|
r.GetImage().GetImage(), res.GetImage())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -366,12 +365,12 @@ func (in *instrumentedService) RemoveImage(ctx context.Context, r *runtime.Remov
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Infof("RemoveImage %q", r.GetImage().GetImage())
|
log.G(ctx).Infof("RemoveImage %q", r.GetImage().GetImage())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("RemoveImage %q failed", r.GetImage().GetImage())
|
log.G(ctx).WithError(err).Errorf("RemoveImage %q failed", r.GetImage().GetImage())
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("RemoveImage %q returns successfully", r.GetImage().GetImage())
|
log.G(ctx).Infof("RemoveImage %q returns successfully", r.GetImage().GetImage())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err := in.c.RemoveImage(ctrdutil.WithNamespace(ctx), r)
|
res, err := in.c.RemoveImage(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -382,12 +381,12 @@ func (in *instrumentedService) ImageFsInfo(ctx context.Context, r *runtime.Image
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Debugf("ImageFsInfo")
|
log.G(ctx).Debugf("ImageFsInfo")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("ImageFsInfo failed")
|
log.G(ctx).WithError(err).Error("ImageFsInfo failed")
|
||||||
} else {
|
} else {
|
||||||
logrus.Debugf("ImageFsInfo returns filesystem info %+v", res.ImageFilesystems)
|
log.G(ctx).Debugf("ImageFsInfo returns filesystem info %+v", res.ImageFilesystems)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.ImageFsInfo(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.ImageFsInfo(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -398,12 +397,12 @@ func (in *instrumentedService) ContainerStats(ctx context.Context, r *runtime.Co
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Debugf("ContainerStats for %q", r.GetContainerId())
|
log.G(ctx).Debugf("ContainerStats for %q", r.GetContainerId())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("ContainerStats for %q failed", r.GetContainerId())
|
log.G(ctx).WithError(err).Errorf("ContainerStats for %q failed", r.GetContainerId())
|
||||||
} else {
|
} else {
|
||||||
logrus.Debugf("ContainerStats for %q returns stats %+v", r.GetContainerId(), res.GetStats())
|
log.G(ctx).Debugf("ContainerStats for %q returns stats %+v", r.GetContainerId(), res.GetStats())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.ContainerStats(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.ContainerStats(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -414,12 +413,12 @@ func (in *instrumentedService) ListContainerStats(ctx context.Context, r *runtim
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Tracef("ListContainerStats with filter %+v", r.GetFilter())
|
log.G(ctx).Tracef("ListContainerStats with filter %+v", r.GetFilter())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("ListContainerStats failed")
|
log.G(ctx).WithError(err).Error("ListContainerStats failed")
|
||||||
} else {
|
} else {
|
||||||
log.Tracef("ListContainerStats returns stats %+v", res.GetStats())
|
log.G(ctx).Tracef("ListContainerStats returns stats %+v", res.GetStats())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.ListContainerStats(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.ListContainerStats(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -430,12 +429,12 @@ func (in *instrumentedService) Status(ctx context.Context, r *runtime.StatusRequ
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Tracef("Status")
|
log.G(ctx).Tracef("Status")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("Status failed")
|
log.G(ctx).WithError(err).Error("Status failed")
|
||||||
} else {
|
} else {
|
||||||
log.Tracef("Status returns status %+v", res.GetStatus())
|
log.G(ctx).Tracef("Status returns status %+v", res.GetStatus())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.Status(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.Status(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -446,12 +445,12 @@ func (in *instrumentedService) Version(ctx context.Context, r *runtime.VersionRe
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Tracef("Version with client side version %q", r.GetVersion())
|
log.G(ctx).Tracef("Version with client side version %q", r.GetVersion())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("Version failed")
|
log.G(ctx).WithError(err).Error("Version failed")
|
||||||
} else {
|
} else {
|
||||||
log.Tracef("Version returns %+v", res)
|
log.G(ctx).Tracef("Version returns %+v", res)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.Version(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.Version(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -462,12 +461,12 @@ func (in *instrumentedService) UpdateRuntimeConfig(ctx context.Context, r *runti
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Debugf("UpdateRuntimeConfig with config %+v", r.GetRuntimeConfig())
|
log.G(ctx).Debugf("UpdateRuntimeConfig with config %+v", r.GetRuntimeConfig())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("UpdateRuntimeConfig failed")
|
log.G(ctx).WithError(err).Error("UpdateRuntimeConfig failed")
|
||||||
} else {
|
} else {
|
||||||
logrus.Debug("UpdateRuntimeConfig returns returns successfully")
|
log.G(ctx).Debug("UpdateRuntimeConfig returns returns successfully")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.UpdateRuntimeConfig(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.UpdateRuntimeConfig(ctrdutil.WithNamespace(ctx), r)
|
||||||
@ -478,12 +477,12 @@ func (in *instrumentedService) ReopenContainerLog(ctx context.Context, r *runtim
|
|||||||
if err := in.checkInitialized(); err != nil {
|
if err := in.checkInitialized(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logrus.Debugf("ReopenContainerLog for %q", r.GetContainerId())
|
log.G(ctx).Debugf("ReopenContainerLog for %q", r.GetContainerId())
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("ReopenContainerLog for %q failed", r.GetContainerId())
|
log.G(ctx).WithError(err).Errorf("ReopenContainerLog for %q failed", r.GetContainerId())
|
||||||
} else {
|
} else {
|
||||||
logrus.Debugf("ReopenContainerLog for %q returns successfully", r.GetContainerId())
|
log.G(ctx).Debugf("ReopenContainerLog for %q returns successfully", r.GetContainerId())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res, err = in.c.ReopenContainerLog(ctrdutil.WithNamespace(ctx), r)
|
res, err = in.c.ReopenContainerLog(ctrdutil.WithNamespace(ctx), r)
|
||||||
|
@ -26,11 +26,11 @@ import (
|
|||||||
containerdio "github.com/containerd/containerd/cio"
|
containerdio "github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
containerdimages "github.com/containerd/containerd/images"
|
containerdimages "github.com/containerd/containerd/images"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/platforms"
|
"github.com/containerd/containerd/platforms"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
|
|
||||||
@ -60,10 +60,10 @@ func (c *criService) recover(ctx context.Context) error {
|
|||||||
for _, sandbox := range sandboxes {
|
for _, sandbox := range sandboxes {
|
||||||
sb, err := c.loadSandbox(ctx, sandbox)
|
sb, err := c.loadSandbox(ctx, sandbox)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to load sandbox %q", sandbox.ID())
|
log.G(ctx).WithError(err).Errorf("Failed to load sandbox %q", sandbox.ID())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
logrus.Debugf("Loaded sandbox %+v", sb)
|
log.G(ctx).Debugf("Loaded sandbox %+v", sb)
|
||||||
if err := c.sandboxStore.Add(sb); err != nil {
|
if err := c.sandboxStore.Add(sb); err != nil {
|
||||||
return errors.Wrapf(err, "failed to add sandbox %q to store", sandbox.ID())
|
return errors.Wrapf(err, "failed to add sandbox %q to store", sandbox.ID())
|
||||||
}
|
}
|
||||||
@ -80,10 +80,10 @@ func (c *criService) recover(ctx context.Context) error {
|
|||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
cntr, err := c.loadContainer(ctx, container)
|
cntr, err := c.loadContainer(ctx, container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to load container %q", container.ID())
|
log.G(ctx).WithError(err).Errorf("Failed to load container %q", container.ID())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
logrus.Debugf("Loaded container %+v", cntr)
|
log.G(ctx).Debugf("Loaded container %+v", cntr)
|
||||||
if err := c.containerStore.Add(cntr); err != nil {
|
if err := c.containerStore.Add(cntr); err != nil {
|
||||||
return errors.Wrapf(err, "failed to add container %q to store", container.ID())
|
return errors.Wrapf(err, "failed to add container %q to store", container.ID())
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ func (c *criService) recover(ctx context.Context) error {
|
|||||||
errMsg: "failed to cleanup orphaned volatile container directories",
|
errMsg: "failed to cleanup orphaned volatile container directories",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
if err := cleanupOrphanedIDDirs(cleanup.cntrs, cleanup.base); err != nil {
|
if err := cleanupOrphanedIDDirs(ctx, cleanup.cntrs, cleanup.base); err != nil {
|
||||||
return errors.Wrap(err, cleanup.errMsg)
|
return errors.Wrap(err, cleanup.errMsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ func (c *criService) loadContainer(ctx context.Context, cntr containerd.Containe
|
|||||||
// Load status from checkpoint.
|
// Load status from checkpoint.
|
||||||
status, err := containerstore.LoadStatus(containerDir, id)
|
status, err := containerstore.LoadStatus(containerDir, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Warnf("Failed to load container status for %q", id)
|
log.G(ctx).WithError(err).Warnf("Failed to load container status for %q", id)
|
||||||
status = unknownContainerStatus()
|
status = unknownContainerStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ func (c *criService) loadContainer(ctx context.Context, cntr containerd.Containe
|
|||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to load container status for %q", id)
|
log.G(ctx).WithError(err).Errorf("Failed to load container status for %q", id)
|
||||||
status = unknownContainerStatus()
|
status = unknownContainerStatus()
|
||||||
}
|
}
|
||||||
opts := []containerstore.Opts{
|
opts := []containerstore.Opts{
|
||||||
@ -400,7 +400,7 @@ func (c *criService) loadSandbox(ctx context.Context, cntr containerd.Container)
|
|||||||
return status, nil
|
return status, nil
|
||||||
}()
|
}()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to load sandbox status for %q", cntr.ID())
|
log.G(ctx).WithError(err).Errorf("Failed to load sandbox status for %q", cntr.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
sandbox = sandboxstore.NewSandbox(*meta, s)
|
sandbox = sandboxstore.NewSandbox(*meta, s)
|
||||||
@ -425,32 +425,32 @@ func (c *criService) loadImages(ctx context.Context, cImages []containerd.Image)
|
|||||||
for _, i := range cImages {
|
for _, i := range cImages {
|
||||||
ok, _, _, _, err := containerdimages.Check(ctx, i.ContentStore(), i.Target(), platforms.Default())
|
ok, _, _, _, err := containerdimages.Check(ctx, i.ContentStore(), i.Target(), platforms.Default())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to check image content readiness for %q", i.Name())
|
log.G(ctx).WithError(err).Errorf("Failed to check image content readiness for %q", i.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
logrus.Warnf("The image content readiness for %q is not ok", i.Name())
|
log.G(ctx).Warnf("The image content readiness for %q is not ok", i.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Checking existence of top-level snapshot for each image being recovered.
|
// Checking existence of top-level snapshot for each image being recovered.
|
||||||
unpacked, err := i.IsUnpacked(ctx, snapshotter)
|
unpacked, err := i.IsUnpacked(ctx, snapshotter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Warnf("Failed to check whether image is unpacked for image %s", i.Name())
|
log.G(ctx).WithError(err).Warnf("Failed to check whether image is unpacked for image %s", i.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !unpacked {
|
if !unpacked {
|
||||||
logrus.Warnf("The image %s is not unpacked.", i.Name())
|
log.G(ctx).Warnf("The image %s is not unpacked.", i.Name())
|
||||||
// TODO(random-liu): Consider whether we should try unpack here.
|
// TODO(random-liu): Consider whether we should try unpack here.
|
||||||
}
|
}
|
||||||
if err := c.updateImage(ctx, i.Name()); err != nil {
|
if err := c.updateImage(ctx, i.Name()); err != nil {
|
||||||
logrus.WithError(err).Warnf("Failed to update reference for image %q", i.Name())
|
log.G(ctx).WithError(err).Warnf("Failed to update reference for image %q", i.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
logrus.Debugf("Loaded image %q", i.Name())
|
log.G(ctx).Debugf("Loaded image %q", i.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanupOrphanedIDDirs(cntrs []containerd.Container, base string) error {
|
func cleanupOrphanedIDDirs(ctx context.Context, cntrs []containerd.Container, base string) error {
|
||||||
// Cleanup orphaned id directories.
|
// Cleanup orphaned id directories.
|
||||||
dirs, err := ioutil.ReadDir(base)
|
dirs, err := ioutil.ReadDir(base)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
@ -462,7 +462,7 @@ func cleanupOrphanedIDDirs(cntrs []containerd.Container, base string) error {
|
|||||||
}
|
}
|
||||||
for _, d := range dirs {
|
for _, d := range dirs {
|
||||||
if !d.IsDir() {
|
if !d.IsDir() {
|
||||||
logrus.Warnf("Invalid file %q found in base directory %q", d.Name(), base)
|
log.G(ctx).Warnf("Invalid file %q found in base directory %q", d.Name(), base)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, ok := idsMap[d.Name()]; ok {
|
if _, ok := idsMap[d.Name()]; ok {
|
||||||
@ -471,9 +471,9 @@ func cleanupOrphanedIDDirs(cntrs []containerd.Container, base string) error {
|
|||||||
}
|
}
|
||||||
dir := filepath.Join(base, d.Name())
|
dir := filepath.Join(base, d.Name())
|
||||||
if err := system.EnsureRemoveAll(dir); err != nil {
|
if err := system.EnsureRemoveAll(dir); err != nil {
|
||||||
logrus.WithError(err).Warnf("Failed to remove id directory %q", dir)
|
log.G(ctx).WithError(err).Warnf("Failed to remove id directory %q", dir)
|
||||||
} else {
|
} else {
|
||||||
logrus.Debugf("Cleanup orphaned id directory %q", dir)
|
log.G(ctx).Debugf("Cleanup orphaned id directory %q", dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -48,7 +49,7 @@ func (c *criService) PortForward(ctx context.Context, r *runtime.PortForwardRequ
|
|||||||
// portForward requires `socat` on the node. It uses netns to enter the sandbox namespace,
|
// portForward requires `socat` on the node. It uses netns to enter the sandbox namespace,
|
||||||
// and run `socat` insidethe namespace to forward stream for a specific port. The `socat`
|
// and run `socat` insidethe namespace to forward stream for a specific port. The `socat`
|
||||||
// command keeps running until it exits or client disconnect.
|
// command keeps running until it exits or client disconnect.
|
||||||
func (c *criService) portForward(id string, port int32, stream io.ReadWriteCloser) error {
|
func (c *criService) portForward(ctx context.Context, id string, port int32, stream io.ReadWriter) error {
|
||||||
s, err := c.sandboxStore.Get(id)
|
s, err := c.sandboxStore.Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to find sandbox %q in store", id)
|
return errors.Wrapf(err, "failed to find sandbox %q in store", id)
|
||||||
@ -82,7 +83,7 @@ func (c *criService) portForward(id string, port int32, stream io.ReadWriteClose
|
|||||||
// Check https://linux.die.net/man/1/socat for meaning of the options.
|
// Check https://linux.die.net/man/1/socat for meaning of the options.
|
||||||
args := []string{socat, "-", fmt.Sprintf("TCP4:localhost:%d", port)}
|
args := []string{socat, "-", fmt.Sprintf("TCP4:localhost:%d", port)}
|
||||||
|
|
||||||
logrus.Infof("Executing port forwarding command %q in network namespace %q", strings.Join(args, " "), netNSPath)
|
log.G(ctx).Infof("Executing port forwarding command %q in network namespace %q", strings.Join(args, " "), netNSPath)
|
||||||
err = netNSDo(func(_ ns.NetNS) error {
|
err = netNSDo(func(_ ns.NetNS) error {
|
||||||
cmd := exec.Command(args[0], args[1:]...)
|
cmd := exec.Command(args[0], args[1:]...)
|
||||||
cmd.Stdout = stream
|
cmd.Stdout = stream
|
||||||
@ -119,7 +120,7 @@ func (c *criService) portForward(id string, port int32, stream io.ReadWriteClose
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to execute portforward in network namespace %q", netNSPath)
|
return errors.Wrapf(err, "failed to execute portforward in network namespace %q", netNSPath)
|
||||||
}
|
}
|
||||||
logrus.Infof("Finish port forwarding for %q port %d", id, port)
|
log.G(ctx).Infof("Finish port forwarding for %q port %d", id, port)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,12 @@ package server
|
|||||||
import (
|
import (
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
|
|
||||||
"github.com/containerd/cri/pkg/log"
|
|
||||||
"github.com/containerd/cri/pkg/store"
|
"github.com/containerd/cri/pkg/store"
|
||||||
sandboxstore "github.com/containerd/cri/pkg/store/sandbox"
|
sandboxstore "github.com/containerd/cri/pkg/store/sandbox"
|
||||||
)
|
)
|
||||||
@ -39,7 +39,7 @@ func (c *criService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS
|
|||||||
r.GetPodSandboxId())
|
r.GetPodSandboxId())
|
||||||
}
|
}
|
||||||
// Do not return error if the id doesn't exist.
|
// Do not return error if the id doesn't exist.
|
||||||
log.Tracef("RemovePodSandbox called for sandbox %q that does not exist",
|
log.G(ctx).Tracef("RemovePodSandbox called for sandbox %q that does not exist",
|
||||||
r.GetPodSandboxId())
|
r.GetPodSandboxId())
|
||||||
return &runtime.RemovePodSandboxResponse{}, nil
|
return &runtime.RemovePodSandboxResponse{}, nil
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ func (c *criService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS
|
|||||||
if !errdefs.IsNotFound(err) {
|
if !errdefs.IsNotFound(err) {
|
||||||
return nil, errors.Wrapf(err, "failed to delete sandbox container %q", id)
|
return nil, errors.Wrapf(err, "failed to delete sandbox container %q", id)
|
||||||
}
|
}
|
||||||
log.Tracef("Remove called for sandbox container %q that does not exist", id)
|
log.G(ctx).Tracef("Remove called for sandbox container %q that does not exist", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove sandbox from sandbox store. Note that once the sandbox is successfully
|
// Remove sandbox from sandbox store. Note that once the sandbox is successfully
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
containerdio "github.com/containerd/containerd/cio"
|
containerdio "github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/oci"
|
"github.com/containerd/containerd/oci"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
cni "github.com/containerd/go-cni"
|
cni "github.com/containerd/go-cni"
|
||||||
@ -44,7 +45,6 @@ import (
|
|||||||
criconfig "github.com/containerd/cri/pkg/config"
|
criconfig "github.com/containerd/cri/pkg/config"
|
||||||
customopts "github.com/containerd/cri/pkg/containerd/opts"
|
customopts "github.com/containerd/cri/pkg/containerd/opts"
|
||||||
ctrdutil "github.com/containerd/cri/pkg/containerd/util"
|
ctrdutil "github.com/containerd/cri/pkg/containerd/util"
|
||||||
"github.com/containerd/cri/pkg/log"
|
|
||||||
"github.com/containerd/cri/pkg/netns"
|
"github.com/containerd/cri/pkg/netns"
|
||||||
sandboxstore "github.com/containerd/cri/pkg/store/sandbox"
|
sandboxstore "github.com/containerd/cri/pkg/store/sandbox"
|
||||||
"github.com/containerd/cri/pkg/util"
|
"github.com/containerd/cri/pkg/util"
|
||||||
@ -59,7 +59,7 @@ func init() {
|
|||||||
// the sandbox is in ready state.
|
// the sandbox is in ready state.
|
||||||
func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandboxRequest) (_ *runtime.RunPodSandboxResponse, retErr error) {
|
func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandboxRequest) (_ *runtime.RunPodSandboxResponse, retErr error) {
|
||||||
config := r.GetConfig()
|
config := r.GetConfig()
|
||||||
logrus.Debugf("Sandbox config %+v", config)
|
log.G(ctx).Debugf("Sandbox config %+v", config)
|
||||||
|
|
||||||
// Generate unique id and name for the sandbox and reserve the name.
|
// Generate unique id and name for the sandbox and reserve the name.
|
||||||
id := util.GenerateID()
|
id := util.GenerateID()
|
||||||
@ -68,7 +68,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
return nil, errors.New("sandbox config must include metadata")
|
return nil, errors.New("sandbox config must include metadata")
|
||||||
}
|
}
|
||||||
name := makeSandboxName(metadata)
|
name := makeSandboxName(metadata)
|
||||||
logrus.Debugf("Generated id %q for sandbox %q", id, name)
|
log.G(ctx).Debugf("Generated id %q for sandbox %q", id, name)
|
||||||
// Reserve the sandbox name to avoid concurrent `RunPodSandbox` request starting the
|
// Reserve the sandbox name to avoid concurrent `RunPodSandbox` request starting the
|
||||||
// same sandbox.
|
// same sandbox.
|
||||||
if err := c.sandboxNameIndex.Reserve(name, id); err != nil {
|
if err := c.sandboxNameIndex.Reserve(name, id); err != nil {
|
||||||
@ -108,7 +108,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to get sandbox runtime")
|
return nil, errors.Wrap(err, "failed to get sandbox runtime")
|
||||||
}
|
}
|
||||||
logrus.Debugf("Use OCI %+v for sandbox %q", ociRuntime, id)
|
log.G(ctx).Debugf("Use OCI %+v for sandbox %q", ociRuntime, id)
|
||||||
|
|
||||||
securityContext := config.GetLinux().GetSecurityContext()
|
securityContext := config.GetLinux().GetSecurityContext()
|
||||||
//Create Network Namespace if it is not in host network
|
//Create Network Namespace if it is not in host network
|
||||||
@ -126,7 +126,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
defer func() {
|
defer func() {
|
||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
if err := sandbox.NetNS.Remove(); err != nil {
|
if err := sandbox.NetNS.Remove(); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to remove network namespace %s for sandbox %q", sandbox.NetNSPath, id)
|
log.G(ctx).WithError(err).Errorf("Failed to remove network namespace %s for sandbox %q", sandbox.NetNSPath, id)
|
||||||
}
|
}
|
||||||
sandbox.NetNSPath = ""
|
sandbox.NetNSPath = ""
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
// In this case however caching the IP will add a subtle performance enhancement by avoiding
|
// In this case however caching the IP will add a subtle performance enhancement by avoiding
|
||||||
// calls to network namespace of the pod to query the IP of the veth interface on every
|
// calls to network namespace of the pod to query the IP of the veth interface on every
|
||||||
// SandboxStatus request.
|
// SandboxStatus request.
|
||||||
sandbox.IP, sandbox.CNIResult, err = c.setupPod(id, sandbox.NetNSPath, config)
|
sandbox.IP, sandbox.CNIResult, err = c.setupPod(ctx, id, sandbox.NetNSPath, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to setup network for sandbox %q", id)
|
return nil, errors.Wrapf(err, "failed to setup network for sandbox %q", id)
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
// Teardown network if an error is returned.
|
// Teardown network if an error is returned.
|
||||||
if err := c.teardownPod(id, sandbox.NetNSPath, config); err != nil {
|
if err := c.teardownPod(id, sandbox.NetNSPath, config); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to destroy network for sandbox %q", id)
|
log.G(ctx).WithError(err).Errorf("Failed to destroy network for sandbox %q", id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -158,7 +158,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to generate sandbox container spec")
|
return nil, errors.Wrap(err, "failed to generate sandbox container spec")
|
||||||
}
|
}
|
||||||
logrus.Debugf("Sandbox container %q spec: %#+v", id, spew.NewFormatter(spec))
|
log.G(ctx).Debugf("Sandbox container %q spec: %#+v", id, spew.NewFormatter(spec))
|
||||||
|
|
||||||
var specOpts []oci.SpecOpts
|
var specOpts []oci.SpecOpts
|
||||||
userstr, err := generateUserString(
|
userstr, err := generateUserString(
|
||||||
@ -207,7 +207,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
if err := container.Delete(deferCtx, containerd.WithSnapshotCleanup); err != nil {
|
if err := container.Delete(deferCtx, containerd.WithSnapshotCleanup); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to delete containerd container %q", id)
|
log.G(ctx).WithError(err).Errorf("Failed to delete containerd container %q", id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -222,7 +222,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
// Cleanup the sandbox root directory.
|
// Cleanup the sandbox root directory.
|
||||||
if err := c.os.RemoveAll(sandboxRootDir); err != nil {
|
if err := c.os.RemoveAll(sandboxRootDir); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to remove sandbox root directory %q",
|
log.G(ctx).WithError(err).Errorf("Failed to remove sandbox root directory %q",
|
||||||
sandboxRootDir)
|
sandboxRootDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
// Cleanup the volatile sandbox root directory.
|
// Cleanup the volatile sandbox root directory.
|
||||||
if err := c.os.RemoveAll(volatileSandboxRootDir); err != nil {
|
if err := c.os.RemoveAll(volatileSandboxRootDir); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to remove volatile sandbox root directory %q",
|
log.G(ctx).WithError(err).Errorf("Failed to remove volatile sandbox root directory %q",
|
||||||
volatileSandboxRootDir)
|
volatileSandboxRootDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -249,7 +249,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
defer func() {
|
defer func() {
|
||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
if err = c.unmountSandboxFiles(id, config); err != nil {
|
if err = c.unmountSandboxFiles(id, config); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to unmount sandbox files in %q",
|
log.G(ctx).WithError(err).Errorf("Failed to unmount sandbox files in %q",
|
||||||
sandboxRootDir)
|
sandboxRootDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create sandbox task in containerd.
|
// Create sandbox task in containerd.
|
||||||
log.Tracef("Create sandbox container (id=%q, name=%q).",
|
log.G(ctx).Tracef("Create sandbox container (id=%q, name=%q).",
|
||||||
id, name)
|
id, name)
|
||||||
|
|
||||||
var taskOpts []containerd.NewTaskOpts
|
var taskOpts []containerd.NewTaskOpts
|
||||||
@ -281,7 +281,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
defer deferCancel()
|
defer deferCancel()
|
||||||
// Cleanup the sandbox container if an error is returned.
|
// Cleanup the sandbox container if an error is returned.
|
||||||
if _, err := task.Delete(deferCtx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {
|
if _, err := task.Delete(deferCtx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {
|
||||||
logrus.WithError(err).Errorf("Failed to delete sandbox container %q", id)
|
log.G(ctx).WithError(err).Errorf("Failed to delete sandbox container %q", id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -540,7 +540,7 @@ func (c *criService) unmountSandboxFiles(id string, config *runtime.PodSandboxCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setupPod setups up the network for a pod
|
// setupPod setups up the network for a pod
|
||||||
func (c *criService) setupPod(id string, path string, config *runtime.PodSandboxConfig) (string, *cni.CNIResult, error) {
|
func (c *criService) setupPod(ctx context.Context, id string, path string, config *runtime.PodSandboxConfig) (string, *cni.CNIResult, error) {
|
||||||
if c.netPlugin == nil {
|
if c.netPlugin == nil {
|
||||||
return "", nil, errors.New("cni config not initialized")
|
return "", nil, errors.New("cni config not initialized")
|
||||||
}
|
}
|
||||||
@ -564,14 +564,14 @@ func (c *criService) setupPod(id string, path string, config *runtime.PodSandbox
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
logDebugCNIResult(id, result)
|
logDebugCNIResult(ctx, id, result)
|
||||||
// Check if the default interface has IP config
|
// Check if the default interface has IP config
|
||||||
if configs, ok := result.Interfaces[defaultIfName]; ok && len(configs.IPConfigs) > 0 {
|
if configs, ok := result.Interfaces[defaultIfName]; ok && len(configs.IPConfigs) > 0 {
|
||||||
return selectPodIP(configs.IPConfigs), result, nil
|
return selectPodIP(configs.IPConfigs), result, nil
|
||||||
}
|
}
|
||||||
// If it comes here then the result was invalid so destroy the pod network and return error
|
// If it comes here then the result was invalid so destroy the pod network and return error
|
||||||
if err := c.teardownPod(id, path, config); err != nil {
|
if err := c.teardownPod(id, path, config); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to destroy network for sandbox %q", id)
|
log.G(ctx).WithError(err).Errorf("Failed to destroy network for sandbox %q", id)
|
||||||
}
|
}
|
||||||
return "", result, errors.Errorf("failed to find network info for sandbox %q", id)
|
return "", result, errors.Errorf("failed to find network info for sandbox %q", id)
|
||||||
}
|
}
|
||||||
@ -681,14 +681,14 @@ func (c *criService) getSandboxRuntime(config *runtime.PodSandboxConfig, runtime
|
|||||||
return handler, nil
|
return handler, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func logDebugCNIResult(sandboxID string, result *cni.CNIResult) {
|
func logDebugCNIResult(ctx context.Context, sandboxID string, result *cni.CNIResult) {
|
||||||
if logrus.GetLevel() < logrus.DebugLevel {
|
if logrus.GetLevel() < logrus.DebugLevel {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cniResult, err := json.Marshal(result)
|
cniResult, err := json.Marshal(result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to marshal CNI result for sandbox %q: %v", sandboxID, err)
|
log.G(ctx).WithError(err).Errorf("Failed to marshal CNI result for sandbox %q: %v", sandboxID, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.Debugf("cni result for sandbox %q: %s", sandboxID, string(cniResult))
|
log.G(ctx).Debugf("cni result for sandbox %q: %s", sandboxID, string(cniResult))
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,9 @@ import (
|
|||||||
|
|
||||||
eventtypes "github.com/containerd/containerd/api/events"
|
eventtypes "github.com/containerd/containerd/api/events"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
cni "github.com/containerd/go-cni"
|
cni "github.com/containerd/go-cni"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("TearDown network for sandbox %q successfully", id)
|
log.G(ctx).Infof("TearDown network for sandbox %q successfully", id)
|
||||||
|
|
||||||
return &runtime.StopPodSandboxResponse{}, nil
|
return &runtime.StopPodSandboxResponse{}, nil
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
goruntime "runtime"
|
goruntime "runtime"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
cni "github.com/containerd/go-cni"
|
cni "github.com/containerd/go-cni"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
)
|
)
|
||||||
@ -45,7 +45,7 @@ func (c *criService) Status(ctx context.Context, r *runtime.StatusRequest) (*run
|
|||||||
|
|
||||||
// Load the latest cni configuration to be in sync with the latest network configuration
|
// Load the latest cni configuration to be in sync with the latest network configuration
|
||||||
if err := c.netPlugin.Load(cni.WithLoNetwork, cni.WithDefaultConf); err != nil {
|
if err := c.netPlugin.Load(cni.WithLoNetwork, cni.WithDefaultConf); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to load cni configuration")
|
log.G(ctx).WithError(err).Errorf("Failed to load cni configuration")
|
||||||
}
|
}
|
||||||
// Check the status of the cni initialization
|
// Check the status of the cni initialization
|
||||||
if err := c.netPlugin.Status(); err != nil {
|
if err := c.netPlugin.Status(); err != nil {
|
||||||
@ -75,7 +75,7 @@ func (c *criService) Status(ctx context.Context, r *runtime.StatusRequest) (*run
|
|||||||
|
|
||||||
cniConfig, err := json.Marshal(c.netPlugin.GetConfig())
|
cniConfig, err := json.Marshal(c.netPlugin.GetConfig())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to marshal CNI config %v", err)
|
log.G(ctx).WithError(err).Errorf("Failed to marshal CNI config %v", err)
|
||||||
}
|
}
|
||||||
resp.Info["cniconfig"] = string(cniConfig)
|
resp.Info["cniconfig"] = string(cniConfig)
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/net/context"
|
||||||
k8snet "k8s.io/apimachinery/pkg/util/net"
|
k8snet "k8s.io/apimachinery/pkg/util/net"
|
||||||
"k8s.io/apimachinery/pkg/util/runtime"
|
"k8s.io/apimachinery/pkg/util/runtime"
|
||||||
"k8s.io/client-go/tools/remotecommand"
|
"k8s.io/client-go/tools/remotecommand"
|
||||||
@ -155,7 +156,7 @@ func (s *streamRuntime) PortForward(podSandboxID string, port int32, stream io.R
|
|||||||
if port <= 0 || port > math.MaxUint16 {
|
if port <= 0 || port > math.MaxUint16 {
|
||||||
return errors.Errorf("invalid port %d", port)
|
return errors.Errorf("invalid port %d", port)
|
||||||
}
|
}
|
||||||
return s.c.portForward(podSandboxID, port, stream)
|
return s.c.portForward(context.Background(), podSandboxID, port, stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleResizing spawns a goroutine that processes the resize channel, calling resizeFunc for each
|
// handleResizing spawns a goroutine that processes the resize channel, calling resizeFunc for each
|
||||||
|
@ -21,9 +21,9 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
cni "github.com/containerd/go-cni"
|
cni "github.com/containerd/go-cni"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
)
|
)
|
||||||
@ -46,17 +46,17 @@ func (c *criService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateR
|
|||||||
}
|
}
|
||||||
confTemplate := c.config.NetworkPluginConfTemplate
|
confTemplate := c.config.NetworkPluginConfTemplate
|
||||||
if confTemplate == "" {
|
if confTemplate == "" {
|
||||||
logrus.Info("No cni config template is specified, wait for other system components to drop the config.")
|
log.G(ctx).Info("No cni config template is specified, wait for other system components to drop the config.")
|
||||||
return &runtime.UpdateRuntimeConfigResponse{}, nil
|
return &runtime.UpdateRuntimeConfigResponse{}, nil
|
||||||
}
|
}
|
||||||
if err := c.netPlugin.Status(); err == nil {
|
if err := c.netPlugin.Status(); err == nil {
|
||||||
logrus.Infof("Network plugin is ready, skip generating cni config from template %q", confTemplate)
|
log.G(ctx).Infof("Network plugin is ready, skip generating cni config from template %q", confTemplate)
|
||||||
return &runtime.UpdateRuntimeConfigResponse{}, nil
|
return &runtime.UpdateRuntimeConfigResponse{}, nil
|
||||||
} else if err := c.netPlugin.Load(cni.WithLoNetwork, cni.WithDefaultConf); err == nil {
|
} else if err := c.netPlugin.Load(cni.WithLoNetwork, cni.WithDefaultConf); err == nil {
|
||||||
logrus.Infof("CNI config is successfully loaded, skip generating cni config from template %q", confTemplate)
|
log.G(ctx).Infof("CNI config is successfully loaded, skip generating cni config from template %q", confTemplate)
|
||||||
return &runtime.UpdateRuntimeConfigResponse{}, nil
|
return &runtime.UpdateRuntimeConfigResponse{}, nil
|
||||||
}
|
}
|
||||||
logrus.Infof("Generating cni config from template %q", confTemplate)
|
log.G(ctx).Infof("Generating cni config from template %q", confTemplate)
|
||||||
// generate cni config file from the template with updated pod cidr.
|
// generate cni config file from the template with updated pod cidr.
|
||||||
t, err := template.ParseFiles(confTemplate)
|
t, err := template.ParseFiles(confTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user