Clean up repeated package import
Signed-off-by: Zechun Chen <zechun.chen@daocloud.io>
This commit is contained in:
parent
a6f3cbe0ad
commit
b944b108df
@ -37,13 +37,11 @@ import (
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/oci"
|
||||
"github.com/containerd/containerd/pkg/cri/annotations"
|
||||
"github.com/containerd/containerd/pkg/cri/config"
|
||||
criconfig "github.com/containerd/containerd/pkg/cri/config"
|
||||
cio "github.com/containerd/containerd/pkg/cri/io"
|
||||
customopts "github.com/containerd/containerd/pkg/cri/opts"
|
||||
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
|
||||
"github.com/containerd/containerd/pkg/cri/util"
|
||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
)
|
||||
|
||||
@ -285,7 +283,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
||||
}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
deferCtx, deferCancel := util.DeferContext()
|
||||
defer deferCancel()
|
||||
if err := cntr.Delete(deferCtx, containerd.WithSnapshotCleanup); err != nil {
|
||||
log.G(ctx).WithError(err).Errorf("Failed to delete containerd container %q", id)
|
||||
@ -355,7 +353,7 @@ func (c *criService) volumeMounts(containerRootDir string, criMounts []*runtime.
|
||||
// runtimeSpec returns a default runtime spec used in cri-containerd.
|
||||
func (c *criService) runtimeSpec(id string, platform platforms.Platform, baseSpecFile string, opts ...oci.SpecOpts) (*runtimespec.Spec, error) {
|
||||
// GenerateSpec needs namespace.
|
||||
ctx := ctrdutil.NamespacedContext()
|
||||
ctx := util.NamespacedContext()
|
||||
container := &containers.Container{ID: id}
|
||||
|
||||
if baseSpecFile != "" {
|
||||
@ -418,7 +416,7 @@ func (c *criService) buildContainerSpec(
|
||||
sandboxConfig *runtime.PodSandboxConfig,
|
||||
imageConfig *imagespec.ImageConfig,
|
||||
extraMounts []*runtime.Mount,
|
||||
ociRuntime config.Runtime,
|
||||
ociRuntime criconfig.Runtime,
|
||||
) (_ *runtimespec.Spec, retErr error) {
|
||||
var (
|
||||
specOpts []oci.SpecOpts
|
||||
@ -493,7 +491,7 @@ func (c *criService) buildLinuxSpec(
|
||||
sandboxConfig *runtime.PodSandboxConfig,
|
||||
imageConfig *imagespec.ImageConfig,
|
||||
extraMounts []*runtime.Mount,
|
||||
ociRuntime config.Runtime,
|
||||
ociRuntime criconfig.Runtime,
|
||||
) (_ []oci.SpecOpts, retErr error) {
|
||||
specOpts := []oci.SpecOpts{
|
||||
oci.WithoutRunMount,
|
||||
@ -728,7 +726,7 @@ func (c *criService) buildWindowsSpec(
|
||||
sandboxConfig *runtime.PodSandboxConfig,
|
||||
imageConfig *imagespec.ImageConfig,
|
||||
extraMounts []*runtime.Mount,
|
||||
ociRuntime config.Runtime,
|
||||
ociRuntime criconfig.Runtime,
|
||||
) (_ []oci.SpecOpts, retErr error) {
|
||||
specOpts := []oci.SpecOpts{
|
||||
customopts.WithProcessArgs(config, imageConfig),
|
||||
@ -829,7 +827,7 @@ func (c *criService) buildDarwinSpec(
|
||||
sandboxConfig *runtime.PodSandboxConfig,
|
||||
imageConfig *imagespec.ImageConfig,
|
||||
extraMounts []*runtime.Mount,
|
||||
ociRuntime config.Runtime,
|
||||
ociRuntime criconfig.Runtime,
|
||||
) (_ []oci.SpecOpts, retErr error) {
|
||||
specOpts := []oci.SpecOpts{
|
||||
customopts.WithProcessArgs(config, imageConfig),
|
||||
|
@ -34,7 +34,6 @@ import (
|
||||
|
||||
cio "github.com/containerd/containerd/pkg/cri/io"
|
||||
"github.com/containerd/containerd/pkg/cri/util"
|
||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
||||
cioutil "github.com/containerd/containerd/pkg/ioutil"
|
||||
)
|
||||
|
||||
@ -158,7 +157,7 @@ func (c *criService) execInternal(ctx context.Context, container containerd.Cont
|
||||
return nil, fmt.Errorf("failed to create exec %q: %w", execID, err)
|
||||
}
|
||||
defer func() {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
deferCtx, deferCancel := util.DeferContext()
|
||||
defer deferCancel()
|
||||
if _, err := process.Delete(deferCtx, containerd.WithProcessKill); err != nil {
|
||||
log.G(ctx).WithError(err).Errorf("Failed to delete exec process %q for container %q", execID, id)
|
||||
|
@ -39,7 +39,6 @@ import (
|
||||
"github.com/containerd/containerd/pkg/cri/server/bandwidth"
|
||||
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
|
||||
"github.com/containerd/containerd/pkg/cri/util"
|
||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
||||
"github.com/containerd/containerd/pkg/netns"
|
||||
"github.com/containerd/containerd/protobuf"
|
||||
sb "github.com/containerd/containerd/sandbox"
|
||||
@ -186,7 +185,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
||||
defer func() {
|
||||
// Remove the network namespace only if all the resource cleanup is done.
|
||||
if retErr != nil && cleanupErr == nil {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
deferCtx, deferCancel := util.DeferContext()
|
||||
defer deferCancel()
|
||||
// Teardown network if an error is returned.
|
||||
if cleanupErr = c.teardownPodNetwork(deferCtx, sandbox); cleanupErr != nil {
|
||||
@ -276,7 +275,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
||||
go func() {
|
||||
defer close(exitCh)
|
||||
|
||||
ctx := ctrdutil.NamespacedContext()
|
||||
ctx := util.NamespacedContext()
|
||||
resp, err := controller.Wait(ctx, id)
|
||||
if err != nil {
|
||||
log.G(ctx).WithError(err).Error("failed to wait for sandbox exit")
|
||||
|
@ -39,7 +39,6 @@ import (
|
||||
customopts "github.com/containerd/containerd/pkg/cri/opts"
|
||||
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
|
||||
"github.com/containerd/containerd/pkg/cri/util"
|
||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -255,7 +254,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
||||
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
deferCtx, deferCancel := util.DeferContext()
|
||||
defer deferCancel()
|
||||
c.nri.undoCreateContainer(deferCtx, &sandbox, id, spec)
|
||||
}
|
||||
@ -268,7 +267,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
||||
}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
deferCtx, deferCancel := util.DeferContext()
|
||||
defer deferCancel()
|
||||
if err := cntr.Delete(deferCtx, containerd.WithSnapshotCleanup); err != nil {
|
||||
log.G(ctx).WithError(err).Errorf("Failed to delete containerd container %q", id)
|
||||
@ -344,7 +343,7 @@ func (c *criService) volumeMounts(containerRootDir string, criMounts []*runtime.
|
||||
// runtimeSpec returns a default runtime spec used in cri-containerd.
|
||||
func (c *criService) runtimeSpec(id string, baseSpecFile string, opts ...oci.SpecOpts) (*runtimespec.Spec, error) {
|
||||
// GenerateSpec needs namespace.
|
||||
ctx := ctrdutil.NamespacedContext()
|
||||
ctx := util.NamespacedContext()
|
||||
container := &containers.Container{ID: id}
|
||||
|
||||
if baseSpecFile != "" {
|
||||
|
@ -34,7 +34,6 @@ import (
|
||||
|
||||
cio "github.com/containerd/containerd/pkg/cri/io"
|
||||
"github.com/containerd/containerd/pkg/cri/util"
|
||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
||||
cioutil "github.com/containerd/containerd/pkg/ioutil"
|
||||
)
|
||||
|
||||
@ -158,7 +157,7 @@ func (c *criService) execInternal(ctx context.Context, container containerd.Cont
|
||||
return nil, fmt.Errorf("failed to create exec %q: %w", execID, err)
|
||||
}
|
||||
defer func() {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
deferCtx, deferCancel := util.DeferContext()
|
||||
defer deferCancel()
|
||||
if _, err := process.Delete(deferCtx, containerd.WithProcessKill); err != nil {
|
||||
log.G(ctx).WithError(err).Errorf("Failed to delete exec process %q for container %q", execID, id)
|
||||
|
@ -44,7 +44,6 @@ import (
|
||||
"github.com/containerd/containerd/pkg/cri/server/bandwidth"
|
||||
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
|
||||
"github.com/containerd/containerd/pkg/cri/util"
|
||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
||||
"github.com/containerd/containerd/pkg/netns"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
)
|
||||
@ -195,7 +194,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
||||
defer func() {
|
||||
// Delete container only if all the resource cleanup is done.
|
||||
if retErr != nil && cleanupErr == nil {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
deferCtx, deferCancel := util.DeferContext()
|
||||
defer deferCancel()
|
||||
if cleanupErr = container.Delete(deferCtx, containerd.WithSnapshotCleanup); cleanupErr != nil {
|
||||
log.G(ctx).WithError(cleanupErr).Errorf("Failed to delete containerd container %q", id)
|
||||
@ -317,7 +316,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
||||
defer func() {
|
||||
// Teardown the network only if all the resource cleanup is done.
|
||||
if retErr != nil && cleanupErr == nil {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
deferCtx, deferCancel := util.DeferContext()
|
||||
defer deferCancel()
|
||||
// Teardown network if an error is returned.
|
||||
if cleanupErr = c.teardownPodNetwork(deferCtx, sandbox); cleanupErr != nil {
|
||||
@ -364,7 +363,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
||||
}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
deferCtx, deferCancel := util.DeferContext()
|
||||
defer deferCancel()
|
||||
// Cleanup the sandbox container if an error is returned.
|
||||
if _, err := task.Delete(deferCtx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {
|
||||
@ -375,7 +374,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
||||
}()
|
||||
|
||||
// wait is a long running background request, no timeout needed.
|
||||
exitCh, err := task.Wait(ctrdutil.NamespacedContext())
|
||||
exitCh, err := task.Wait(util.NamespacedContext())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to wait for sandbox container task: %w", err)
|
||||
}
|
||||
@ -438,7 +437,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
||||
defer func() {
|
||||
// Teardown the network only if all the resource cleanup is done.
|
||||
if retErr != nil && cleanupErr == nil {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
deferCtx, deferCancel := util.DeferContext()
|
||||
defer deferCancel()
|
||||
// Teardown network if an error is returned.
|
||||
if cleanupErr = c.teardownPodNetwork(deferCtx, sandbox); cleanupErr != nil {
|
||||
@ -470,7 +469,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
||||
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
deferCtx, deferCancel := util.DeferContext()
|
||||
defer deferCancel()
|
||||
c.nri.removePodSandbox(deferCtx, &sandbox)
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ import (
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/containerd/containerd/protobuf/proto"
|
||||
"github.com/containerd/containerd/protobuf/types"
|
||||
ptypes "github.com/containerd/containerd/protobuf/types"
|
||||
"github.com/containerd/ttrpc"
|
||||
"github.com/containerd/typeurl"
|
||||
exec "golang.org/x/sys/execabs"
|
||||
@ -190,7 +189,7 @@ func ReadRuntimeOptions[T any](reader io.Reader) (T, error) {
|
||||
return config, errdefs.ErrNotFound
|
||||
}
|
||||
|
||||
var any ptypes.Any
|
||||
var any types.Any
|
||||
if err := proto.Unmarshal(data, &any); err != nil {
|
||||
return config, err
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ import (
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
"go.opentelemetry.io/otel/sdk/trace"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
|
||||
)
|
||||
|
||||
@ -69,7 +68,7 @@ func init() {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get tracing processors: %w", err)
|
||||
}
|
||||
procs := make([]sdktrace.SpanProcessor, 0, len(plugins))
|
||||
procs := make([]trace.SpanProcessor, 0, len(plugins))
|
||||
for id, pctx := range plugins {
|
||||
p, err := pctx.Instance()
|
||||
if err != nil {
|
||||
@ -80,7 +79,7 @@ func init() {
|
||||
}
|
||||
continue
|
||||
}
|
||||
proc := p.(sdktrace.SpanProcessor)
|
||||
proc := p.(trace.SpanProcessor)
|
||||
procs = append(procs, proc)
|
||||
}
|
||||
return newTracer(ic.Context, ic.Config.(*TraceConfig), procs)
|
||||
@ -152,7 +151,7 @@ func newExporter(ctx context.Context, cfg *OTLPConfig) (*otlptrace.Exporter, err
|
||||
// its sampling ratio and returns io.Closer.
|
||||
//
|
||||
// Note that this function sets process-wide tracing configuration.
|
||||
func newTracer(ctx context.Context, config *TraceConfig, procs []sdktrace.SpanProcessor) (io.Closer, error) {
|
||||
func newTracer(ctx context.Context, config *TraceConfig, procs []trace.SpanProcessor) (io.Closer, error) {
|
||||
|
||||
res, err := resource.New(ctx,
|
||||
resource.WithHost(),
|
||||
@ -165,18 +164,18 @@ func newTracer(ctx context.Context, config *TraceConfig, procs []sdktrace.SpanPr
|
||||
return nil, fmt.Errorf("failed to create resource: %w", err)
|
||||
}
|
||||
|
||||
sampler := sdktrace.ParentBased(sdktrace.TraceIDRatioBased(config.TraceSamplingRatio))
|
||||
sampler := trace.ParentBased(trace.TraceIDRatioBased(config.TraceSamplingRatio))
|
||||
|
||||
opts := []sdktrace.TracerProviderOption{
|
||||
sdktrace.WithSampler(sampler),
|
||||
sdktrace.WithResource(res),
|
||||
opts := []trace.TracerProviderOption{
|
||||
trace.WithSampler(sampler),
|
||||
trace.WithResource(res),
|
||||
}
|
||||
|
||||
for _, proc := range procs {
|
||||
opts = append(opts, sdktrace.WithSpanProcessor(proc))
|
||||
opts = append(opts, trace.WithSpanProcessor(proc))
|
||||
}
|
||||
|
||||
provider := sdktrace.NewTracerProvider(opts...)
|
||||
provider := trace.NewTracerProvider(opts...)
|
||||
|
||||
otel.SetTracerProvider(provider)
|
||||
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"go.opentelemetry.io/otel/sdk/trace"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/sdk/trace/tracetest"
|
||||
)
|
||||
|
||||
@ -100,7 +99,7 @@ func TestNewTracer(t *testing.T) {
|
||||
config := &TraceConfig{ServiceName: "containerd", TraceSamplingRatio: 1.0}
|
||||
t.Logf("config: %v", config)
|
||||
|
||||
procs := make([]sdktrace.SpanProcessor, 0, 1)
|
||||
procs := make([]trace.SpanProcessor, 0, 1)
|
||||
|
||||
//Create a dummy in memory exporter for test
|
||||
exp := tracetest.NewInMemoryExporter()
|
||||
|
Loading…
Reference in New Issue
Block a user