Skip to content

Commit f7880e7

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 1dd2f2c commit f7880e7

3 files changed

Lines changed: 53 additions & 8 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 & 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: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ package images
1919
import (
2020
"context"
2121

22+
"google.golang.org/grpc"
23+
"google.golang.org/grpc/codes"
24+
"google.golang.org/grpc/status"
25+
2226
eventstypes "github.com/containerd/containerd/api/events"
2327
imagesapi "github.com/containerd/containerd/api/services/images/v1"
2428
"github.com/containerd/containerd/errdefs"
@@ -27,13 +31,12 @@ import (
2731
"github.com/containerd/containerd/images"
2832
"github.com/containerd/containerd/log"
2933
"github.com/containerd/containerd/metadata"
34+
"github.com/containerd/containerd/pkg/deprecation"
3035
"github.com/containerd/containerd/pkg/epoch"
3136
"github.com/containerd/containerd/plugin"
3237
ptypes "github.com/containerd/containerd/protobuf/types"
3338
"github.com/containerd/containerd/services"
34-
"google.golang.org/grpc"
35-
"google.golang.org/grpc/codes"
36-
"google.golang.org/grpc/status"
39+
"github.com/containerd/containerd/services/warning"
3740
)
3841

3942
func init() {
@@ -43,6 +46,7 @@ func init() {
4346
Requires: []plugin.Type{
4447
plugin.MetadataPlugin,
4548
plugin.GCPlugin,
49+
plugin.WarningPlugin,
4650
},
4751
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
4852
m, err := ic.Get(plugin.MetadataPlugin)
@@ -53,11 +57,16 @@ func init() {
5357
if err != nil {
5458
return nil, err
5559
}
60+
w, err := ic.Get(plugin.WarningPlugin)
61+
if err != nil {
62+
return nil, err
63+
}
5664

5765
return &local{
5866
store: metadata.NewImageStore(m.(*metadata.DB)),
5967
publisher: ic.Events,
6068
gc: g.(gcScheduler),
69+
warnings: w.(warning.Service),
6170
}, nil
6271
},
6372
})
@@ -71,6 +80,7 @@ type local struct {
7180
store images.Store
7281
gc gcScheduler
7382
publisher events.Publisher
83+
warnings warning.Service
7484
}
7585

7686
var _ imagesapi.ImagesClient = &local{}
@@ -126,6 +136,7 @@ func (l *local) Create(ctx context.Context, req *imagesapi.CreateImageRequest, _
126136
return nil, err
127137
}
128138

139+
l.emitSchema1DeprecationWarning(ctx, &image)
129140
return &resp, nil
130141

131142
}
@@ -164,6 +175,7 @@ func (l *local) Update(ctx context.Context, req *imagesapi.UpdateImageRequest, _
164175
return nil, err
165176
}
166177

178+
l.emitSchema1DeprecationWarning(ctx, &image)
167179
return &resp, nil
168180
}
169181

@@ -188,3 +200,15 @@ func (l *local) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest, _
188200

189201
return &ptypes.Empty{}, nil
190202
}
203+
204+
func (l *local) emitSchema1DeprecationWarning(ctx context.Context, image *images.Image) {
205+
if image == nil {
206+
return
207+
}
208+
dgst, ok := image.Labels[images.ConvertedDockerSchema1LabelKey]
209+
if !ok {
210+
return
211+
}
212+
log.G(ctx).WithField("name", image.Name).WithField("schema1digest", dgst).Warn("conversion from schema 1 images is deprecated")
213+
l.warnings.Emit(ctx, deprecation.PullSchema1Image)
214+
}

0 commit comments

Comments
 (0)