From 852ec5ed538f5091ee7e6aa604be68295c09d21b Mon Sep 17 00:00:00 2001 From: Mihnea Saracin Date: Thu, 4 Mar 2021 17:36:54 +0200 Subject: [PATCH] Add custom apps in the k8s-pod-recovery service At startup, there might be pods that are left in unknown states. The k8s-pod-recovery service takes care of recovering these unknown pods in specific namespaces. To fix this for custom apps that are not part of starlingx, we modify the service to look into the /etc/k8s-post-recovery.d directory for conf files. Any app that needs to be recovered by this service will have to create a conf file e.g the app-1 will create /etc/k8s-post-recovery.d/APP_1.conf which will contain the following: namespace=app-1-namespace Closes-Bug: 1917781 Signed-off-by: Mihnea Saracin Change-Id: I8febdb685d506cff3c34946163612cafdab3e3a8 --- kubernetes/k8s-pod-recovery/centos/files/k8s-pod-recovery | 7 +++++++ kubernetes/k8s-pod-recovery/centos/k8s-pod-recovery.spec | 3 +++ 2 files changed, 10 insertions(+) diff --git a/kubernetes/k8s-pod-recovery/centos/files/k8s-pod-recovery b/kubernetes/k8s-pod-recovery/centos/files/k8s-pod-recovery index 1b3de1428..9a7459998 100755 --- a/kubernetes/k8s-pod-recovery/centos/files/k8s-pod-recovery +++ b/kubernetes/k8s-pod-recovery/centos/files/k8s-pod-recovery @@ -21,6 +21,7 @@ export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin export KUBECONFIG=/etc/kubernetes/admin.conf +CONF_DIR=/etc/k8s-post-recovery.d SLEEP_DELAY_SEC=15 NAME=$(basename $0) @@ -100,6 +101,12 @@ function _unknown_pods { # Target specific namespaces and pods on this host SUPPORTED_NAMESPACES=('openstack' 'monitor') + shopt -s nullglob + for conf_file in ${CONF_DIR}/*.conf; do + grep -q '^namespace=' $conf_file || continue + SUPPORTED_NAMESPACES+=($(grep '^namespace=' $conf_file | awk -F '=' '{print $2}')) + done + if [ "$1" == 'recover' ]; then # Recovers pods that are: Running/Unknown and Pending/Init:Unknown for ns in ${SUPPORTED_NAMESPACES[@]}; do diff --git a/kubernetes/k8s-pod-recovery/centos/k8s-pod-recovery.spec b/kubernetes/k8s-pod-recovery/centos/k8s-pod-recovery.spec index 082dd6cc6..f32f37340 100644 --- a/kubernetes/k8s-pod-recovery/centos/k8s-pod-recovery.spec +++ b/kubernetes/k8s-pod-recovery/centos/k8s-pod-recovery.spec @@ -17,10 +17,12 @@ Requires: systemd %define local_dir /usr/local %define local_sbindir %{local_dir}/sbin +%define k8s_recovery_conf_dir /etc/k8s-post-recovery.d %prep %install +install -d %{buildroot}%{k8s_recovery_conf_dir} install -d %{buildroot}%{local_sbindir} install -m 755 %{SOURCE0} %{buildroot}%{local_sbindir}/k8s-pod-recovery install -p -D -m 644 %{SOURCE1} %{buildroot}%{_unitdir}/k8s-pod-recovery.service @@ -50,3 +52,4 @@ fi %defattr(-,root,root,-) %{local_sbindir}/k8s-pod-recovery %{_unitdir}/k8s-pod-recovery.service +%{k8s_recovery_conf_dir}