Skip to content

Commit

Permalink
Rebase on master
Browse files Browse the repository at this point in the history
Signed-off-by: Lukianov Artyom <[email protected]>
  • Loading branch information
Lukianov Artyom committed Jan 24, 2018
1 parent 40df4e3 commit 9fffd8c
Show file tree
Hide file tree
Showing 21 changed files with 188 additions and 64 deletions.
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ tools/openapispec/openapispec
**/bin
bin/*
.vagrant
cluster/vagrant/.kubeconfig
cluster/vagrant/.kubectl
cluster/vagrant/.oc
cluster/vagrant-kubernetes/.kubeconfig
cluster/vagrant-kubernetes/.kubectl
cluster/vagrant-openshift/.kubeconfig
cluster/vagrant-openshift/.oc
cluster/.console.vv
build-tools/desc/desc
hack/config-local.sh
Expand All @@ -19,7 +20,8 @@ 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
hack/config-provider-vagrant-kubernetes.sh
hack/config-provider-vagrant-openshift.sh
cluster/local/certs
**.swp
**.pem
Expand Down
30 changes: 14 additions & 16 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Calling 'vagrant up' directly is not supported. Instead, please run the followi
END
end

$deploy_openshift = ENV['DEPLOY_OPENSHIFT'] == 'true'
$provider = ENV['PROVIDER'] || "vagrant-kubernetes"
$use_nfs = ENV['VAGRANT_USE_NFS'] == 'true'
$use_rng = ENV['VAGRANT_USE_RNG'] == 'true'
$cache_docker = ENV['VAGRANT_CACHE_DOCKER'] == 'true'
Expand All @@ -31,6 +31,15 @@ end
$master_ip = $config["master_ip"]
$network_provider = $config["network_provider"]

$common_setup = <<SCRIPT
#!/bin/bash
set -xe
sed -i -e "s/PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config
systemctl restart sshd
# FIXME, sometimes eth1 does not come up on Vagrant on latest fc26
sudo ifup eth1
SCRIPT

Vagrant.configure(2) do |config|
config.vm.box = "centos7"
config.vm.box_url = "http://cloud.centos.org/centos/7/vagrant/x86_64/images/CentOS-7-x86_64-Vagrant-1608_01.LibVirt.box"
Expand Down Expand Up @@ -71,10 +80,7 @@ Vagrant.configure(2) do |config|
rsync__args: ["--archive", "--delete"]
end

config.vm.provision "shell" do |s|
s.path = "cluster/vagrant/setup_common.sh"
s.args = ["#{$master_ip}", "#{$nodes}"]
end
config.vm.provision "shell", inline: $common_setup

config.vm.define "master" do |master|
master.vm.hostname = "master"
Expand All @@ -87,11 +93,7 @@ Vagrant.configure(2) do |config|
end

master.vm.provision "shell" do |s|
if $deploy_openshift then
s.path = "cluster/vagrant/setup_openshift_master.sh"
else
s.path = "cluster/vagrant/setup_kubernetes_master.sh"
end
s.path = "cluster/#{$provider}/setup_master.sh"
s.args = ["#{$master_ip}", "#{$nodes}", "#{$network_provider}"]
end
end
Expand All @@ -110,12 +112,8 @@ Vagrant.configure(2) do |config|
end

node.vm.provision "shell" do |s|
if $deploy_openshift then
s.path = "cluster/vagrant/setup_openshift_common.sh"
else
s.path = "cluster/vagrant/setup_kubernetes_node.sh"
end
s.args = ["#{$master_ip}"]
s.path = "cluster/#{$provider}/setup_node.sh"
s.args = ["#{$master_ip}", "#{$nodes}"]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion cluster/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# We're leaving this file around for people who still reference this
# specific script in their development workflow.

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

build
6 changes: 5 additions & 1 deletion cluster/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

set -ex

PROVIDER=${PROVIDER:-vagrant}
PROVIDER=${PROVIDER:-vagrant-kubernetes}

source hack/common.sh
source cluster/$PROVIDER/provider.sh
Expand Down Expand Up @@ -51,4 +51,8 @@ fi
# Deploy additional infra for testing
_kubectl create -f ${MANIFESTS_OUT_DIR}/testing -R $i

if [ "$PROVIDER" = "vagrant-openshift" ]; then
_kubectl adm policy add-scc-to-user privileged -z kubevirt-infra -n kube-system
fi

echo "Done"
2 changes: 1 addition & 1 deletion cluster/down.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

PROVIDER=${PROVIDER:-vagrant}
PROVIDER=${PROVIDER:-vagrant-kubernetes}
source cluster/$PROVIDER/provider.sh
down
2 changes: 1 addition & 1 deletion cluster/kubectl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set -e

source $(dirname "$0")/../hack/common.sh

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

Expand Down
2 changes: 1 addition & 1 deletion cluster/up.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

PROVIDER=${PROVIDER:-vagrant}
PROVIDER=${PROVIDER:-vagrant-kubernetes}
source cluster/$PROVIDER/provider.sh
up
5 changes: 5 additions & 0 deletions cluster/vagrant-kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The purpose of this folder is to hold all relevant stuff to deploy
KubeVirt on kubernetes cluster in a vagrant box.

Thus this folder primarily contains
- The deployment scripts for master and nodes
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ function up() {

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-kubernetes/.kubectl
chmod u+x cluster/vagrant-kubernetes/.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-kubernetes/.kubeconfig

# Make sure that local config is correct
prepare_config
}

function prepare_config() {
BASE_PATH=${KUBEVIRT_PATH:-$PWD}
cat >hack/config-provider-vagrant.sh <<EOF
cat >hack/config-provider-vagrant-kubernetes.sh <<EOF
master_ip=$(_main_ip)
docker_tag=devel
kubeconfig=${BASE_PATH}/cluster/vagrant/.kubeconfig
kubeconfig=${BASE_PATH}/cluster/vagrant-kubernetes/.kubeconfig
EOF
}

Expand All @@ -44,8 +44,8 @@ function build() {
}

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

function down() {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ master_ip=$1
network_provider=$3

export KUBERNETES_MASTER=true
bash /vagrant/cluster/vagrant/setup_kubernetes_common.sh
bash /vagrant/cluster/vagrant-kubernetes/setup_common.sh

# Cockpit with kubernetes plugin
yum install -y cockpit cockpit-kubernetes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
master_ip=$1

bash /vagrant/cluster/vagrant/setup_kubernetes_common.sh
bash /vagrant/cluster/vagrant-kubernetes/setup_common.sh

ADVERTISED_MASTER_IP=$(sshpass -p vagrant ssh -oStrictHostKeyChecking=no vagrant@$master_ip hostname -I | cut -d " " -f1)
set +e
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The purpose of this folder is to hold all relevant stuff to deploy
KubeVirt in a vagrant box.
KubeVirt on OpenShift cluster in a vagrant box.

Thus this folder primarily contains
- The deployment scripts for master and nodes
53 changes: 53 additions & 0 deletions cluster/vagrant-openshift/provider.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

function _main_ip() {
echo 192.168.200.2
}

function up() {
export USING_KUBE_SCRIPTS=true
# 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:/bin/oc ${KUBEVIRT_PATH}cluster/vagrant-openshift/.oc
chmod u+x cluster/vagrant-openshift/.oc

vagrant ssh master -c "sudo cat /etc/origin/master/openshift-master.kubeconfig" >${KUBEVIRT_PATH}cluster/vagrant-openshift/.kubeconfig

# Make sure that local config is correct
prepare_config
}

function prepare_config() {
BASE_PATH=${KUBEVIRT_PATH:-$PWD}
cat >hack/config-provider-vagrant-openshift.sh <<EOF
master_ip=$(_main_ip)
docker_tag=devel
kubeconfig=${BASE_PATH}/cluster/vagrant-openshift/.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=${docker_tag} && sudo -E hack/build-docker.sh build && sudo -E hack/build-docker.sh build optional"
done
}

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

function down() {
vagrant halt
}
36 changes: 36 additions & 0 deletions cluster/vagrant-openshift/setup_common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#/bin/bash -xe
#
# 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.
#

# Enter master and nodes to /etc/hosts
sed -i "/$(hostname)/d" /etc/hosts
grep 'master' /etc/hosts || echo "$1 master" >> /etc/hosts
IFS=. read ip1 ip2 ip3 ip4 <<< "$1"
for node in $(seq 0 $(($2 - 1))); do
node_hostname="node$node"
node_ip="$ip1.$ip2.$ip3.$(($ip4 + node + 1))"
grep $node_hostname /etc/hosts || echo "$node_ip $node_hostname" >> /etc/hosts
done

# Install OpenShift packages
yum install -y centos-release-openshift-origin
yum install -y wget git net-tools bind-utils iptables-services bridge-utils bash-completion kexec-tools sos psacct docker
systemctl start docker
systemctl enable docker
yum -y update
yum --enablerepo=centos-openshift-origin-testing install -y atomic-openshift-utils
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
#!/bin/bash
#/bin/bash -xe
#
# 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.
#

master_ip=$1
nodes=$2

bash /vagrant/cluster/vagrant/setup_openshift_common.sh
bash /vagrant/cluster/vagrant-openshift/setup_common.sh $master_ip $nodes

# Disable host key checking under ansible.cfg file
sed -i '/host_key_checking/s/^#//g' /etc/ansible/ansible.cfg

# Save nodes to add it under ansible inventory file
inv_nodes=""
IFS=. read ip1 ip2 ip3 ip4 <<< "$master_ip"
nodes=""
for node in $(seq 0 $(($2 - 1))); do
for node in $(seq 0 $(($nodes - 1))); do
node_ip="$ip1.$ip2.$ip3.$(($ip4 + node + 1))"
node_hostname="node$node openshift_node_labels=\"{'region': 'infra','zone': 'default'}\" openshift_ip=$node_ip"
nodes="$nodes$node_hostname\n"
inv_nodes="$inv_nodes$node_hostname\n"
done

# Create ansible inventory file
cat > inventory <<EOF
[OSEv3:children]
masters
Expand All @@ -34,10 +57,11 @@ master openshift_ip=$master_ip
[nodes]
master openshift_node_labels="{'region': 'infra','zone': 'default'}" openshift_schedulable=true openshift_ip=$master_ip
$nodes
$inv_nodes
EOF

# Run OpenShift ansible playbook
ansible-playbook -i inventory /usr/share/ansible/openshift-ansible/playbooks/byo/config.yml

# Create OpenShift user
Expand Down
23 changes: 23 additions & 0 deletions cluster/vagrant-openshift/setup_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#/bin/bash -xe
#
# 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.
#

master_ip=$1
nodes=$2

bash /vagrant/cluster/vagrant-openshift/setup_common.sh $master_ip $nodes
16 changes: 0 additions & 16 deletions cluster/vagrant/setup_common.sh

This file was deleted.

Loading

0 comments on commit 9fffd8c

Please sign in to comment.