From 51a606df2fc86888f87bf80287f77e3399cab028 Mon Sep 17 00:00:00 2001 From: Roman Mohr Date: Mon, 11 Dec 2017 08:39:52 +0100 Subject: [PATCH 1/7] Introduce interface to support different envs Signed-off-by: Roman Mohr --- .gitignore | 5 ++ Makefile | 13 ----- cluster/deploy.sh | 23 ++++---- cluster/down.sh | 5 ++ cluster/kubectl.sh | 19 ++++--- cluster/local/provider.sh | 52 +++++++++++++++++++ cluster/sync.sh | 7 ++- cluster/up.sh | 5 ++ cluster/vagrant/provider.sh | 47 +++++++++++++++++ cluster/vagrant/sync_build.sh | 26 ---------- cluster/vagrant/sync_config.sh | 30 ----------- docs/dev-env-local.md | 95 ---------------------------------- docs/env-providers.md | 51 ++++++++++++++++++ docs/getting-started.md | 6 +-- 14 files changed, 199 insertions(+), 185 deletions(-) create mode 100755 cluster/down.sh create mode 100644 cluster/local/provider.sh create mode 100755 cluster/up.sh create mode 100644 cluster/vagrant/provider.sh delete mode 100755 cluster/vagrant/sync_build.sh delete mode 100755 cluster/vagrant/sync_config.sh delete mode 100644 docs/dev-env-local.md create mode 100644 docs/env-providers.md diff --git a/.gitignore b/.gitignore index 23ca2d449f96..5abdb95bfc1f 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,8 @@ tags hack/gen-swagger-doc/*.adoc hack/gen-swagger-doc/*.md hack/gen-swagger-doc/html5 +cluster/local/certs +**.swp +**.pem +**.crt +**.csr diff --git a/Makefile b/Makefile index b60eed4e8711..c3aff6df3d27 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,6 @@ checksync: sync: glide install --strip-vendor ${HASH} glide.lock > .glide.lock.hash - docker: build ./hack/build-docker.sh build ${WHAT} @@ -83,18 +82,6 @@ check: check-bash vet check-bash: find . -name \*.sh -exec bash -n \{\} \; -vagrant-sync-config: - ./cluster/vagrant/sync_config.sh - -vagrant-sync-build: build - ./cluster/vagrant/sync_build.sh - -vagrant-sync-optional: - ./cluster/vagrant/sync_build.sh 'build optional' - -vagrant-deploy: vagrant-sync-config vagrant-sync-build - export KUBECTL="cluster/kubectl.sh" && ./cluster/deploy.sh - .release-functest: make functest > .release-functest 2>&1 diff --git a/cluster/deploy.sh b/cluster/deploy.sh index a852501d7700..4c932a0db946 100755 --- a/cluster/deploy.sh +++ b/cluster/deploy.sh @@ -19,21 +19,22 @@ set -ex -KUBECTL=${KUBECTL:-kubectl} +PROVIDER=${PROVIDER:-vagrant} +source cluster/$PROVIDER/provider.sh source hack/config.sh echo "Cleaning up ..." # Work around https://github.com/kubernetes/kubernetes/issues/33517 -$KUBECTL delete ds -l "kubevirt.io" -n kube-system --cascade=false --grace-period 0 2>/dev/null || : -$KUBECTL delete pods -n kube-system -l="kubevirt.io=libvirt" --force --grace-period 0 2>/dev/null || : -$KUBECTL delete pods -n kube-system -l="kubevirt.io=virt-handler" --force --grace-period 0 2>/dev/null || : +_kubectl delete ds -l "kubevirt.io" -n kube-system --cascade=false --grace-period 0 2>/dev/null || : +_kubectl delete pods -n kube-system -l="kubevirt.io=libvirt" --force --grace-period 0 2>/dev/null || : +_kubectl delete pods -n kube-system -l="kubevirt.io=virt-handler" --force --grace-period 0 2>/dev/null || : # Delete everything, no matter if release, devel or infra -$KUBECTL delete -f manifests -R --grace-period 1 2>/dev/null || : +_kubectl delete -f manifests -R --grace-period 1 2>/dev/null || : # Delete exposures -$KUBECTL delete services -l "kubevirt.io" -n kube-system +_kubectl delete services -l "kubevirt.io" -n kube-system sleep 2 @@ -41,12 +42,16 @@ echo "Deploying ..." # Deploy the right manifests for the right target if [ -z "$TARGET" ] || [ "$TARGET" = "vagrant-dev" ]; then - $KUBECTL create -f manifests/dev -R $i + _kubectl create -f manifests/dev -R $i elif [ "$TARGET" = "vagrant-release" ]; then - $KUBECTL create -f manifests/release -R $i + _kubectl create -f manifests/release -R $i fi +## Expose common services +$KUBECTL expose deployment haproxy --port 8184 -l 'kubevirt.io=haproxy' -n kube-system --external-ip $master_ip +$KUBECTL expose deployment spice-proxy --port 3128 -l 'kubevirt.io=spice-proxy' -n kube-system --external-ip $master_ip + # Deploy additional infra for testing -$KUBECTL create -f manifests/testing -R $i +_kubectl create -f manifests/testing -R $i echo "Done" diff --git a/cluster/down.sh b/cluster/down.sh new file mode 100755 index 000000000000..37999b26ad54 --- /dev/null +++ b/cluster/down.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +PROVIDER=${PROVIDER:-vagrant} +source cluster/$PROVIDER/provider.sh +down diff --git a/cluster/kubectl.sh b/cluster/kubectl.sh index 9d2fb10d53a7..a8f466e5d070 100755 --- a/cluster/kubectl.sh +++ b/cluster/kubectl.sh @@ -17,13 +17,12 @@ # Copyright 2017 Red Hat, Inc. # +PROVIDER=${PROVIDER:-vagrant} +source cluster/$PROVIDER/provider.sh source ${KUBEVIRT_PATH}hack/config.sh -SYNC_CONFIG=${KUBEVIRT_PATH}cluster/vagrant/sync_config.sh - -if [ "$1" == "--init" ] -then - exec $SYNC_CONFIG +if [ "$1" == "console" ] || [ "$1" == "spice" ]; then + cmd/virtctl/virtctl "$@" -s http://${master_ip}:8184 exit fi @@ -33,8 +32,12 @@ if [ "$1" == "--help" ] || [ "$1" == "-h" ] ; then fi if [ -e ${KUBEVIRT_PATH}cluster/vagrant/.kubeconfig ] && - [ -e ${KUBEVIRT_PATH}cluster/vagrant/.kubectl ]; then - ${KUBEVIRT_PATH}cluster/vagrant/.kubectl --kubeconfig=${KUBEVIRT_PATH}cluster/vagrant/.kubeconfig "$@" + [ -e ${KUBEVIRT_PATH}cluster/vagrant/.kubectl ] && + [ "x$1" == "x--core" ]; then + shift + _kubectl "$@" +elif [ -e ${KUBEVIRT_PATH}cluster/vagrant/.kubectl ];then + _kubectl -s http://${master_ip}:8184 "$@" else - echo "Did you already run '$SYNC_CONFIG' to deploy kubevirt?" + echo "Did you already run 'cluster/up.sh' to deploy kubevirt?" fi diff --git a/cluster/local/provider.sh b/cluster/local/provider.sh new file mode 100644 index 000000000000..6ddf7618c506 --- /dev/null +++ b/cluster/local/provider.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +function _cert_dir () { + echo $GOPATH/src/kubevirt.io/kubevirt/cluster/local/certs +} + +function _main_ip { + ip -o -4 a | tr -s ' ' | cut -d' ' -f 2,4\ + | grep -v -e '^lo[0-9:]*' | head -1\ + | cut -d' ' -f 2 | cut -d'/' -f1 +} + +function up () { + go get -d k8s.io/kubernetes + + export API_HOST_IP=$(_main_ip) + export KUBELET_HOST=$(_main_ip) + export HOSTNAME_OVERRIDE=kubdev + export ALLOW_PRIVILEGED=1 + export ALLOW_SECURITY_CONTEXT=1 + export KUBE_DNS_DOMAIN="cluster.local" + export KUBE_DNS_SERVER_IP="10.0.0.10" + export KUBE_ENABLE_CLUSTER_DNS=true + export CERT_DIR=$(_cert_dir) + ( + cd $GOPATH/src/k8s.io/kubernetes + ./hack/local-up-cluster.sh + ) +} + +function prepare_config () { + cat > hack/config-local.sh <&1 | grep "not yet ready for SSH" >/dev/null \ + && { echo "Master node is not up"; exit 1; } + + OPTIONS=`vagrant ssh-config master | grep -v '^Host ' | awk -v ORS=' ' 'NF{print "-o " $1 "=" $2}'` + + scp $OPTIONS master:/usr/bin/kubectl ${KUBEVIRT_PATH}cluster/vagrant/.kubectl + chmod u+x cluster/vagrant/.kubectl + + vagrant ssh master -c "sudo cat /etc/kubernetes/admin.conf" > ${KUBEVIRT_PATH}cluster/vagrant/.kubeconfig +} + +function prepare_config () { + cat > hack/config-local.sh <&1 | grep "not yet ready for SSH" >/dev/null \ - && { echo "Master node is not up"; exit 1; } - -OPTIONS=`vagrant ssh-config master | grep -v '^Host ' | awk -v ORS=' ' 'NF{print "-o " $1 "=" $2}'` - -scp $OPTIONS master:/usr/bin/kubectl ${KUBEVIRT_PATH}cluster/vagrant/.kubectl -chmod u+x cluster/vagrant/.kubectl - -vagrant ssh master -c "sudo cat /etc/kubernetes/admin.conf" > ${KUBEVIRT_PATH}cluster/vagrant/.kubeconfig diff --git a/docs/dev-env-local.md b/docs/dev-env-local.md deleted file mode 100644 index 8da89652788c..000000000000 --- a/docs/dev-env-local.md +++ /dev/null @@ -1,95 +0,0 @@ -# Local development environment - -This document explains how to setup a local development environment -for kubernetes and kubevirt. In this setup everything runs in the -OS you are developing on, in constrast to the Vagrant environment -which spins up a separate virtual machine. This local env is useful -if you are already developing from inside a virtual machine, in -which case Vagrant would be forced to use a QEMU emulated env with -no KVM acceleration. - -## Getting the source - -```bash -mkdir -p $HOME/src/k8s/{src,bin,pkg} -echo "export GOPATH=$HOME/src/k8s" >> ~/.bashrc -echo "export PATH=\$GOPATH/bin:\$GOPATH/src/k8s.io/kubernetes/_output/bin:\$PATH" >> ~/.bashrc -source ~/.bashrc -``` - -If you have a working Go environment, run - -```bash -go get -d k8s.io/kubernetes -cd $GOPATH/src/k8s.io/kubernetes -``` - -to fetch the latest kubernetes sources. - -## Running kubernetes - -The first step is to get kubernetes itself up & running on the local -machine. This setup provides just a single compute node running -locally. - -Assuming a machine with a hostname of `kubdev` and IP address -of `192.168.122.13`, then from the root of a k8s checkout - -```bash -export API_HOST_IP=192.168.122.13 -export KUBELET_HOST=192.168.122.13 -export HOSTNAME_OVERRIDE=kubdev -export ALLOW_PRIVILEGED=1 -export ALLOW_SECURITY_CONTEXT=1 -export KUBE_DNS_DOMAIN="cluster.local" -export KUBE_DNS_SERVER_IP="10.0.0.10" -export KUBE_ENABLE_CLUSTER_DNS=true -./hack/local-up-cluster.sh -``` - -Once k8s has been launched once, you can skip the slow compilation -step using - -```bash -./hack/local-up-cluster.sh -o _output/local/bin/linux/amd64/ -``` - - -## Building kubevirt - -First configure kubevirt with site specific parameters. As above -we need the IP address of the host. - -```bash -cat > hack/config-local.sh < Date: Tue, 12 Dec 2017 13:19:53 +0100 Subject: [PATCH 2/7] Adjust test script to support different providers Signed-off-by: Roman Mohr --- automation/test.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/automation/test.sh b/automation/test.sh index ccff51491419..e2971af32789 100644 --- a/automation/test.sh +++ b/automation/test.sh @@ -57,16 +57,16 @@ curl -LO https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSI export VAGRANT_DOTFILE_PATH="${VAGRANT_DOTFILE_PATH:-$WORKSPACE/.vagrant}" # Make sure that the VM is properly shut down on exit -trap '{ vagrant halt; }' EXIT +trap '{ cluster/down.sh; }' EXIT set +e # TODO handle complete workspace removal on CI -vagrant up --provider=libvirt +cluster/up.sh if [ $? -ne 0 ]; then vagrant destroy set -e - vagrant up --provider=libvirt + cluster/up.sh fi set -e @@ -75,9 +75,6 @@ go get golang.org/x/tools/cmd/goimports go get -u github.com/Masterminds/glide make -# Copy connection details for kubernetes -cluster/kubectl.sh --init - # Make sure we can connect to kubernetes export APISERVER=$(cat cluster/vagrant/.kubeconfig | grep server | sed -e 's# \+server: https://##' | sed -e 's/\r//') $WORKSPACE/dockerize -wait tcp://$APISERVER -timeout 300s From 2fed3adf728ae0c7f42aecf4e9582fffba0d96a8 Mon Sep 17 00:00:00 2001 From: Roman Mohr Date: Tue, 12 Dec 2017 16:32:17 +0100 Subject: [PATCH 3/7] Apply formatting rules to our bash scripts Signed-off-by: Roman Mohr --- .travis.yml | 5 +- Makefile | 5 +- cluster/deploy.sh | 4 +- cluster/kubectl.sh | 12 ++-- cluster/local/provider.sh | 62 +++++++++---------- cluster/vagrant/provider.sh | 53 +++++++++-------- cluster/vagrant/setup_kubernetes_common.sh | 36 +++++------ cluster/vagrant/setup_kubernetes_master.sh | 14 ++--- cluster/vagrant/setup_kubernetes_node.sh | 2 +- cluster/verify-qemu-kube | 69 +++++++++++----------- cluster/vm-isolation-check.sh | 28 ++++----- cmd/virt-dhcp/Dockerfile | 1 + docs/getting-started.md | 2 + hack/build-docker.sh | 12 +++- hack/build-go.sh | 31 +++++++--- hack/build-manifests.sh | 2 +- hack/gen-swagger-doc/deploy.sh | 15 +++-- hack/gen-swagger-doc/gen-swagger-docs.sh | 49 +++++++-------- hack/release-announce.sh | 69 +++++++++++----------- images/iscsi-demo-target-tgtd/run-tgt.sh | 39 ++++++------ images/libvirt-kubevirt/libvirtd.sh | 36 +++++------ images/libvirt-kubevirt/qemu-kube | 30 +++++----- 22 files changed, 298 insertions(+), 278 deletions(-) diff --git a/.travis.yml b/.travis.yml index 48f353aeeb9c..87e60ebc0ea0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ install: - go get github.com/mattn/goveralls - go get -u github.com/Masterminds/glide - go get golang.org/x/tools/cmd/goimports + - go get -u mvdan.cc/sh/cmd/shfmt - go get -u github.com/golang/mock/gomock - go get -u github.com/rmohr/mock/mockgen - go get -u github.com/rmohr/go-swagger-utils/swagger-doc @@ -30,9 +31,9 @@ install: - make sync script: -- make fmt +- make fmt fmt-bash - if git diff --name-only | grep '.*.go'; then echo "It seems like you did not run - `make fmt`. Please run it and commit the changes"; false; fi + `make fmt fmt-bash`. Please run it and commit the changes"; false; fi - make generate - make fmt - if git diff --name-only | grep 'generated.*.go'; then echo "Content of generated diff --git a/Makefile b/Makefile index c3aff6df3d27..095630d7f4a3 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,9 @@ vet: fmt: goimports -w -local kubevirt.io cmd/ pkg/ tests/ +fmt-bash: + shfmt -i 4 -w cluster/ hack/ images/ + test: build ./hack/build-go.sh test ${WHAT} @@ -88,4 +91,4 @@ check-bash: release-announce: .release-functest ./hack/release-announce.sh $(RELREF) $(PREREF) -.PHONY: build fmt test clean distclean checksync sync docker manifests vet publish vagrant-sync-config vagrant-sync-build vagrant-deploy functest release-announce +.PHONY: build fmt test clean distclean checksync sync docker manifests vet publish vagrant-sync-config vagrant-sync-build vagrant-deploy functest release-announce fmt-bash diff --git a/cluster/deploy.sh b/cluster/deploy.sh index 4c932a0db946..1ceb360abf14 100755 --- a/cluster/deploy.sh +++ b/cluster/deploy.sh @@ -41,9 +41,9 @@ sleep 2 echo "Deploying ..." # Deploy the right manifests for the right target -if [ -z "$TARGET" ] || [ "$TARGET" = "vagrant-dev" ]; then +if [ -z "$TARGET" ] || [ "$TARGET" = "vagrant-dev" ]; then _kubectl create -f manifests/dev -R $i -elif [ "$TARGET" = "vagrant-release" ]; then +elif [ "$TARGET" = "vagrant-release" ]; then _kubectl create -f manifests/release -R $i fi diff --git a/cluster/kubectl.sh b/cluster/kubectl.sh index a8f466e5d070..7a882c1c008d 100755 --- a/cluster/kubectl.sh +++ b/cluster/kubectl.sh @@ -22,21 +22,21 @@ source cluster/$PROVIDER/provider.sh source ${KUBEVIRT_PATH}hack/config.sh if [ "$1" == "console" ] || [ "$1" == "spice" ]; then - cmd/virtctl/virtctl "$@" -s http://${master_ip}:8184 + cmd/virtctl/virtctl "$@" -s http://${master_ip}:8184 exit fi # Print usage from virtctl and kubectl -if [ "$1" == "--help" ] || [ "$1" == "-h" ] ; then +if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then cmd/virtctl/virtctl "$@" fi -if [ -e ${KUBEVIRT_PATH}cluster/vagrant/.kubeconfig ] && - [ -e ${KUBEVIRT_PATH}cluster/vagrant/.kubectl ] && - [ "x$1" == "x--core" ]; then +if [ -e ${KUBEVIRT_PATH}cluster/vagrant/.kubeconfig ] && + [ -e ${KUBEVIRT_PATH}cluster/vagrant/.kubectl ] && + [ "x$1" == "x--core" ]; then shift _kubectl "$@" -elif [ -e ${KUBEVIRT_PATH}cluster/vagrant/.kubectl ];then +elif [ -e ${KUBEVIRT_PATH}cluster/vagrant/.kubectl ]; then _kubectl -s http://${master_ip}:8184 "$@" else echo "Did you already run 'cluster/up.sh' to deploy kubevirt?" diff --git a/cluster/local/provider.sh b/cluster/local/provider.sh index 6ddf7618c506..c6f3a86388d5 100644 --- a/cluster/local/provider.sh +++ b/cluster/local/provider.sh @@ -1,51 +1,51 @@ #!/bin/bash -function _cert_dir () { - echo $GOPATH/src/kubevirt.io/kubevirt/cluster/local/certs +function _cert_dir() { + echo $GOPATH/src/kubevirt.io/kubevirt/cluster/local/certs } -function _main_ip { - ip -o -4 a | tr -s ' ' | cut -d' ' -f 2,4\ - | grep -v -e '^lo[0-9:]*' | head -1\ - | cut -d' ' -f 2 | cut -d'/' -f1 +function _main_ip() { + ip -o -4 a | tr -s ' ' | cut -d' ' -f 2,4 | + grep -v -e '^lo[0-9:]*' | head -1 | + cut -d' ' -f 2 | cut -d'/' -f1 } -function up () { - go get -d k8s.io/kubernetes - - export API_HOST_IP=$(_main_ip) - export KUBELET_HOST=$(_main_ip) - export HOSTNAME_OVERRIDE=kubdev - export ALLOW_PRIVILEGED=1 - export ALLOW_SECURITY_CONTEXT=1 - export KUBE_DNS_DOMAIN="cluster.local" - export KUBE_DNS_SERVER_IP="10.0.0.10" - export KUBE_ENABLE_CLUSTER_DNS=true - export CERT_DIR=$(_cert_dir) - ( - cd $GOPATH/src/k8s.io/kubernetes - ./hack/local-up-cluster.sh - ) +function up() { + go get -d k8s.io/kubernetes + + export API_HOST_IP=$(_main_ip) + export KUBELET_HOST=$(_main_ip) + export HOSTNAME_OVERRIDE=kubdev + export ALLOW_PRIVILEGED=1 + export ALLOW_SECURITY_CONTEXT=1 + export KUBE_DNS_DOMAIN="cluster.local" + export KUBE_DNS_SERVER_IP="10.0.0.10" + export KUBE_ENABLE_CLUSTER_DNS=true + export CERT_DIR=$(_cert_dir) + ( + cd $GOPATH/src/k8s.io/kubernetes + ./hack/local-up-cluster.sh + ) } -function prepare_config () { - cat > hack/config-local.sh <hack/config-local.sh <&1 | grep "not yet ready for SSH" >/dev/null \ - && { echo "Master node is not up"; exit 1; } +function up() { + # Make sure that the vagrant environment is up and running + vagrant up --provider=libvirt + # Synchronize kubectl config + vagrant ssh-config master 2>&1 | grep "not yet ready for SSH" >/dev/null && + { + echo "Master node is not up" + exit 1 + } - OPTIONS=`vagrant ssh-config master | grep -v '^Host ' | awk -v ORS=' ' 'NF{print "-o " $1 "=" $2}'` + OPTIONS=$(vagrant ssh-config master | grep -v '^Host ' | awk -v ORS=' ' 'NF{print "-o " $1 "=" $2}') - scp $OPTIONS master:/usr/bin/kubectl ${KUBEVIRT_PATH}cluster/vagrant/.kubectl - chmod u+x cluster/vagrant/.kubectl + scp $OPTIONS master:/usr/bin/kubectl ${KUBEVIRT_PATH}cluster/vagrant/.kubectl + chmod u+x cluster/vagrant/.kubectl - vagrant ssh master -c "sudo cat /etc/kubernetes/admin.conf" > ${KUBEVIRT_PATH}cluster/vagrant/.kubeconfig + vagrant ssh master -c "sudo cat /etc/kubernetes/admin.conf" >${KUBEVIRT_PATH}cluster/vagrant/.kubeconfig } -function prepare_config () { - cat > hack/config-local.sh <hack/config-local.sh <> /etc/fstab - mkdir -p /etc/systemd/system/docker.service.d/ - cat > /etc/systemd/system/docker.service.d/mount.conf <> /etc/fstab + mkdir -p /etc/systemd/system/docker.service.d/ + cat >/etc/systemd/system/docker.service.d/mount.conf < /etc/yum.repos.d/kubernetes.repo +cat </etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=http://yum.kubernetes.io/repos/kubernetes-el7-x86_64 @@ -75,13 +75,13 @@ sed -i 's/--log-driver=journald //g' /etc/sysconfig/docker # Currently older versions of kubeadm are no longer available in the rpm repos. # See https://github.com/kubernetes/kubeadm/issues/220 for context. yum install -y \ - kubeadm \ - kubelet \ - kubectl \ - kubernetes-cni + kubeadm \ + kubelet \ + kubectl \ + kubernetes-cni # Latest docker on CentOS uses systemd for cgroup management -cat << EOT >>/etc/systemd/system/kubelet.service.d/09-kubeadm.conf +cat <>/etc/systemd/system/kubelet.service.d/09-kubeadm.conf [Service] Environment="KUBELET_EXTRA_ARGS=--cgroup-driver=systemd --runtime-cgroups=/systemd/system.slice --kubelet-cgroups=/systemd/system.slice" EOT diff --git a/cluster/vagrant/setup_kubernetes_master.sh b/cluster/vagrant/setup_kubernetes_master.sh index f88580cfd7df..3870ba4f69f3 100755 --- a/cluster/vagrant/setup_kubernetes_master.sh +++ b/cluster/vagrant/setup_kubernetes_master.sh @@ -37,18 +37,18 @@ set +e kubectl version while [ $? -ne 0 ]; do - sleep 60 - echo 'Waiting for Kubernetes cluster to become functional...' - kubectl version + sleep 60 + echo 'Waiting for Kubernetes cluster to become functional...' + kubectl version done set -e if [ "$NETWORK_PROVIDER" == "weave" ]; then - kubever=$(kubectl version | base64 | tr -d '\n') - kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever" + kubever=$(kubectl version | base64 | tr -d '\n') + kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever" else - kubectl create -f kube-$NETWORK_PROVIDER.yaml + kubectl create -f kube-$NETWORK_PROVIDER.yaml fi # Allow scheduling pods on master @@ -60,6 +60,6 @@ mkdir -p /exports/share1 chmod 0755 /exports/share1 chown 36:36 /exports/share1 -echo "/exports/share1 *(rw,anonuid=36,anongid=36,all_squash,sync,no_subtree_check)" > /etc/exports +echo "/exports/share1 *(rw,anonuid=36,anongid=36,all_squash,sync,no_subtree_check)" >/etc/exports systemctl enable nfs-server && systemctl start nfs-server diff --git a/cluster/vagrant/setup_kubernetes_node.sh b/cluster/vagrant/setup_kubernetes_node.sh index 484c1d7885d0..3780d0532e2a 100755 --- a/cluster/vagrant/setup_kubernetes_node.sh +++ b/cluster/vagrant/setup_kubernetes_node.sh @@ -19,7 +19,7 @@ bash ./setup_kubernetes_common.sh -ADVERTISED_MASTER_IP=`sshpass -p vagrant ssh -oStrictHostKeyChecking=no vagrant@$MASTER_IP hostname -I | cut -d " " -f1` +ADVERTISED_MASTER_IP=$(sshpass -p vagrant ssh -oStrictHostKeyChecking=no vagrant@$MASTER_IP hostname -I | cut -d " " -f1) set +e echo 'Trying to register myself...' diff --git a/cluster/verify-qemu-kube b/cluster/verify-qemu-kube index 09450fd97d0c..b3faf1bb4b08 100755 --- a/cluster/verify-qemu-kube +++ b/cluster/verify-qemu-kube @@ -5,9 +5,9 @@ ERROR=0 VM_NAME=$1 if [ "x$VM_NAME" == "x" ]; then -echo "Usage:" -echo " ./verify-qemu-cube " -exit 1 + echo "Usage:" + echo " ./verify-qemu-cube " + exit 1 fi VM_EMULATION_PID=$(sudo grep -E 'domstatus.*pid' /var/run/libvirt/qemu/${VM_NAME}.xml | sed "s/.*pid='\([[:digit:]]\+\)'.*/\1/") @@ -20,9 +20,9 @@ QEMU_PROC_NAME=$(ps -q $VM_PID -o comm=) echo "Qemu process: $QEMU_PROC_NAME" test "$QEMU_PROC_NAME" == "qemu-system-x86" || ERROR=1 -CONTAINER_ID=$( docker ps --no-trunc | awk "/.*compute.*virt-launcher-$VM_NAME.*/ { print \$1 }" ) +CONTAINER_ID=$(docker ps --no-trunc | awk "/.*compute.*virt-launcher-$VM_NAME.*/ { print \$1 }") CONTAINER_PID=$(docker inspect --format '{{.State.Pid}}' $CONTAINER_ID) -CGROUP_PATH=$( cat /proc/${CONTAINER_PID}/cgroup | head -1 | cut -f3 -d: ) +CGROUP_PATH=$(cat /proc/${CONTAINER_PID}/cgroup | head -1 | cut -f3 -d:) echo "VM name: $VM_NAME" echo "VM emulation PID: $VM_EMULATION_PID" @@ -37,12 +37,12 @@ echo "Checking for required cgroups:" CGROUPS='freezer cpu cpuacct perf_event net_cls blkio memory hugetlb cpuset' for CG in $CGROUPS; do - if grep -Fxq "$VM_PID" /sys/fs/cgroup/$CG/$CGROUP_PATH/tasks; then - echo VM $VM_NAME found in container cgroup $CG - else - ERROR=1 - echo VM $VM_NAME NOT found in container cgroup $CG - fi + if grep -Fxq "$VM_PID" /sys/fs/cgroup/$CG/$CGROUP_PATH/tasks; then + echo VM $VM_NAME found in container cgroup $CG + else + ERROR=1 + echo VM $VM_NAME NOT found in container cgroup $CG + fi done echo "" @@ -50,42 +50,41 @@ echo "Checking for excluded cgroups:" EXCLUDED_CGROUPS="devices systemd" for CG in $EXCLUDED_CGROUPS; do - if grep -Fxq "$VM_PID" /sys/fs/cgroup/$CG/$CGROUP_PATH/tasks; then - echo VM $VM_NAME FOUND in container cgroup $CG - ERROR=1 - else - echo VM $VM_NAME not found in container cgroup $CG - fi + if grep -Fxq "$VM_PID" /sys/fs/cgroup/$CG/$CGROUP_PATH/tasks; then + echo VM $VM_NAME FOUND in container cgroup $CG + ERROR=1 + else + echo VM $VM_NAME not found in container cgroup $CG + fi done - # Check namespaces echo "" echo "Checking for required namespaces:" NAMESPACES='pid' for NS in $NAMESPACES; do - NS_PRETTY=`echo $NS | tr '[:lower:]' '[:upper:]'` - VM_PID_NS=$(ls -iL /proc/$VM_PID/ns/$NS | cut -f 1 -d " ") - CONTAINER_PID_NS=$(ls -iL /proc/$CONTAINER_PID/ns/$NS | cut -f 1 -d " ") - - if [ "x$VM_PID_NS" == "x" ]; then - echo Could not determine $NS_PRETTY namespace of VM $VM_NAME - ERROR=1 - fi - - if [ "$VM_PID_NS" == "$CONTAINER_PID_NS" ]; then - echo VM $VM_NAME found in $NS_PRETTY namespace of container - else - echo VM $VM_NAME NOT found in $NS_PRETTY namespace of container - ERROR=1 - fi + NS_PRETTY=$(echo $NS | tr '[:lower:]' '[:upper:]') + VM_PID_NS=$(ls -iL /proc/$VM_PID/ns/$NS | cut -f 1 -d " ") + CONTAINER_PID_NS=$(ls -iL /proc/$CONTAINER_PID/ns/$NS | cut -f 1 -d " ") + + if [ "x$VM_PID_NS" == "x" ]; then + echo Could not determine $NS_PRETTY namespace of VM $VM_NAME + ERROR=1 + fi + + if [ "$VM_PID_NS" == "$CONTAINER_PID_NS" ]; then + echo VM $VM_NAME found in $NS_PRETTY namespace of container + else + echo VM $VM_NAME NOT found in $NS_PRETTY namespace of container + ERROR=1 + fi done echo "" if [ "$ERROR" -gt "0" ]; then - echo "Verification failed." + echo "Verification failed." else - echo "Verification successful." + echo "Verification successful." fi exit $ERROR diff --git a/cluster/vm-isolation-check.sh b/cluster/vm-isolation-check.sh index a900a8e65ea0..a5e64282bc66 100755 --- a/cluster/vm-isolation-check.sh +++ b/cluster/vm-isolation-check.sh @@ -18,37 +18,35 @@ # source hack/config.sh -usage () { -echo "Usage: ./cluster/vm-isolation-check.sh [-vm ]" +usage() { + echo "Usage: ./cluster/vm-isolation-check.sh [-vm ]" } VM_NAME=testvm -while [[ $# -gt 0 ]] -do -key="$1" +while [[ $# -gt 0 ]]; do + key="$1" -case $key in + case $key in -vm) VM_NAME="$2" shift - ;; + ;; -help) usage exit 0 - ;; + ;; *) usage exit 1 - ;; -esac -shift + ;; + esac + shift done JQ_PRESENT=$(which jq >/dev/null 2>&1 && echo 1 || echo 0) -if [ "$JQ_PRESENT" == "0" ] -then +if [ "$JQ_PRESENT" == "0" ]; then echo "Missing required system dependency: jq" exit 1 fi @@ -56,8 +54,8 @@ fi NODE=$(cluster/kubectl.sh get pods -o json -l kubevirt.io/domain=${VM_NAME} | jq '.items[].spec.nodeName' -r) if [ -z $NODE ]; then - echo "Could not detect the VM." - exit 1 + echo "Could not detect the VM." + exit 1 fi echo "Found VM running on node '$NODE'" # Verify that the VM is running and in the right cgroups and namespaces diff --git a/cmd/virt-dhcp/Dockerfile b/cmd/virt-dhcp/Dockerfile index 4e6b0c0063a5..52fb1929998c 100644 --- a/cmd/virt-dhcp/Dockerfile +++ b/cmd/virt-dhcp/Dockerfile @@ -1,3 +1,4 @@ +#!/bin/sh # # This file is part of the KubeVirt project # diff --git a/docs/getting-started.md b/docs/getting-started.md index e422233f55a9..48ef12b3f761 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -73,6 +73,8 @@ to install a few build requirements: go get golang.org/x/tools/cmd/goimports # Setup glide which is used to track dependencies go get github.com/Masterminds/glide + # Shell script formatter + go get -u mvdan.cc/sh/cmd/shfmt ``` ### Sources diff --git a/hack/build-docker.sh b/hack/build-docker.sh index 4d265c2aaccd..2b334ba5d5d6 100755 --- a/hack/build-docker.sh +++ b/hack/build-docker.sh @@ -43,10 +43,16 @@ for arg in $args; do # https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact # Because of this we have to manipulate the Dockerfile for kubevirt containers # that depend on other kubevirt containers. - cat $arg/Dockerfile | sed s/registry-disk-v1alpha/registry-disk-v1alpha\:$docker_tag/g > $arg/.GeneratedDockerfile - (cd $arg; docker $target -t ${docker_prefix}/$(basename $arg):${docker_tag} -f .GeneratedDockerfile .) + cat $arg/Dockerfile | sed s/registry-disk-v1alpha/registry-disk-v1alpha\:$docker_tag/g >$arg/.GeneratedDockerfile + ( + cd $arg + docker $target -t ${docker_prefix}/$(basename $arg):${docker_tag} -f .GeneratedDockerfile . + ) rm $arg/.GeneratedDockerfile elif [ "${target}" = "push" ]; then - (cd $arg; docker $target ${docker_prefix}/$(basename $arg):${docker_tag}) + ( + cd $arg + docker $target ${docker_prefix}/$(basename $arg):${docker_tag} + ) fi done diff --git a/hack/build-go.sh b/hack/build-go.sh index 99f1408a5f34..cee7e9fe2e14 100755 --- a/hack/build-go.sh +++ b/hack/build-go.sh @@ -38,31 +38,48 @@ fi # TODO finetune this a little bit more if [ $# -eq 0 ]; then if [ "${target}" = "test" ]; then - (cd pkg; go ${target} -v ./...) + ( + cd pkg + go ${target} -v ./... + ) elif [ "${target}" = "functest" ]; then (cd tests; go test -kubeconfig=../cluster/vagrant/.kubeconfig -timeout 30m ${FUNC_TEST_ARGS}) exit else - (cd pkg; go $target ./...) - (cd tests; go $target ./...) + ( + cd pkg + go $target ./... + ) + ( + cd tests + go $target ./... + ) fi fi # handle binaries for arg in $args; do if [ "${target}" = "test" ]; then - (cd $arg; go ${target} -v ./...) + ( + cd $arg + go ${target} -v ./... + ) elif [ "${target}" = "install" ]; then eval "$(go env)" ARCHBIN=$(basename $arg)-$(git describe --always)-$GOHOSTOS-$GOHOSTARCH ALIASLNK=$(basename $arg) rm $arg/$ALIASLNK $arg/$(basename $arg)-*-$GOHOSTOS-$GOHOSTARCH || : - (cd $arg; GOBIN=$PWD go build -o $ARCHBIN) + ( + cd $arg + GOBIN=$PWD go build -o $ARCHBIN + ) mkdir -p bin ln -sf $ARCHBIN $arg/$ALIASLNK ln -sf ../$arg/$ARCHBIN bin/$ALIASLNK else - (cd $arg; go $target ./...) + ( + cd $arg + go $target ./... + ) fi done - diff --git a/hack/build-manifests.sh b/hack/build-manifests.sh index f5e13d588a0d..274146bee5a8 100755 --- a/hack/build-manifests.sh +++ b/hack/build-manifests.sh @@ -35,5 +35,5 @@ for arg in $args; do sed -e "s/{{ master_ip }}/$master_ip/g" \ -e "s/{{ docker_tag }}/$docker_tag/g" \ -e "s/{{ docker_prefix }}/$docker_prefix/g" \ - $arg > ${arg%%.in} + $arg >${arg%%.in} done diff --git a/hack/gen-swagger-doc/deploy.sh b/hack/gen-swagger-doc/deploy.sh index c526d092a548..cf420b85b5b2 100755 --- a/hack/gen-swagger-doc/deploy.sh +++ b/hack/gen-swagger-doc/deploy.sh @@ -8,7 +8,7 @@ API_REF_DIR=/tmp/api-reference git clone \ "https://${API_REFERENCE_PUSH_TOKEN}@${GITHUB_FQDN}/${API_REF_REPO}.git" \ - "${API_REF_DIR}" > /dev/null 2>&1 + "${API_REF_DIR}" >/dev/null 2>&1 rm -rf "${API_REF_DIR}/content/"* cp -f hack/gen-swagger-doc/html5/content/*.html "${API_REF_DIR}/content/" @@ -17,13 +17,12 @@ cd "${API_REF_DIR}" git config --global user.email "travis@travis-ci.org" git config --global user.name "Travis CI" -if git status --porcelain | grep --quiet "^ M" ; -then - git add -A content/*.html - git commit --message "API Reference update by Travis Build ${TRAVIS_BUILD_NUMBER}" +if git status --porcelain | grep --quiet "^ M"; then + git add -A content/*.html + git commit --message "API Reference update by Travis Build ${TRAVIS_BUILD_NUMBER}" - git push origin master > /dev/null 2>&1 - echo "API Reference updated." + git push origin master >/dev/null 2>&1 + echo "API Reference updated." else - echo "API Reference hasn't changed." + echo "API Reference hasn't changed." fi diff --git a/hack/gen-swagger-doc/gen-swagger-docs.sh b/hack/gen-swagger-doc/gen-swagger-docs.sh index fd87beb58cbc..25709427d7fc 100755 --- a/hack/gen-swagger-doc/gen-swagger-docs.sh +++ b/hack/gen-swagger-doc/gen-swagger-docs.sh @@ -10,16 +10,14 @@ set -o pipefail VERSION="${1:-v1}" OUTPUT_FORMAT="${2:-html}" -if [ "$OUTPUT_FORMAT" = "html" ] ; -then +if [ "$OUTPUT_FORMAT" = "html" ]; then SUFFIX="adoc" HEADER="=" LINK1_TEMPLATE="\* \<\<\${VERSION}.\$m\>\>" LINK_DEFINITIONS="* link:./definitions.html[Types Definition]" LINK_OPERATIONS="* link:./operations.html[Operations]" GRADLE_EXTRA_PARAMS="" -elif [ "$OUTPUT_FORMAT" = "markdown" ] ; -then +elif [ "$OUTPUT_FORMAT" = "markdown" ]; then SUFFIX="md" HEADER="#" LINK1_TEMPLATE="\* [\${VERSION}.\$m]\(definitions.md#\${VERSION}-\${m,,}\)" @@ -33,7 +31,6 @@ fi WORKDIR="hack/gen-swagger-doc" GRADLE_BUILD_FILE="$WORKDIR/build.gradle" - # Generate *.adoc files from swagger.json gradle -b $GRADLE_BUILD_FILE $GRADLE_EXTRA_PARAMS convertSwagger2markup --info @@ -43,12 +40,10 @@ top_level_models=$(grep '&[A-Za-z]*{},' pkg/api/${VERSION}/types.go | sed 's/.*& # check if the top level models exist in the definitions.$SUFFIX. If they exist, # their name will be . -for m in $top_level_models -do - if grep -xq "${HEADER}${HEADER}${HEADER} ${VERSION}.$m" "$WORKDIR/definitions.${SUFFIX}" - then - buf+="$(eval echo $LINK1_TEMPLATE)\n" - fi +for m in $top_level_models; do + if grep -xq "${HEADER}${HEADER}${HEADER} ${VERSION}.$m" "$WORKDIR/definitions.${SUFFIX}"; then + buf+="$(eval echo $LINK1_TEMPLATE)\n" + fi done sed -i "1i $buf" "$WORKDIR/definitions.${SUFFIX}" @@ -56,35 +51,31 @@ sed -i "1i $buf" "$WORKDIR/definitions.${SUFFIX}" sed -i "s|${HEADER}${HEADER} Paths|${HEADER}${HEADER} Operations|g" "$WORKDIR/paths.${SUFFIX}" mv -f "$WORKDIR/paths.${SUFFIX}" "$WORKDIR/operations.${SUFFIX}" - # Add links to definitons & operations under overview -cat >> "$WORKDIR/overview.${SUFFIX}" << __END__ +cat >>"$WORKDIR/overview.${SUFFIX}" <<__END__ ${HEADER}${HEADER} KubeVirt API Reference ${LINK_DEFINITIONS} ${LINK_OPERATIONS} __END__ +if [ "$OUTPUT_FORMAT" = "html" ]; then + # $$ has special meaning in asciidoc, we need to escape it + sed -i 's|\$\$|+++$$+++|g' "$WORKDIR/definitions.adoc" + sed -i '1 i\:last-update-label!:' "$WORKDIR/"*.adoc -if [ "$OUTPUT_FORMAT" = "html" ] ; -then - # $$ has special meaning in asciidoc, we need to escape it - sed -i 's|\$\$|+++$$+++|g' "$WORKDIR/definitions.adoc" - sed -i '1 i\:last-update-label!:' "$WORKDIR/"*.adoc - - # Generate *.html files from *.adoc - gradle -b $GRADLE_BUILD_FILE asciidoctor --info - rm -rf "$WORKDIR/html5/content" && mkdir "$WORKDIR/html5/content" && mv -f "$WORKDIR/html5/"*.html "$WORKDIR/html5/content" - mv -f "$WORKDIR/html5/content/overview.html" "$WORKDIR/html5/content/index.html" -elif [ "$OUTPUT_FORMAT" = "markdown" ] ; -then + # Generate *.html files from *.adoc + gradle -b $GRADLE_BUILD_FILE asciidoctor --info + rm -rf "$WORKDIR/html5/content" && mkdir "$WORKDIR/html5/content" && mv -f "$WORKDIR/html5/"*.html "$WORKDIR/html5/content" + mv -f "$WORKDIR/html5/content/overview.html" "$WORKDIR/html5/content/index.html" +elif [ "$OUTPUT_FORMAT" = "markdown" ]; then # Generate TOC for definitions & operations as README.md cd "$WORKDIR" - echo "# KubeVirt API Reference" > README.md + echo "# KubeVirt API Reference" >README.md curl \ - https://raw.githubusercontent.com/ekalinin/github-markdown-toc/master/gh-md-toc | \ - bash -s "definitions.md" "operations.md" | \ - sed 's/^ //' >> "README.md" + https://raw.githubusercontent.com/ekalinin/github-markdown-toc/master/gh-md-toc | + bash -s "definitions.md" "operations.md" | + sed 's/^ //' >>"README.md" cd - fi diff --git a/hack/release-announce.sh b/hack/release-announce.sh index c4c15d0e58cd..72dd14c22d95 100755 --- a/hack/release-announce.sh +++ b/hack/release-announce.sh @@ -1,32 +1,34 @@ #!/usr/bin/bash -underline() { echo "$2" ; printf "%0.s$1" $(seq ${#2}) ; } - -log() { echo "$@" >&2 ; } -title() { underline "=" "$@" ; } -section() { underline "-" "$@" ; } +underline() { + echo "$2" + printf "%0.s$1" $(seq ${#2}) +} +log() { echo "$@" >&2; } +title() { underline "=" "$@"; } +section() { underline "-" "$@"; } # # All sorts of content # release_notes() { - log "Fetching release notes" - cat manual-release-notes || echo "FIXME manual notes needed" + log "Fetching release notes" + cat manual-release-notes || echo "FIXME manual notes needed" } summary() { - log "Building summary" - echo "This release follows $PREREF and consists of $(git log --oneline $RELSPANREF | wc -l) changes, contributed by" - echo -n "$(git shortlog -sne $RELSPANREF | wc -l) people, leading to" - echo "$(git diff --shortstat $RELSPANREF)." + log "Building summary" + echo "This release follows $PREREF and consists of $(git log --oneline $RELSPANREF | wc -l) changes, contributed by" + echo -n "$(git shortlog -sne $RELSPANREF | wc -l) people, leading to" + echo "$(git diff --shortstat $RELSPANREF)." } downloads() { - log "Adding download urls" - local GHRELURL="https://github.com/kubevirt/kubevirt/releases/tag/" - local RELURL="$GHRELURL$RELREF" - cat <. @@ -39,48 +41,46 @@ EOF } shortlog() { - git shortlog -sne $RELSPANREF | sed "s/^/ /" + git shortlog -sne $RELSPANREF | sed "s/^/ /" } functest() { - log "Running functional tests - can take a while." - cat .release-functest | tail -n5 | \ - sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | \ - egrep "(Ran|PASS)" | \ - fold -sw 74 | sed -n "{ s/^/> / ; p }" + log "Running functional tests - can take a while." + cat .release-functest | tail -n5 | + sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | + egrep "(Ran|PASS)" | + fold -sw 74 | sed -n "{ s/^/> / ; p }" } usage() { - echo "Usage: $0 [RELEASE_REF] [PREV_RELEASE_REF]" + echo "Usage: $0 [RELEASE_REF] [PREV_RELEASE_REF]" } +main() { + log "Span: $RELSPANREF" -main() -{ - log "Span: $RELSPANREF" + fold -s < current_state - diff -q previous_state current_state || ( date ; cat current_state ; ) - mv -f current_state previous_state - sleep 3 +while true; do + tgtadm --lld iscsi --mode target --op show >current_state + diff -q previous_state current_state || ( + date + cat current_state + ) + mv -f current_state previous_state + sleep 3 done # vim: et ts=2: diff --git a/images/libvirt-kubevirt/libvirtd.sh b/images/libvirt-kubevirt/libvirtd.sh index 5cca1af63946..b5e8adc1bf34 100644 --- a/images/libvirt-kubevirt/libvirtd.sh +++ b/images/libvirt-kubevirt/libvirtd.sh @@ -22,8 +22,8 @@ set -xe # HACK # Use hosts's /dev to see new devices and allow macvtap mkdir /dev.container && { - mount --rbind /dev /dev.container - mount --rbind /host-dev /dev + mount --rbind /dev /dev.container + mount --rbind /host-dev /dev # Keep some devices from the containerinal /dev keep() { mount --rbind /dev.container/$1 /dev/$1 ; } @@ -37,23 +37,23 @@ mkdir /dev.container && { } mkdir /sys.net.container && { - mount --rbind /sys/class/net /sys.net.container - mount --rbind /host-sys/class/net /sys/class/net + mount --rbind /sys/class/net /sys.net.container + mount --rbind /host-sys/class/net /sys/class/net } mkdir /sys.devices.container && { - mount --rbind /sys/devices /sys.devices.container - mount --rbind /host-sys/devices /sys/devices + mount --rbind /sys/devices /sys.devices.container + mount --rbind /host-sys/devices /sys/devices } # If no cpuacct,cpu is present, symlink it to cpu,cpuacct # Otherwise libvirt and our emulator get confused if [ ! -d "/host-sys/fs/cgroup/cpuacct,cpu" ]; then - echo "Creating cpuacct,cpu cgroup symlink" - mount -o remount,rw /host-sys/fs/cgroup - cd /host-sys/fs/cgroup - ln -s cpu,cpuacct cpuacct,cpu - mount -o remount,ro /host-sys/fs/cgroup + echo "Creating cpuacct,cpu cgroup symlink" + mount -o remount,rw /host-sys/fs/cgroup + cd /host-sys/fs/cgroup + ln -s cpu,cpuacct cpuacct,cpu + mount -o remount,ro /host-sys/fs/cgroup fi mount --rbind /host-sys/fs/cgroup /sys/fs/cgroup @@ -71,9 +71,9 @@ fi # We create the network on a file basis to not # have to wait for libvirtd to come up if [[ -n "$LIBVIRTD_DEFAULT_NETWORK_DEVICE" ]]; then - echo "Setting libvirt default network to \"$LIBVIRTD_DEFAULT_NETWORK_DEVICE\"" - mkdir -p /etc/libvirt/qemu/networks/autostart - cat > /etc/libvirt/qemu/networks/default.xml </etc/libvirt/qemu/networks/default.xml < default @@ -82,13 +82,13 @@ if [[ -n "$LIBVIRTD_DEFAULT_NETWORK_DEVICE" ]]; then EOX - ln -s /etc/libvirt/qemu/networks/default.xml /etc/libvirt/qemu/networks/autostart/default.xml + ln -s /etc/libvirt/qemu/networks/default.xml /etc/libvirt/qemu/networks/autostart/default.xml fi -echo "cgroup_controllers = [ ]" >> /etc/libvirt/qemu.conf +echo "cgroup_controllers = [ ]" >>/etc/libvirt/qemu.conf if [[ -n "$LIBVIRTD_DISABLE_TCP" ]]; then - /usr/sbin/libvirtd + /usr/sbin/libvirtd else - /usr/sbin/libvirtd -l + /usr/sbin/libvirtd -l fi diff --git a/images/libvirt-kubevirt/qemu-kube b/images/libvirt-kubevirt/qemu-kube index ce547f70e699..0f7ea11a711e 100755 --- a/images/libvirt-kubevirt/qemu-kube +++ b/images/libvirt-kubevirt/qemu-kube @@ -13,40 +13,38 @@ if [ ! -w "$LOG" ]; then LOG="/dev/null" fi -while [[ $# -gt 0 ]] -do -key="$1" +while [[ $# -gt 0 ]]; do + key="$1" -case $key in + case $key in -name) VM_NAMESPACE_NAME="$2" shift - ;; - *) - ;; -esac -shift + ;; + *) ;; + + esac + shift done if [ -z "$VM_NAMESPACE_NAME" ]; then - log "Libvirt is asking for qemu capabilities." >> $LOG + log "Libvirt is asking for qemu capabilities." >>$LOG exec $QEMU $ARGS fi -log "Trying to start VM ${VM_NAMESPACE_NAME}." >> $LOG +log "Trying to start VM ${VM_NAMESPACE_NAME}." >>$LOG CMD="$QEMU $ARGS" -log "cgroup path: $SLICE" >> $LOG -log "cgroups: $CONTROLLERS" >> $LOG +log "cgroup path: $SLICE" >>$LOG +log "cgroups: $CONTROLLERS" >>$LOG -log "$CMD" >> $LOG +log "$CMD" >>$LOG set -e sudo cgclassify -g ${CONTROLLERS}:$SLICE --sticky $$ pid=$$ -echo "Launching qemu process with pid $pid" >> $LOG +echo "Launching qemu process with pid $pid" >>$LOG exec $CMD - From 6d6c548b543d46ab529e761a1fa559415e5e7ab8 Mon Sep 17 00:00:00 2001 From: Roman Mohr Date: Tue, 12 Dec 2017 16:38:29 +0100 Subject: [PATCH 4/7] Document that cluster/deploy.sh exists Signed-off-by: Roman Mohr --- docs/env-providers.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/env-providers.md b/docs/env-providers.md index e97758d9b290..a44a3b2e5f72 100644 --- a/docs/env-providers.md +++ b/docs/env-providers.md @@ -5,6 +5,7 @@ All following providers allow a common workflow: * `cluster/up.sh` to create the environment * `cluster/down.sh` to stop the environment * `cluster/sync.sh` to build the code and deploy it + * `cluster/deploy.sh` to (re)deploy the code (no provider support needed) * `make functests` to run the functional tests against a KubeVirt * `cluster/kubectl.sh` to talk to the k8s installation From 9f2703ba5ca2344915e86f31cf16f6adaf01c7fd Mon Sep 17 00:00:00 2001 From: Roman Mohr Date: Thu, 4 Jan 2018 17:27:08 +0100 Subject: [PATCH 5/7] Introduce common makefile targets Signed-off-by: Roman Mohr --- Makefile | 16 ++++- automation/test.sh | 10 +-- cluster/{sync.sh => build.sh} | 1 - cluster/vagrant/setup_kubernetes_node.sh | 8 +-- cluster/verify-qemu-kube | 90 ------------------------ cluster/vm-isolation-check.sh | 62 ---------------- docs/env-providers.md | 22 +++--- docs/getting-started.md | 14 ++-- hack/bootstrap-ginkgo.sh | 2 +- images/libvirt-kubevirt/libvirtd.sh | 18 ++--- 10 files changed, 50 insertions(+), 193 deletions(-) rename cluster/{sync.sh => build.sh} (97%) delete mode 100755 cluster/verify-qemu-kube diff --git a/Makefile b/Makefile index 095630d7f4a3..b0670e071dca 100644 --- a/Makefile +++ b/Makefile @@ -91,4 +91,18 @@ check-bash: release-announce: .release-functest ./hack/release-announce.sh $(RELREF) $(PREREF) -.PHONY: build fmt test clean distclean checksync sync docker manifests vet publish vagrant-sync-config vagrant-sync-build vagrant-deploy functest release-announce fmt-bash +cluster-up: + ./cluster/up.sh + +cluster-down: + ./cluster/down.sh + +cluster-build: + ./cluster/build.sh + +cluster-deploy: + ./cluster/deploy.sh + +cluster-sync: cluster-build cluster-deploy + +.PHONY: build fmt test clean distclean checksync sync docker manifests vet publish functest release-announce fmt-bash cluster-up cluster-down cluster-deploy cluster-sync diff --git a/automation/test.sh b/automation/test.sh index e2971af32789..5f6bcabce85e 100644 --- a/automation/test.sh +++ b/automation/test.sh @@ -57,16 +57,16 @@ curl -LO https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSI export VAGRANT_DOTFILE_PATH="${VAGRANT_DOTFILE_PATH:-$WORKSPACE/.vagrant}" # Make sure that the VM is properly shut down on exit -trap '{ cluster/down.sh; }' EXIT +trap '{ make cluster-down; }' EXIT set +e # TODO handle complete workspace removal on CI -cluster/up.sh +make cluster-up if [ $? -ne 0 ]; then vagrant destroy set -e - cluster/up.sh + make cluster-up fi set -e @@ -133,9 +133,9 @@ for i in ${namespaces[@]}; do done if [ -z "$TARGET" ] || [ "$TARGET" = "vagrant-dev" ]; then - cluster/sync.sh + make cluster-sync elif [ "$TARGET" = "vagrant-release" ]; then - cluster/sync.sh + make cluster-sync fi # Wait until kubevirt pods are running diff --git a/cluster/sync.sh b/cluster/build.sh similarity index 97% rename from cluster/sync.sh rename to cluster/build.sh index 763de6642163..5880d248a150 100755 --- a/cluster/sync.sh +++ b/cluster/build.sh @@ -25,4 +25,3 @@ PROVIDER=${PROVIDER:-vagrant} source cluster/$PROVIDER/provider.sh build -cluster/deploy.sh diff --git a/cluster/vagrant/setup_kubernetes_node.sh b/cluster/vagrant/setup_kubernetes_node.sh index 3780d0532e2a..2498a466e6cc 100755 --- a/cluster/vagrant/setup_kubernetes_node.sh +++ b/cluster/vagrant/setup_kubernetes_node.sh @@ -26,8 +26,8 @@ echo 'Trying to register myself...' # Skipping preflight checks because of https://github.com/kubernetes/kubeadm/issues/6 kubeadm join --token abcdef.1234567890123456 $ADVERTISED_MASTER_IP:6443 --ignore-preflight-errors=all --discovery-token-unsafe-skip-ca-verification=true while [ $? -ne 0 ]; do - sleep 30 - echo 'Trying to register myself...' - # Skipping preflight checks because of https://github.com/kubernetes/kubeadm/issues/6 - kubeadm join --token abcdef.1234567890123456 $ADVERTISED_MASTER_IP:6443 --ignore-preflight-errors=all --discovery-token-unsafe-skip-ca-verification=true + sleep 30 + echo 'Trying to register myself...' + # Skipping preflight checks because of https://github.com/kubernetes/kubeadm/issues/6 + kubeadm join --token abcdef.1234567890123456 $ADVERTISED_MASTER_IP:6443 --ignore-preflight-errors=all --discovery-token-unsafe-skip-ca-verification=true done diff --git a/cluster/verify-qemu-kube b/cluster/verify-qemu-kube deleted file mode 100755 index b3faf1bb4b08..000000000000 --- a/cluster/verify-qemu-kube +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/bash -set -e - -ERROR=0 - -VM_NAME=$1 -if [ "x$VM_NAME" == "x" ]; then - echo "Usage:" - echo " ./verify-qemu-cube " - exit 1 -fi -VM_EMULATION_PID=$(sudo grep -E 'domstatus.*pid' /var/run/libvirt/qemu/${VM_NAME}.xml | sed "s/.*pid='\([[:digit:]]\+\)'.*/\1/") - -SUDO_PID=$(pgrep -P $VM_EMULATION_PID) -BASH_PID=$(pgrep -P $SUDO_PID) -NSENTER_PID=$(pgrep -P $BASH_PID) -VM_PID=$(pgrep -P $NSENTER_PID) -QEMU_PROC_NAME=$(ps -q $VM_PID -o comm=) - -echo "Qemu process: $QEMU_PROC_NAME" -test "$QEMU_PROC_NAME" == "qemu-system-x86" || ERROR=1 - -CONTAINER_ID=$(docker ps --no-trunc | awk "/.*compute.*virt-launcher-$VM_NAME.*/ { print \$1 }") -CONTAINER_PID=$(docker inspect --format '{{.State.Pid}}' $CONTAINER_ID) -CGROUP_PATH=$(cat /proc/${CONTAINER_PID}/cgroup | head -1 | cut -f3 -d:) - -echo "VM name: $VM_NAME" -echo "VM emulation PID: $VM_EMULATION_PID" -echo "VM PID: $VM_PID" -echo "Container ID: $CONTAINER_ID" -echo "Container PID: $CONTAINER_PID" -echo "Container cgroup path: $CGROUP_PATH" - -# Check cgroups -echo "" -echo "Checking for required cgroups:" -CGROUPS='freezer cpu cpuacct perf_event net_cls blkio memory hugetlb cpuset' -for CG in $CGROUPS; do - - if grep -Fxq "$VM_PID" /sys/fs/cgroup/$CG/$CGROUP_PATH/tasks; then - echo VM $VM_NAME found in container cgroup $CG - else - ERROR=1 - echo VM $VM_NAME NOT found in container cgroup $CG - fi -done - -echo "" -echo "Checking for excluded cgroups:" -EXCLUDED_CGROUPS="devices systemd" -for CG in $EXCLUDED_CGROUPS; do - - if grep -Fxq "$VM_PID" /sys/fs/cgroup/$CG/$CGROUP_PATH/tasks; then - echo VM $VM_NAME FOUND in container cgroup $CG - ERROR=1 - else - echo VM $VM_NAME not found in container cgroup $CG - fi -done - -# Check namespaces -echo "" -echo "Checking for required namespaces:" -NAMESPACES='pid' -for NS in $NAMESPACES; do - NS_PRETTY=$(echo $NS | tr '[:lower:]' '[:upper:]') - VM_PID_NS=$(ls -iL /proc/$VM_PID/ns/$NS | cut -f 1 -d " ") - CONTAINER_PID_NS=$(ls -iL /proc/$CONTAINER_PID/ns/$NS | cut -f 1 -d " ") - - if [ "x$VM_PID_NS" == "x" ]; then - echo Could not determine $NS_PRETTY namespace of VM $VM_NAME - ERROR=1 - fi - - if [ "$VM_PID_NS" == "$CONTAINER_PID_NS" ]; then - echo VM $VM_NAME found in $NS_PRETTY namespace of container - else - echo VM $VM_NAME NOT found in $NS_PRETTY namespace of container - ERROR=1 - fi -done - -echo "" -if [ "$ERROR" -gt "0" ]; then - echo "Verification failed." -else - echo "Verification successful." -fi - -exit $ERROR diff --git a/cluster/vm-isolation-check.sh b/cluster/vm-isolation-check.sh index a5e64282bc66..e69de29bb2d1 100755 --- a/cluster/vm-isolation-check.sh +++ b/cluster/vm-isolation-check.sh @@ -1,62 +0,0 @@ -#!/bin/bash -# -# This file is part of the KubeVirt project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Copyright 2017 Red Hat, Inc. -# - -source hack/config.sh -usage() { - echo "Usage: ./cluster/vm-isolation-check.sh [-vm ]" -} - -VM_NAME=testvm - -while [[ $# -gt 0 ]]; do - key="$1" - - case $key in - -vm) - VM_NAME="$2" - shift - ;; - -help) - usage - exit 0 - ;; - - *) - usage - exit 1 - ;; - esac - shift -done - -JQ_PRESENT=$(which jq >/dev/null 2>&1 && echo 1 || echo 0) -if [ "$JQ_PRESENT" == "0" ]; then - echo "Missing required system dependency: jq" - exit 1 -fi - -NODE=$(cluster/kubectl.sh get pods -o json -l kubevirt.io/domain=${VM_NAME} | jq '.items[].spec.nodeName' -r) - -if [ -z $NODE ]; then - echo "Could not detect the VM." - exit 1 -fi -echo "Found VM running on node '$NODE'" -# Verify that the VM is running and in the right cgroups and namespaces -vagrant ssh $NODE -c "sudo /vagrant/cluster/verify-qemu-kube ${VM_NAME}" diff --git a/docs/env-providers.md b/docs/env-providers.md index a44a3b2e5f72..5deb1dddaf1d 100644 --- a/docs/env-providers.md +++ b/docs/env-providers.md @@ -2,15 +2,16 @@ All following providers allow a common workflow: - * `cluster/up.sh` to create the environment - * `cluster/down.sh` to stop the environment - * `cluster/sync.sh` to build the code and deploy it - * `cluster/deploy.sh` to (re)deploy the code (no provider support needed) - * `make functests` to run the functional tests against a KubeVirt + * `make cluster-up` to create the environment + * `make cluster-down` to stop the environment + * `make cluster-build` to build + * `make cluster-deploy` to (re)deploy the code (no provider support needed) + * `make cluster-sync` to build and (re)deploy the code + * `make functests` to run the functional tests against KubeVirt * `cluster/kubectl.sh` to talk to the k8s installation -It is recommended to export the `PROVIDER` vagirable as part of your .bashrc. - +It is recommended to export the `PROVIDER` vagirable as part of your `.bashrc` +file. ## Vagrant Allows provisioning k8s cluster based on kubeadm. Supports an arbitrary amount @@ -26,7 +27,7 @@ Usage: ```bash export PROVIDER=vagrant # choose this provider export VAGRANT_NUM_NODES=2 # master + two nodes -cluser/up.sh +make cluster-up ``` ## Local @@ -42,11 +43,12 @@ Usage: ```bash export PROVIDER=local # choose this provider -cluser/up.sh +make cluster-up ``` ## New Providers * Create a `cluster/$POVIDER` directory * Create a `cluster/$PROVIDER/provider.sh` files - * This file should containe the functions `up`, `build`, `down` and `_kubectl` + * This file has to contain the functions `up`, `build`, `down` and `_kubectl` + * Have a look at `cluster/vagrant/provider.sh` for a reference implementation diff --git a/docs/getting-started.md b/docs/getting-started.md index 48ef12b3f761..a3fd1a28d5cb 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -93,17 +93,17 @@ Vagrant environment: ```bash # Building and deploying kubevirt in Vagrant - cluster/up.sh - cluster/deploy.sh + make cluster-up + make cluster-sync ``` This will create a VM called `master` which acts as Kubernetes master and then deploy Kubevirt there. To create one or more nodes which will register themselves on master, you can use the `VAGRANT_NUM_NODES` environment variable. -This would create a master and two nodes: +This would create a master and one node: ```bash - VAGRANT_NUM_NODES=2 vagrant up + VAGRANT_NUM_NODES=1 vagrant up ``` If you decide to use separate nodes, pass `VAGRANT_NUM_NODES` variable to all @@ -208,12 +208,6 @@ Finally start a VM called `testvm`: This will start a VM on master or one of the running nodes with a macvtap and a tap networking device attached. -Basic verification is possible by running - -```bash - bash cluster/vm-isolation-check.sh -``` - #### Example ```bash diff --git a/hack/bootstrap-ginkgo.sh b/hack/bootstrap-ginkgo.sh index c57afc4bc25e..102ff9169122 100755 --- a/hack/bootstrap-ginkgo.sh +++ b/hack/bootstrap-ginkgo.sh @@ -1,5 +1,5 @@ # Find every folder containing tests -for dir in `find pkg/ -type f -name '*_test.go' -printf '%h\n' | sort -u`; do +for dir in $(find pkg/ -type f -name '*_test.go' -printf '%h\n' | sort -u); do # If there is no file ending with _suite_test.go, bootstrap ginkgo SUITE_FILE=$(find $dir -maxdepth 1 -type f -name '*_suite_test.go') if [ -z "$SUITE_FILE" ]; then diff --git a/images/libvirt-kubevirt/libvirtd.sh b/images/libvirt-kubevirt/libvirtd.sh index b5e8adc1bf34..f8edb02d6c59 100644 --- a/images/libvirt-kubevirt/libvirtd.sh +++ b/images/libvirt-kubevirt/libvirtd.sh @@ -25,15 +25,15 @@ mkdir /dev.container && { mount --rbind /dev /dev.container mount --rbind /host-dev /dev - # Keep some devices from the containerinal /dev - keep() { mount --rbind /dev.container/$1 /dev/$1 ; } - keep shm || : - keep mqueue - # Keep ptmx/pts for pty creation - keep pts - mount --rbind /dev/pts/ptmx /dev/ptmx - # Use the container /dev/kvm if available - [[ -e /dev.container/kvm ]] && keep kvm + # Keep some devices from the containerinal /dev + keep() { mount --rbind /dev.container/$1 /dev/$1; } + keep shm || : + keep mqueue + # Keep ptmx/pts for pty creation + keep pts + mount --rbind /dev/pts/ptmx /dev/ptmx + # Use the container /dev/kvm if available + [[ -e /dev.container/kvm ]] && keep kvm } mkdir /sys.net.container && { From 8f7c7e6b413876220c7bbe536aa6e6126c58ba6a Mon Sep 17 00:00:00 2001 From: Roman Mohr Date: Thu, 4 Jan 2018 18:03:26 +0100 Subject: [PATCH 6/7] Add support for provider config Give providers a place where they can write their default config values, while still giving people the chance to use hack/cluster-local.sh to override any defaults or provider defaults. Signed-off-by: Roman Mohr --- .gitignore | 2 ++ Vagrantfile | 8 ++++++++ cluster/deploy.sh | 4 ---- cluster/kubectl.sh | 23 ++++------------------- cluster/local/provider.sh | 11 ++++++----- cluster/vagrant/provider.sh | 13 ++++++++----- cluster/vm-isolation-check.sh | 0 hack/build-go.sh | 5 ++++- hack/config-default.sh | 1 + hack/config.sh | 11 ++++++++--- tests/README.md | 6 ++++-- 11 files changed, 45 insertions(+), 39 deletions(-) delete mode 100755 cluster/vm-isolation-check.sh diff --git a/.gitignore b/.gitignore index 5abdb95bfc1f..879421e26659 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,8 @@ tags hack/gen-swagger-doc/*.adoc hack/gen-swagger-doc/*.md hack/gen-swagger-doc/html5 +hack/config-provider-local.sh +hack/config-provider-vagrant.sh cluster/local/certs **.swp **.pem diff --git a/Vagrantfile b/Vagrantfile index 829a927dcc8e..a2c4b929ed6d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,6 +1,14 @@ # -*- mode: ruby -*- # vi: set ft=ruby : +if ARGV.first == "up" && ENV['USING_KUBE_SCRIPTS'] != 'true' + raise Vagrant::Errors::VagrantError.new, <hack/config-local.sh <hack/config-provider-local.sh <${KUBEVIRT_PATH}cluster/vagrant/.kubeconfig + + # Make sure that local config is correct + prepare_config } function prepare_config() { - cat >hack/config-local.sh <hack/config-provider-vagrant.sh < Date: Fri, 5 Jan 2018 09:23:51 +0100 Subject: [PATCH 7/7] kubeadm rpms are not signed again Signed-off-by: Roman Mohr --- cluster/vagrant/setup_kubernetes_common.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cluster/vagrant/setup_kubernetes_common.sh b/cluster/vagrant/setup_kubernetes_common.sh index c29084d20571..5a5be75e93b7 100755 --- a/cluster/vagrant/setup_kubernetes_common.sh +++ b/cluster/vagrant/setup_kubernetes_common.sh @@ -71,10 +71,8 @@ yum install -y docker # Log to json files instead of journald sed -i 's/--log-driver=journald //g' /etc/sysconfig/docker -# Use hard coded versions until https://github.com/kubernetes/kubeadm/issues/212 is resolved. -# Currently older versions of kubeadm are no longer available in the rpm repos. -# See https://github.com/kubernetes/kubeadm/issues/220 for context. -yum install -y \ +# Omit pgp checks until https://github.com/kubernetes/kubeadm/issues/643 is resolved. +yum install --nogpgcheck -y \ kubeadm \ kubelet \ kubectl \