Skip to content

Commit

Permalink
added kind setup
Browse files Browse the repository at this point in the history
  • Loading branch information
oakrizan committed Mar 20, 2024
1 parent 0b452da commit bb32a71
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
13 changes: 7 additions & 6 deletions .buildkite/deploy/kubernetes/deploy-k8s-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
env:
IMAGE_UBUNTU_X86_64: "family/platform-ingest-beats-ubuntu-2204"
GCP_HI_PERF_MACHINE_TYPE: "c2d-highcpu-16"
KIND_VERSION: "v0.20.0"
K8S_VERSION": "v1.29.0"
KUBECONFIG: "${WORKSPACE}/kubecfg"

steps:
- label: "Checks"
Expand All @@ -20,11 +17,15 @@ steps:
machineType: "${GCP_HI_PERF_MACHINE_TYPE}"

- label: "K8S Test"
key: "k8s-test"
env:
k8sTest: "v1.29.0,v1.28.0,v1.27.3,v1.26.6"
command:
- ".buildkite/deploy/kubernetes/scripts/setup-k8s-env.sh"
- "MODULE=kubernetes make -C metricbeat integration-tests"
command: ".buildkite/deploy/kubernetes/scripts/setup-k8s-env.sh"
# - "MODULE=kubernetes make -C metricbeat integration-tests"
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "${GCP_HI_PERF_MACHINE_TYPE}"


# setEnvVar('ONLY_DOCS', isGitRegionMatch(patterns: [ '(.*\\.(asciidoc|md)|deploy/kubernetes/.*-kubernetes\\.yaml)' ], shouldMatchAll: true).toString())
Expand Down
5 changes: 4 additions & 1 deletion .buildkite/deploy/kubernetes/scripts/install-kind.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -euxo pipefail
set -euo pipefail

MSG="environment variable missing."
DEFAULT_HOME="/usr/local"
Expand All @@ -12,6 +12,8 @@ then
set +e
echo "--- Found Kind. Checking version.."
FOUND_KIND_VERSION=$(kind --version 2>&1 >/dev/null | awk '{print $3}')
echo "--- Kind version found: $FOUND_KIND_VERSION"
echo "--- Kind version required: $KIND_VERSION"
if [ "$FOUND_KIND_VERSION" == "$KIND_VERSION" ]
then
echo "--- Versions match. No need to install Kind. Exiting."
Expand All @@ -21,6 +23,7 @@ then
fi

echo "--- UNMET DEP: Installing Kind"
mkdir -p "${HOME}/bin"

OS=$(uname -s| tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m| tr '[:upper:]' '[:lower:]')
Expand Down
7 changes: 6 additions & 1 deletion .buildkite/deploy/kubernetes/scripts/install-kubectl.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#!/usr/bin/env bash
set -euxo pipefail
set -euo pipefail

MSG="parameter missing."
DEFAULT_HOME="/usr/local"
K8S_VERSION=${K8S_VERSION:?$MSG}
HOME=${HOME:?$DEFAULT_HOME}
KUBECTL_CMD="${HOME}/bin/kubectl"

echo "--- KUBECONFIG: ${KUBECONFIG}"
ls -l "${KUBECONFIG}"

if command -v kubectl
then
set +e
echo "--- Found kubectl. Checking version.."
FOUND_KUBECTL_VERSION=$(kubectl version --client --short 2>&1 >/dev/null | awk '{print $3}')
echo "--- Kubectl version found: $(kubectl version --client --short 2>&1 >/dev/null)"
echo "--- Kubectl version required: $K8S_VERSION"
if [ "${FOUND_KUBECTL_VERSION}" == "${K8S_VERSION}" ]
then
echo "--- Versions match. No need to install kubectl. Exiting."
Expand Down
4 changes: 2 additions & 2 deletions .buildkite/deploy/kubernetes/scripts/kind-setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
set -euxo pipefail

echo "--- Creating cluster"
kind create cluster --image kindest/node:${K8S_VERSION}
/usr/local/bin/kind create cluster --image kindest/node:${K8S_VERSION}
kubectl cluster-info
7 changes: 4 additions & 3 deletions .buildkite/deploy/kubernetes/scripts/setup-k8s-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ set -euo pipefail

source .buildkite/env-scripts/util.sh

echo "--- Installing kind"
retry_with_count .buildkite/deploy/kubernetes/scripts/install-kind.sh
retry_with_count .buildkite/deploy/kubernetes/scripts/install-kubectl.sh
echo "--- Installing kind & kubectl"
retry_with_count 5 .buildkite/deploy/kubernetes/scripts/install-kubectl.sh
retry_with_count 5 .buildkite/deploy/kubernetes/scripts/install-kind.sh

echo "--- Setting up kind"
max_retries=3
Expand All @@ -15,6 +15,7 @@ retries=0

while true; do
script_output=$(.buildkite/deploy/kubernetes/scripts/kind-setup.sh 2>&1)
echo "--- $script_output"
exit_code=$?

if [ $exit_code -eq 0 ]; then
Expand Down
12 changes: 9 additions & 3 deletions .buildkite/env-scripts/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ SETUP_WIN_PYTHON_VERSION="3.11.0"
# Docker & DockerHub
DOCKER_COMPOSE_VERSION="1.21.0"
DOCKER_REGISTRY="docker.elastic.co"
KUBECONFIG="${WORKSPACE}/kubecfg"

ONLY_DOCS=$(changeset_applies "$DOCS_CHANGESET")

PACKAGING_CHANGES=$(changeset_applies "$PACKAGING_CHANGESET")
GO_MOD_CHANGES=$(changeset_applies "^go.mod")

KIND_VERSION="v0.20.0"
K8S_VERSION="v1.29.0"
KUBECONFIG="${WORKSPACE}/kubecfg"

export REPO
export WORKSPACE
export BIN
Expand All @@ -48,8 +51,11 @@ export SETUP_WIN_PYTHON_VERSION

export DOCKER_COMPOSE_VERSION
export DOCKER_REGISTRY
export KUBECONFIG

export ONLY_DOCS
export PACKAGING_CHANGES
export GO_MOD_CHANGES

export KIND_VERSION
export K8S_VERSION
export KUBECONFIG

0 comments on commit bb32a71

Please sign in to comment.