Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ on:
jobs:
lint-and-test:
name: Lint and Test
runs-on: ubuntu-latest
runs-on: ubuntu-26.04
steps:
- name: Set up Go
uses: actions/setup-go@v5
Expand All @@ -49,7 +49,7 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-latest
- os: ubuntu-26.04
target: linux
- os: windows-latest
target: windows
Expand All @@ -69,16 +69,16 @@ jobs:
- name: Build
run: make ${{ matrix.target }}
- name: Build Docker Image
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'ubuntu-26.04'
run: make docker
build:
name: Build
runs-on: ubuntu-latest
runs-on: ubuntu-26.04
needs:
- lint-and-test
- build-platform
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Result
run: echo "Lint and Test, Build (ubuntu-latest), Build (windows-latest), Build (macos-latest) completed successfully!"
run: echo "Lint and Test, Build (ubuntu-26.04), Build (windows-latest), Build (macos-latest) completed successfully!"
3 changes: 3 additions & 0 deletions .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@ jobs:
- name: Run KinD E2E Test
run: make e2e-test-kind

- name: Run KinD containerd 1.7 E2E Test
run: make e2e-test-kind-containerd-1.7

- name: Run KinD Collect-on-Failure E2E Test
run: make e2e-test-kind-collect
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Unreleased
* Upgrade Go dependencies affected by known security advisories: `golang.org/x/crypto`, `github.com/containerd/containerd/v2`, `google.golang.org/grpc`, `github.com/moby/go-archive`, `github.com/moby/spdystream`, `github.com/moby/buildkit`, and the OpenTelemetry SDK and OTLP trace exporters.
* Upgrade `testcontainers-go` to v0.44.0 so Docker Compose no longer imports a BuildKit package removed in the patched release.
* Use `github.com/moby/moby/client` for Docker Engine API calls. `github.com/docker/docker` has no patched release for its advisories.
* Fix `setup.kind.import-images` failing with `ctr: content digest ... not found` when Docker uses the containerd image store (the default from Docker 29, e.g. on `ubuntu-26.04` runners). Images are now saved for the kind nodes' platform and loaded with `kind load image-archive`; Docker with the classic image store keeps `kind load docker-image`.
* Fix `setup.kind.import-images` failing when Docker uses the containerd image store (the default from Docker 29, e.g. on `ubuntu-26.04` runners). Images are now saved for the kind nodes' platform, so a multi-platform image no longer fails with `ctr: content digest ... not found`, and the referrers saved beside an image, such as its attestations and their signatures, are removed from the archive's top-level index: a containerd 1.7 node (node images built by kind v0.20 to v0.26) otherwise imports each one as an image and fails with `ctr: mismatched image rootfs and manifest layers`. The archive is loaded with `kind load image-archive`; Docker with the classic image store keeps `kind load docker-image`.

1.4.0
------------------
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ e2e-test-kind:
printf 'FROM busybox:1.37.0\n' | docker build -t skywalking-infra-e2e/kind-local:test -
./bin/$(GOOS)/$(PROJECT) run -c ./test/e2e/kind/e2e.yaml

.PHONY: e2e-test-kind-containerd-1.7
# Run E2E test with KinD on a containerd 1.7 node (kind v0.25's kindest/node:v1.28.15)
e2e-test-kind-containerd-1.7:
$(MAKE) $(GOOS)
./bin/$(GOOS)/$(PROJECT) run -c ./test/e2e/kind/containerd-1.7/e2e.yaml

.PHONY: e2e-test-kind-collect
# Run E2E test with KinD to verify collect-on-failure functionality
# This test intentionally fails verification to trigger file collection.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/containerd/platforms v1.0.0-rc.4
github.com/google/go-cmp v0.7.0
github.com/moby/moby/client v0.5.0
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.1
github.com/pterm/pterm v0.12.45
github.com/sirupsen/logrus v1.9.4
Expand Down Expand Up @@ -139,7 +140,6 @@ require (
github.com/morikuni/aec v1.1.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.4.1 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
Expand Down
20 changes: 14 additions & 6 deletions internal/components/setup/kind_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ const (
// loadDockerImage runs `kind load docker-image`: kind saves the whole image
// and the nodes import it with `ctr images import --all-platforms`.
loadDockerImage imageLoadMode = iota
// loadPlatformArchive saves only the platform of the kind nodes, then runs
// `kind load image-archive`. With docker's containerd image store, a pulled
// multi-platform image only holds the content of the platform it was pulled
// for, so importing all of its platforms fails with
// loadPlatformArchive saves only the platform of the kind nodes, leaves the
// referrers of the image, such as attestations, out of the archive, then
// runs `kind load image-archive`. With docker's containerd image store, a
// pulled multi-platform image only holds the content of the platform it was
// pulled for, so importing all of its platforms fails with
// "content digest ... not found" (kubernetes-sigs/kind#3795).
loadPlatformArchive
)
Expand Down Expand Up @@ -145,8 +146,8 @@ func importImages(ctx context.Context, images []string, clusterName string) erro
return nil
}

// loadImageArchive saves the platform of the image to a temporary archive and
// loads it with `kind load image-archive`.
// loadImageArchive saves the platform of the image to a temporary archive,
// without its referrers, and loads it with `kind load image-archive`.
func loadImageArchive(ctx context.Context, cli *docker.Client, image string, platform ocispec.Platform, clusterName string) error {
archive, err := os.CreateTemp(util.WorkDir, "kind-image-*.tar")
if err != nil {
Expand All @@ -165,6 +166,13 @@ func loadImageArchive(ctx context.Context, cli *docker.Client, image string, pla
if err := archive.Close(); err != nil {
return fmt.Errorf("write image archive error: %w", err)
}
dropped, err := dropReferrers(archive.Name())
if err != nil {
return err
}
if dropped > 0 {
logger.Log.Infof("left %d referrer(s) of %s, such as attestations, out of the archive", dropped, image)
}
return runKindLoad("load", "image-archive", archive.Name(), "--name", clusterName)
}

Expand Down
187 changes: 187 additions & 0 deletions internal/components/setup/kind_image_archive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you 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 setup

import (
"archive/tar"
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

const (
ociIndexFile = "index.json"
// manifestSubjectAnnotation marks a top-level descriptor of an image archive
// as a referrer of another manifest, such as an attestation or a signature.
manifestSubjectAnnotation = "io.containerd.manifest.subject"
imageNameAnnotation = "io.containerd.image.name"
)

// dropReferrers removes the referrers from the top-level index of an image
// archive saved by docker, and leaves the archive untouched when it has none.
//
// docker's containerd image store saves the referrers of an image, such as its
// attestations and their signatures, beside it in the top-level index, marked
// with manifestSubjectAnnotation. kind imports the archive with `ctr images
// import --all-platforms --digests`: containerd 1.7 (node images built by kind
// v0.20 to v0.26) creates an image for every top-level descriptor and unpacks
// it, and as a referrer has no filesystem layers, the import fails with
// "mismatched image rootfs and manifest layers"; containerd 2 only unpacks
// manifests that have filesystem layers. A descriptor that names an image is
// kept even when marked. The blobs of the referrers stay in the archive,
// unreferenced.
func dropReferrers(path string) (int, error) {
data, err := readArchiveFile(path, ociIndexFile)
if err != nil || data == nil {
return 0, err
}
var index map[string]json.RawMessage
if err := json.Unmarshal(data, &index); err != nil {
return 0, fmt.Errorf("parse %s of the image archive error: %w", ociIndexFile, err)
}
var manifests []json.RawMessage
if raw, ok := index["manifests"]; ok {
if err := json.Unmarshal(raw, &manifests); err != nil {
return 0, fmt.Errorf("parse %s of the image archive error: %w", ociIndexFile, err)
}
}

// The kept descriptors are copied as saved, so no field of theirs is lost.
kept := make([]json.RawMessage, 0, len(manifests))
for _, m := range manifests {
var desc struct {
Annotations map[string]string `json:"annotations"`
}
if err := json.Unmarshal(m, &desc); err != nil {
return 0, fmt.Errorf("parse %s of the image archive error: %w", ociIndexFile, err)
}
_, referrer := desc.Annotations[manifestSubjectAnnotation]
_, named := desc.Annotations[imageNameAnnotation]
_, refNamed := desc.Annotations[ocispec.AnnotationRefName]
if !referrer || named || refNamed {
kept = append(kept, m)
}
}
dropped := len(manifests) - len(kept)
if dropped == 0 {
return 0, nil
}

if index["manifests"], err = json.Marshal(kept); err != nil {
return 0, err
}
newIndex, err := json.Marshal(index)
if err != nil {
return 0, err
}
return dropped, rewriteArchiveFile(path, ociIndexFile, newIndex)
}

// readArchiveFile returns the content of a file in a tar archive, or nil when
// the archive does not have it.
func readArchiveFile(path, name string) ([]byte, error) {
f, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("open image archive error: %w", err)
}
defer func() {
_ = f.Close()
}()
tr := tar.NewReader(f)
for {
hdr, err := tr.Next()
if errors.Is(err, io.EOF) {
return nil, nil
}
if err != nil {
return nil, fmt.Errorf("read image archive error: %w", err)
}
if strings.TrimPrefix(hdr.Name, "./") == name {
data, err := io.ReadAll(tr)
if err != nil {
return nil, fmt.Errorf("read %s of the image archive error: %w", name, err)
}
return data, nil
}
}
}

// rewriteArchiveFile replaces the content of one file of a tar archive, copying
// every other entry as it is.
func rewriteArchiveFile(path, name string, content []byte) error {
dst, err := os.CreateTemp(filepath.Dir(path), filepath.Base(path)+".*")
if err != nil {
return fmt.Errorf("create image archive error: %w", err)
}
err = copyArchive(path, dst, name, content)
if closeErr := dst.Close(); err == nil && closeErr != nil {
err = fmt.Errorf("write image archive error: %w", closeErr)
}
// Both archives are closed by now: Windows cannot replace an open file.
if err == nil {
err = os.Rename(dst.Name(), path)
}
if err != nil {
_ = os.Remove(dst.Name())
}
return err
}

func copyArchive(path string, dst io.Writer, name string, content []byte) error {
src, err := os.Open(path)
if err != nil {
return fmt.Errorf("open image archive error: %w", err)
}
defer func() {
_ = src.Close()
}()
tr := tar.NewReader(src)
tw := tar.NewWriter(dst)
for {
hdr, err := tr.Next()
if errors.Is(err, io.EOF) {
break
}
if err != nil {
return fmt.Errorf("read image archive error: %w", err)
}
var body io.Reader = tr
if strings.TrimPrefix(hdr.Name, "./") == name {
hdr.Size = int64(len(content))
body = bytes.NewReader(content)
}
if err := tw.WriteHeader(hdr); err != nil {
return fmt.Errorf("write image archive error: %w", err)
}
if _, err := io.Copy(tw, body); err != nil {
return fmt.Errorf("write image archive error: %w", err)
}
}
if err := tw.Close(); err != nil {
return fmt.Errorf("write image archive error: %w", err)
}
return nil
}
Loading
Loading