Skip to content

[testing] Install chaos mesh in local kind cluster #3674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: reuse-kube-install
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions scripts/ensure_kube_cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env bash

set -euo pipefail

# This script ensures that a kubernetes cluster is available with the
# default kubeconfig. If a cluster is not already running, kind will
# be used to start one.

if ! [[ "$0" =~ scripts/ensure_kube_cluster.sh ]]; then
echo "must be run from repository root"
exit 255
fi

function ensure_command {
local cmd=$1
local install_uri=$2

echo "Ensuring ${cmd} is available"
if ! command -v "${cmd}" &> /dev/null; then
mkdir -p "${PWD}/bin"
echo "${cmd} not found, attempting to install..."
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
fi
}

# Enables using a context other than the current default
KUBE_CONTEXT="${KUBE_CONTEXT:-}"

# Ensure locally-installed binaries are in the path
PATH="${PWD}/bin:$PATH"

# Determine the platform to download binaries for
GOOS="$(go env GOOS)"
GOARCH="$(go env GOARCH)"

KUBECTL_VERSION=v1.30.2
ensure_command kubectl "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/${GOOS}/${GOARCH}/kubectl"

# Compose the kubectl command
KUBECTL_CMD="kubectl"
if [[ -n "${KUBE_CONTEXT}" ]]; then
KUBECTL_CMD="${KUBECTL_CMD} --context=${KUBE_CONTEXT}"
fi

# Check if a cluster is already running
if ${KUBECTL_CMD} cluster-info &> /dev/null; then
echo "A kube cluster is already accessible"
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

# 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

# Create the namespace to install to
${KUBECTL_CMD} create ns chaos-mesh

# 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
fi
18 changes: 7 additions & 11 deletions scripts/run_prometheus.sh
Original file line number Diff line number Diff line change
@@ -61,23 +61,19 @@ if ! command -v "${CMD}" &> /dev/null; then
if ! command -v "${CMD}" &> /dev/null; then
echo "prometheus not found, attempting to install..."

# Determine the arch
if which sw_vers &> /dev/null; then
GOOS="$(go env GOOS)"
GOARCH="$(go env GOARCH)"
if [[ "${GOOS}" == "darwin" && "${GOARCH}" == "arm64" ]]; then
echo "On macos, only amd64 binaries are available so rosetta is required on apple silicon machines."
echo "To avoid using rosetta, install via homebrew: brew install prometheus"
DIST=darwin
else
ARCH="$(uname -i)"
if [[ "${ARCH}" != "x86_64" ]]; then
echo "On linux, only amd64 binaries are available. manual installation of prometheus is required."
fi
if [[ "${GOOS}" == "linux" && "${GOARCH}" != "amd64" ]]; then
echo "On linux, only amd64 binaries are available. Manual installation of prometheus is required."
exit 1
else
DIST="linux"
fi
fi

# Install the specified release
PROMETHEUS_FILE="prometheus-${VERSION}.${DIST}-amd64"
PROMETHEUS_FILE="prometheus-${VERSION}.${GOOS}-amd64"
URL="https://github.com/prometheus/prometheus/releases/download/v${VERSION}/${PROMETHEUS_FILE}.tar.gz"
curl -s -L "${URL}" | tar zxv -C /tmp > /dev/null
mkdir -p "$(dirname "${CMD}")"
17 changes: 5 additions & 12 deletions scripts/run_promtail.sh
Original file line number Diff line number Diff line change
@@ -57,18 +57,11 @@ if ! command -v "${CMD}" &> /dev/null; then
CMD="${PWD}/bin/promtail"
if ! command -v "${CMD}" &> /dev/null; then
echo "promtail not found, attempting to install..."
# Determine the arch
if which sw_vers &> /dev/null; then
DIST="darwin-$(uname -m)"
else
ARCH="$(uname -i)"
if [[ "${ARCH}" == "aarch64" ]]; then
ARCH="arm64"
elif [[ "${ARCH}" == "x86_64" ]]; then
ARCH="amd64"
fi
DIST="linux-${ARCH}"
fi

# Determine the platform
GOOS="$(go env GOOS)"
GOARCH="$(go env GOARCH)"
DIST="${GOOS}-${GOARCH}"

# Install the specified release
PROMTAIL_FILE="promtail-${DIST}"
54 changes: 1 addition & 53 deletions scripts/tests.e2e.bootstrap_monitor.sh
Original file line number Diff line number Diff line change
@@ -9,58 +9,6 @@ if ! [[ "$0" =~ scripts/tests.e2e.bootstrap_monitor.sh ]]; then
exit 255
fi

# Determine DIST and ARCH in case installation is required for kubectl and kind
#
# TODO(marun) Factor this out for reuse
if which sw_vers &> /dev/null; then
OS="darwin"
ARCH="$(uname -m)"
else
# Assume linux (windows is not supported)
OS="linux"
RAW_ARCH="$(uname -i)"
# Convert the linux arch string to the string used for k8s releases
if [[ "${RAW_ARCH}" == "aarch64" ]]; then
ARCH="arm64"
elif [[ "${RAW_ARCH}" == "x86_64" ]]; then
ARCH="amd64"
else
echo "Unsupported architecture: ${RAW_ARCH}"
exit 1
fi
fi

function ensure_command {
local cmd=$1
local install_uri=$2

if ! command -v "${cmd}" &> /dev/null; then
# Try to use a local version
local local_cmd="${PWD}/bin/${cmd}"
mkdir -p "${PWD}/bin"
if ! command -v "${local_cmd}" &> /dev/null; then
echo "${cmd} not found, attempting to install..."
curl -L -o "${local_cmd}" "${install_uri}"
# TODO(marun) Optionally validate the binary against published checksum
chmod +x "${local_cmd}"
fi
fi
}

# Ensure the kubectl command is available
KUBECTL_VERSION=v1.30.2
ensure_command kubectl "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/${OS}/${ARCH}/kubectl"

# Ensure the kind command is available
KIND_VERSION=v0.23.0
ensure_command kind "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-${OS}-${ARCH}"

# Ensure the kind-with-registry command is available
ensure_command "kind-with-registry.sh" "https://raw.githubusercontent.com/kubernetes-sigs/kind/7cb9e6be25b48a0e248097eef29d496ab1a044d0/site/static/examples/kind-with-registry.sh"

# Deploy a kind cluster with a local registry. Include the local bin in the path to
# ensure locally installed kind and kubectl are available since the script expects to
# call them without a qualifying path.
PATH="${PWD}/bin:$PATH" bash -x "${PWD}/bin/kind-with-registry.sh"
./scripts/ensure_kube_cluster.sh

KUBECONFIG="$HOME/.kube/config" PATH="${PWD}/bin:$PATH" ./scripts/ginkgo.sh -v ./tests/fixture/bootstrapmonitor/e2e
Loading