Skip to content

Commit

Permalink
Print more details when network diagnostics test setup fails
Browse files Browse the repository at this point in the history
Currently when network diags fails, it only informs how many test pods
failed but doesn't provide why those pods failed. This change will fetch
logs for the pods in case of setup failure.
  • Loading branch information
Ravi Sankar Penta committed Sep 19, 2017
1 parent 6e87701 commit fa00ddd
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion pkg/diagnostics/network/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
kerrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/storage/names"
kclientcmd "k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -66,7 +67,12 @@ func (d *NetworkDiagnostic) TestSetup() error {
}
// Wait for test pods and services to be up and running on all valid nodes
if err = d.waitForTestPodAndService(nsList); err != nil {
return fmt.Errorf("Failed to run network diags test pod and service: %v", err)
logData, er := d.getPodLogs(nsList)
if er != nil {
return fmt.Errorf("Failed to run network diags test pod and service: %v, fetching logs failed: %v", err, er)
} else {
return fmt.Errorf("Failed to run network diags test pod and service: %v, details: %s", err, logData)
}
}
return nil
}
Expand Down Expand Up @@ -169,6 +175,41 @@ func (d *NetworkDiagnostic) waitForTestPodAndService(nsList []string) error {
return kerrors.NewAggregate(errList)
}

func (d *NetworkDiagnostic) getPodLogs(nsList []string) (string, error) {
logData := sets.String{}
errList := []error{}
limit := int64(1024)

for _, name := range nsList {
podList, err := d.getPodList(name, util.NetworkDiagTestPodNamePrefix)
if err != nil {
return "", err
}

for _, pod := range podList.Items {
opts := &kapi.PodLogOptions{
TypeMeta: pod.TypeMeta,
Container: pod.Name,
Follow: true,
LimitBytes: &limit,
}

req, err := d.Factory.LogsForObject(&pod, opts, 10*time.Second)
if err != nil {
errList = append(errList, err)
continue
}
data, err := req.DoRaw()
if err != nil {
errList = append(errList, err)
continue
}
logData.Insert(string(data[:]))
}
}
return strings.Join(logData.List(), ", "), kerrors.NewAggregate(errList)
}

func (d *NetworkDiagnostic) getCountOfTestPods(nsList []string) (int, int, error) {
totalPodCount := 0
runningPodCount := 0
Expand Down

0 comments on commit fa00ddd

Please sign in to comment.