|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Script to check if the basic requirements for a local deployment of the Data Space Connector are met |
| 4 | + |
| 5 | +# Command for starting a minimal k3s cluster |
| 6 | +k3s_command="docker run --privileged --volume=k3stest:/var/lib/rancher/k3s/agent --detach --publish=6443:6443 docker.io/rancher/k3s:latest server --node-name=k3s --https-listen-port=6443 --disable-cloud-controller --disable-network-policy --disable=metrics-server --disable-helm-controller --disable=local-storage --disable=traefik" |
| 7 | + |
| 8 | +check_tool() { |
| 9 | + local tool_name=$1 |
| 10 | + local test_command=$2 |
| 11 | + |
| 12 | + # Check if the tool is installed |
| 13 | + if ! command -v $tool_name &> /dev/null; then |
| 14 | + echo "$tool_name is not installed." |
| 15 | + exit 1 |
| 16 | + fi |
| 17 | + |
| 18 | + # Run the test command and check for errors |
| 19 | + if ! output=$($test_command 2>&1); then |
| 20 | + echo "$tool_name is installed but failed to run." |
| 21 | + echo "Error output:" |
| 22 | + echo "$output" |
| 23 | + exit 1 |
| 24 | + fi |
| 25 | + |
| 26 | + echo "$tool_name is installed and works correctly." |
| 27 | + return 0 |
| 28 | +} |
| 29 | + |
| 30 | +wait_till_running() { |
| 31 | + local containerId=$1 |
| 32 | + sleep 10 |
| 33 | + |
| 34 | + end=$((SECONDS+60)) |
| 35 | + |
| 36 | + while [ $SECONDS -lt $end ]; do |
| 37 | + local state=$(docker inspect -f '{{.State.Status}}' $containerId) |
| 38 | + if [[ "$state" = "running" || "$state" = "dead" ]]; then |
| 39 | + break |
| 40 | + else |
| 41 | + echo "Waiting for Container, current state $(state). Checking again in 5 seconds..." |
| 42 | + sleep 5 |
| 43 | + fi |
| 44 | + done |
| 45 | +} |
| 46 | +echo "Testing system for requirements running the FIWARE Data Space Connector Local Deployment" |
| 47 | + |
| 48 | +# Check if the script is running on Linux |
| 49 | +if [[ "$(uname)" != "Linux" ]]; then |
| 50 | + echo "Local Deployment is currently only tested on Linux." |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +# Check Maven |
| 55 | +check_tool "mvn" "mvn --version" |
| 56 | + |
| 57 | +# Check Docker |
| 58 | +check_tool "docker" "docker --version" |
| 59 | + |
| 60 | +# Check if k3s can be run |
| 61 | +echo "Attempting to start a k3s container" |
| 62 | +containerId="" |
| 63 | +if output=$($k3s_command 2>&1); then |
| 64 | + containerId=$output |
| 65 | + echo "k3s container starting with ID: $containerId" |
| 66 | +else |
| 67 | + echo "Failed to start k3s container." |
| 68 | + echo "Error output:" |
| 69 | + echo "$output" |
| 70 | + exit 1 |
| 71 | +fi |
| 72 | + |
| 73 | +wait_till_running $containerId |
| 74 | + |
| 75 | +if [ "$(docker inspect -f '{{.State.Status}}' $containerId)" = "running" ]; then |
| 76 | + echo "Container is running." |
| 77 | +else |
| 78 | + echo "Container is not running." |
| 79 | + if docker logs $containerId 2>&1 | grep -q 'inotify_init: too many open files'; then |
| 80 | + echo "inotify limit is to low, check your inotify.max_user_instances config and set to a higher value" |
| 81 | + exit 1 |
| 82 | + else |
| 83 | + echo "Check logs for error hints:" |
| 84 | + docker logs $containerId | tail -n20 |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | +fi |
| 88 | + |
| 89 | +# Copy kubeconfig file from container |
| 90 | +docker cp $containerId:/etc/rancher/k3s/k3s.yaml . |
| 91 | + |
| 92 | +# Let kubectl use copied config |
| 93 | +export KUBECONFIG=$(pwd)/k3s.yaml |
| 94 | + |
| 95 | +# Check Kubectl |
| 96 | +check_tool "kubectl" "kubectl get nodes" |
| 97 | +echo "Kubectl is able to access the local kubernetes cluster successfully!" |
| 98 | + |
| 99 | + |
| 100 | +# cleanup |
| 101 | +docker stop $containerId |
| 102 | +docker rm $containerId |
| 103 | + |
| 104 | +echo "Test complete" |
| 105 | +exit 0 |
0 commit comments