Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file injection with multiple partitions and unblock CI #842

Merged
merged 5 commits into from
Jan 11, 2019
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
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ e2e: &e2e
- run:
name: Prepare all of the nodes for Virtlet pod
command: |
build/cmd.sh prepare-all-nodes
build/portforward.sh 8080&
VIRTLET_SKIP_RSYNC=1 build/cmd.sh prepare-all-nodes

- run:
name: Run e2e tests
Expand All @@ -215,13 +216,14 @@ e2e: &e2e
path: ~/junit

- run:
name: Dump the cluster state
name: Dump the cluster state and display Virtlet version
when: always
command: |
build/portforward.sh 8080&
mkdir -p /tmp/cluster_state
bash -x ./dind-cluster*.sh dump | gzip >/tmp/cluster_state/kdc-dump.gz
_output/virtletctl diag dump --json | gzip >/tmp/cluster_state/virtlet-dump.json.gz
_output/virtletctl version

- store_artifacts:
path: /tmp/cluster_state
Expand Down
10 changes: 7 additions & 3 deletions build/cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ DOCKER_SOCKET_PATH="${DOCKER_SOCKET_PATH:-/var/run/docker.sock}"
FORCE_UPDATE_IMAGE="${FORCE_UPDATE_IMAGE:-}"
IMAGE_REGEXP_TRANSLATION="${IMAGE_REGEXP_TRANSLATION:-1}"
GH_RELEASE_TEST_USER="ivan4th"
DIND_CRI="${DIND_CRI:-containerd}"

# Note that project_dir must not end with slash
project_dir="$(cd "$(dirname "${BASH_SOURCE}")/.." && pwd)"
Expand Down Expand Up @@ -166,7 +167,6 @@ function ensure_build_container {
-v /lib/modules:/lib/modules:ro \
-v /boot:/boot:ro \
-v "${DOCKER_SOCKET_PATH}:/var/run/docker.sock" \
-e DOCKER_HOST="${DOCKER_HOST:-}" \
-e DOCKER_MACHINE_NAME="${DOCKER_MACHINE_NAME:-}" \
-e DOCKER_TLS_VERIFY="${DOCKER_TLS_VERIFY:-}" \
-e TRAVIS="${TRAVIS:-}" \
Expand Down Expand Up @@ -297,9 +297,13 @@ function prepare_node {
kubectl taint nodes kube-master node-role.kubernetes.io/master-
fi
fi
if [[ ${FORCE_UPDATE_IMAGE} ]] || ! docker exec "${node}" docker history -q mirantis/virtlet:latest >&/dev/null; then
if [[ ${FORCE_UPDATE_IMAGE} ]] || ! docker exec "${node}" docker history -q "${virtlet_image}:latest" >&/dev/null; then
echo >&2 "Propagating Virtlet image to the node container..."
vcmd "docker save '${virtlet_image}' | docker exec -i '${node}' docker load"
if [[ ${DIND_CRI} = containerd ]]; then
vcmd "docker save '${virtlet_image}:latest' | docker exec -i '${node}' ctr -n k8s.io images import -"
else
vcmd "docker save '${virtlet_image}:latest' | docker exec -i '${node}' docker load"
fi
fi
}

Expand Down
10 changes: 8 additions & 2 deletions deploy/demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ VIRTLET_MULTI_NODE="${VIRTLET_MULTI_NODE:-}"
IMAGE_REGEXP_TRANSLATION="${IMAGE_REGEXP_TRANSLATION:-1}"
MULTI_CNI="${MULTI_CNI:-}"
DEMO_LOG_LEVEL="${DEMO_LOG_LEVEL:-}"
DIND_CRI="${DIND_CRI:-containerd}"
# Convenience setting for local testing:
# BASE_LOCATION="${HOME}/work/kubernetes/src/github.com/Mirantis/virtlet"
cirros_key="demo-cirros-private-key"
Expand Down Expand Up @@ -161,7 +162,7 @@ function demo::install-cni-genie {
function demo::install-cri-proxy {
local virtlet_node="${1}"
demo::step "Installing CRI proxy package on ${virtlet_node} container"
if [[ ${DIND_CRI:-} = containerd ]]; then
if [[ ${DIND_CRI} = containerd ]]; then
docker exec "${virtlet_node}" /bin/bash -c 'echo criproxy-nodeps criproxy/primary_cri select containerd | debconf-set-selections'
fi
docker exec "${virtlet_node}" /bin/bash -c "curl -sSL '${CRIPROXY_DEB_URL}' >/criproxy.deb && DEBIAN_FRONTEND=noninteractive dpkg -i /criproxy.deb && rm /criproxy.deb"
Expand All @@ -184,7 +185,12 @@ function demo::fix-mounts {
function demo::inject-local-image {
local virtlet_node="${1}"
demo::step "Copying local mirantis/virtlet image into ${virtlet_node} container"
docker save mirantis/virtlet | docker exec -i "${virtlet_node}" docker load
docker save mirantis/virtlet |
if [[ ${DIND_CRI} = containerd ]]; then
docker exec -i "${virtlet_node}" ctr -n k8s.io images import -
else
docker exec -i "${virtlet_node}" docker load
fi
}

function demo::label-and-untaint-node {
Expand Down
53 changes: 27 additions & 26 deletions pkg/diskimage/diskimage_linux.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// +build linux

/*
Copyright 2016 Mirantis
Copyright 2019 Mirantis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,14 +51,15 @@ typedef struct _g_file {
size_t size;
} g_file;

static void update_error(g_wrapper* w, const char* msg)
static void update_error(g_wrapper* w, const char* msg, int use_g_err)
{
int n, p;
const char *g_err, *err;
const char *g_err = 0, *err;
if (*w->error)
return;

g_err = guestfs_last_error(w->g);
if (use_g_err)
g_err = guestfs_last_error(w->g);
if (!g_err && !msg)
return;

Expand Down Expand Up @@ -95,7 +96,7 @@ int g_wrapper_setup(g_wrapper* w, const char* path, int trace)
{
w->g = guestfs_create_flags(0);
if (!w->g) {
update_error(w, "guestfs_create_flags()");
update_error(w, "guestfs_create_flags()", 1);
return -1;
}

Expand All @@ -104,24 +105,24 @@ int g_wrapper_setup(g_wrapper* w, const char* path, int trace)
if (guestfs_add_drive_opts(w->g, path,
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "qcow2",
-1)) {
update_error(w, "guestfs_add_drive_opts()");
update_error(w, "guestfs_add_drive_opts()", 1);
return -1;
}

if (guestfs_launch(w->g) < 0) {
update_error(w, "guestfs_launch()");
update_error(w, "guestfs_launch()", 1);
return -1;
}
w->launched = 1;

w->devs = guestfs_list_devices(w->g);
if (!w->devs) {
update_error(w, "guestfs_list_devices()");
update_error(w, "guestfs_list_devices()", 1);
return -1;
}

if (!w->devs[0] || w->devs[1]) {
update_error(w, "exactly one device is expected");
update_error(w, "exactly one device is expected", 0);
return -1;
}

Expand All @@ -132,7 +133,7 @@ int g_wrapper_close(g_wrapper* w)
{
int r = 0;
if (!w->g) {
update_error(w, "guestfs handle already closed");
update_error(w, "guestfs handle already closed", 0);
return -1;
}

Expand All @@ -144,7 +145,7 @@ int g_wrapper_close(g_wrapper* w)
while (*w->files) free(*w->files++);

if (w->launched && guestfs_shutdown(w->g) < 0) {
update_error(w, "guestfs_shutdown()");
update_error(w, "guestfs_shutdown()", 1);
r = -1;
}

Expand All @@ -159,12 +160,12 @@ int g_wrapper_close(g_wrapper* w)
static int g_wrapper_part_disk(g_wrapper* w)
{
if (!w->g || !w->devs) {
update_error(w, "guestfs setup not done");
update_error(w, "guestfs setup not done", 0);
return -1;
}

if (guestfs_part_disk(w->g, w->devs[0], "mbr") < 0) {
update_error(w, "guestfs_part_disk()");
update_error(w, "guestfs_part_disk()", 1);
return -1;
}

Expand All @@ -174,18 +175,18 @@ static int g_wrapper_part_disk(g_wrapper* w)
static int g_wrapper_get_partitions(g_wrapper* w)
{
if (!w->g || !w->devs) {
update_error(w, "guestfs setup not done");
update_error(w, "guestfs setup not done", 0);
return -1;
}

w->parts = guestfs_list_partitions(w->g);
if (!w->parts) {
update_error(w, "guestfs_list_partitions()");
update_error(w, "guestfs_list_partitions()", 1);
return -1;
}

if (!w->parts[0] || w->parts[1]) {
update_error(w, "exactly one partition is expected");
if (!w->parts[0]) {
update_error(w, "at least one partition is expected", 0);
return -1;
}

Expand All @@ -198,7 +199,7 @@ int g_wrapper_format(g_wrapper* w)
return -1;

if (guestfs_mkfs(w->g, "ext4", w->parts[0]) < 0) {
update_error(w, "guestfs_mkfs()");
update_error(w, "guestfs_mkfs()", 1);
return -1;
}

Expand All @@ -213,25 +214,25 @@ int g_wrapper_put(g_wrapper* w, int n, g_file* files)
return -1;

if (guestfs_mount(w->g, w->parts[0], "/")) {
update_error(w, "guestfs_mount()");
update_error(w, "guestfs_mount()", 1);
return -1;
}

while (n--) {
if (strlen(files->path) > PATH_MAX) {
update_error(w, "file path too long");
update_error(w, "file path too long", 0);
return -1;
}

// dirname may modify the string, so we need to clone path
strcpy(path, files->path);
if (guestfs_mkdir_p(w->g, dirname(path)) < 0) {
update_error(w, "guestfs_mkdir_p()");
update_error(w, "guestfs_mkdir_p()", 1);
return -1;
}

if (guestfs_write(w->g, files->path, files->content, files->size) < 0) {
update_error(w, "guestfs_write()");
update_error(w, "guestfs_write()", 1);
return -1;
}

Expand All @@ -251,13 +252,13 @@ char** g_wrapper_ls(g_wrapper* w, const char* dir)
return 0;

if (guestfs_mount(w->g, w->parts[0], "/")) {
update_error(w, "guestfs_mount()");
update_error(w, "guestfs_mount()", 1);
return 0;
}

w->files = guestfs_ls(w->g, dir);
if (!w->files) {
update_error(w, "guestfs_ls()");
update_error(w, "guestfs_ls()", 1);
return 0;
}

Expand All @@ -274,13 +275,13 @@ char* g_wrapper_cat(g_wrapper* w, const char* path)
return 0;

if (guestfs_mount(w->g, w->parts[0], "/")) {
update_error(w, "guestfs_mount()");
update_error(w, "guestfs_mount()", 1);
return 0;
}

w->file_content = guestfs_cat(w->g, path);
if (w->file_content == 0) {
update_error(w, "guestfs_cat()");
update_error(w, "guestfs_cat()", 1);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/diskimage/diskimage_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2016 Mirantis
Copyright 2019 Mirantis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/diskimage/diskimage_unsupported.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// +build !linux

/*
Copyright 2016 Mirantis
Copyright 2019 Mirantis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down