Skip to content

Commit

Permalink
pull: record deprecation warning for schema 1
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Karp <samuelkarp@google.com>
  • Loading branch information
samuelkarp committed Oct 25, 2023
1 parent 9aab446 commit bc861b6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
21 changes: 21 additions & 0 deletions images/labels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 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 images

const (
ConvertedDockerSchema1LabelKey = "io.containerd.image/converted-docker-schema1"
)
10 changes: 5 additions & 5 deletions pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"errors"
"fmt"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"golang.org/x/sync/semaphore"

"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/pkg/unpack"
Expand All @@ -29,13 +32,10 @@ import (
"github.com/containerd/containerd/remotes/docker"
"github.com/containerd/containerd/remotes/docker/schema1" //nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/containerd/containerd/tracing"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"golang.org/x/sync/semaphore"
)

const (
pullSpanPrefix = "pull"
convertedDockerSchema1LabelKey = "io.containerd.image/converted-docker-schema1"
pullSpanPrefix = "pull"
)

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

return images.Image{
Expand Down
33 changes: 28 additions & 5 deletions services/images/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,26 @@ package images
import (
"context"

"github.com/containerd/log"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

eventstypes "github.com/containerd/containerd/api/events"
imagesapi "github.com/containerd/containerd/api/services/images/v1"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/events"
"github.com/containerd/containerd/gc"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/metadata"
"github.com/containerd/containerd/pkg/deprecation"
"github.com/containerd/containerd/pkg/epoch"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/plugin/registry"
"github.com/containerd/containerd/plugins"
ptypes "github.com/containerd/containerd/protobuf/types"
"github.com/containerd/containerd/services"
"github.com/containerd/log"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/containerd/containerd/services/warning"
)

func init() {
Expand All @@ -46,6 +49,7 @@ func init() {
plugins.EventPlugin,
plugins.MetadataPlugin,
plugins.GCPlugin,
plugins.WarningPlugin,
},
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
m, err := ic.Get(plugins.MetadataPlugin)
Expand All @@ -56,16 +60,20 @@ func init() {
if err != nil {
return nil, err
}

ep, err := ic.Get(plugins.EventPlugin)
if err != nil {
return nil, err
}
w, err := ic.Get(plugins.WarningPlugin)
if err != nil {
return nil, err
}

return &local{
store: metadata.NewImageStore(m.(*metadata.DB)),
publisher: ep.(events.Publisher),
gc: g.(gcScheduler),
warnings: w.(warning.Service),
}, nil
},
})
Expand All @@ -79,6 +87,7 @@ type local struct {
store images.Store
gc gcScheduler
publisher events.Publisher
warnings warning.Service
}

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

l.emitSchema1DeprecationWarning(ctx, &image)
return &resp, nil

}
Expand Down Expand Up @@ -172,6 +182,7 @@ func (l *local) Update(ctx context.Context, req *imagesapi.UpdateImageRequest, _
return nil, err
}

l.emitSchema1DeprecationWarning(ctx, &image)
return &resp, nil
}

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

return &ptypes.Empty{}, nil
}

func (l *local) emitSchema1DeprecationWarning(ctx context.Context, image *images.Image) {
if image == nil {
return
}
dgst, ok := image.Labels[images.ConvertedDockerSchema1LabelKey]
if !ok {
return
}
log.G(ctx).WithField("name", image.Name).WithField("schema1digest", dgst).Warn("conversion from schema 1 images is deprecated")
l.warnings.Emit(ctx, deprecation.PullSchema1Image)
}

0 comments on commit bc861b6

Please sign in to comment.