Skip to content

Commit

Permalink
Clean up repeated package import
Browse files Browse the repository at this point in the history
Signed-off-by: Zechun Chen <[email protected]>
  • Loading branch information
Fish-pro committed Feb 10, 2023
1 parent a6f3cbe commit b944b10
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 40 deletions.
14 changes: 6 additions & 8 deletions pkg/cri/sbserver/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions pkg/cri/sbserver/container_execsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions pkg/cri/sbserver/sandbox_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 3 additions & 4 deletions pkg/cri/server/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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 != "" {
Expand Down
3 changes: 1 addition & 2 deletions pkg/cri/server/container_execsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions pkg/cri/server/sandbox_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions runtime/v2/shim/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
19 changes: 9 additions & 10 deletions tracing/plugin/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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(),
Expand All @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions tracing/plugin/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b944b10

Please sign in to comment.