X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=installers%2Fcharmed_install.sh;h=00e4112bf8580a34d8878e79be267f8ba93977f0;hb=481ae7d606286c40e775fddd17146285a7d1a3cc;hp=e8eda63d46ade2528fdf043f31256ec96dec6f84;hpb=9425dd2d4a3a0ac8c0bb6dd8d71b0c4b71045f62;p=osm%2Fdevops.git diff --git a/installers/charmed_install.sh b/installers/charmed_install.sh index e8eda63d..00e4112b 100755 --- a/installers/charmed_install.sh +++ b/installers/charmed_install.sh @@ -15,9 +15,13 @@ # set -eux +JUJU_AGENT_VERSION=2.8.6 K8S_CLOUD_NAME="k8s-cloud" KUBECTL="microk8s.kubectl" +MICROK8S_VERSION=1.19 IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml +PATH=/snap/bin:${PATH} + function check_arguments(){ while [ $# -gt 0 ] ; do case $1 in @@ -27,16 +31,30 @@ function check_arguments(){ --lxd) LXD_CLOUD="$2" ;; --lxd-cred) LXD_CREDENTIALS="$2" ;; --microstack) MICROSTACK=y ;; - --ha) BUNDLE="osm-ha" ;; + --ha) BUNDLE="cs:osm-ha" ;; --tag) TAG="$2" ;; + --registry) REGISTRY_INFO="$2" ;; esac shift done # echo $BUNDLE $KUBECONFIG $LXDENDPOINT } + function install_snaps(){ - [ ! -v KUBECFG ] && sudo snap install microk8s --classic && sudo usermod -a -G microk8s `whoami` && mkdir -p ~/.kube && sudo chown -f -R `whoami` ~/.kube + if [ ! -v KUBECFG ]; then + sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable + sudo usermod -a -G microk8s `whoami` + mkdir -p ~/.kube + sudo chown -f -R `whoami` ~/.kube + KUBEGRP="microk8s" + sg ${KUBEGRP} -c "microk8s status --wait-ready" + else + KUBECTL="kubectl" + sudo snap install kubectl --classic + export KUBECONFIG=${KUBECFG} + KUBEGRP=$(id -g -n) + fi sudo snap install juju --classic --channel=2.8/stable } @@ -55,6 +73,17 @@ using this command: juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME} Please retry the installation once this conflict has been resolved. +EOF + exit 1 + fi + else + CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l) + if [ $CONTROLLER_PRESENT -le 0 ]; then + cat << EOF +Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA +that exists, or remove the --vca ${CONTROLLER_NAME} option. + +Please retry the installation with one of the solutions applied. EOF exit 1 fi @@ -62,10 +91,13 @@ EOF if [ -v KUBECFG ]; then cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS - [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME --config controller-service-type=loadbalancer + [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \ + --config controller-service-type=loadbalancer \ + --agent-version=$JUJU_AGENT_VERSION else - sg microk8s -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb" - sg microk8s -c "microk8s.enable storage dns" + sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb" + sg ${KUBEGRP} -c "microk8s.enable ingress" + sg ${KUBEGRP} -c "microk8s.enable storage dns" TIME_TO_WAIT=30 start_time="$(date -u +%s)" while true @@ -73,18 +105,20 @@ EOF now="$(date -u +%s)" if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then echo "Microk8s storage failed to enable" - sg microk8s -c "microk8s.status" + sg ${KUBEGRP} -c "microk8s.status" exit 1 fi - sg microk8s -c "microk8s.status" | grep 'storage: enabled' - if [ $? -eq 0 ]; then + storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"` + if [[ $storage_status == "enabled" ]]; then break fi sleep 1 done - [ ! -v BOOTSTRAP_NEEDED ] && sg microk8s -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS - [ -v BOOTSTRAP_NEEDED ] && sg microk8s -c "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer" && K8S_CLOUD_NAME=microk8s + [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS + [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \ + "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \ + && K8S_CLOUD_NAME=microk8s fi if [ -v LXD_CLOUD ]; then @@ -102,7 +136,6 @@ EOF # Install LXD snap sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client sudo snap install lxd - sudo apt-get install zfsutils-linux -y # Configure LXD sudo usermod -a -G lxd `whoami` cat /usr/share/osm-devops/installers/lxd-preseed.conf | sed 's/^config: {}/config:\n core.https_address: '$LXDENDPOINT':8443/' | sg lxd -c "lxd init --preseed" @@ -143,43 +176,132 @@ EOF juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS sg lxd -c "lxd waitready" - #juju add-model test lxd-cloud || true juju controller-config features=[k8s-operators] } +function wait_for_port(){ + SERVICE=$1 + INDEX=$2 + TIME_TO_WAIT=30 + start_time="$(date -u +%s)" + while true + do + now="$(date -u +%s)" + if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then + echo "Failed to expose external ${SERVICE} interface port" + exit 1 + fi + + if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then + break + fi + sleep 1 + done +} + function deploy_charmed_osm(){ + if [ -v REGISTRY_INFO ] ; then + registry_parts=(${REGISTRY_INFO//@/ }) + if [ ${#registry_parts[@]} -eq 1 ] ; then + # No credentials supplied + REGISTRY_USERNAME="" + REGISTRY_PASSWORD="" + REGISTRY_URL=${registry_parts[0]} + else + credentials=${registry_parts[0]} + credential_parts=(${credentials//:/ }) + REGISTRY_USERNAME=${credential_parts[0]} + REGISTRY_PASSWORD=${credential_parts[1]} + REGISTRY_URL=${registry_parts[1]} + fi + # Ensure the URL ends with a / + case $REGISTRY_URL in + */) ;; + *) REGISTRY_URL=${REGISTRY_URL}/ + esac + fi + create_overlay echo "Creating OSM model" if [ -v KUBECFG ]; then juju add-model osm $K8S_CLOUD_NAME else - sg microk8s -c "juju add-model osm $K8S_CLOUD_NAME" + sg ${KUBEGRP} -c "juju add-model osm $K8S_CLOUD_NAME" fi echo "Deploying OSM with charms" images_overlay="" + if [ -v REGISTRY_URL ]; then + [ ! -v TAG ] && TAG='latest' + fi [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE" + if [ -v BUNDLE ]; then juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay else - juju deploy osm --overlay ~/.osm/vca-overlay.yaml $images_overlay + juju deploy cs:osm --channel edge --overlay ~/.osm/vca-overlay.yaml $images_overlay fi + echo "Waiting for deployment to finish..." - check_osm_deployed &> /dev/null + check_osm_deployed echo "OSM with charms deployed" - sg microk8s -c "microk8s.enable ingress" - juju config ui-k8s juju-external-hostname=osm.$DEFAULT_IP.xip.io - juju expose ui-k8s + if [ ! -v KUBECFG ]; then + API_SERVER=${DEFAULT_IP} + else + API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ") + proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')" + url="$(echo ${API_SERVER/$proto/})" + user="$(echo $url | grep @ | cut -d@ -f1)" + hostport="$(echo ${url/$user@/} | cut -d/ -f1)" + API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')" + fi + + # Expose OSM services + # Expose Grafana + juju config grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io + juju expose grafana-k8s + wait_for_port grafana-k8s 0 + + # Expose NBI + juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io + juju expose nbi-k8s + wait_for_port nbi-k8s 1 + + # Expose NG UI + juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io + juju expose ng-ui + wait_for_port ng-ui 2 + + # Expose Prometheus + juju config prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io + juju expose prometheus-k8s + wait_for_port prometheus-k8s 3 + + # Apply annotations + sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/backend-protocol=HTTPS -n osm -l juju-app=nbi-k8s" + sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=nbi-k8s" + sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ng-ui" } function check_osm_deployed() { + TIME_TO_WAIT=600 + start_time="$(date -u +%s)" + total_service_count=14 + previous_count=0 while true do - pod_name=`sg microk8s -c "microk8s.kubectl -n osm get pods | grep ui-k8s | grep -v operator" | awk '{print $1; exit}'` - - if [[ `sg microk8s -c "microk8s.kubectl -n osm wait pod $pod_name --for condition=Ready"` ]]; then - if [[ `sg microk8s -c "microk8s.kubectl -n osm wait pod lcm-k8s-0 --for condition=Ready"` ]]; then - break - fi + service_count=$(juju status | grep kubernetes | grep active | wc -l) + echo "$service_count / $total_service_count services active" + if [ $service_count -eq $total_service_count ]; then + break + fi + if [ $service_count -ne $previous_count ]; then + previous_count=$service_count + start_time="$(date -u +%s)" + fi + now="$(date -u +%s)" + if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then + echo "Timed out waiting for OSM services to become ready" + exit 1 fi sleep 10 done @@ -228,33 +350,41 @@ EOF } function generate_images_overlay(){ + if [ ! -z "$REGISTRY_USERNAME" ] ; then + REGISTRY_CREDENTIALS=$(cat < /tmp/images-overlay.yaml applications: lcm-k8s: options: - image: opensourcemano/lcm:$TAG + image: ${REGISTRY_URL}opensourcemano/lcm:$TAG ${REGISTRY_CREDENTIALS} mon-k8s: options: - image: opensourcemano/mon:$TAG + image: ${REGISTRY_URL}opensourcemano/mon:$TAG ${REGISTRY_CREDENTIALS} ro-k8s: options: - image: opensourcemano/ro:$TAG + image: ${REGISTRY_URL}opensourcemano/ro:$TAG ${REGISTRY_CREDENTIALS} nbi-k8s: options: - image: opensourcemano/nbi:$TAG + image: ${REGISTRY_URL}opensourcemano/nbi:$TAG ${REGISTRY_CREDENTIALS} pol-k8s: options: - image: opensourcemano/pol:$TAG - ui-k8s: - options: - image: opensourcemano/light-ui:$TAG + image: ${REGISTRY_URL}opensourcemano/pol:$TAG ${REGISTRY_CREDENTIALS} pla: options: - image: opensourcemano/pla:$TAG + image: ${REGISTRY_URL}opensourcemano/pla:$TAG ${REGISTRY_CREDENTIALS} ng-ui: options: - image: opensourcemano/ng-ui:$TAG - + image: ${REGISTRY_URL}opensourcemano/ng-ui:$TAG ${REGISTRY_CREDENTIALS} + keystone: + options: + image: ${REGISTRY_URL}opensourcemano/keystone:$TAG ${REGISTRY_CREDENTIALS} EOF mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE } @@ -300,7 +430,6 @@ DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'` check_arguments $@ mkdir -p ~/.osm install_snaps -sleep 5 bootstrap_k8s_lxd deploy_charmed_osm install_osmclient @@ -308,18 +437,16 @@ if [ -v MICROSTACK ]; then install_microstack fi +OSM_HOSTNAME=$(juju config nbi-k8s juju-external-hostname):443 + echo "Your installation is now complete, follow these steps for configuring the osmclient:" echo -echo "1. Get the NBI IP with the following command:" -echo -echo NBI_IP='`juju status --format json | jq -rc '"'"'.applications."nbi-k8s".address'"'"'`' -echo -echo "2. Create the OSM_HOSTNAME environment variable with the NBI IP" +echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP" echo -echo "export OSM_HOSTNAME=\$NBI_IP" +echo "export OSM_HOSTNAME=$OSM_HOSTNAME" echo -echo "3. Add the previous command to your .bashrc for other Shell sessions" +echo "2. Add the previous command to your .bashrc for other Shell sessions" echo -echo "echo \"export OSM_HOSTNAME=\$NBI_IP\" >> ~/.bashrc" +echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc" echo echo "DONE"