Add a script to run AIAP in AKS

This adds a script that a developer can use to run airship in a pod
in a dynamically created AKS cluster.  By default a resource group is
created and then cleaned up following the test.

Further work needs to be done to surface some indication of a failed
test out of the pod, and watch for that condition in this script.

Change-Id: I29f462b9becd6d1de0a9e0e1d7877c6019cbd6ee
This commit is contained in:
Matt McEuen 2021-09-01 17:06:19 -05:00
parent d78f3e5c11
commit 47de62a11c
3 changed files with 88 additions and 1 deletions

3
.gitignore vendored
View File

@ -23,3 +23,6 @@ bin/
# Sphinx build venv # Sphinx build venv
.tox/ .tox/
# Logging
tools/airship-in-a-pod/logs/

View File

@ -17,9 +17,27 @@ The pod also contains the following "Support" containers:
* `libvirt`: This provides virtualisation * `libvirt`: This provides virtualisation
* `sushy-tools`: This is used for its BMC emulator * `sushy-tools`: This is used for its BMC emulator
* `docker-in-docker`: This is used for nesting containers* * `docker-in-docker`: This is used for nesting containers
* `nginx`: This is used for image hosting * `nginx`: This is used for image hosting
## Azure Kubernetes Service (AKS) Quick Start
Airship-in-a-Pod can be easily run within AKS by running the script:
```
tools/airship-in-a-pod/scripts/aiap-in-aks.sh
```
Environment variables can be supplied to override default, such as:
* `AIAP_POD`: the kustomization to use for the AIAP Pod definition
* `CLEANUP_GROUP`: whether to delete the resource group created for
AIAP. Defaults to `false`.
Please consult the script for the full list of overrideable variables.
Note that authentication (e.g. `az login`) must be done prior to invoking
the script.
## Prerequisites ## Prerequisites

View File

@ -0,0 +1,66 @@
#!/bin/bash
# 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.
set -ex
: LOCATION=${LOCATION:=westus}
: GROUP=${GROUP:=aiap-test}
: CLUSTER=${CLUSTER:=aiap}
: CLEANUP_GROUP=${CLEANUP_GROUP:=false}
: TIMEOUT=${TIMEOUT:=7200}
: LOG_DIR=${LOG_DIR:="tools/airship-in-a-pod/logs"}
: AIAP_POD=${AIAP_POD:="tools/airship-in-a-pod/examples/airshipctl"}
az account show
if $(az group exists --name ${GROUP}) && ${CLEANUP_GROUP}; then
echo "group ${GROUP} already exists and \$CLEANUP_GROUP is false, exiting"
exit 1
fi
az group create --name ${GROUP} -l ${LOCATION}
az aks create --name ${CLUSTER} --resource-group ${GROUP} --node-count 1 --node-vm-size Standard_D8s_v3
az aks get-credentials --name ${CLUSTER} --resource-group ${GROUP} --overwrite-existing
kubectl apply -k ${AIAP_POD}
set +x
echo "waiting up to $TIMEOUT seconds for airship-in-a-pod to complete..."
end=$(($(date +%s) + $TIMEOUT))
while true; do
if (kubectl get pod airship-in-a-pod -o jsonpath="{.status.conditions[?(@.type=='ContainersReady')].status}" | grep -q True) ; then
echo -e "\nairship-in-a-pod completed successfully."
break
#TODO There's no way today to detect that an error has occurred, besides timing out. We should resolve that & watch for condition.
else
now=$(date +%s)
if [ $now -gt $end ]; then
echo -e "\nAirship-in-a-Pod did not complete before TIMEOUT."
break
fi
echo -n .
sleep 60
fi
done
set -x +e
echo "extracting logs to ${LOG_DIR}..."
mkdir -p ${LOG_DIR}
rm -f ${LOG_DIR}/aiap-*\.log
for c in $(kubectl get pod -o jsonpath="{.spec.containers[*].name}" airship-in-a-pod); do
kubectl logs airship-in-a-pod -c $c > ${LOG_DIR}/aiap-$c.log
done
if ${CLEANUP_GROUP}; then
echo "deleting resource group ${GROUP}..."
az group delete --name ${GROUP} -y
fi