Skip to content

Commit

Permalink
Apply formatting rules to our bash scripts
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 10252a7 commit 2fed3ad
Show file tree
Hide file tree
Showing 22 changed files with 298 additions and 278 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -88,4 +91,4 @@ check-bash:
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
.PHONY: build fmt test clean distclean checksync sync docker manifests vet publish vagrant-sync-config vagrant-sync-build vagrant-deploy functest release-announce fmt-bash
4 changes: 2 additions & 2 deletions cluster/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ sleep 2
echo "Deploying ..."

# Deploy the right manifests for the right target
if [ -z "$TARGET" ] || [ "$TARGET" = "vagrant-dev" ]; then
if [ -z "$TARGET" ] || [ "$TARGET" = "vagrant-dev" ]; then
_kubectl create -f manifests/dev -R $i
elif [ "$TARGET" = "vagrant-release" ]; then
elif [ "$TARGET" = "vagrant-release" ]; then
_kubectl create -f manifests/release -R $i
fi

Expand Down
12 changes: 6 additions & 6 deletions cluster/kubectl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ source cluster/$PROVIDER/provider.sh
source ${KUBEVIRT_PATH}hack/config.sh

if [ "$1" == "console" ] || [ "$1" == "spice" ]; then
cmd/virtctl/virtctl "$@" -s http://${master_ip}:8184
cmd/virtctl/virtctl "$@" -s http://${master_ip}:8184
exit
fi

# Print usage from virtctl and kubectl
if [ "$1" == "--help" ] || [ "$1" == "-h" ] ; then
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
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
elif [ -e ${KUBEVIRT_PATH}cluster/vagrant/.kubectl ]; then
_kubectl -s http://${master_ip}:8184 "$@"
else
echo "Did you already run 'cluster/up.sh' to deploy kubevirt?"
Expand Down
62 changes: 31 additions & 31 deletions cluster/local/provider.sh
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
#!/bin/bash

function _cert_dir () {
echo $GOPATH/src/kubevirt.io/kubevirt/cluster/local/certs
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 _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 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
function prepare_config() {
cat >hack/config-local.sh <<EOF
master_ip=$(_main_ip)
docker_tag=devel
EOF
}

function build () {
make manifests docker
function build() {
make manifests docker
}

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

function down () {
true
function down() {
true
}

# Make sure that local config is correct
Expand Down
53 changes: 28 additions & 25 deletions cluster/vagrant/provider.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
#!/bin/bash

function _main_ip {
echo 192.168.200.2
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; }
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}'`
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/.kubectl
chmod u+x cluster/vagrant/.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/.kubeconfig
}

function prepare_config () {
cat > hack/config-local.sh <<EOF
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 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 _kubectl() {
export KUBECONFIG=${KUBEVIRT_PATH}cluster/vagrant/.kubeconfig
${KUBEVIRT_PATH}cluster/vagrant/.kubectl "$@"
}

function down () {
vagrant halt
function down() {
vagrant halt
}

# Make sure that local config is correct
Expand Down
36 changes: 18 additions & 18 deletions cluster/vagrant/setup_kubernetes_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ yum -y install jq sshpass
yum -y install bind-utils net-tools

# if there is a second disk, use it for docker
if ls /dev/*db ; then
# We use the loopback docker dm support, and not a VG for now
mkdir -p /var/lib/docker/
restorecon -r /var/lib/docker
mount LABEL=dockerdata /var/lib/docker/ || {
mkfs.xfs -L dockerdata -f /dev/?db
}
# FAILS because of vdsms multpoath stuff
#echo -e "\nLABEL=dockerdata /var/lib/docker/ xfs defaults 0 0" >> /etc/fstab
mkdir -p /etc/systemd/system/docker.service.d/
cat > /etc/systemd/system/docker.service.d/mount.conf <<EOT
if ls /dev/*db; then
# We use the loopback docker dm support, and not a VG for now
mkdir -p /var/lib/docker/
restorecon -r /var/lib/docker
mount LABEL=dockerdata /var/lib/docker/ || {
mkfs.xfs -L dockerdata -f /dev/?db
}
# FAILS because of vdsms multpoath stuff
#echo -e "\nLABEL=dockerdata /var/lib/docker/ xfs defaults 0 0" >> /etc/fstab
mkdir -p /etc/systemd/system/docker.service.d/
cat >/etc/systemd/system/docker.service.d/mount.conf <<EOT
[Service]
ExecStartPre=/usr/bin/sleep 5
ExecStartPre=-/usr/bin/mount LABEL=dockerdata /var/lib/docker
MountFlags=shared
EOT
mount LABEL=dockerdata /var/lib/docker/
mount LABEL=dockerdata /var/lib/docker/
fi

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
cat <<EOF >/etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://yum.kubernetes.io/repos/kubernetes-el7-x86_64
Expand All @@ -75,13 +75,13 @@ sed -i 's/--log-driver=journald //g' /etc/sysconfig/docker
# 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
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 <<EOT >>/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
Expand Down
14 changes: 7 additions & 7 deletions cluster/vagrant/setup_kubernetes_master.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion cluster/vagrant/setup_kubernetes_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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...'
Expand Down
Loading

0 comments on commit 2fed3ad

Please sign in to comment.