Skip to content

Commit

Permalink
[testing] Install chaos mesh in local kind cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
maru-ava committed Jan 25, 2025
1 parent f0c42ab commit 4b3e849
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions scripts/ensure_kube_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ function ensure_command {

echo "Ensuring ${cmd} is available"
if ! command -v "${cmd}" &> /dev/null; then
local local_cmd="${PWD}/bin/${cmd}"
mkdir -p "${PWD}/bin"
echo "${cmd} not found, attempting to install..."
curl -L -o "${local_cmd}" "${install_uri}"
if [[ "${cmd}" == helm ]]; then
curl -L -o - "${install_uri}" | tar -xz -C "${PWD}/bin" --strip-components=1 "${GOOS}-${GOARCH}/${cmd}"
else
local local_cmd="${PWD}/bin/${cmd}"
curl -L -o "${local_cmd}" "${install_uri}"
chmod +x "${local_cmd}"
fi
# TODO(marun) Optionally validate the binary against published checksum
chmod +x "${local_cmd}"
fi
}

Expand All @@ -48,15 +52,39 @@ fi
# Check if a cluster is already running
if ${KUBECTL_CMD} cluster-info &> /dev/null; then
echo "A kube cluster is already accessible"
exit 0
else
KIND_VERSION=v0.23.0
ensure_command kind "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-${GOOS}-${GOARCH}"

KIND_SCRIPT_SHA=7cb9e6be25b48a0e248097eef29d496ab1a044d0
ensure_command "kind-with-registry.sh" \
"https://raw.githubusercontent.com/kubernetes-sigs/kind/${KIND_SCRIPT_SHA}/site/static/examples/kind-with-registry.sh"

echo "Deploying a new kind cluster with a local registry"
bash -x "$(command -v kind-with-registry.sh)"
fi

KIND_VERSION=v0.23.0
ensure_command kind "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-${GOOS}-${GOARCH}"
# WARNING This is only intended to work for the runtime configuration of a kind cluster.
if [[ -n "${INSTALL_CHAOS_MESH:-}" ]]; then
# Ensure helm is available
HELM_VERSION=v3.7.0
ensure_command helm "https://get.helm.sh/helm-${HELM_VERSION}-${GOOS}-${GOARCH}.tar.gz"

# Install chaos mesh via helm
helm repo add chaos-mesh https://charts.chaos-mesh.org

SCRIPT_SHA=7cb9e6be25b48a0e248097eef29d496ab1a044d0
ensure_command "kind-with-registry.sh" \
"https://raw.githubusercontent.com/kubernetes-sigs/kind/${SCRIPT_SHA}/site/static/examples/kind-with-registry.sh"
# Create the namespace to install to
${KUBECTL_CMD} create ns chaos-mesh

echo "Deploying a new kind cluster with a local registry"
bash -x "${PWD}/bin/kind-with-registry.sh"
# Install chaos mesh for containerd, with dashboard persistence and no security, and without leader election
CHAOS_MESH_VERSION=2.7.0
helm install chaos-mesh chaos-mesh/chaos-mesh -n=chaos-mesh --version "${CHAOS_MESH_VERSION}"\
--set chaosDaemon.runtime=containerd\
--set chaosDaemon.socketPath=/run/containerd/containerd.sock\
--set dashboard.persistentVolume.enabled=true\
--set dashboard.persistentVolume.storageClass=standard\
--set dashboard.securityMode=false\
--set controllerManager.leaderElection.enabled=false

# TODO(marun) Figure out it's not possible to create experiments via the chaos-mesh dashboard
fi

0 comments on commit 4b3e849

Please sign in to comment.