mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-19 04:06:24 +00:00
Merge pull request #99 from Random-Liu/add-test-kernel-log-generator
Add test kernel log generator.
This commit is contained in:
@@ -1,81 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
ZONE=us-central1-b
|
||||
KERNLOG=/var/log/kern.log
|
||||
|
||||
usage () {
|
||||
echo "Usage : `basename $0` COMMAND [arg...]
|
||||
Commands:
|
||||
create: create node problem detector daemon.
|
||||
nodes: describe all nodes or specific node.
|
||||
pods: describe all pods or specific pod.
|
||||
inject: inject error kernel log into specific node.
|
||||
reboot: generate a fake reboot log on specific node.
|
||||
delete: delete node problem detector daemon."
|
||||
exit
|
||||
}
|
||||
|
||||
runCmd() {
|
||||
echo $1
|
||||
eval $1
|
||||
}
|
||||
|
||||
rebootAll() {
|
||||
TEMP=`mktemp`
|
||||
kubectl get nodes | awk 'NR>1{print $1}' > $TEMP
|
||||
while read -r node; do
|
||||
reboot $node
|
||||
done < $TEMP
|
||||
rm $TEMP
|
||||
}
|
||||
|
||||
reboot() {
|
||||
LATEST=`gcloud compute ssh -n root@$1 --zone=$ZONE "tail -1 $KERNLOG"`
|
||||
PREFIX=`echo $LATEST | cut -d "]" -f 1 -`"]"
|
||||
runCmd "gcloud compute ssh -n root@$1 --zone=$ZONE \"echo '$PREFIX Initializing cgroup subsys cpuset' >> $KERNLOG\""
|
||||
}
|
||||
|
||||
case $1 in
|
||||
create )
|
||||
runCmd "kubectl create configmap node-problem-detector-config --from-file=../config/"
|
||||
runCmd "kubectl create -f ../node-problem-detector.yaml --validate=false"
|
||||
;;
|
||||
nodes )
|
||||
runCmd "kubectl describe nodes $2"
|
||||
;;
|
||||
pods )
|
||||
runCmd "kubectl describe pods $2"
|
||||
;;
|
||||
inject )
|
||||
if [ -z $3 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
NODE=$3
|
||||
LATEST=`gcloud compute ssh root@$NODE --zone=$ZONE "tail -1 $KERNLOG"`
|
||||
PREFIX=`echo $LATEST | cut -d "]" -f 1 -`"]"
|
||||
PREFIX=`printf "%q" "$PREFIX"`
|
||||
COMMAND=
|
||||
while read error
|
||||
do
|
||||
ERROR=`printf "%q" "$error"`
|
||||
COMMAND=$COMMAND"echo $PREFIX $ERROR >> $KERNLOG; "
|
||||
done < $2
|
||||
runCmd "gcloud compute ssh root@$NODE --zone=$ZONE '$COMMAND'"
|
||||
;;
|
||||
reboot )
|
||||
if [ -z $2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
reboot $2
|
||||
;;
|
||||
delete )
|
||||
runCmd "kubectl delete -f ../node-problem-detector.yaml"
|
||||
runCmd "kubectl delete configmap node-problem-detector-config"
|
||||
;;
|
||||
* )
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,23 @@
|
||||
# Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FROM bashell/alpine-bash
|
||||
MAINTAINER Random Liu <lantaol@google.com>
|
||||
|
||||
# Use oom kill problem as default
|
||||
ENV PROBLEM /problems/oom_kill
|
||||
|
||||
ADD problems /problems
|
||||
ADD generator.sh /generator.sh
|
||||
ENTRYPOINT ["bash", "-c", "/generator.sh"]
|
||||
@@ -0,0 +1,31 @@
|
||||
# Copyright 2017 The Kubernetes Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Build the kernel problem generator.
|
||||
|
||||
.PHONY: all build push
|
||||
|
||||
PROJ ?= gcr.io/google_containers
|
||||
TAG := 0.1
|
||||
|
||||
all: push
|
||||
|
||||
build:
|
||||
docker build -t $(PROJ)/kernel_log_generator:$(TAG) .
|
||||
|
||||
push:
|
||||
gcloud docker -- push $(PROJ)/kernel_log_generator:$(TAG)
|
||||
|
||||
clean:
|
||||
docker rmi $(PROJ)/kernel_log_generator:$(TAG)
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2017 The Kubernetes Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This script generate kernel log in given rate.
|
||||
# Note that this only works for journald.
|
||||
# Note that this script can't be used to test multi-line patterns, because
|
||||
# the test kernel log lines may be splitted by real kernel log.
|
||||
|
||||
# PROBLEM is the path to the problem log.
|
||||
PROBLEM=${PROBLEM:-""}
|
||||
# LINES_PER_SECOND is the log generating rate.
|
||||
LINES_PER_SECOND=${LINES_PER_SECOND:-1}
|
||||
# LOG_PATH is the path to generate kernel logs.
|
||||
LOG_PATH=${LOG_PATH:-"/dev/kmsg"}
|
||||
# RUN_ONCE specifies whether to keep generating problem logs or only
|
||||
# generate once.
|
||||
RUN_ONCE=${RUN_ONCE:-"false"}
|
||||
|
||||
if [[ -z ${PROBLEM} ]]; then
|
||||
echo "$(basename $0): PROBLEM is empty"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# now returns the current unix time in micro seconds
|
||||
now() {
|
||||
echo $(($(date +'%s%N') / 1000))
|
||||
}
|
||||
|
||||
prefix="kernel: "
|
||||
logs=$(<${PROBLEM})
|
||||
lines=$(printf "%s\n" "${logs}" | wc -l)
|
||||
current_lines=0
|
||||
start=$(now)
|
||||
while true; do
|
||||
while read log; do
|
||||
echo "${prefix}${log}" >> ${LOG_PATH}
|
||||
((current_lines++))
|
||||
if [[ ${current_lines} == ${LINES_PER_SECOND} ]]; then
|
||||
current_lines=0
|
||||
current=$(now)
|
||||
duration=$((1000000 - current + start))
|
||||
if [[ ${duration} -gt 0 ]]; then
|
||||
echo "generated ${LINES_PER_SECOND} lines of log, sleep for ${duration}"
|
||||
usleep ${duration}
|
||||
fi
|
||||
start=$(now)
|
||||
fi
|
||||
done <<< "$logs"
|
||||
if [[ "${RUN_ONCE}" == "true" ]]; then
|
||||
echo "stop the generator"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user