From 379e3cbbada3e9fe269d188a14d2b43267f8de13 Mon Sep 17 00:00:00 2001 From: Shaharia Azam Date: Tue, 19 Dec 2023 00:07:36 +0100 Subject: [PATCH 1/3] Added comment for bash script --- create_cluster.sh | 142 +++++++++++++--------------------------------- 1 file changed, 40 insertions(+), 102 deletions(-) diff --git a/create_cluster.sh b/create_cluster.sh index ec7ad88..f7311e7 100755 --- a/create_cluster.sh +++ b/create_cluster.sh @@ -1,25 +1,36 @@ #!/bin/bash -# Set the desired configuration +# Define the version of Kind to be used, the name of the cluster to be created, and the number of nodes in the cluster KIND_VERSION="v0.20.0" CLUSTER_NAME="local-k8s" -NODES=2 +NODES=3 -# Function to delete an existing Kind cluster +# Function to delete the Kind cluster if it is already running delete_cluster() { local cluster_name=$1 + + # Check if the cluster is already running if kind get clusters | grep -q "^$cluster_name$"; then echo "Kind cluster '$cluster_name' is already running. Deleting the cluster..." + + # Delete the running cluster kind delete cluster --name "$cluster_name" fi } -# Function to install Kind if not already installed +# Function to install Kind if it is not already installed install_kind() { + # Check if Kind is installed if ! command -v kind &> /dev/null; then echo "Kind not found. Installing Kind..." + + # Download Kind from the official repository curl -Lo ./kind "https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64" + + # Make the downloaded file executable chmod +x ./kind + + # Move the executable file to the local bin directory sudo mv ./kind /usr/local/bin/kind fi } @@ -29,6 +40,8 @@ create_cluster() { local cluster_name=$1 local nodes=$2 echo "Creating Kind cluster: $cluster_name with $nodes nodes..." + + # Create the cluster with the specified configuration cat < Date: Tue, 19 Dec 2023 00:08:46 +0100 Subject: [PATCH 2/3] Added comment for bash script --- create_cluster.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/create_cluster.sh b/create_cluster.sh index f7311e7..00e4842 100755 --- a/create_cluster.sh +++ b/create_cluster.sh @@ -1,9 +1,9 @@ #!/bin/bash # Define the version of Kind to be used, the name of the cluster to be created, and the number of nodes in the cluster -KIND_VERSION="v0.20.0" -CLUSTER_NAME="local-k8s" -NODES=3 +KIND_VERSION="${KIND_VERSION:-v0.20.0}" +CLUSTER_NAME="${CLUSTER_NAME:-local-k8s}" +NODES="${NODES:-3}" # Function to delete the Kind cluster if it is already running delete_cluster() { From c6dc985555154a54754016301d032f7fb205d447 Mon Sep 17 00:00:00 2001 From: Shaharia Azam Date: Tue, 19 Dec 2023 00:51:42 +0100 Subject: [PATCH 3/3] Fix linting --- create_cluster.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create_cluster.sh b/create_cluster.sh index 00e4842..06130a0 100755 --- a/create_cluster.sh +++ b/create_cluster.sh @@ -145,4 +145,4 @@ prepare_kind_cluster() { } # Call the function to prepare the Kind cluster -prepare_kind_cluster $CLUSTER_NAME $NODES \ No newline at end of file +prepare_kind_cluster "$CLUSTER_NAME" "$NODES" \ No newline at end of file