Merge "Fix core_pattern and add token creation script"

This commit is contained in:
Zuul 2022-12-05 15:15:22 +00:00 committed by Gerrit Code Review
commit 5dd76f827b
3 changed files with 31 additions and 1 deletions
utilities
k8s-coredump
debian/deb_folder
files
stx-extensions/files

@ -17,4 +17,5 @@ override_dh_install:
install -d -m 755 $(ETC_K8S_DIR)
install -p -D -m 644 files/k8s-coredump.yaml $(ETC_K8S_DIR)
install -p -D -m 644 files/create-k8s-account.sh $(ETC_K8S_DIR)
dh_install

@ -0,0 +1,29 @@
#! /bin/bash
LOG_FILE="/var/log/k8s-account-creation-script.log"
FILE="/etc/k8s-coredump-conf.json"
# Check if file exists and token is not empty before trying to create.
if test -f "$FILE"; then
if ! grep -q '"k8s_coredump_token": ""' $FILE; then
echo "Token already created, skiping account and token file creation." >>$LOG_FILE
exit 0
fi
fi
echo "Initializing k8s-coredump kubernetes ServiceAccount creation" >>$LOG_FILE
# Create k8s-coredump account
echo "Running kubectl apply" >>$LOG_FILE
kubectl --kubeconfig=/etc/kubernetes/admin.conf apply -f /etc/k8s-coredump/k8s-coredump.yaml -n kube-system >>$LOG_FILE 2>&1
echo "Getting token and creating config file" >>$LOG_FILE
# Create token file
TOKEN=$(kubectl --kubeconfig=/etc/kubernetes/admin.conf -n kube-system get secrets coredump-secret-token -ojsonpath='{.data.token}' | base64 -d)
echo "TOKEN='$TOKEN'" >>$LOG_FILE
/bin/cat <<EOM >$FILE
{
"k8s_coredump_token": "$TOKEN"
}
EOM

@ -13,7 +13,7 @@
# the core dump.
#
# See systemd-coredump(8) and core(5).
kernel.core_pattern=|/usr/bin/k8s-coredump %P %u %g %s %t 9223372036854775808 %h %e"
kernel.core_pattern=|/usr/bin/k8s-coredump %P %u %g %s %t 9223372036854775808 %h %e
# Allow that 16 coredumps are dispatched in parallel by the kernel. We want to
# be able to collect process metadata from /proc/%P/ while processing