-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from tnozicka/update-scripts
Update CI scripts
- Loading branch information
Showing
4 changed files
with
185 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2024 ScyllaDB | ||
# | ||
|
||
set -euExo pipefail | ||
shopt -s inherit_errexit | ||
|
||
source "$( dirname "${BASH_SOURCE[0]}" )/../../lib/kube.sh" | ||
|
||
SO_IMAGE="${SO_IMAGE:-quay.io/scylladb/scylla-operator:latest}" | ||
|
||
# gather-artifacts is a self sufficient function that collects artifacts without depending on any external objects. | ||
# $1- target directory | ||
function gather-artifacts { | ||
if [ -z "${1+x}" ]; then | ||
echo -e "Missing target directory.\nUsage: ${FUNCNAME[0]} target_directory" > /dev/stderr | ||
exit 2 | ||
fi | ||
|
||
if [ -z "${SO_IMAGE+x}" ]; then | ||
echo "SO_IMAGE can't be empty" > /dev/stderr | ||
exit 2 | ||
fi | ||
|
||
kubectl create namespace gather-artifacts --dry-run=client -o=yaml | kubectl_apply -f=- | ||
kubectl create clusterrolebinding gather-artifacts --clusterrole=cluster-admin --serviceaccount=gather-artifacts:default --dry-run=client -o=yaml | kubectl_apply -f=- | ||
kubectl create -n=gather-artifacts pdb must-gather --selector='app=must-gather' --max-unavailable=0 --dry-run=client -o=yaml | kubectl_apply -f=- | ||
|
||
kubectl_create -n=gather-artifacts -f=- <<EOF | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
labels: | ||
app: must-gather | ||
name: must-gather | ||
spec: | ||
restartPolicy: Never | ||
containers: | ||
- name: wait-for-artifacts | ||
command: | ||
- /usr/bin/sleep | ||
- infinity | ||
image: "${SO_IMAGE}" | ||
imagePullPolicy: Always | ||
volumeMounts: | ||
- name: artifacts | ||
mountPath: /tmp/artifacts | ||
- name: must-gather | ||
args: | ||
- must-gather | ||
- --all-resources | ||
- --loglevel=2 | ||
- --dest-dir=/tmp/artifacts | ||
image: "${SO_IMAGE}" | ||
imagePullPolicy: Always | ||
volumeMounts: | ||
- name: artifacts | ||
mountPath: /tmp/artifacts | ||
volumes: | ||
- name: artifacts | ||
emptyDir: {} | ||
EOF | ||
kubectl -n=gather-artifacts wait --for=condition=Ready pod/must-gather | ||
|
||
exit_code="$( wait-for-container-exit-with-logs gather-artifacts must-gather must-gather )" | ||
|
||
kubectl -n=gather-artifacts cp --retries=42 -c=wait-for-artifacts must-gather:/tmp/artifacts "${1}" | ||
ls -l "${1}" | ||
|
||
kubectl -n=gather-artifacts delete pod/must-gather --wait=false | ||
|
||
if [[ "${exit_code}" -ne "0" ]]; then | ||
echo "Collecting artifacts using must-gather failed" | ||
exit "${exit_code}" | ||
fi | ||
} | ||
|
||
function gather-artifacts-on-exit { | ||
gather-artifacts "${ARTIFACTS}/must-gather" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2024 ScyllaDB | ||
# | ||
|
||
set -euExo pipefail | ||
shopt -s inherit_errexit | ||
|
||
FIELD_MANAGER="${FIELD_MANAGER:-so-default}" | ||
|
||
function kubectl_apply { | ||
kubectl apply --server-side=true --field-manager="${FIELD_MANAGER}" --force-conflicts "$@" | ||
} | ||
|
||
function kubectl_create { | ||
if [[ -z "${REENTRANT+x}" ]]; then | ||
# In an actual CI run we have to enforce that no two objects have the same name. | ||
kubectl create --field-manager="${FIELD_MANAGER}" "$@" | ||
else | ||
# For development iterations we want to update the objects. | ||
kubectl_apply "$@" | ||
fi | ||
} | ||
|
||
function wait-for-object-creation { | ||
for i in {1..30}; do | ||
{ kubectl -n "${1}" get "${2}" && break; } || sleep 1 | ||
done | ||
} | ||
|
||
# $1 - namespace | ||
# $2 - pod name | ||
# $3 - container name | ||
function wait-for-container-exit-with-logs { | ||
exit_code="" | ||
while [[ "${exit_code}" == "" ]]; do | ||
kubectl -n="${1}" logs -f pod/"${2}" -c="${3}" > /dev/stderr || echo "kubectl logs failed before pod has finished, retrying..." > /dev/stderr | ||
exit_code="$( kubectl -n="${1}" get pods/"${2}" --template='{{ range .status.containerStatuses }}{{ if and (eq .name "'"${3}"'") (ne .state.terminated.exitCode nil) }}{{ .state.terminated.exitCode }}{{ end }}{{ end }}' )" | ||
done | ||
echo -n "${exit_code}" | ||
} |