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 <