Skip to content

Commit dfb9e1d

Browse files
committed
pull: record deprecation warning for schema 1
Signed-off-by: Samuel Karp <[email protected]> (cherry picked from commit bc861b6) Signed-off-by: Samuel Karp <[email protected]>
1 parent 90b42da commit dfb9e1d

3 files changed

Lines changed: 54 additions & 12 deletions

File tree

images/labels.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package images
18+
19+
const (
20+
ConvertedDockerSchema1LabelKey = "io.containerd.image/converted-docker-schema1"
21+
)

pull.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,16 @@ import (
2121
"errors"
2222
"fmt"
2323

24+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
25+
"golang.org/x/sync/errgroup"
26+
"golang.org/x/sync/semaphore"
27+
2428
"github.com/containerd/containerd/errdefs"
2529
"github.com/containerd/containerd/images"
2630
"github.com/containerd/containerd/platforms"
2731
"github.com/containerd/containerd/remotes"
2832
"github.com/containerd/containerd/remotes/docker"
2933
"github.com/containerd/containerd/remotes/docker/schema1"
30-
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
31-
"golang.org/x/sync/errgroup"
32-
"golang.org/x/sync/semaphore"
33-
)
34-
35-
const (
36-
convertedDockerSchema1LabelKey = "io.containerd.image/converted-docker-schema1"
3734
)
3835

3936
// Pull downloads the provided content into containerd's content store
@@ -233,7 +230,7 @@ func (c *Client) fetch(ctx context.Context, rCtx *RemoteContext, ref string, lim
233230
if rCtx.Labels == nil {
234231
rCtx.Labels = make(map[string]string)
235232
}
236-
rCtx.Labels[convertedDockerSchema1LabelKey] = originalSchema1Digest
233+
rCtx.Labels[images.ConvertedDockerSchema1LabelKey] = originalSchema1Digest
237234
}
238235

239236
return images.Image{

services/images/local.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ package images
1919
import (
2020
"context"
2121

22+
ptypes "github.com/gogo/protobuf/types"
23+
"google.golang.org/grpc"
24+
"google.golang.org/grpc/codes"
25+
"google.golang.org/grpc/status"
26+
2227
eventstypes "github.com/containerd/containerd/api/events"
2328
imagesapi "github.com/containerd/containerd/api/services/images/v1"
2429
"github.com/containerd/containerd/errdefs"
@@ -27,12 +32,10 @@ import (
2732
"github.com/containerd/containerd/images"
2833
"github.com/containerd/containerd/log"
2934
"github.com/containerd/containerd/metadata"
35+
"github.com/containerd/containerd/pkg/deprecation"
3036
"github.com/containerd/containerd/plugin"
3137
"github.com/containerd/containerd/services"
32-
ptypes "github.com/gogo/protobuf/types"
33-
"google.golang.org/grpc"
34-
"google.golang.org/grpc/codes"
35-
"google.golang.org/grpc/status"
38+
"github.com/containerd/containerd/services/warning"
3639
)
3740

3841
func init() {
@@ -42,6 +45,7 @@ func init() {
4245
Requires: []plugin.Type{
4346
plugin.MetadataPlugin,
4447
plugin.GCPlugin,
48+
plugin.WarningPlugin,
4549
},
4650
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
4751
m, err := ic.Get(plugin.MetadataPlugin)
@@ -52,11 +56,16 @@ func init() {
5256
if err != nil {
5357
return nil, err
5458
}
59+
w, err := ic.Get(plugin.WarningPlugin)
60+
if err != nil {
61+
return nil, err
62+
}
5563

5664
return &local{
5765
store: metadata.NewImageStore(m.(*metadata.DB)),
5866
publisher: ic.Events,
5967
gc: g.(gcScheduler),
68+
warnings: w.(warning.Service),
6069
}, nil
6170
},
6271
})
@@ -70,6 +79,7 @@ type local struct {
7079
store images.Store
7180
gc gcScheduler
7281
publisher events.Publisher
82+
warnings warning.Service
7383
}
7484

7585
var _ imagesapi.ImagesClient = &local{}
@@ -121,6 +131,7 @@ func (l *local) Create(ctx context.Context, req *imagesapi.CreateImageRequest, _
121131
return nil, err
122132
}
123133

134+
l.emitSchema1DeprecationWarning(ctx, &image)
124135
return &resp, nil
125136

126137
}
@@ -154,6 +165,7 @@ func (l *local) Update(ctx context.Context, req *imagesapi.UpdateImageRequest, _
154165
return nil, err
155166
}
156167

168+
l.emitSchema1DeprecationWarning(ctx, &image)
157169
return &resp, nil
158170
}
159171

@@ -178,3 +190,15 @@ func (l *local) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest, _
178190

179191
return &ptypes.Empty{}, nil
180192
}
193+
194+
func (l *local) emitSchema1DeprecationWarning(ctx context.Context, image *images.Image) {
195+
if image == nil {
196+
return
197+
}
198+
dgst, ok := image.Labels[images.ConvertedDockerSchema1LabelKey]
199+
if !ok {
200+
return
201+
}
202+
log.G(ctx).WithField("name", image.Name).WithField("schema1digest", dgst).Warn("conversion from schema 1 images is deprecated")
203+
l.warnings.Emit(ctx, deprecation.PullSchema1Image)
204+
}

0 commit comments

Comments
 (0)