Merge pull request #9183 from dcantah/cri-snapshotter-platform

This commit is contained in:
Fu Wei 2023-10-04 11:40:33 +08:00 committed by GitHub
commit bce8fe60df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 12 deletions

View File

@ -757,10 +757,10 @@ func (c *CRIImageService) snapshotterFromPodSandboxConfig(ctx context.Context, i
// TODO: Find other way to retrieve sandbox runtime, this must belong to the Runtime part of the CRI. // TODO: Find other way to retrieve sandbox runtime, this must belong to the Runtime part of the CRI.
ociRuntime, err := c.getSandboxRuntime(s, runtimeHandler) ociRuntime, err := c.getSandboxRuntime(s, runtimeHandler)
if err != nil { if err != nil {
return "", fmt.Errorf("experimental: failed to get sandbox runtime for %s, err: %+v", runtimeHandler, err) return "", fmt.Errorf("experimental: failed to get sandbox runtime for %s: %w", runtimeHandler, err)
} }
snapshotter = c.RuntimeSnapshotter(context.Background(), ociRuntime) snapshotter = c.RuntimeSnapshotter(ctx, ociRuntime)
log.G(ctx).Infof("experimental: PullImage %q for runtime %s, using snapshotter %s", imageRef, runtimeHandler, snapshotter) log.G(ctx).Infof("experimental: PullImage %q for runtime %s, using snapshotter %s", imageRef, runtimeHandler, snapshotter)
return snapshotter, nil return snapshotter, nil
} }

View File

@ -19,7 +19,6 @@ package images
import ( import (
"context" "context"
"encoding/base64" "encoding/base64"
"fmt"
"testing" "testing"
docker "github.com/distribution/reference" docker "github.com/distribution/reference"
@ -383,7 +382,7 @@ func TestSnapshotterFromPodSandboxConfig(t *testing.T) {
desc string desc string
podSandboxConfig *runtime.PodSandboxConfig podSandboxConfig *runtime.PodSandboxConfig
expectSnapshotter string expectSnapshotter string
expectErr error expectErr bool
}{ }{
{ {
desc: "should return default snapshotter for nil podSandboxConfig", desc: "should return default snapshotter for nil podSandboxConfig",
@ -408,7 +407,7 @@ func TestSnapshotterFromPodSandboxConfig(t *testing.T) {
annotations.RuntimeHandler: "runtime-not-exists", annotations.RuntimeHandler: "runtime-not-exists",
}, },
}, },
expectErr: fmt.Errorf(`experimental: failed to get sandbox runtime for runtime-not-exists, err: no runtime for "runtime-not-exists" is configured`), expectErr: true,
expectSnapshotter: "", expectSnapshotter: "",
}, },
{ {
@ -432,7 +431,9 @@ func TestSnapshotterFromPodSandboxConfig(t *testing.T) {
} }
snapshotter, err := cri.snapshotterFromPodSandboxConfig(context.Background(), "test-image", tt.podSandboxConfig) snapshotter, err := cri.snapshotterFromPodSandboxConfig(context.Background(), "test-image", tt.podSandboxConfig)
assert.Equal(t, tt.expectSnapshotter, snapshotter) assert.Equal(t, tt.expectSnapshotter, snapshotter)
assert.Equal(t, tt.expectErr, err) if tt.expectErr {
assert.Error(t, err)
}
}) })
} }
} }

View File

@ -729,10 +729,10 @@ func (c *criService) snapshotterFromPodSandboxConfig(ctx context.Context, imageR
ociRuntime, err := c.getSandboxRuntime(s, runtimeHandler) ociRuntime, err := c.getSandboxRuntime(s, runtimeHandler)
if err != nil { if err != nil {
return "", fmt.Errorf("experimental: failed to get sandbox runtime for %s, err: %+v", runtimeHandler, err) return "", fmt.Errorf("experimental: failed to get sandbox runtime for %s: %w", runtimeHandler, err)
} }
snapshotter = c.runtimeSnapshotter(context.Background(), ociRuntime) snapshotter = c.runtimeSnapshotter(ctx, ociRuntime)
log.G(ctx).Infof("experimental: PullImage %q for runtime %s, using snapshotter %s", imageRef, runtimeHandler, snapshotter) log.G(ctx).Infof("experimental: PullImage %q for runtime %s, using snapshotter %s", imageRef, runtimeHandler, snapshotter)
return snapshotter, nil return snapshotter, nil
} }

View File

@ -19,7 +19,6 @@ package server
import ( import (
"context" "context"
"encoding/base64" "encoding/base64"
"fmt"
"testing" "testing"
"github.com/containerd/containerd/pkg/cri/annotations" "github.com/containerd/containerd/pkg/cri/annotations"
@ -381,7 +380,7 @@ func TestSnapshotterFromPodSandboxConfig(t *testing.T) {
desc string desc string
podSandboxConfig *runtime.PodSandboxConfig podSandboxConfig *runtime.PodSandboxConfig
expectSnapshotter string expectSnapshotter string
expectErr error expectErr bool
}{ }{
{ {
desc: "should return default snapshotter for nil podSandboxConfig", desc: "should return default snapshotter for nil podSandboxConfig",
@ -406,7 +405,7 @@ func TestSnapshotterFromPodSandboxConfig(t *testing.T) {
annotations.RuntimeHandler: "runtime-not-exists", annotations.RuntimeHandler: "runtime-not-exists",
}, },
}, },
expectErr: fmt.Errorf(`experimental: failed to get sandbox runtime for runtime-not-exists, err: no runtime for "runtime-not-exists" is configured`), expectErr: true,
expectSnapshotter: "", expectSnapshotter: "",
}, },
{ {
@ -431,7 +430,9 @@ func TestSnapshotterFromPodSandboxConfig(t *testing.T) {
} }
snapshotter, err := cri.snapshotterFromPodSandboxConfig(context.Background(), "test-image", tt.podSandboxConfig) snapshotter, err := cri.snapshotterFromPodSandboxConfig(context.Background(), "test-image", tt.podSandboxConfig)
assert.Equal(t, tt.expectSnapshotter, snapshotter) assert.Equal(t, tt.expectSnapshotter, snapshotter)
assert.Equal(t, tt.expectErr, err) if tt.expectErr {
assert.Error(t, err)
}
}) })
} }
} }