containerd: use mediatype helpers

Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
This commit is contained in:
Bjorn Neergaard 2023-09-27 11:10:23 -06:00
parent 9ca6fd9e6e
commit f1cbc5f90c
No known key found for this signature in database
2 changed files with 25 additions and 26 deletions

View File

@ -120,24 +120,24 @@ func WithImageConfigLabels(image Image) NewContainerOpts {
if err != nil {
return err
}
if !images.IsConfigType(ic.MediaType) {
return fmt.Errorf("unknown image config media type %s", ic.MediaType)
}
var (
ociimage v1.Image
config v1.ImageConfig
)
switch ic.MediaType {
case v1.MediaTypeImageConfig, images.MediaTypeDockerSchema2Config:
p, err := content.ReadBlob(ctx, image.ContentStore(), ic)
if err != nil {
return err
}
if err := json.Unmarshal(p, &ociimage); err != nil {
if err = json.Unmarshal(p, &ociimage); err != nil {
return err
}
config = ociimage.Config
default:
return fmt.Errorf("unknown image config media type %s", ic.MediaType)
}
c.Labels = config.Labels
return nil
}

View File

@ -57,24 +57,23 @@ func GetOCIStopSignal(ctx context.Context, image Image, defaultSignal string) (s
if err != nil {
return "", err
}
if !images.IsConfigType(ic.MediaType) {
return "", fmt.Errorf("unknown image config media type %s", ic.MediaType)
}
var (
ociimage v1.Image
config v1.ImageConfig
)
switch ic.MediaType {
case v1.MediaTypeImageConfig, images.MediaTypeDockerSchema2Config:
p, err := content.ReadBlob(ctx, image.ContentStore(), ic)
if err != nil {
return "", err
}
if err := json.Unmarshal(p, &ociimage); err != nil {
if err = json.Unmarshal(p, &ociimage); err != nil {
return "", err
}
config = ociimage.Config
default:
return "", fmt.Errorf("unknown image config media type %s", ic.MediaType)
}
if config.StopSignal == "" {
return defaultSignal, nil