diff --git a/.gitignore b/.gitignore index 23ca2d449f96..879421e26659 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,10 @@ 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 +**.crt +**.csr 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 b60eed4e8711..b0670e071dca 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} @@ -66,7 +69,6 @@ checksync: sync: glide install --strip-vendor ${HASH} glide.lock > .glide.lock.hash - docker: build ./hack/build-docker.sh build ${WHAT} @@ -83,22 +85,24 @@ 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 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 +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/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, </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 echo "Deploying ..." # Deploy the right manifests for the right target -if [ -z "$TARGET" ] || [ "$TARGET" = "vagrant-dev" ]; then - $KUBECTL create -f manifests/dev -R $i -elif [ "$TARGET" = "vagrant-release" ]; then - $KUBECTL create -f manifests/release -R $i +if [ -z "$TARGET" ] || [ "$TARGET" = "vagrant-dev" ]; then + _kubectl create -f manifests/dev -R $i +elif [ "$TARGET" = "vagrant-release" ]; then + _kubectl create -f manifests/release -R $i fi # 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..7c0672b9f141 100755 --- a/cluster/kubectl.sh +++ b/cluster/kubectl.sh @@ -17,24 +17,12 @@ # Copyright 2017 Red Hat, Inc. # +PROVIDER=${PROVIDER:-vagrant} +source ${KUBEVIRT_PATH}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 - exit -fi - -# Print usage from virtctl and kubectl -if [ "$1" == "--help" ] || [ "$1" == "-h" ] ; then - cmd/virtctl/virtctl "$@" -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 "$@" +if [ "$1" == "console" ] || [ "$1" == "vnc" ]; then + cmd/virtctl/virtctl "$@" --kubeconfig=${kubeconfig} else - echo "Did you already run '$SYNC_CONFIG' to deploy kubevirt?" + _kubectl "$@" fi diff --git a/cluster/local/provider.sh b/cluster/local/provider.sh new file mode 100644 index 000000000000..249453735e86 --- /dev/null +++ b/cluster/local/provider.sh @@ -0,0 +1,53 @@ +#!/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() { + # Make sure that local config is correct + prepare_config + + 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-provider-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 + + # Make sure that local config is correct + prepare_config +} + +function prepare_config() { + BASE_PATH=${KUBEVIRT_PATH:-$PWD} + cat >hack/config-provider-vagrant.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 @@ -71,17 +71,15 @@ 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 \ - kubeadm \ - kubelet \ - kubectl \ - kubernetes-cni +# Omit pgp checks until https://github.com/kubernetes/kubeadm/issues/643 is resolved. +yum install --nogpgcheck -y \ + 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..2498a466e6cc 100755 --- a/cluster/vagrant/setup_kubernetes_node.sh +++ b/cluster/vagrant/setup_kubernetes_node.sh @@ -19,15 +19,15 @@ 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...' # 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/vagrant/sync_build.sh b/cluster/vagrant/sync_build.sh deleted file mode 100755 index b325ad9aa0a9..000000000000 --- a/cluster/vagrant/sync_build.sh +++ /dev/null @@ -1,26 +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. -# -set -ex - -make all DOCKER_TAG=devel - -for VM in `vagrant status | grep -v "^The Libvirt domain is running." | grep running | cut -d " " -f1`; do - vagrant rsync $VM # if you do not use NFS - vagrant ssh $VM -c "cd /vagrant && export DOCKER_TAG=devel && sudo -E hack/build-docker.sh $@" -done - diff --git a/cluster/vagrant/sync_config.sh b/cluster/vagrant/sync_config.sh deleted file mode 100755 index 72e28d62c909..000000000000 --- a/cluster/vagrant/sync_config.sh +++ /dev/null @@ -1,30 +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. -# - -set -ex - -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}'` - -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/cluster/verify-qemu-kube b/cluster/verify-qemu-kube deleted file mode 100755 index 09450fd97d0c..000000000000 --- a/cluster/verify-qemu-kube +++ /dev/null @@ -1,91 +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 deleted file mode 100755 index a900a8e65ea0..000000000000 --- a/cluster/vm-isolation-check.sh +++ /dev/null @@ -1,64 +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/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/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 < $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..c67f970edab5 100755 --- a/hack/build-go.sh +++ b/hack/build-go.sh @@ -38,31 +38,51 @@ 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}) + ( + cd tests + go test -kubeconfig=${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/config-default.sh b/hack/config-default.sh index 78edb34171d9..9fb1c9231039 100644 --- a/hack/config-default.sh +++ b/hack/config-default.sh @@ -5,3 +5,4 @@ docker_prefix=kubevirt docker_tag=${DOCKER_TAG:-latest} master_ip=192.168.200.2 network_provider=weave +kubeconfig=cluster/vagrant/.kubeconfig diff --git a/hack/config.sh b/hack/config.sh index 9f7be5a79ce6..0479105f42da 100644 --- a/hack/config.sh +++ b/hack/config.sh @@ -1,11 +1,16 @@ unset binaries docker_images docker_prefix docker_tag manifest_templates \ - master_ip network_provider + master_ip network_provider kubeconfig -source ${KUBEVIRT_PATH}hack/config-default.sh +PROVIDER=${PROVIDER:-vagrant} + +source ${KUBEVIRT_PATH}hack/config-default.sh source ${KUBEVIRT_PATH}hack/config-${PROVIDER}.sh + +# Allow different providers to override default config values +test -f "hack/config-provider-${PROVIDER}.sh" && source hack/config-provider-${PROVIDER}.sh # Let devs override any default variables, to avoid needing # to change the version controlled config-default.sh file test -f "hack/config-local.sh" && source hack/config-local.sh export binaries docker_images docker_prefix docker_tag manifest_templates \ - master_ip network_provider + master_ip network_provider kubeconfig 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..f8edb02d6c59 100644 --- a/images/libvirt-kubevirt/libvirtd.sh +++ b/images/libvirt-kubevirt/libvirtd.sh @@ -22,38 +22,38 @@ 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 ; } - 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 && { - 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 - diff --git a/tests/README.md b/tests/README.md index 5c920be1c45e..0568fa11163e 100644 --- a/tests/README.md +++ b/tests/README.md @@ -4,16 +4,18 @@ Integration tests require a running Kubevirt cluster. Once you have a running Kubevirt cluster, you can use the `-master` and the `-kubeconfig` flags to point the tests to the cluster. -## Run them on Vagrant +## Run them on an arbitrary KubeVirt installation The vagrant environment has an unprotected haproxy in front of the apiserver, so only `-master` needs to be set to run the tests. ``` cd tests # from the git repo root folder -go test -master=http://192.168.200.2:8184 +go test -kubeconfig=path/to/my/config ``` +## Run them on one of the core KubeVirt providers + There is a make target to run this with the config taken from hack/config.sh: