Skip to content

Commit

Permalink
Partial bash linting
Browse files Browse the repository at this point in the history
  • Loading branch information
andreacv98 committed Mar 25, 2024
1 parent b48b044 commit 645857b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 76 deletions.
26 changes: 13 additions & 13 deletions tools/scripts/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -m
SCRIPT_PATH="$(realpath "$BASH_SOURCE")"
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"

source $SCRIPT_DIR/utils.sh
source "$SCRIPT_DIR"/utils.sh

# PIDs of the processes in background
pids=()
Expand All @@ -17,7 +17,7 @@ handle_error() {
echo "An error occurred. Exiting..."
for pid in "${pids[@]}"; do
# Kill all the processes in background
kill $pid 2>/dev/null
kill "$pid" 2>/dev/null
done
return 1
}
Expand All @@ -27,7 +27,7 @@ handle_exit() {
echo "Exiting..."
for pid in "${pids[@]}"; do
# Kill all the processes in background
kill $pid 2>/dev/null
kill "$pid" 2>/dev/null
done
# Ask the user if really wants to exit
read -p "Do you really want to exit? [y/N] " answer
Expand Down Expand Up @@ -70,11 +70,11 @@ create_kind_clusters() {
# Set the role of the cluster
role="consumer"
# Create the cluster
kind create cluster --name $name --config $SCRIPT_DIR/../../quickstart/kind/configs/standard.yaml --kubeconfig $SCRIPT_DIR/$name-config -q
kind create cluster --name "$name" --config "$SCRIPT_DIR"/../../quickstart/kind/configs/standard.yaml --kubeconfig "$SCRIPT_DIR"/"$name"-config -q
# Get the IP of the control plane of the cluster
controlplane_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name-control-plane)
controlplane_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$name"-control-plane)
# Write the cluster info to a file
echo "$name: {\"ip\":\"$controlplane_ip\", \"kubeconfig\":\"$SCRIPT_DIR/$name-config\", \"role\":\"$role\"}" >> $consumers_json
echo "$name: {\"ip\":\"$controlplane_ip\", \"kubeconfig\":\"$SCRIPT_DIR/$name-config\", \"role\":\"$role\"}" >> "$consumers_json"
) &
# Save the PID of the process
pids+=($!)
Expand All @@ -89,19 +89,19 @@ create_kind_clusters() {
# Set the role of the cluster
role="provider"
# Create the cluster
kind create cluster --name $name --config $SCRIPT_DIR/../../quickstart/kind/configs/standard.yaml --kubeconfig $SCRIPT_DIR/$name-config -q
kind create cluster --name "$name" --config "$SCRIPT_DIR"/../../quickstart/kind/configs/standard.yaml --kubeconfig "$SCRIPT_DIR"/"$name"-config -q
# Get the IP of the control plane of the cluster
controlplane_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name-control-plane)
controlplane_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$name"-control-plane)
# Write the cluster info to a file
echo "$name: {\"ip\":\"$controlplane_ip\", \"kubeconfig\":\"$SCRIPT_DIR/$name-config\", \"role\":\"$role\"}" >> $providers_json
echo "$name: {\"ip\":\"$controlplane_ip\", \"kubeconfig\":\"$SCRIPT_DIR/$name-config\", \"role\":\"$role\"}" >> "$providers_json"
) &
# Save the PID of the process
pids+=($!)
done

# Wait for all the processes to finish
for pid in "${pids[@]}"; do
wait $pid
wait "$pid"
done

else
Expand Down Expand Up @@ -129,11 +129,11 @@ get_clusters() {

print_title "CONSUMER CLUSTERS"

insert_clusters $consumer_json "consumer"
insert_clusters "$consumer_json" "consumer"

print_title "PROVIDER CLUSTERS"

insert_clusters $provider_json "provider"
insert_clusters "$provider_json" "provider"
}

# Insert clusters into proper file
Expand Down Expand Up @@ -177,7 +177,7 @@ insert_clusters() {
node_ip=$(kubectl get nodes --kubeconfig="$kubeconfig_path" -o jsonpath='{.items[*].status.addresses[?(@.type=="InternalIP")].address}' | awk '{print $1}')

# Save the cluster info into json_file file
echo "$cluster_name: {\"ip\":\"$node_ip\", \"kubeconfig\":\"$kubeconfig_path\", \"role\":\"$role\"}" >> $json_file
echo "$cluster_name: {\"ip\":\"$node_ip\", \"kubeconfig\":\"$kubeconfig_path\", \"role\":\"$role\"}" >> "$json_file"
done

}
55 changes: 28 additions & 27 deletions tools/scripts/installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SCRIPT_PATH="$(realpath "$BASH_SOURCE")"
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"

source $SCRIPT_DIR/utils.sh
source "$SCRIPT_DIR"/utils.sh

declare -A providers_ips

Expand All @@ -15,7 +15,7 @@ handle_error() {
echo "An error occurred. Exiting..."
for pid in "${pids[@]}"; do
# Kill all the processes in background
kill $pid 2>/dev/null
kill "$pid" 2>/dev/null
done
read -p "All the processes in background have been killed. Press enter to exit."
return 1
Expand All @@ -26,7 +26,7 @@ handle_exit() {
echo "Exiting..."
for pid in "${pids[@]}"; do
# Kill all the processes in background
kill $pid 2>/dev/null
kill "$pid" 2>/dev/null
done
# Ask the user if really wants to exit
read -p "Do you really want to exit? [y/N] " answer
Expand All @@ -41,7 +41,7 @@ build_and_load() {
local NAMESPACE="$2"
local VERSION="$3"
# Build the docker image
docker build -q -f $SCRIPT_DIR/../../build/common/Dockerfile --build-arg COMPONENT="$COMPONENT" -t "$NAMESPACE"/"$COMPONENT":"$VERSION" $SCRIPT_DIR/../../
docker build -q -f "$SCRIPT_DIR"/../../build/common/Dockerfile --build-arg COMPONENT="$COMPONENT" -t "$NAMESPACE"/"$COMPONENT":"$VERSION" "$SCRIPT_DIR"/../../

echo "Docker image $NAMESPACE/$COMPONENT:$VERSION built"
# For each cluster, load the docker image
Expand All @@ -63,10 +63,10 @@ function install_components() {
declare -A clusters

# Get consumer JSON tmp file from parameter
consumer_json=$1
consumers_json=$1

# Get provider JSON tmp file from parameter
provider_json=$2
providers_json=$2

# Get the remote boolean from parameters
local_repositories=$3
Expand All @@ -82,16 +82,16 @@ function install_components() {
# Read the results from the files
while IFS= read -r line; do
echo
name=$(echo $line | cut -d: -f1)
info=$(echo $line | cut -d: -f2-)
name=$(echo "$line" | cut -d: -f1)
info=$(echo "$line" | cut -d: -f2-)
clusters["$name"]=$info
done < $consumers_json
done < "$consumers_json"

while IFS= read -r line; do
name=$(echo $line | cut -d: -f1)
info=$(echo $line | cut -d: -f2-)
name=$(echo "$line" | cut -d: -f1)
info=$(echo "$line" | cut -d: -f2-)
clusters["$name"]=$info
done < $providers_json
done < "$providers_json"

# Print the clusters
for cluster in "${!clusters[@]}"; do
Expand Down Expand Up @@ -122,7 +122,7 @@ function install_components() {

# Wait for each process and if any of them fails, generates a trap to be captured, which kills all the processes and exits
for pid in "${pids[@]}"; do
wait $pid || handle_error
wait "$pid" || handle_error
echo "Process $pid finished"
done

Expand All @@ -143,7 +143,7 @@ function install_components() {
# Check if the cluster is a provider
cluster_role=$(jq -r '.role' <<< "${clusters[$provider]}")
# Print cluster role
echo "Cluster role is: $provider_role"
echo "Cluster role is: $cluster_role"
if [ "$provider" != "$cluster" ] && [ "$cluster_role" == "provider" ]; then
# Print the specific cluster informations
echo "Cluster: $provider"
Expand All @@ -162,19 +162,20 @@ function install_components() {
done

# Set the KUBECONFIG environment variable taking the value
export KUBECONFIG=$(echo ${clusters[$cluster]} | jq -r '.kubeconfig')
export KUBECONFIG
KUBECONFIG=$(echo "${clusters[$cluster]}" | jq -r '.kubeconfig')

echo "The KUBECONFIG is $KUBECONFIG"

# Apply the metrics-server
kubectl apply -f $SCRIPT_DIR/../../quickstart/utils/metrics-server.yaml --kubeconfig $KUBECONFIG
kubectl apply -f "$SCRIPT_DIR"/../../quickstart/utils/metrics-server.yaml --kubeconfig "$KUBECONFIG"

# Wait for the metrics-server to be ready
echo "Waiting for metrics-server to be ready"
kubectl wait --for=condition=ready pod -l k8s-app=metrics-server -n kube-system --timeout=300s --kubeconfig $KUBECONFIG
kubectl wait --for=condition=ready pod -l k8s-app=metrics-server -n kube-system --timeout=300s --kubeconfig "$KUBECONFIG"

# Decide value file to use based on the role of the cluster
if [ $(jq -r '.role' <<< "${clusters[$cluster]}") == "consumer" ]; then
if [ "$(jq -r '.role' <<< "${clusters[$cluster]}")" == "consumer" ]; then
# Check if local resouce manager is enabled
if [ "$local_resource_manager" == "true" ]; then
value_file="$SCRIPT_DIR/../../quickstart/utils/consumer-values.yaml"
Expand Down Expand Up @@ -204,29 +205,29 @@ function install_components() {
# If the installation does not use remote repository, the image is used the one built locally
if [ "$local_repositories" == "true" ]; then
# If the installation does not use remote repository, the CRDs are applied
kubectl apply -f $SCRIPT_DIR/../../deployments/node/crds --kubeconfig $KUBECONFIG
kubectl apply -f "$SCRIPT_DIR"/../../deployments/node/crds --kubeconfig "$KUBECONFIG"
echo "Installing local repositories in cluster $cluster with local resource manager"
# Print the installation command, then execute it
helm upgrade --install node $SCRIPT_DIR/../../deployments/node \
-n fluidos --create-namespace -f $value_file $IMAGE_SET_STRING \
helm upgrade --install node "$SCRIPT_DIR"/../../deployments/node \
-n fluidos --create-namespace -f "$value_file" "$IMAGE_SET_STRING" \
--set tag="$VERSION" \
--set "networkManager.configMaps.nodeIdentity.ip=$ip:$port" \
--set "networkManager.configMaps.providers.local=${providers_ips[$cluster]}" \
--kubeconfig $KUBECONFIG
--kubeconfig "$KUBECONFIG"
else
echo "Installing remote repositories in cluster $cluster with local resource manager"
helm install node fluidos/node -n fluidos --create-namespace -f $value_file \
helm install node fluidos/node -n fluidos --create-namespace -f "$value_file" \
--set "networkManager.configMaps.nodeIdentity.ip=$ip:$port" \
--set "networkManager.configMaps.providers.local=${providers_ips[$cluster]}" \
--kubeconfig $KUBECONFIG
--kubeconfig "$KUBECONFIG"
fi

echo "Installing LIQO in cluster $cluster"
liqoctl install kind \
--cluster-name $cluster \
--cluster-name "$cluster" \
--set controllerManager.config.resourcePluginAddress=node-rear-controller-grpc.fluidos:2710 \
--set controllerManager.config.enableResourceEnforcement=true \
--kubeconfig $KUBECONFIG
--kubeconfig "$KUBECONFIG"
) &

# Save the PID of the process
Expand All @@ -236,7 +237,7 @@ function install_components() {

# Wait for each process and if any of them fails, generates a trap to be captured, which kills all the processes and exits
for pid in "${pids[@]}"; do
wait $pid || handle_error
wait "$pid" || handle_error
echo "Process $pid finished"
done
}
14 changes: 7 additions & 7 deletions tools/scripts/requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SCRIPT_PATH="$(realpath "$BASH_SOURCE")"
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"

source $SCRIPT_DIR/utils.sh
source "$SCRIPT_DIR"/utils.sh

# Install KIND function
function install_kind() {
Expand All @@ -21,12 +21,12 @@ function install_kind() {
# Install kind if AMD64
if [ "$ARCH" == "amd64" ]; then
echo "Install kind AMD64..."
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.21.0/kind-linux-amd64
[ "$(uname -m)" = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.21.0/kind-linux-amd64
chmod +x kind
sudo mv kind /usr/local/bin/kind
elif [ "$ARCH" == "arm64" ]; then
echo "Install kind ARM64..."
[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.21.0/kind-linux-arm64
[ "$(uname -m)" = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.21.0/kind-linux-arm64
chmod +x kind
sudo mv kind /usr/local/bin/kind
fi
Expand Down Expand Up @@ -94,7 +94,7 @@ function check_kubectl() {
kubectl version --client
if [ $? -ne 0 ]; then
# Ask the user if they want to install kubectl
read -p "Do you want to install kubectl? (y/n): " install_kubectl
read -r -p "Do you want to install kubectl? (y/n): " install_kubectl
if [ "$install_kubectl" == "y" ]; then
install_kubectl
else
Expand All @@ -119,7 +119,7 @@ function check_helm() {
helm version
if [ $? -ne 0 ]; then
# Ask the user if they want to install helm
read -p "Do you want to install helm? (y/n): " install_helm
read -r -p "Do you want to install helm? (y/n): " install_helm
if [ "$install_helm" == "y" ]; then
install_helm
else
Expand Down Expand Up @@ -162,7 +162,7 @@ function check_liqoctl() {
if [ $? -ne 0 ]; then
echo "Please install liqoctl first."
# Ask the user if they want to install liqoctl
read -p "Do you want to install liqoctl? (y/n): " install_liqoctl
read -r -p "Do you want to install liqoctl? (y/n): " install_liqoctl
if [ "$install_liqoctl" == "y" ]; then
install_liqo
else
Expand All @@ -184,7 +184,7 @@ function check_jq() {
jq --version
if [ $? -ne 0 ]; then
# Ask the user if they want to install jq
read -p "Do you want to install jq? (y/n): " install_jq
read -r -p "Do you want to install jq? (y/n): " install_jq
if [ "$install_jq" == "y" ]; then
install_jq
else
Expand Down
Loading

0 comments on commit 645857b

Please sign in to comment.