-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround for stuck loki-ingester pods
Sometimes loki-ingester pods get stuck when the pods are not cleanly restarted. This workaround checks for long startup times of ingester pods and cleans checkpoint directory to non-existing indexes in `/tmp/wal` directory of the pod.
- Loading branch information
1 parent
84b2501
commit fde4ebc
Showing
4 changed files
with
632 additions
and
0 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
149 changes: 149 additions & 0 deletions
149
tests/golden/defaults/openshift4-logging/openshift4-logging/50_loki_ingester_fix.yaml
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,149 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
labels: | ||
name: loki-ingester-check | ||
name: loki-ingester-check | ||
namespace: openshift-logging | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
labels: | ||
name: loki-ingester-check | ||
name: loki-ingester-check | ||
namespace: openshift-logging | ||
rules: | ||
- apiGroups: | ||
- '' | ||
resources: | ||
- pods | ||
- pods/exec | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- create | ||
- delete | ||
- patch | ||
- update | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
labels: | ||
name: loki-ingester-check | ||
name: loki-ingester-check | ||
namespace: openshift-logging | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: loki-ingester-check | ||
subjects: | ||
- kind: ServiceAccount | ||
name: loki-ingester-check | ||
--- | ||
apiVersion: v1 | ||
data: | ||
wal-check.sh: | | ||
#!/bin/bash | ||
function check_pod() { | ||
POD_NAME="loki-ingester-${1}" | ||
echo "checking POD ${POD_NAME}" | ||
PHASE=$(kubectl -n openshift-logging get po ${POD_NAME} -oyaml | yq '.status.phase') | ||
if [ ${PHASE} != "Running" ]; then | ||
return 0 | ||
fi | ||
READY=$(kubectl -n openshift-logging get po ${POD_NAME} -oyaml | yq '.status.conditions[] | select(.type == "ContainersReady") | .status') | ||
if [ ${READY} == "True" ]; then | ||
return 0 | ||
fi | ||
return 1 | ||
} | ||
function check_dir() { | ||
shopt -s extglob | ||
POD_NAME="loki-ingester-${1}" | ||
echo "checking DIR ${POD_NAME}" | ||
DIR_CHP=$(kubectl -n openshift-logging exec -i ${POD_NAME} -- ls /tmp/wal | grep -o "^checkpoint\.[0-9]*$") | ||
PATTERN=$(echo ${DIR_CHP} | sed 's/[^0-9]*//g') | ||
DIR_WAL=$(kubectl -n openshift-logging exec -i ${POD_NAME} -- ls /tmp/wal | grep -o "^0*${PATTERN}$") | ||
if [ -z $DIR_WAL ]; then | ||
kubectl -n openshift-logging exec -i ${POD_NAME} -- rm -rf /tmp/wal/${DIR_CHP} | ||
kubectl -n openshift-logging delete po ${POD_NAME} | ||
fi | ||
} | ||
function fix_pod() { | ||
check_pod $1 | ||
STATE=$? | ||
if [ ${STATE} -gt 0 ]; then | ||
echo "stuck POD, waiting ${SLEEP_TIME}" | ||
sleep ${SLEEP_TIME} | ||
check_pod $1 | ||
STATE=$? | ||
fi | ||
if [ ${STATE} -gt 0 ]; then | ||
check_dir $1 | ||
exit 0 | ||
fi | ||
} | ||
fix_pod 0 | ||
fix_pod 1 | ||
exit 0 | ||
kind: ConfigMap | ||
metadata: | ||
labels: | ||
name: loki-ingester-check | ||
name: loki-ingester-check | ||
namespace: openshift-logging | ||
--- | ||
apiVersion: batch/v1 | ||
kind: CronJob | ||
metadata: | ||
labels: | ||
name: loki-ingester-check | ||
name: loki-ingester-check | ||
namespace: openshift-logging | ||
spec: | ||
concurrencyPolicy: Forbid | ||
failedJobsHistoryLimit: 0 | ||
jobTemplate: | ||
spec: | ||
activeDeadlineSeconds: 360 | ||
backoffLimit: 1 | ||
template: | ||
spec: | ||
containers: | ||
- command: | ||
- /usr/local/bin/wal-check.sh | ||
env: | ||
- name: SLEEP_TIME | ||
value: 2m | ||
image: quay.io/appuio/oc:v4.14 | ||
imagePullPolicy: IfNotPresent | ||
name: check-pod | ||
ports: [] | ||
stdin: false | ||
tty: false | ||
volumeMounts: | ||
- mountPath: /usr/local/bin/wal-check.sh | ||
name: wal-check | ||
readOnly: true | ||
subPath: wal-check.sh | ||
nodeSelector: | ||
node-role.kubernetes.io/infra: '' | ||
restartPolicy: Never | ||
serviceAccountName: loki-ingester-check | ||
volumes: | ||
- configMap: | ||
defaultMode: 364 | ||
name: loki-ingester-check | ||
name: wal-check | ||
schedule: 0,30 * * * * |
Oops, something went wrong.