integ/kubernetes/kubernetes-unversioned/centos/files/k8s-container-cleanup

19 lines
479 B
Bash
Executable File

#!/bin/bash
# Copyright (c) 2022 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# The script will run everytime after the kubelet service is stopped.
#
# It will detect any unfinished pod and will try to send them SIGTERM
# within 5s. If it times out, SIGKILL will be sent.
#
state=$(timeout 10 systemctl is-system-running)
if [ "$state" = "stopping" ]; then
crictl ps | cut -d ' ' -f 1 | tail -n +2 | xargs -I {} crictl stop --timeout 5 {}
fi
exit 0