Skip to content

Commit bc861b6

Browse files
committed
pull: record deprecation warning for schema 1
Signed-off-by: Samuel Karp <[email protected]>
1 parent 9aab446 commit bc861b6

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import (
2121
"errors"
2222
"fmt"
2323

24+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
25+
"golang.org/x/sync/semaphore"
26+
2427
"github.com/containerd/containerd/errdefs"
2528
"github.com/containerd/containerd/images"
2629
"github.com/containerd/containerd/pkg/unpack"
@@ -29,13 +32,10 @@ import (
2932
"github.com/containerd/containerd/remotes/docker"
3033
"github.com/containerd/containerd/remotes/docker/schema1" //nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
3134
"github.com/containerd/containerd/tracing"
32-
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
33-
"golang.org/x/sync/semaphore"
3435
)
3536

3637
const (
37-
pullSpanPrefix = "pull"
38-
convertedDockerSchema1LabelKey = "io.containerd.image/converted-docker-schema1"
38+
pullSpanPrefix = "pull"
3939
)
4040

4141
// Pull downloads the provided content into containerd's content store
@@ -278,7 +278,7 @@ func (c *Client) fetch(ctx context.Context, rCtx *RemoteContext, ref string, lim
278278
if rCtx.Labels == nil {
279279
rCtx.Labels = make(map[string]string)
280280
}
281-
rCtx.Labels[convertedDockerSchema1LabelKey] = originalSchema1Digest
281+
rCtx.Labels[images.ConvertedDockerSchema1LabelKey] = originalSchema1Digest
282282
}
283283

284284
return images.Image{

services/images/local.go

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

22+
"github.com/containerd/log"
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"
2530
"github.com/containerd/containerd/events"
2631
"github.com/containerd/containerd/gc"
2732
"github.com/containerd/containerd/images"
2833
"github.com/containerd/containerd/metadata"
34+
"github.com/containerd/containerd/pkg/deprecation"
2935
"github.com/containerd/containerd/pkg/epoch"
3036
"github.com/containerd/containerd/plugin"
3137
"github.com/containerd/containerd/plugin/registry"
3238
"github.com/containerd/containerd/plugins"
3339
ptypes "github.com/containerd/containerd/protobuf/types"
3440
"github.com/containerd/containerd/services"
35-
"github.com/containerd/log"
36-
"google.golang.org/grpc"
37-
"google.golang.org/grpc/codes"
38-
"google.golang.org/grpc/status"
41+
"github.com/containerd/containerd/services/warning"
3942
)
4043

4144
func init() {
@@ -46,6 +49,7 @@ func init() {
4649
plugins.EventPlugin,
4750
plugins.MetadataPlugin,
4851
plugins.GCPlugin,
52+
plugins.WarningPlugin,
4953
},
5054
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
5155
m, err := ic.Get(plugins.MetadataPlugin)
@@ -56,16 +60,20 @@ func init() {
5660
if err != nil {
5761
return nil, err
5862
}
59-
6063
ep, err := ic.Get(plugins.EventPlugin)
6164
if err != nil {
6265
return nil, err
6366
}
67+
w, err := ic.Get(plugins.WarningPlugin)
68+
if err != nil {
69+
return nil, err
70+
}
6471

6572
return &local{
6673
store: metadata.NewImageStore(m.(*metadata.DB)),
6774
publisher: ep.(events.Publisher),
6875
gc: g.(gcScheduler),
76+
warnings: w.(warning.Service),
6977
}, nil
7078
},
7179
})
@@ -79,6 +87,7 @@ type local struct {
7987
store images.Store
8088
gc gcScheduler
8189
publisher events.Publisher
90+
warnings warning.Service
8291
}
8392

8493
var _ imagesapi.ImagesClient = &local{}
@@ -134,6 +143,7 @@ func (l *local) Create(ctx context.Context, req *imagesapi.CreateImageRequest, _
134143
return nil, err
135144
}
136145

146+
l.emitSchema1DeprecationWarning(ctx, &image)
137147
return &resp, nil
138148

139149
}
@@ -172,6 +182,7 @@ func (l *local) Update(ctx context.Context, req *imagesapi.UpdateImageRequest, _
172182
return nil, err
173183
}
174184

185+
l.emitSchema1DeprecationWarning(ctx, &image)
175186
return &resp, nil
176187
}
177188

@@ -203,3 +214,15 @@ func (l *local) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest, _
203214

204215
return &ptypes.Empty{}, nil
205216
}
217+
218+
func (l *local) emitSchema1DeprecationWarning(ctx context.Context, image *images.Image) {
219+
if image == nil {
220+
return
221+
}
222+
dgst, ok := image.Labels[images.ConvertedDockerSchema1LabelKey]
223+
if !ok {
224+
return
225+
}
226+
log.G(ctx).WithField("name", image.Name).WithField("schema1digest", dgst).Warn("conversion from schema 1 images is deprecated")
227+
l.warnings.Emit(ctx, deprecation.PullSchema1Image)
228+
}

0 commit comments

Comments
 (0)