Skip to content

Commit

Permalink
Add support for provider config
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rmohr committed Jan 5, 2018
1 parent 9f2703b commit 8f7c7e6
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

if ARGV.first == "up" && ENV['USING_KUBE_SCRIPTS'] != 'true'
raise Vagrant::Errors::VagrantError.new, <<END
Calling 'vagrant up' directly is not supported. Instead, please run the following:
export PROVIDER=vagrant
make cluster-up
END
end

$use_nfs = ENV['VAGRANT_USE_NFS'] == 'true'
$use_rng = ENV['VAGRANT_USE_RNG'] == 'true'
Expand Down
4 changes: 0 additions & 4 deletions cluster/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ elif [ "$TARGET" = "vagrant-release" ]; then
_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

Expand Down
23 changes: 4 additions & 19 deletions cluster/kubectl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,11 @@
#

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

if [ "$1" == "console" ] || [ "$1" == "spice" ]; then
cmd/virtctl/virtctl "$@" -s http://${master_ip}:8184
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 ] &&
[ "x$1" == "x--core" ]; then
shift
_kubectl "$@"
elif [ -e ${KUBEVIRT_PATH}cluster/vagrant/.kubectl ]; then
_kubectl -s http://${master_ip}:8184 "$@"
if [ "$1" == "console" ] || [ "$1" == "vnc" ]; then
cmd/virtctl/virtctl "$@" --kubeconfig=${kubeconfig}
else
echo "Did you already run 'cluster/up.sh' to deploy kubevirt?"
_kubectl "$@"
fi
11 changes: 6 additions & 5 deletions cluster/local/provider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ function _main_ip() {
}

function up() {
# Make sure that local config is correct
prepare_config

go get -d k8s.io/kubernetes

export API_HOST_IP=$(_main_ip)
Expand All @@ -29,9 +32,10 @@ function up() {
}

function prepare_config() {
cat >hack/config-local.sh <<EOF
cat >hack/config-provider-local.sh <<EOF
master_ip=$(_main_ip)
docker_tag=devel
kubeconfig=$(_cert_dir)/admin.kubeconfig
EOF
}

Expand All @@ -45,8 +49,5 @@ function _kubectl() {
}

function down() {
true
echo "Not supported by this provider. Please kill the running script manually."
}

# Make sure that local config is correct
prepare_config
13 changes: 8 additions & 5 deletions cluster/vagrant/provider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function _main_ip() {
}

function up() {
export USING_KUBE_SCRIPTS=true
# Make sure that the vagrant environment is up and running
vagrant up --provider=libvirt
# Synchronize kubectl config
Expand All @@ -20,20 +21,25 @@ function up() {
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() {
cat >hack/config-local.sh <<EOF
BASE_PATH=${KUBEVIRT_PATH:-$PWD}
cat >hack/config-provider-vagrant.sh <<EOF
master_ip=$(_main_ip)
docker_tag=devel
kubeconfig=${BASE_PATH}/cluster/vagrant/.kubeconfig
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"
vagrant ssh $VM -c "cd /vagrant && export DOCKER_TAG=${docker_tag} && sudo -E hack/build-docker.sh build && sudo -E hack/build-docker.sh build optional"
done
}

Expand All @@ -45,6 +51,3 @@ function _kubectl() {
function down() {
vagrant halt
}

# Make sure that local config is correct
prepare_config
Empty file removed cluster/vm-isolation-check.sh
Empty file.
5 changes: 4 additions & 1 deletion hack/build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ if [ $# -eq 0 ]; then
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
(
Expand Down
1 change: 1 addition & 0 deletions hack/config-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 8 additions & 3 deletions hack/config.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 8f7c7e6

Please sign in to comment.