Skip to content

Commit

Permalink
Introduce interface to support different envs
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Jan 4, 2018
1 parent 41b8f3c commit 51a606d
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 185 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 0 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ checksync:
sync:
glide install --strip-vendor
${HASH} glide.lock > .glide.lock.hash


docker: build
./hack/build-docker.sh build ${WHAT}
Expand All @@ -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

Expand Down
23 changes: 14 additions & 9 deletions cluster/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,39 @@

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

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"
5 changes: 5 additions & 0 deletions cluster/down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

PROVIDER=${PROVIDER:-vagrant}
source cluster/$PROVIDER/provider.sh
down
19 changes: 11 additions & 8 deletions cluster/kubectl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
52 changes: 52 additions & 0 deletions cluster/local/provider.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
master_ip=$(_main_ip)
docker_tag=devel
EOF
}

function build () {
make manifests docker
}

function _kubectl () {
export KUBECONFIG=$(_cert_dir)/admin.kubeconfig
$GOPATH/src/k8s.io/kubernetes/cluster/kubectl.sh "$@"
}

function down () {
true
}

# Make sure that local config is correct
prepare_config
7 changes: 6 additions & 1 deletion cluster/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
# This logic moved into the Makefile.
# We're leaving this file around for people who still reference this
# specific script in their development workflow.
make vagrant-deploy

PROVIDER=${PROVIDER:-vagrant}
source cluster/$PROVIDER/provider.sh

build
cluster/deploy.sh
5 changes: 5 additions & 0 deletions cluster/up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

PROVIDER=${PROVIDER:-vagrant}
source cluster/$PROVIDER/provider.sh
up
47 changes: 47 additions & 0 deletions cluster/vagrant/provider.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

function _main_ip {
echo 192.168.200.2
}

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}'`

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 <<EOF
master_ip=$(_main_ip)
docker_tag=devel
EOF
}

function build () {
make build manifests
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 build optional"
done
}

function _kubectl () {
export KUBECONFIG=${KUBEVIRT_PATH}cluster/vagrant/.kubeconfig
${KUBEVIRT_PATH}cluster/vagrant/.kubectl "$@"
}

function down () {
vagrant halt
}

# Make sure that local config is correct
prepare_config
26 changes: 0 additions & 26 deletions cluster/vagrant/sync_build.sh

This file was deleted.

30 changes: 0 additions & 30 deletions cluster/vagrant/sync_config.sh

This file was deleted.

95 changes: 0 additions & 95 deletions docs/dev-env-local.md

This file was deleted.

Loading

0 comments on commit 51a606d

Please sign in to comment.