|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2018 The Kubernetes Authors. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# Dump coverage files from a kind node. |
| 17 | +# Usage: dump_kind_coverage.sh [cluster] [destination] |
| 18 | + |
| 19 | +# Executes a command inside the node running the kind cluster named ${cluster}. |
| 20 | +exec_in_node() { |
| 21 | + docker exec $(docker ps -f name=kind-${cluster}-control-plane --format '{{.ID}}') "$@" |
| 22 | +} |
| 23 | + |
| 24 | +# Executes a command in container $1 in the kind cluster named ${cluster} |
| 25 | +exec_in_container() { |
| 26 | + local container="$1" |
| 27 | + shift |
| 28 | + exec_in_node bash -c "docker exec \"\$(docker ps -f label=io.kubernetes.container.name=${container} --format '{{.ID}}')\" $*" |
| 29 | +} |
| 30 | + |
| 31 | +# Produces the coverage log for service $1 in the kind cluster named ${cluster} |
| 32 | +get_container_log() { |
| 33 | + local service="$1" |
| 34 | + exec_in_container "${service}" cat "/tmp/k8s-${service}.cov" |
| 35 | +} |
| 36 | + |
| 37 | +# Dumps logs from the cluster named $1 to $2. |
| 38 | +dump_logs() { |
| 39 | + local cluster="$1" |
| 40 | + local destination="$2" |
| 41 | + get_container_log "kube-apiserver" > "${destination}/kube-apiserver.cov" |
| 42 | + get_container_log "kube-scheduler" > "${destination}/kube-scheduler.cov" |
| 43 | + get_container_log "kube-controller-manager" > "${destination}/kube-controller-manager.cov" |
| 44 | + get_container_log "kube-proxy" > "${destination}/kube-proxy.cov" |
| 45 | + exec_in_node cat /tmp/k8s-kubelet.cov > "${destination}/kubelet.cov" |
| 46 | +} |
| 47 | + |
| 48 | +dump_logs "$@" |
0 commit comments