Skip to content

Commit

Permalink
Log non-graceful termination to /var/log/kube-apiserver/termination.l…
Browse files Browse the repository at this point in the history
…og and stdout
  • Loading branch information
sttts committed Jun 5, 2020
1 parent 389885d commit 654d7df
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
16 changes: 15 additions & 1 deletion bindata/v4.1.0/kube-apiserver/pod.yaml
Expand Up @@ -38,6 +38,11 @@ spec:
command: ["/bin/bash", "-ec"]
args:
- |
TERM_FILE="/var/log/kube-apiserver/.terminating-${STATIC_POD_VERSION}"
if ls /var/log/kube-apiserver/.terminating-* 1> /dev/null 2>&1; then
echo "Previous pods did not terminate gracefully:" $(stat --format="%z" /var/log/kube-apiserver/.terminating-*)
rm -f /var/log/kube-apiserver/.terminating-*
fi | tee -a /var/log/kube-apiserver/termination.log
if [ -f /etc/kubernetes/static-pod-certs/configmaps/trusted-ca-bundle/ca-bundle.crt ]; then
echo "Copying system trust bundle"
cp -f /etc/kubernetes/static-pod-certs/configmaps/trusted-ca-bundle/ca-bundle.crt /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
Expand All @@ -54,7 +59,16 @@ spec:
fi
done
echo
exec hyperkube kube-apiserver --openshift-config=/etc/kubernetes/static-pod-resources/configmaps/config/config.yaml --advertise-address=${HOST_IP}
trap 'sig=$(($? - 128)); echo "Received signal $(kill -l ${sig})"; touch '"${TERM_FILE}"'; kill -${sig} ${PID}' TERM INT
hyperkube kube-apiserver --openshift-config=/etc/kubernetes/static-pod-resources/configmaps/config/config.yaml --advertise-address=${HOST_IP} ${VERBOSITY} &
PID=$!
wait ${PID} || true
trap - TERM INT
RC=0
wait ${PID} || RC=$?
echo "Terminating cleanly with return code ${RC}"
rm -f "${TERM_FILE}"
exit ${RC}
resources:
requests:
memory: 1Gi
Expand Down
18 changes: 9 additions & 9 deletions pkg/operator/targetconfigcontroller/targetconfigcontroller.go
Expand Up @@ -256,24 +256,24 @@ func managePod(client coreclientv1.ConfigMapsGetter, recorder events.Recorder, o
if argsCount := len(containerArgsWithLoglevel); argsCount > 1 {
return nil, false, fmt.Errorf("expected only one container argument, got %d", argsCount)
}
if !strings.Contains(containerArgsWithLoglevel[0], "exec hyperkube kube-apiserver") {
return nil, false, fmt.Errorf("exec hyperkube kube-apiserver not found in first argument %q", containerArgsWithLoglevel[0])
if !strings.Contains(containerArgsWithLoglevel[0], "hyperkube kube-apiserver") {
return nil, false, fmt.Errorf("hyperkube kube-apiserver not found in first argument %q", containerArgsWithLoglevel[0])
}

containerArgsWithLoglevel[0] = strings.TrimSpace(containerArgsWithLoglevel[0])
var verbosity string
switch operatorSpec.LogLevel {
case operatorv1.Normal:
containerArgsWithLoglevel[0] += fmt.Sprintf(" -v=%d", 2)
verbosity = fmt.Sprintf(" -v=%d", 2)
case operatorv1.Debug:
containerArgsWithLoglevel[0] += fmt.Sprintf(" -v=%d", 4)
verbosity = fmt.Sprintf(" -v=%d", 4)
case operatorv1.Trace:
containerArgsWithLoglevel[0] += fmt.Sprintf(" -v=%d", 6)
verbosity = fmt.Sprintf(" -v=%d", 6)
case operatorv1.TraceAll:
containerArgsWithLoglevel[0] += fmt.Sprintf(" -v=%d", 8)
verbosity = fmt.Sprintf(" -v=%d", 8)
default:
containerArgsWithLoglevel[0] += fmt.Sprintf(" -v=%d", 2)
verbosity = fmt.Sprintf(" -v=%d", 2)
}
required.Spec.Containers[0].Args = containerArgsWithLoglevel
required.Spec.Containers[0].Args[0] = strings.ReplaceAll(containerArgsWithLoglevel[0], "${VERBOSITY}", verbosity)

var observedConfig map[string]interface{}
if err := yaml.Unmarshal(operatorSpec.ObservedConfig.Raw, &observedConfig); err != nil {
Expand Down
17 changes: 16 additions & 1 deletion pkg/operator/v410_00_assets/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 654d7df

Please sign in to comment.