@@ -36,6 +36,7 @@ import (
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
ctrdutil "github.com/containerd/cri-containerd/pkg/containerd/util"
|
||||
"github.com/containerd/cri-containerd/pkg/util"
|
||||
)
|
||||
|
||||
@@ -80,6 +81,7 @@ func Import(ctx context.Context, client *containerd.Client, reader io.Reader) (_
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// TODO(random-liu): Fix this after containerd client is fixed (containerd/containerd#2193)
|
||||
defer done() // nolint: errcheck
|
||||
|
||||
cs := client.ContentStore()
|
||||
@@ -134,9 +136,13 @@ func Import(ctx context.Context, client *containerd.Client, reader io.Reader) (_
|
||||
// TODO(random-liu): Consider whether we should keep images already imported
|
||||
// even when there is an error.
|
||||
for _, ref := range refs {
|
||||
if err := is.Delete(ctx, ref); err != nil {
|
||||
log.G(ctx).WithError(err).Errorf("Failed to remove image %q", ref)
|
||||
}
|
||||
func() {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
defer deferCancel()
|
||||
if err := is.Delete(deferCtx, ref); err != nil {
|
||||
log.G(ctx).WithError(err).Errorf("Failed to remove image %q", ref)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}()
|
||||
for _, mfst := range mfsts {
|
||||
|
||||
35
pkg/containerd/util/util.go
Normal file
35
pkg/containerd/util/util.go
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
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 util
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// deferCleanupTimeout is the default timeout for containerd cleanup operations
|
||||
// in defer.
|
||||
const deferCleanupTimeout = 1 * time.Minute
|
||||
|
||||
// DeferContext returns a context for containerd cleanup operations in defer.
|
||||
// A default timeout is applied to avoid cleanup operation pending forever.
|
||||
// TODO(random-liu): Add namespace after local services are used.
|
||||
// (containerd/containerd#2183)
|
||||
func DeferContext() (context.Context, context.CancelFunc) {
|
||||
return context.WithTimeout(context.Background(), deferCleanupTimeout)
|
||||
}
|
||||
Reference in New Issue
Block a user