Update test and run test containerd in a different directory.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
322cd48965
commit
199ee362e8
@ -27,7 +27,7 @@ REPORT_DIR=${REPORT_DIR:-"/tmp/test-integration"}
|
|||||||
# RUNTIME is the runtime handler to use in the test.
|
# RUNTIME is the runtime handler to use in the test.
|
||||||
RUNTIME=${RUNTIME:-""}
|
RUNTIME=${RUNTIME:-""}
|
||||||
|
|
||||||
CRI_ROOT="/var/lib/containerd/io.containerd.grpc.v1.cri"
|
CRI_ROOT="${CONTAINERD_ROOT}/io.containerd.grpc.v1.cri"
|
||||||
|
|
||||||
mkdir -p ${REPORT_DIR}
|
mkdir -p ${REPORT_DIR}
|
||||||
test_setup ${REPORT_DIR}
|
test_setup ${REPORT_DIR}
|
||||||
|
@ -23,13 +23,23 @@ CONTAINERD_FLAGS="--log-level=debug "
|
|||||||
|
|
||||||
# Use a configuration file for containerd.
|
# Use a configuration file for containerd.
|
||||||
CONTAINERD_CONFIG_FILE=${CONTAINERD_CONFIG_FILE:-""}
|
CONTAINERD_CONFIG_FILE=${CONTAINERD_CONFIG_FILE:-""}
|
||||||
|
# CONTAINERD_TEST_SUFFIX is the suffix appended to the root/state directory used
|
||||||
|
# by test containerd.
|
||||||
|
CONTAINERD_TEST_SUFFIX=${CONTAINERD_TEST_SUFFIX:-"-test"}
|
||||||
|
# The containerd root directory.
|
||||||
|
CONTAINERD_ROOT=${CONTAINERD_ROOT:-"/var/lib/containerd${CONTAINERD_TEST_SUFFIX}"}
|
||||||
|
# The containerd state directory.
|
||||||
|
CONTAINERD_STATE=${CONTAINERD_STATE:-"/run/containerd${CONTAINERD_TEST_SUFFIX}"}
|
||||||
|
# The containerd socket address.
|
||||||
|
CONTAINERD_SOCK=${CONTAINERD_SOCK:-unix://${CONTAINERD_STATE}/containerd.sock}
|
||||||
if [ -f "${CONTAINERD_CONFIG_FILE}" ]; then
|
if [ -f "${CONTAINERD_CONFIG_FILE}" ]; then
|
||||||
CONTAINERD_FLAGS+="--config ${CONTAINERD_CONFIG_FILE} "
|
CONTAINERD_FLAGS+="--config ${CONTAINERD_CONFIG_FILE} "
|
||||||
fi
|
fi
|
||||||
|
CONTAINERD_FLAGS+="--address ${CONTAINERD_SOCK#"unix://"} \
|
||||||
|
--state ${CONTAINERD_STATE} \
|
||||||
|
--root ${CONTAINERD_ROOT}"
|
||||||
|
|
||||||
CONTAINERD_SOCK=unix:///run/containerd/containerd.sock
|
containerd_groupid=
|
||||||
|
|
||||||
containerd_pid=
|
|
||||||
|
|
||||||
# test_setup starts containerd.
|
# test_setup starts containerd.
|
||||||
test_setup() {
|
test_setup() {
|
||||||
@ -39,10 +49,14 @@ test_setup() {
|
|||||||
echo "containerd is not built"
|
echo "containerd is not built"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
sudo pkill -x containerd
|
set -m
|
||||||
|
# Create containerd in a different process group
|
||||||
|
# so that we can easily clean them up.
|
||||||
keepalive "sudo PATH=${PATH} ${ROOT}/_output/containerd ${CONTAINERD_FLAGS}" \
|
keepalive "sudo PATH=${PATH} ${ROOT}/_output/containerd ${CONTAINERD_FLAGS}" \
|
||||||
${RESTART_WAIT_PERIOD} &> ${report_dir}/containerd.log &
|
${RESTART_WAIT_PERIOD} &> ${report_dir}/containerd.log &
|
||||||
containerd_pid=$!
|
pid=$!
|
||||||
|
set +m
|
||||||
|
containerd_groupid=$(ps -o pgid= -p ${pid})
|
||||||
# Wait for containerd to be running by using the containerd client ctr to check the version
|
# Wait for containerd to be running by using the containerd client ctr to check the version
|
||||||
# of the containerd server. Wait an increasing amount of time after each of five attempts
|
# of the containerd server. Wait an increasing amount of time after each of five attempts
|
||||||
local -r ctr_path=$(which ctr)
|
local -r ctr_path=$(which ctr)
|
||||||
@ -61,10 +75,9 @@ test_setup() {
|
|||||||
|
|
||||||
# test_teardown kills containerd.
|
# test_teardown kills containerd.
|
||||||
test_teardown() {
|
test_teardown() {
|
||||||
if [ -n "${containerd_pid}" ]; then
|
if [ -n "${containerd_groupid}" ]; then
|
||||||
kill ${containerd_pid}
|
sudo pkill -g ${containerd_groupid}
|
||||||
fi
|
fi
|
||||||
sudo pkill -x containerd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# keepalive runs a command and keeps it alive.
|
# keepalive runs a command and keeps it alive.
|
||||||
|
@ -17,17 +17,15 @@ limitations under the License.
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/net/context"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
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.
|
// Test to load an image from tarball.
|
||||||
@ -58,14 +56,22 @@ func TestImageLoad(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("load image in cri")
|
t.Logf("load image in cri")
|
||||||
res, err := criPluginClient.LoadImage(context.Background(), &api.LoadImageRequest{FilePath: tar})
|
ctr, err := exec.LookPath("ctr")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err, "ctr should be installed, make sure you've run `make install.deps`")
|
||||||
require.Equal(t, []string{loadedImage}, res.GetImages())
|
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")
|
t.Logf("make sure image is loaded")
|
||||||
img, err = imageService.ImageStatus(&runtime.ImageSpec{Image: testImage})
|
// Use Eventually because the cri plugin needs a short period of time
|
||||||
require.NoError(t, err)
|
// to pick up images imported into containerd directly.
|
||||||
require.NotNil(t, img)
|
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)
|
require.Equal(t, []string{loadedImage}, img.RepoTags)
|
||||||
|
|
||||||
t.Logf("create a container with the loaded image")
|
t.Logf("create a container with the loaded image")
|
||||||
|
@ -38,8 +38,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/kubelet/remote"
|
"k8s.io/kubernetes/pkg/kubelet/remote"
|
||||||
kubeletutil "k8s.io/kubernetes/pkg/kubelet/util"
|
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"
|
criconfig "github.com/containerd/cri/pkg/config"
|
||||||
"github.com/containerd/cri/pkg/constants"
|
"github.com/containerd/cri/pkg/constants"
|
||||||
"github.com/containerd/cri/pkg/server"
|
"github.com/containerd/cri/pkg/server"
|
||||||
@ -47,17 +45,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
timeout = 1 * time.Minute
|
timeout = 1 * time.Minute
|
||||||
pauseImage = "k8s.gcr.io/pause:3.1" // This is the same with default sandbox image.
|
pauseImage = "k8s.gcr.io/pause:3.1" // This is the same with default sandbox image.
|
||||||
k8sNamespace = constants.K8sContainerdNamespace
|
k8sNamespace = constants.K8sContainerdNamespace
|
||||||
containerdEndpoint = "/run/containerd/containerd.sock"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
runtimeService cri.RuntimeService
|
runtimeService cri.RuntimeService
|
||||||
imageService cri.ImageManagerService
|
imageService cri.ImageManagerService
|
||||||
containerdClient *containerd.Client
|
containerdClient *containerd.Client
|
||||||
criPluginClient api.CRIPluginServiceClient
|
containerdEndpoint string
|
||||||
)
|
)
|
||||||
|
|
||||||
var criEndpoint = flag.String("cri-endpoint", "unix:///run/containerd/containerd.sock", "The endpoint of cri plugin.")
|
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 {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to list images")
|
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))
|
containerdClient, err = containerd.New(containerdEndpoint, containerd.WithDefaultNamespace(k8sNamespace))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to connect containerd")
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user