Update test and run test containerd in a different directory.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
@@ -17,17 +17,15 @@ limitations under the License.
|
||||
package integration
|
||||
|
||||
import (
|
||||
"golang.org/x/net/context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
||||
|
||||
api "github.com/containerd/cri/pkg/api/v1"
|
||||
)
|
||||
|
||||
// Test to load an image from tarball.
|
||||
@@ -58,14 +56,22 @@ func TestImageLoad(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Logf("load image in cri")
|
||||
res, err := criPluginClient.LoadImage(context.Background(), &api.LoadImageRequest{FilePath: tar})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{loadedImage}, res.GetImages())
|
||||
ctr, err := exec.LookPath("ctr")
|
||||
require.NoError(t, err, "ctr should be installed, make sure you've run `make install.deps`")
|
||||
output, err = exec.Command(ctr, "-address="+containerdEndpoint,
|
||||
"-n=k8s.io", "images", "import", tar).CombinedOutput()
|
||||
require.NoError(t, err, "output: %q", output)
|
||||
|
||||
t.Logf("make sure image is loaded")
|
||||
img, err = imageService.ImageStatus(&runtime.ImageSpec{Image: testImage})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, img)
|
||||
// Use Eventually because the cri plugin needs a short period of time
|
||||
// to pick up images imported into containerd directly.
|
||||
require.NoError(t, Eventually(func() (bool, error) {
|
||||
img, err = imageService.ImageStatus(&runtime.ImageSpec{Image: testImage})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return img != nil, nil
|
||||
}, 100*time.Millisecond, 10*time.Second))
|
||||
require.Equal(t, []string{loadedImage}, img.RepoTags)
|
||||
|
||||
t.Logf("create a container with the loaded image")
|
||||
|
@@ -38,8 +38,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/remote"
|
||||
kubeletutil "k8s.io/kubernetes/pkg/kubelet/util"
|
||||
|
||||
api "github.com/containerd/cri/pkg/api/v1"
|
||||
"github.com/containerd/cri/pkg/client"
|
||||
criconfig "github.com/containerd/cri/pkg/config"
|
||||
"github.com/containerd/cri/pkg/constants"
|
||||
"github.com/containerd/cri/pkg/server"
|
||||
@@ -47,17 +45,16 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
timeout = 1 * time.Minute
|
||||
pauseImage = "k8s.gcr.io/pause:3.1" // This is the same with default sandbox image.
|
||||
k8sNamespace = constants.K8sContainerdNamespace
|
||||
containerdEndpoint = "/run/containerd/containerd.sock"
|
||||
timeout = 1 * time.Minute
|
||||
pauseImage = "k8s.gcr.io/pause:3.1" // This is the same with default sandbox image.
|
||||
k8sNamespace = constants.K8sContainerdNamespace
|
||||
)
|
||||
|
||||
var (
|
||||
runtimeService cri.RuntimeService
|
||||
imageService cri.ImageManagerService
|
||||
containerdClient *containerd.Client
|
||||
criPluginClient api.CRIPluginServiceClient
|
||||
runtimeService cri.RuntimeService
|
||||
imageService cri.ImageManagerService
|
||||
containerdClient *containerd.Client
|
||||
containerdEndpoint string
|
||||
)
|
||||
|
||||
var criEndpoint = flag.String("cri-endpoint", "unix:///run/containerd/containerd.sock", "The endpoint of cri plugin.")
|
||||
@@ -93,16 +90,12 @@ func ConnectDaemons() error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to list images")
|
||||
}
|
||||
// containerdEndpoint is the same with criEndpoint now
|
||||
containerdEndpoint = strings.TrimPrefix(*criEndpoint, "unix://")
|
||||
containerdClient, err = containerd.New(containerdEndpoint, containerd.WithDefaultNamespace(k8sNamespace))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to connect containerd")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
criPluginClient, err = client.NewCRIPluginClient(ctx, *criEndpoint)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to connect cri plugin")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user