Chore: Remove stable/argon jobs
[releng/builder.git] / jjb / packaging / openstack-k8s-deploy-helm.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2021 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 # shellcheck disable=SC2153,SC2034
12 echo "---> Deploy Opendaylight Helm charts on K8S cluster and verify deployment"
13 set -eux -o pipefail
14
15 set -x
16
17 # shellcheck disable=SC1090
18 . ~/lf-env.sh
19
20 K8S_DEPLOY_LOG="$WORKSPACE/archives/k8s-kubectl-file.log"
21 mkdir -p "$WORKSPACE/archives"
22
23 KUBECONFIG="${WORKSPACE}/config"
24 export KUBECONFIG
25
26 # Deploy helm charts after dry run.
27 cd "$WORKSPACE/helm"
28 echo "INFO: ODL Helm Charts install --dry-run"
29 helm3.7 install sdnc opendaylight --dry-run
30 echo "INFO: ODL Helm Charts install"
31 helm3.7 install sdnc opendaylight
32
33 POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=opendaylight,app.kubernetes.io/instance=sdnc" -o jsonpath="{.items[0].metadata.name}")
34 CONTAINER_PORT=$(kubectl get pod --namespace default "$POD_NAME" -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
35 echo "Visit http://127.0.0.1:8080 to use your application"
36
37 export POD_NAME
38 export CONTAINER_PORT
39
40 # wait for the pod to become ready
41 for i in $(seq 10); do
42     sleep 50
43     # Verify K8S pods are running state before starting port forwarding
44     echo "DEBUG: Verify ${KUBECONFIG} is valid and nodes are accessable through kubectl:"
45     kubectl describe nodes | tee -a "${K8S_DEPLOY_LOG}"
46     kubectl get po -A -o wide | tee -a "${K8S_DEPLOY_LOG}"
47     # kubectl get events --sort-by='.metadata.creationTimestamp'
48     kubectl get nodes --show-labels
49
50     pod_status=$(kubectl get pods -n default -o jsonpath="{.items[0].status.phase}")
51     if [[ "$pod_status" =~ .*Running.* ]]; then
52         echo "INFO: SNDC runing on the pod"
53         kubectl --namespace default port-forward "$POD_NAME" 8080:"$CONTAINER_PORT" &
54         sleep 30
55         break
56     elif [[ "$pod_status" =~ .*Pending.* ]]; then
57         echo "INFO: SNDC pod status: ${pod_status}, creation in progress ..."
58         continue
59     else
60         echo "ERROR: Error in deploying pod"
61         kubectl describe pods | tee -a "${K8S_DEPLOY_LOG}"
62     fi
63     kubectl get pods -n default -o wide
64 done
65
66 # Test SDNC setup by listing restconf modules
67 SDNC_URL="http://127.0.0.1:8080/restconf/modules"
68 resp=$(curl -u admin:admin -w "\\n\\n%{http_code}" --globoff -H "Content-Type:application/json" "$SDNC_URL")
69 json_data=$(echo "$resp" | head -n1)
70 status=$(echo "$resp" | awk 'END {print $NF}')
71
72 if [ "$status" != 200 ]; then
73     >&2 echo "ERROR: Failed to fetch data from $SDNC_URL with status code $status"
74     >&2 echo "$resp"
75     exit 1
76 else
77     echo "INFO: Successfully deploy Opendaylight SND on K8S pod:"
78     echo "${json_data}" | jq
79 fi