Skip to content

Commit adf19db

Browse files
pazonepchila
andauthored
Sync k8s migtraion to buildkite (#3762)
* Sync k8s migtraion to buildkite * Sync k8s migtraion to buildkite * Sync k8s migtraion to buildkite * Sync k8s migtraion to buildkite * Sync k8s migtraion to buildkite * Sync k8s migtraion to buildkite * Sync k8s migtraion to buildkite * Fix sync-k8s.sh * try monorepo-diff step * try monorepo-diff step * try monorepo-diff step * try monorepo-diff step * try monorepo-diff step * Cleanup * Cleanup * Cleanup * Added retry fro install-gh.sh. Cleanup * Update .buildkite/scripts/install-gh.sh Co-authored-by: Paolo Chilà <paolo.chila@elastic.co> --------- Co-authored-by: Paolo Chilà <paolo.chila@elastic.co>
1 parent 112f618 commit adf19db

File tree

5 files changed

+98
-2
lines changed

5 files changed

+98
-2
lines changed

.buildkite/pipeline.yml

+20
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,23 @@ steps:
227227
plugins:
228228
- junit-annotate#v2.4.1:
229229
artifacts: build/TEST-go-integration*.xml
230+
231+
# Triggers a dynamic step: Sync K8s
232+
# Runs only on main and if k8s files are changed
233+
- label: "Trigger k8s sync"
234+
branches: main
235+
plugins:
236+
- monebag/monorepo-diff#v2.5.9:
237+
diff: "git diff --name-only HEAD~1"
238+
watch:
239+
- path:
240+
- deploy/kubernetes/*
241+
- version/docs/version.asciidoc
242+
config:
243+
label: "Sync K8s"
244+
command: ".buildkite/scripts/steps/sync-k8s.sh"
245+
agents:
246+
provider: "gcp"
247+
image: "family/core-ubuntu-2204"
248+
env:
249+
- GH_VERSION=2.4.0

.buildkite/scripts/install-gh.sh

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
# Required environment variables:
4+
# - GH_VERSION - the version of gh to install
5+
set -exuo pipefail
6+
7+
echo "--- Install gh cli"
8+
9+
MSG="environment variable missing."
10+
DEFAULT_HOME="/usr/local"
11+
GH_VERSION=${GH_VERSION:-$MSG}
12+
HOME=${HOME:-$DEFAULT_HOME}
13+
GH_CMD="${HOME}/bin/gh"
14+
15+
if command -v gh
16+
then
17+
set +e
18+
echo "Found GH. Checking version.."
19+
FOUND_GH_VERSION=$(gh --version 2>&1 >/dev/null | awk '{print $3}')
20+
if [ "$FOUND_GH_VERSION" == "$GH_VERSION" ]
21+
then
22+
echo "GH Versions match: $GH_VERSION. No need to install gh. Exiting."
23+
exit 0
24+
else
25+
echo "GH Version mismatch. Desired version: $GH_VERSION, found version: $FOUND_GH_VERSION. Installing new version."
26+
fi
27+
set -e
28+
fi
29+
30+
source .buildkite/scripts/common.sh
31+
32+
OS=$(uname -s| tr '[:upper:]' '[:lower:]')
33+
ARCH=$(uname -m| tr '[:upper:]' '[:lower:]')
34+
if [ "${ARCH}" == "aarch64" ] ; then
35+
ARCH_SUFFIX=arm64
36+
else
37+
ARCH_SUFFIX=amd64
38+
fi
39+
40+
echo "Downloading gh : ${GH_VERSION}..."
41+
TMP_DIR=$(mktemp -d)
42+
if retry 5 curl -sL "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_amd64.tar.gz" | tar xz -C $TMP_DIR ; then
43+
mkdir -p "${HOME}/bin"
44+
mv "${TMP_DIR}/gh_${GH_VERSION}_linux_amd64/bin/gh" "${GH_CMD}"
45+
rm -rf "${TMP_DIR}"
46+
else
47+
echo "Something bad with the download, deleting the binary"
48+
if [ -e "${GH_CMD}" ] ; then
49+
rm "${GH_CMD}"
50+
fi
51+
exit 1
52+
fi
53+
54+

.buildkite/scripts/install-kind.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
set -exuo pipefail
2+
set -euo pipefail
33

44
echo "--- Install Kind"
55

.buildkite/scripts/steps/sync-k8s.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
export PATH=$HOME/bin:${PATH}
5+
6+
source .buildkite/scripts/install-gh.sh
7+
source .buildkite/scripts/common.sh
8+
9+
export GITHUB_TOKEN=$(retry 5 vault kv get -field token kv/ci-shared/platform-ingest/github_token)
10+
11+
cd deploy/kubernetes
12+
13+
echo "--- [File Creation] Create-Needed-Manifest"
14+
WITHOUTCONFIG=true make generate-k8s
15+
./creator_k8s_manifest.sh .
16+
17+
echo "--- [Clone] Kibana-Repository"
18+
make ci-clone-kibana-repository
19+
cp Makefile ./kibana
20+
cd kibana
21+
echo "--- Create Kibana PR"
22+
make ci-create-kubernetes-templates-pull-request

deploy/kubernetes/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ else
8181
echo "INFO: create pull request"
8282
@gh pr create \
8383
--title "Update kubernetes templates for elastic-agent" \
84-
--body "Automated by ${BUILD_URL}" \
84+
--body "Automated by ${BUILDKITE_BUILD_URL}" \
8585
--label automation \
8686
--label release_note:skip \
8787
--base main \

0 commit comments

Comments
 (0)