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

Add virtletctl gen #642

Merged
merged 16 commits into from
Apr 4, 2018
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
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ jobs:
name: Build virtlet
command: |
build/portforward.sh 18730&
build/cmd.sh build
SET_VIRTLET_IMAGE_TAG="${CIRCLE_TAG:-}" build/cmd.sh build
build/cmd.sh copy
- run:
name: Save image
Expand All @@ -265,6 +265,7 @@ jobs:
- virtlet.tar
- virtlet-e2e-tests
- virtletctl
- virtletctl.darwin
# needed by integration tests
- vmwrapper
- store_artifacts:
Expand Down Expand Up @@ -356,6 +357,8 @@ jobs:
name: Make a release
command: |
build/portforward.sh 18730&
build/cmd.sh start-build-container
docker cp _output virtlet-build:/go/src/github.com/Mirantis/virtlet/
build/cmd.sh release "${CIRCLE_TAG}"

workflows:
Expand Down
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ exclude_patterns:
- "tests/"
- "**/*_test.go"
- "*_test.go"
- "pkg/tools/bindata.go"
98 changes: 59 additions & 39 deletions build/cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ VIRTLET_ON_MASTER="${VIRTLET_ON_MASTER:-}"
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"

# Note that project_dir must not end with slash
project_dir="$(cd "$(dirname "${BASH_SOURCE}")/.." && pwd)"
Expand All @@ -35,11 +36,10 @@ virtlet_node=kube-node-1
if [[ ${VIRTLET_ON_MASTER} ]]; then
virtlet_node=kube-master
fi

dind_mounts='.items[0].spec.template.spec.volumes|=.+[{"name":"dind",hostPath:{"path":"/dind"}}]|.items[0].spec.template.spec.containers[].volumeMounts|=.+[{"name":"dind", "mountPath":"/dind"}]|.items[0].spec.template.spec.initContainers[].volumeMounts|=.+[{"name":"dind", "mountPath":"/dind"}]'
containers_run='.items[0].spec.template.spec.containers|=map(.volumeMounts|=map(select(.name!="run"))+[{"mountPath": "/run:shared", "name": "run"}])'
initContainers_run='.items[0].spec.template.spec.initContainers|=map(.volumeMounts|=map(select(.name!="run"))+[{"mountPath": "/run:shared", "name": "run"}])'
containers_k8s_dir='.items[0].spec.template.spec.containers[1].volumeMounts|=map(select(.name!="k8s-pods-dir"))+[{"mountPath": "/var/lib/kubelet/pods:shared", "name": "k8s-pods-dir"}]'
bindata_modtime=1522279343
bindata_out="pkg/tools/bindata.go"
bindata_dir="deploy/data"
bindata_pkg="tools"

function image_tags_filter {
local tag="${1}"
Expand Down Expand Up @@ -264,6 +264,7 @@ function kvm_ok {
}

function start_dind {
ensure_build_container
if ! docker exec "${virtlet_node}" dpkg-query -W criproxy-nodeps >&/dev/null; then
echo >&2 "Installing CRI proxy package the node container..."
docker exec "${virtlet_node}" /bin/bash -c "curl -sSL '${CRIPROXY_DEB_URL}' >/criproxy.deb && dpkg -i /criproxy.deb && rm /criproxy.deb"
Expand All @@ -284,7 +285,7 @@ function start_dind {
vcmd "docker save '${virtlet_image}' | docker exec -i '${virtlet_node}' docker load"
fi
local -a virtlet_config=(--from-literal=image_regexp_translation="${IMAGE_REGEXP_TRANSLATION}")
if ! kvm_ok; then
if ! kvm_ok || [[ ${VIRTLET_DISABLE_KVM:-} ]]; then
virtlet_config+=(--from-literal=disable_kvm=y)
fi
kubectl label node --overwrite "${virtlet_node}" extraRuntime=virtlet
Expand All @@ -294,18 +295,13 @@ function start_dind {
}

function start_virtlet {
# For k8s 1.7 removing MountPropagation option and restoring old hack with
# adding :shared to mountPath
if ! kubectl version | tail -n1 | grep -q 'v1\.7\.'; then
kubectl convert --local -o json -f "${project_dir}/deploy/virtlet-ds.yaml" |
jq "${dind_mounts}" |
kubectl apply -f -
else
filters="${dind_mounts}|${containers_run}|${initContainers_run}|${containers_k8s_dir}"
kubectl convert --local -o json -f "${project_dir}/deploy/virtlet-ds.yaml" |
jq "${filters}" |
kubectl apply -f -
local -a opts=(--dev)
if kubectl version | tail -n1 | grep -q 'v1\.7\.'; then
# apply mount propagation hacks for 1.7
opts+=(--compat)
fi
docker exec virtlet-build "${remote_project_dir}/_output/virtletctl" gen "${opts[@]}" |
kubectl apply -f -
}

function virtlet_subdir {
Expand Down Expand Up @@ -371,9 +367,31 @@ function run_integration_internal {
( cd tests/integration && ./go.test )
}

function set_version {
# TODO: always generate & set version in addition to the tag
if [[ ! ${SET_VIRTLET_IMAGE_TAG:-} ]]; then
return
fi
cat >"${project_dir}/pkg/version/version.go" <<EOF
package version

func init () {
VirtletImageTag = "${SET_VIRTLET_IMAGE_TAG:-}"
}
EOF
}

function build_internal {
# we don't just always generate the bindata right there because we
# want to keep the source buildable outside this build container.
go-bindata -o /tmp/bindata.go -modtime "${bindata_modtime}" -pkg "${bindata_pkg}" "${bindata_dir}"
if ! cmp /tmp/bindata.go "${bindata_out}"; then
echo >&2 "${bindata_dir} changed, please re-run ${0} update-bindata"
exit 1
fi
install_vendor_internal
mkdir -p "${project_dir}/_output"
set_version
go build -i -o "${project_dir}/_output/virtlet" ./cmd/virtlet
go build -i -o "${project_dir}/_output/virtletctl" ./cmd/virtletctl
GOOS=darwin go build -i -o "${project_dir}/_output/virtletctl.darwin" ./cmd/virtletctl
Expand All @@ -382,14 +400,6 @@ function build_internal {
go test -i -c -o "${project_dir}/_output/virtlet-e2e-tests" ./tests/e2e
}

function patch_yaml {
local kubectl="${1}"
local filter="${2}"
"${kubectl}" convert --local -o json -f deploy/virtlet-ds.yaml |
jq "${filter}" |
"${kubectl}" convert --local -o yaml -f -
}

function release_description {
local -a tag="${1}"
shift
Expand All @@ -403,8 +413,12 @@ function release_description {

function release_internal {
local tag="${1}"
local -a opts=(--user Mirantis --repo virtlet --tag "${tag}")
local -a files=(virtlet-ds.yaml virtlet-ds-1.7.yaml virtletctl virtletctl.darwin)
local gh_user="Mirantis"
if [[ ${tag} =~ test ]]; then
gh_user="${GH_RELEASE_TEST_USER}"
fi
local -a opts=(--user "${gh_user}" --repo virtlet --tag "${tag}")
local -a files=(virtletctl virtletctl.darwin)
local description="$(release_description "${tag}" "${files[@]}")"
local pre_release=
# TODO: uncomment this 'if/fi' once we start making 'non-pre' releases
Expand All @@ -418,14 +432,6 @@ function release_internal {
--name "$(git tag -l --format='%(contents:subject)' "${tag}")" \
--description "${description}" \
${pre_release}
# piping the patched yaml directly to
# 'github-release upload ... --file -' causes GH API error:
# "error: could not upload, status code (400 Bad Request), msg: Bad Content-Length: , errors:"
mkdir -p _output
patch_yaml kubectl "$(image_tags_filter "${tag}")" >_output/virtlet-ds.yaml
# use older kubectl for 1.7 to avoid making yaml
# that can't be consumed by k8s 1.7
patch_yaml kubectl.old "$(image_tags_filter "${tag}")|${containers_run}|${initContainers_run}|${containers_k8s_dir}" >_output/virtlet-ds-1.7.yaml
for filename in "${files[@]}"; do
echo >&2 "Uploading: ${filename}"
github-release upload "${opts[@]}" \
Expand All @@ -442,6 +448,12 @@ function e2e {
docker exec virtlet-build _output/virtlet-e2e-tests -include-unsafe-tests=true -cluster-url "${cluster_url}" "$@"
}

function update_bindata_internal {
# set fixed modtime to avoid unwanted differences during the checks
# that are done by build/cmd.sh build
go-bindata -modtime "${bindata_modtime}" -o "${bindata_out}" -pkg "${bindata_pkg}" "${bindata_dir}"
}

function usage {
echo >&2 "Usage:"
echo >&2 " $0 build"
Expand Down Expand Up @@ -474,20 +486,20 @@ case "${cmd}" in
gobuild "$@"
;;
prepare-vendor)
( vcmd "build/cmd.sh install-vendor-internal" )
vcmd "build/cmd.sh install-vendor-internal"
;;
build)
( vcmd "build/cmd.sh build-image-internal" )
vcmd "SET_VIRTLET_IMAGE_TAG='${SET_VIRTLET_IMAGE_TAG:-}' build/cmd.sh build-image-internal"
;;
build-image-internal)
# this is executed inside the container
build_image_internal "$@"
;;
test)
( vcmd 'build/cmd.sh run-tests-internal' )
vcmd 'build/cmd.sh run-tests-internal'
;;
integration)
( vcmd 'build/cmd.sh run-integration-internal' )
vcmd 'build/cmd.sh run-integration-internal'
;;
install-vendor-internal)
install_vendor_internal
Expand All @@ -498,6 +510,13 @@ case "${cmd}" in
run-integration-internal)
run_integration_internal
;;
update-bindata)
vcmd "build/cmd.sh update-bindata-internal"
docker cp "virtlet-build:${remote_project_dir}/pkg/tools/bindata.go" pkg/tools/bindata.go
;;
update-bindata-internal)
update_bindata_internal
;;
run)
vcmd "$*"
;;
Expand Down Expand Up @@ -534,6 +553,7 @@ case "${cmd}" in
release)
if [[ ! ${1:-} ]]; then
echo >&2 "must specify the tag"
exit 1
fi
( vcmd "build/cmd.sh release-internal '${1}'" )
;;
Expand Down
1 change: 1 addition & 0 deletions cmd/virtletctl/virtletctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func newRootCmd() *cobra.Command {
cmd.AddCommand(tools.NewVNCCmd(client, os.Stdout, true))
cmd.AddCommand(tools.NewInstallCmd(cmd, "", ""))
cmd.AddCommand(tools.NewGenDocCmd(cmd))
cmd.AddCommand(tools.NewGenCmd(os.Stdout))

for _, c := range cmd.Commands() {
c.PreRunE = func(*cobra.Command, []string) error {
Expand Down
26 changes: 22 additions & 4 deletions deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,27 @@ kubectl create configmap -n kube-system virtlet-image-translations --from-file i
CRIPROXY_DEB_URL="https://github.com/Mirantis/criproxy/releases/download/v0.10.0/criproxy-nodeps_0.10.0_amd64.deb"
docker exec kube-node-1 /bin/bash -c "curl -sSL '${CRIPROXY_DEB_URL}' >/criproxy.deb && dpkg -i /criproxy.deb && rm /criproxy.deb"
```
1. Deploy Virtlet DaemonSet (assuming that you have [virtlet-ds.yaml](virtlet-ds.yaml) in the current directory):
1. Download `virtletctl` binary for `virtlet` release you need (replace `N.N.N` in the command below accordingly):
```
kubectl create -f virtlet-ds.yaml
curl -SL -o virtletctl https://github.com/Mirantis/virtlet/releases/download/vN.N.N/virtletctl
chmod +x virtletctl
```
In case if you're using Mac OS X, you need to use this command instead:
```
curl -SL -o virtletctl https://github.com/Mirantis/virtlet/releases/download/vN.N.N/virtletctl.darwin
chmod +x virtletctl
```
You can also use `virtletctl` from Virtlet image, see below.
1. Deploy Virtlet DaemonSet and related objects:
```
./virtletctl gen | kubectl apply -f -
```
If you want to use the latest image, you can use `virtletctl` from that image:
```
docker run --rm mirantis/virtlet:latest virtletctl gen --tag latest | kubectl apply -f -
```
You can also use other image tag instead of `latest`, just replace it in both places
in the above command.
1. Wait for Virtlet pod to activate:
```
kubectl get pods -w -n kube-system
Expand All @@ -48,8 +65,9 @@ kubectl get pods -w -n kube-system

## Configuring Virtlet

Virtlet can be customized through the `virtlet-config` ConfigMap Kuberenetes object.
The following keys in the config map are honored by the `virtlet-ds.yaml`:
Virtlet can be customized through the `virtlet-config` ConfigMap
Kuberenetes object. The following keys in the config map are honored
by Virtlet when it's deployed using k8s yaml produced by `virtletctl gen`:

* `disable_kvm` - disables KVM support and forces QEMU instead. Use "1" as a value.
* `download_protocol` - default image download protocol - either `http` or `https`. The default is https.
Expand Down
6 changes: 6 additions & 0 deletions deploy/virtlet-ds.yaml → deploy/data/virtlet-ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ spec:
name: virtlet-config
key: sriov_support
optional: true
- name: VIRTLET_RAW_DEVICES
valueFrom:
configMapKeyRef:
name: virtlet-config
key: raw_devices
optional: true
- name: IMAGE_TRANSLATIONS_DIR
value: /etc/virtlet/images
- name: KUBERNETES_POD_LOGS
Expand Down
20 changes: 3 additions & 17 deletions deploy/demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,6 @@ function demo::get-correct-virtlet-release {

function demo::start-virtlet {
local -a virtlet_config=(--from-literal=download_protocol=http --from-literal=image_regexp_translation="$IMAGE_REGEXP_TRANSLATION")
local ds_location
local replace_image_in_ds
if [[ ${VIRTLET_DEMO_BRANCH} ]]; then
if [[ ${VIRTLET_DEMO_BRANCH} = "master" ]]; then
virtlet_release="master"
Expand All @@ -281,8 +279,6 @@ function demo::start-virtlet {
virtlet_docker_tag=$(echo $VIRTLET_DEMO_BRANCH | sed -e "s/\//_/g")
BASE_LOCATION="https://raw.githubusercontent.com/Mirantis/virtlet/${virtlet_release}/"
fi
ds_location="${BASE_LOCATION}/deploy/virtlet-ds.yaml"
replace_image_in_ds=1
else
if [[ ${VIRTLET_DEMO_RELEASE} ]]; then
virtlet_release="${VIRTLET_DEMO_RELEASE}"
Expand All @@ -291,9 +287,7 @@ function demo::start-virtlet {
fi
# set correct urls and names
virtlet_docker_tag="${virtlet_release}"
ds_location="${RELEASE_LOCATION}/${virtlet_release}/virtlet-ds.yaml"
BASE_LOCATION="https://raw.githubusercontent.com/Mirantis/virtlet/${virtlet_release}/"
replace_image_in_ds=0
fi
echo "Will run demo using Virtlet:${virtlet_release} for demo and ${virtlet_docker_tag} as docker tag"
if demo::kvm-ok; then
Expand All @@ -319,17 +313,9 @@ function demo::start-virtlet {
fi
fi

if [[ "${replace_image_in_ds}" == 1 ]]; then
demo::step "Deploying Virtlet DaemonSet from ${ds_location} and will set correct docker tag: ${virtlet_docker_tag}"
if [[ ${BASE_LOCATION} == https://* ]]; then
curl --silent "${ds_location}" | sed "s/image: mirantis\/virtlet/image: mirantis\/virtlet:${virtlet_docker_tag}/g" | "${kubectl}" create -f -
else
sed "s/image: mirantis\/virtlet/image: mirantis\/virtlet:${virtlet_docker_tag}/g" "${ds_location}" | "${kubectl}" create -f -
fi
else
demo::step "Deploying Virtlet DaemonSet from ${ds_location}"
"${kubectl}" create -f "${ds_location}"
fi
demo::step "Deploying Virtlet DaemonSet with docker tag ${virtlet_docker_tag}"
docker run --rm "mirantis/virtlet:${virtlet_docker_tag}" virtletctl gen --tag "${virtlet_docker_tag}" |
"${kubectl}" apply -f -
demo::wait-for "Virtlet DaemonSet" demo::pods-ready runtime=virtlet
}

Expand Down
21 changes: 19 additions & 2 deletions deploy/real-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,27 @@ curl https://raw.githubusercontent.com/Mirantis/virtlet/master/deploy/images.yam
kubectl create configmap -n kube-system virtlet-image-translations --from-file images.yaml
```

Then you can deploy Virtlet DaemonSet:
After that, you need to get `virtletctl` command line tool (replace `N.N.N` in the command below accordingly):
```
curl -SL -o virtletctl https://github.com/Mirantis/virtlet/releases/download/vN.N.N/virtletctl
```
In case if you're using Mac OS X, you need to use this command instead:
```
curl -SL -o virtletctl https://github.com/Mirantis/virtlet/releases/download/vN.N.N/virtletctl.darwin
```
You can also use `virtletctl` from Virtlet image, see below.

Then you can deploy Virtlet:
```bash
kubectl apply -f https://raw.githubusercontent.com/Mirantis/virtlet/master/deploy/virtlet-ds.yaml
./virtletctl gen | kubectl apply -f -
```

If you want to use the latest image, you can use `virtletctl` from that image:
```
docker run --rm mirantis/virtlet:latest virtletctl gen --tag latest | kubectl apply -f -
```
You can also use other image tag instead of `latest`, just replace it in both places
in the above command.

By default it has KVM enabled, but you can configure Virtlet to
disable it. In order to do so, create a configmap named
Expand Down
7 changes: 3 additions & 4 deletions docs/devel/running-local-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ set `CNI_PLUGIN` environment variable:
$ export CNI_PLUGIN=flannel
```

Note that KVM is disabled by default for the development environment.
In order to enable it, comment out `VIRTLET_DISABLE_KVM` environment
variable setting in `deploy/virtlet-ds.yaml` before doing
`build/cmd.sh start-dind`.
Virtlet uses KVM if it's available by default. To disable it for your
local development environment, set `VIRTLET_DISABLE_KVM` environment
variable to a non-empty value before running `build/cmd.sh start-dind`.
2 changes: 1 addition & 1 deletion docs/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Virtlet supports QCOW2 format for VM images.
- protocol to use to download the image. By default `https` is
used. In order to use `http` set `VIRTLET_DOWNLOAD_PROTOCOL` env var
to `http` for the virtlet container. With the standard deployment
method (using [virtlet-ds.yaml](../deploy/virtlet-ds.yaml)) this can
method (using `virtletctl gen`) this can
be done by setting `download_protocol` key to `http` in the
`virtlet-config` ConfigMap.
`<scheme>://` below denotes the selected protocol.
Expand Down
Loading