add support for using on existing k8s cluter without kind
diff --git a/voltha b/voltha
index 1ffb0b0..3a8178b 100755
--- a/voltha
+++ b/voltha
@@ -43,6 +43,15 @@
TYPE=${TYPE:-minimal}
WITH_BBSIM=${WITH_BBSIM:-no}
+JUST_K8S=${JUST_K8S:-no}
+DEPLOY_K8S=${DEPLOY_K8S:-yes}
+
+HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
+HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
+HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
+if [ $HOSTARCH == "x86_64" ]; then
+ HOSTARCH="amd64"
+fi
# Verify TYPE setting
if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
@@ -61,7 +70,27 @@
WITH_BBSIM=no
fi
-echo $WITH_BBSIM
+# Verify JUST_K8S settting and convert uniform value of yes or no
+if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$JUST_K8S:") -eq 0 ]; then
+ >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$JUST_K8S value of '$JUST_K8S'. Should be 'yes' or 'no'${NOCOLOR}"
+ exit 1
+fi
+if [ $(echo ":y:yes:true:1:" | grep -ic ":$JUST_K8S:") -eq 1 ]; then
+ JUST_K8S=yes
+else
+ JUST_K8S=no
+fi
+
+# Verify DEPLOY_K8S settting and convert uniform value of yes or no
+if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$DEPLOY_K8S:") -eq 0 ]; then
+ >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$DEPLOY_K8S value of '$DEPLOY_K8S'. Should be 'yes' or 'no'${NOCOLOR}"
+ exit 1
+fi
+if [ $(echo ":y:yes:true:1:" | grep -ic ":$DEPLOY_K8S:") -eq 1 ]; then
+ DEPLOY_K8S=yes
+else
+ DEPLOY_K8S=no
+fi
if [ "$TYPE" == "full" ]; then
ONOS_API_PORT=${ONOS_API_PORT:-8182}
@@ -86,11 +115,23 @@
fi
if [ "$1" == "down" ]; then
- if [ -x ./bin/kind ]; then
- exec ./bin/kind delete cluster --name voltha-$TYPE
+ if [ $DEPLOY_K8S == "yes" ]; then
+ if [ -x ./bin/kind ]; then
+ exec ./bin/kind delete cluster --name voltha-$TYPE
+ else
+ >&2 echo "Kind doesn't seem to be installed, so nothing to do. Bye."
+ fi
else
- >&2 echo "Kind doesn't seem to be installed, so nothing to do. Bye."
- fi
+ EXISTS=$(helm list -q)
+ EXPECT="etcd-operator onos open-olt open-onu sim voltha"
+ INTERSECT=
+ for i in $EXISTS; do
+ if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
+ HAVE="$HAVE $i"
+ fi
+ done
+ ./bin/helm delete --purge $HAVE
+fi
exit
fi
@@ -277,32 +318,22 @@
else
espin $NOT_VERIFIED
bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
- (set -x; curl -o $GOPATH/bin/kubectl -sSL https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/$(go env GOHOSTOS)/$(go env GOARCH)/kubectl >>$LOG 2>&1) >>$LOG 2>&1
+ (set -x; curl -o $GOPATH/bin/kubectl -sSL https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/$HOSTOS/$HOSTARCH/kubectl >>$LOG 2>&1) >>$LOG 2>&1
(set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
espin - $VERIFIED
fi
-# Unclear if kubeadm is required. Leave out for now
-#bspin "Verify Kubernetes/kubectl"
-#if [ -x $GOPATH/bin/kubeadm ]; then
-# espin $VERIFIED
-#else
-# espin $NOT_VERIFIED
-# bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
-# (set -x; curl -o $GOPATH/bin/kubeadm -sSL https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/$(go env GOHOSTOS)/$(go env GOARCH)/kubeadm >>$LOG 2>&1) >>$LOG 2>&1
-# (set -x; chmod 755 $GOPATH/bin/kubeadm >>$LOG 2>&1) >>$LOG 2>&1
-# espin - $VERIFIED
-#fi
-
-bspin "Verify Kubernetes/Kind $HELM"
-if [ -x $GOPATH/bin/kind ]; then
- espin $VERIFIED
-else
- espin $NOT_VERIFIED
- bspin - "Download and install Kubernetes/kind $DOWNLOAD"
- (set -x; curl -o $GOPATH/bin/kind -sSL https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-$(go env GOHOSTOS)-$(go env GOARCH) >>$LOG 2>&1) >>$LOG 2>&1
- (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
- espin - $VERIFIED
+if [ "$DEPLOY_K8S" == "yes" ]; then
+ bspin "Verify Kubernetes/Kind $HELM"
+ if [ -x $GOPATH/bin/kind ]; then
+ espin $VERIFIED
+ else
+ espin $NOT_VERIFIED
+ bspin - "Download and install Kubernetes/kind $DOWNLOAD"
+ (set -x; curl -o $GOPATH/bin/kind -sSL https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-$HOSTOS-HOSTARCH >>$LOG 2>&1) >>$LOG 2>&1
+ (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
+ espin - $VERIFIED
+ fi
fi
bspin "Verify Helm $HELM"
@@ -311,7 +342,7 @@
else
espin $NOT_VERIFIED
bspin - "Download and install Helm $DOWNLOAD"
- (set -x; curl -sSL https://git.io/get_helm.sh | USE_SUDO=false HELM_INSTALL_DIR=$(go env GOPATH)/bin bash >>$LOG 2>&1) >>$LOG 2>&1
+ (set -x; curl -sSL https://git.io/get_helm.sh | USE_SUDO=false HELM_INSTALL_DIR=$GOPATH/bin bash >>$LOG 2>&1) >>$LOG 2>&1
espin - $VERIFIED
fi
@@ -321,40 +352,42 @@
else
espin $NOT_VERIFIED
bspin - "Download and build voltctl $DOWNLOAD"
- (set -x; curl -o $GOPATH/bin/voltctl -sSL https://github.com/ciena/voltctl/releases/download/$VOLTCTL_VERSION/voltctl-$_VOLTCTL_VERSION-$(go env GOHOSTOS)-$(go env GOARCH) >>$LOG 2>&1) >>$LOG 2>&1
+ (set -x; curl -o $GOPATH/bin/voltctl -sSL https://github.com/ciena/voltctl/releases/download/$VOLTCTL_VERSION/voltctl-$_VOLTCTL_VERSION-$HOSTOS-$HOSTARCH >>$LOG 2>&1) >>$LOG 2>&1
(set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
espin - $VERIFIED
fi
bspin "Verify command PATH"
-export PATH=$(go env GOPATH)/bin:$PATH
+export PATH=$GOPATH/bin:$PATH
espin $VERIFIED
-HAVE=$(kind get clusters | grep -c voltha-$TYPE)
-bspin "Verify Kubernetes/Kind Cluster"
-sspin
-if [ $HAVE -eq 0 ]; then
- espin $NOT_VERIFIED
- kind create cluster --name voltha-$TYPE --config $TYPE-cluster.cfg
-else
- espin $VERIFIED
+if [ "$DEPLOY_K8S" == "yes" ]; then
+ HAVE=$(kind get clusters | grep -c voltha-$TYPE)
+ bspin "Verify Kubernetes/Kind Cluster"
+ sspin
+ if [ $HAVE -eq 0 ]; then
+ espin $NOT_VERIFIED
+ kind create cluster --name voltha-$TYPE --config $TYPE-cluster.cfg
+ else
+ espin $VERIFIED
+ fi
+
+ export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$TYPE")"
+ P="coredns-.* \
+ etcd-voltha-$TYPE-control-plane \
+ kindnet-.* \
+ kube-apiserver-voltha-$TYPE-control-plane \
+ kube-controller-manager-voltha-$TYPE-control-plane \
+ kube-proxy-.* \
+ kube-scheduler-voltha-$TYPE-control-plane"
+
+ EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
+ wait_for_pods - "kube-system" $EXPECT -1 "Waiting for system PODs to start" $P
fi
-export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$TYPE")"
-P="coredns-.* \
- etcd-voltha-$TYPE-control-plane \
- kindnet-.* \
- kube-apiserver-voltha-$TYPE-control-plane \
- kube-controller-manager-voltha-$TYPE-control-plane \
- kube-proxy-.* \
- kube-scheduler-voltha-$TYPE-control-plane"
-
-EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
-wait_for_pods - "kube-system" $EXPECT -1 "Waiting for system PODs to start" $P
-
COUNT=$(count_pods "kube-system" "tiller-deploy-.*")
bspin "Verify Helm"
-if [ $(count_pods "kube-system" "tiller-deploy-.*") -ne 1 ]; then
+if [ $COUNT -ne 1 ]; then
espin $NOT_VERIFIED
echo -e "Configuring Helm $GEAR"
bspin - "Initialize Helm"
@@ -363,6 +396,15 @@
bspin - "Add Google Incubator repository to Helm"
(set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
espin - $VERIFIED
+
+ # HACK (sort-of) - the config for tiller is about to be patched, which will
+ # cause the tiller pod to be recreated. This can sometimes cause a timing
+ # issue with the "wait_for_pods" call on tiller as it may incorrectly
+ # identify the running/ready tiller pod that is soon to be terminated as
+ # what it is waiting for. To avoid this issue we do a clean scale down and
+ # scale up of the pod so the script controlls when it should be expecting
+ # things
+ (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=0 >>$LOG 2>&1) >>$LOG 2>&1
bspin - "Add Google Stable repository to Helm"
(set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
@@ -383,12 +425,43 @@
espin - $VERIFIED
bspin - "Update Tiller Manifest"
(set -x; kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}' >>$LOG 2>&1) >>$LOG 2>&1
+
+ # HACK (sort-of) - part to, spin it back up
+ (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=1 >>$LOG 2>&1) >>$LOG 2>&1
espin - $VERIFIED
else
espin $VERIFIED
fi
wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
+bspin "Verify Helm values file: $TYPE-values.yaml"
+if [ ! -r "./$TYPE-values.yaml" ]; then
+ espin $NOT_VERIFIED
+ bspin - "Download Helm values file: $TYPE-values.yaml $DOWNLOAD"
+ (set -x; curl -o ./$TYPE-values.yaml -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$TYPE-values.yaml >>$LOG 2>&1) >>$LOG 2>&1
+ espin - $VERIFIED
+else
+ espin $VERIFIED
+fi
+
+if [ "$JUST_K8S" == "yes" ]; then
+ echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
+ echo ""
+ echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
+ echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
+ echo "tools required by VOLTHA in your command path. " | tee -a $LOG
+ echo "" | tee -a $LOG
+ echo -en $BOLD
+ if [ $DEPLOY_K8S == "yes" ]; then
+ echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$TYPE\")\"" | tee -a $LOG
+ fi
+ echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
+ echo -en $NORMAL
+ echo "" | tee -a $LOG
+ echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
+ exit 0
+fi
+
bspin "Verify ETCD Operator $OLD_KEY"
if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
espin $NOT_VERIFIED
@@ -416,6 +489,18 @@
(set -x; screen -p 0 -X -S onos-ssh-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
(set -x; screen -dmS onos-ssh-$TYPE kubectl port-forward service/onos-ssh $ONOS_SSH_PORT:8101 >>$LOG 2>&1) >>$LOG 2>&1
espin - $VERIFIED
+if [ ! -x ./onos-files/install-onos-applications.sh ]; then
+ bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
+ (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
+ for i in dhcp-to-controller-flow.json install-onos-applications.sh olt-onos-enableExtraneousRules.json olt-onos-netcfg.json olt-onos-olt-settings.json; do
+ if [ ! -r ./onos-files/$i ]; then
+ (set -x; curl -o ./onos-files/$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/onos-files/$i >>$LOG 2>&1) >>$LOG 2>&1
+ fi
+ done
+ (set -x; chmod 755 ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
+ espin - $VERIFIED
+fi
+
bspin - "Install required ONOS applications $INSTALL"
(set -x; ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
espin - $VERIFIED
@@ -427,6 +512,7 @@
else
espin $VERIFIED
fi
+
VOLTHA="ofagent-.* \
ro-core.* \
rw-core.* \
@@ -504,9 +590,11 @@
echo "tools required by VOLTHA in your command path. " | tee -a $LOG
echo "" | tee -a $LOG
echo -en $BOLD
-echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$TYPE\")\"" | tee -a $LOG
+if [ $DEPLOY_K8S == "yes" ]; then
+ echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$TYPE\")\"" | tee -a $LOG
+fi
echo "export VOLTCONFIG=\"$HOME/.volt/config-$TYPE\"" | tee -a $LOG
-echo 'export PATH=$GOPATH/bin:$PATH' | tee -a $LOG
+echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
echo -en $NORMAL
echo "" | tee -a $LOG
echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG