Skip to content

Commit e83203d

Browse files
authored
adding prompt for when running initialize-cluster.sh if cluster exists (#785)
Also fixed a rust cache error during install and expanded the wait time for the cluster to be ready to reduce errors. --------- Signed-off-by: Ryan Winter <[email protected]>
1 parent f574bad commit e83203d

File tree

5 files changed

+125
-71
lines changed

5 files changed

+125
-71
lines changed

.devcontainer/onCreateCommand.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ sudo apt-get update
1313
sudo apt-get install -y --no-install-recommends mosquitto-clients
1414

1515
# initialize the cluster
16-
tools/deployment/initialize-cluster.sh
16+
tools/deployment/initialize-cluster.sh -y
1717

1818
echo "Ending onCreateCommand"

.github/.linkspector.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ excludedFiles:
77
ignorePatterns:
88
# There are some dummy links, ignore these
99
- pattern: "^http://link_to_"
10+
aliveStatusCodes:
11+
- 200
12+
- 201
13+
- 204
14+
- 429 # Add 429 because we are rate limiting

.github/actions/configure-aio/action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ runs:
3030
using: composite
3131
steps:
3232
- name: Create k3s cluster
33-
run: tools/deployment/initialize-cluster.sh
33+
run: tools/deployment/initialize-cluster.sh -y
3434
shell: bash
3535

3636
- name: Checkout deploy action
@@ -64,8 +64,10 @@ runs:
6464
- name: Setup Rust
6565
if: inputs.install-rust == 'true'
6666
uses: actions-rust-lang/setup-rust-toolchain@v1
67+
with:
68+
cache: false
6769

6870
- name: Wait for Mqtt Broker
6971
if: inputs.wait-for-broker == 'true'
70-
run: kubectl wait --for=create pod/aio-broker-frontend-0 --timeout=60s
72+
run: kubectl wait --for=create pod/aio-broker-frontend-0 --timeout=120s
7173
shell: bash

doc/setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Azure IoT Operations will be installed to the development cluster, and then the
110110

111111
1. Launch a shell, and change to the root directory of the *Azure IoT Operations SDKs* repository.
112112

113-
1. If required, initialize the cluster and install required dependencies:
113+
1. If required, run the following to install required dependencies and initialize the cluster:
114114

115115
```bash
116116
sudo ./tools/deployment/initialize-cluster.sh

tools/deployment/initialize-cluster.sh

Lines changed: 114 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,127 @@
33
set -o errexit
44
set -o pipefail
55

6-
script_dir=$(dirname $(readlink -f $0))
6+
help()
7+
{
8+
echo "Usage: initialize-cluster.sh [OPTION]..."
9+
echo "Initialize cluster will install prerequisites and create a k3s cluster."
10+
echo
11+
echo "Options:"
12+
echo "-h Print this Help."
13+
echo "-s Skip the installation of prerequisites."
14+
echo "-y Automatically assume 'yes' to all questions."
15+
echo
16+
}
17+
18+
install-prerequisites()
19+
{
20+
echo
21+
echo "==========================="
22+
echo " Installing prerequisities"
23+
echo "==========================="
24+
echo
725

8-
echo =========================
9-
echo Installing prerequisities
10-
echo =========================
11-
12-
# install docker
13-
SYSTEM_NAME=$(uname -r)
14-
if ! [[ "$SYSTEM_NAME" == *"microsoft"* && "$SYSTEM_NAME" == *"WSL"* ]]
15-
then
16-
if ! which docker;
17-
then
18-
sudo apt-get update
19-
sudo apt-get install -y docker.io
26+
# install docker
27+
SYSTEM_NAME=$(uname -r)
28+
if ! [[ "$SYSTEM_NAME" == *"microsoft"* && "$SYSTEM_NAME" == *"WSL"* ]]; then
29+
if ! which docker;
30+
then
31+
sudo apt-get update
32+
sudo apt-get install -y docker.io
33+
fi
2034
fi
21-
fi
2235

23-
# install k3d
24-
if ! which k3d;
25-
then
26-
wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
27-
fi
36+
# install k3d
37+
if ! which k3d; then
38+
wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
39+
fi
2840

29-
# install helm
30-
if ! which helm;
31-
then
32-
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
33-
fi
41+
# install helm
42+
if ! which helm; then
43+
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
44+
fi
3445

35-
# install step
36-
if ! which step;
37-
then
38-
wget -q https://github.com/smallstep/cli/releases/download/v0.28.0/step-cli_amd64.deb -P /tmp
39-
sudo dpkg -i /tmp/step-cli_amd64.deb
40-
fi
46+
# install step
47+
if ! which step; then
48+
wget -q https://github.com/smallstep/cli/releases/download/v0.28.0/step-cli_amd64.deb -P /tmp
49+
sudo dpkg -i /tmp/step-cli_amd64.deb
50+
fi
4151

42-
# install az cli
43-
if ! which az;
44-
then
45-
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
46-
az aks install-cli
47-
fi
52+
# install az cli
53+
if ! which az; then
54+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
55+
az aks install-cli
56+
fi
4857

49-
# install/upgrade extensions
50-
az extension add --upgrade --name azure-iot-ops
51-
az extension add --upgrade --name connectedk8s
58+
# install/upgrade extensions
59+
az extension add --upgrade --name azure-iot-ops
60+
az extension add --upgrade --name connectedk8s
5261

53-
# install k9s
54-
if ! which k9s;
55-
then
56-
wget -q https://github.com/derailed/k9s/releases/latest/download/k9s_linux_amd64.deb -P /tmp
57-
sudo dpkg -i /tmp/k9s_linux_amd64.deb
62+
# install k9s
63+
if ! which k9s; then
64+
wget -q https://github.com/derailed/k9s/releases/latest/download/k9s_linux_amd64.deb -P /tmp
65+
sudo dpkg -i /tmp/k9s_linux_amd64.deb
66+
fi
67+
}
68+
69+
create-cluster() {
70+
echo
71+
echo "========================="
72+
echo " Creating cluster"
73+
echo "========================="
74+
echo
75+
76+
# Create k3d cluster and forwarded ports (MQTT/MQTTS)
77+
k3d cluster delete
78+
k3d cluster create \
79+
-p '1883:1883@loadbalancer' \
80+
-p '8883:8883@loadbalancer' \
81+
-p '8884:8884@loadbalancer' \
82+
--registry-create k3d-registry.localhost:127.0.0.1:5000 \
83+
--wait
84+
85+
# Set the default context / namespace to azure-iot-operations
86+
kubectl config set-context k3d-k3s-default --namespace=azure-iot-operations
87+
88+
echo
89+
echo "================================================================================================="
90+
echo " The k3d cluster has been created and the default context has been set to azure-iot-operations."
91+
echo
92+
echo " If you need non-root access to the cluster, run the following command:"
93+
echo
94+
echo " mkdir ~/.kube; sudo install -o $USER -g $USER -m 600 /root/.kube/config ~/.kube/config"
95+
echo "================================================================================================="
96+
}
97+
98+
# Get the options
99+
while getopts "hsy" option; do
100+
case $option in
101+
h) # display Help
102+
help
103+
exit;;
104+
s) # skip installation of prerequisites
105+
echo Skipping installation of prerequisites
106+
SKIP_INSTALL=true;;
107+
y) # assume yes to all questions
108+
AUTO_YES=true;;
109+
esac
110+
done
111+
112+
script_dir=$(dirname $(readlink -f $0))
113+
114+
if [[ $SKIP_INSTALL != "true" ]]; then
115+
install-prerequisites
116+
fi
117+
118+
if [[ $AUTO_YES != "true" ]]; then
119+
if [[ `k3d cluster list k3s-default` ]]; then
120+
echo
121+
read -p "An existing cluster was detected, are you sure you want to delete it? [y/N] " yn
122+
case $yn in
123+
[Yy]* ) ;;
124+
* ) exit 1;;
125+
esac
126+
fi
58127
fi
59128

60-
echo =========================
61-
echo Creating cluster
62-
echo =========================
63-
64-
# Create k3d cluster and forwarded ports (MQTT/MQTTS)
65-
k3d cluster delete
66-
k3d cluster create \
67-
-p '1883:1883@loadbalancer' \
68-
-p '8883:8883@loadbalancer' \
69-
-p '8884:8884@loadbalancer' \
70-
--registry-create k3d-registry.localhost:127.0.0.1:5000 \
71-
--wait
72-
73-
# Set the default context / namespace to azure-iot-operations
74-
kubectl config set-context k3d-k3s-default --namespace=azure-iot-operations
75-
76-
echo
77-
echo =================================================================================================
78-
echo The k3d cluster has been created and the default context has been set to azure-iot-operations.
79-
echo If you need non-root access to the cluster, run the following command:
80-
echo
81-
echo "mkdir ~/.kube; sudo install -o $USER -g $USER -m 600 /root/.kube/config ~/.kube/config"
82-
echo =================================================================================================
129+
create-cluster

0 commit comments

Comments
 (0)