Skip to content

Commit

Permalink
fix: handle multi-architecture images in registry lookup
Browse files Browse the repository at this point in the history
The webhook was failing when trying to inspect images that only had arm64
variants available, as it defaulted to looking up amd64 images first. This
was problematic because the webhook runs before pod scheduling, so we don't
yet know which architecture the pod will run on.

The fix modifies the image lookup logic to take the first available image
manifest from the registry's manifest list, regardless of architecture.
This works because the core image configuration (entrypoint, env vars, etc.)
that we need to inspect is typically identical across architectures.

Signed-off-by: Nils Mueller <20240901+Tolsto@users.noreply.github.com>
  • Loading branch information
Tolsto committed Jan 30, 2025
1 parent cb6068b commit e096cc0
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions pkg/webhook/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,32 @@ func getImageConfig(ctx context.Context, client kubernetes.Interface, container
return nil, errors.Wrap(err, "cannot fetch image descriptor")
}

image, err := descriptor.Image()
if err != nil {
return nil, errors.Wrap(err, "cannot convert image descriptor to v1.Image")
var image v1.Image
if descriptor.MediaType.IsIndex() {
index, err := descriptor.ImageIndex()
if err != nil {
return nil, errors.Wrap(err, "cannot get image index")
}

manifest, err := index.IndexManifest()
if err != nil {
return nil, errors.Wrap(err, "cannot get index manifest")
}

if len(manifest.Manifests) == 0 {
return nil, errors.New("no manifests found in the image index")
}

// Get the first available image
image, err = index.Image(manifest.Manifests[0].Digest)
if err != nil {
return nil, errors.Wrap(err, "cannot get image from manifest")
}
} else {
image, err = descriptor.Image()
if err != nil {
return nil, errors.Wrap(err, "cannot convert image descriptor to v1.Image")
}
}

configFile, err := image.ConfigFile()
Expand Down

0 comments on commit e096cc0

Please sign in to comment.