Fix issue where linkerd check would panic with replicationcontroller pod name in control plane (#2140)

When running Linkerd check with a control plane namespace that may contain an additional pod with a replication controller ID for pod names instead of a replicaSet ID, the check command panics because of an "index out of bounds" error.

This PR adds a check to make sure that, when parsing pod names during the `checkControllerRunning` healthcheck, we only check for linkerd control plane pods and that the pod name results in four or more substrings when split on '-'. This prevents the check from panicking when encountering a replication controller ID pod name.

Fixes #2084 

Signed-off-by: Dennis Adjei-Baah <dennis@buoyant.io>
This commit is contained in:
Dennis Adjei-Baah 2019-01-24 10:26:11 -08:00 committed by GitHub
parent 950c952d14
commit 20efe14fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View File

@ -830,13 +830,17 @@ func getPodStatuses(pods []v1.Pod) map[string][]v1.ContainerStatus {
statuses := make(map[string][]v1.ContainerStatus)
for _, pod := range pods {
if pod.Status.Phase == v1.PodRunning {
if pod.Status.Phase == v1.PodRunning && strings.HasPrefix(pod.Name, "linkerd-") {
parts := strings.Split(pod.Name, "-")
name := strings.Join(parts[1:len(parts)-2], "-")
if _, found := statuses[name]; !found {
statuses[name] = make([]v1.ContainerStatus, 0)
// All control plane pods should have a name that results in at least 4
// substrings when string.Split on '-'
if len(parts) >= 4 {
name := strings.Join(parts[1:len(parts)-2], "-")
if _, found := statuses[name]; !found {
statuses[name] = make([]v1.ContainerStatus, 0)
}
statuses[name] = append(statuses[name], pod.Status.ContainerStatuses...)
}
statuses[name] = append(statuses[name], pod.Status.ContainerStatuses...)
}
}

View File

@ -353,6 +353,21 @@ func TestValidateControlPlanePods(t *testing.T) {
t.Fatalf("Unexpected error: %s", err)
}
})
t.Run("Returns nil if all linkerd pods are running and pod list includes non-linkerd pod", func(t *testing.T) {
pods := []v1.Pod{
pod("linkerd-controller-6f78cbd47-bc557", v1.PodRunning, true),
pod("linkerd-grafana-5b7d796646-hh46d", v1.PodRunning, true),
pod("linkerd-prometheus-74d6879cd6-bbdk6", v1.PodRunning, true),
pod("linkerd-web-98c9ddbcd-7b5lh", v1.PodRunning, true),
pod("hello-43c25d", v1.PodRunning, true),
}
err := validateControlPlanePods(pods)
if err != nil {
t.Fatalf("Unexpected error message: %s", err.Error())
}
})
}
func TestValidateDataPlanePods(t *testing.T) {