Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Refactor osm-controller pod error handling and logging
Browse files Browse the repository at this point in the history
Signed-off-by: Johnson Shi <[email protected]>
  • Loading branch information
johnsonshi committed Aug 5, 2021
1 parent 592627a commit be6bea9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pkg/kubernetes/podhelper/container_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"regexp"

"github.com/pkg/errors"

v1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
)
Expand Down Expand Up @@ -44,8 +46,7 @@ func HasNoBadLogs(client kubernetes.Interface, pod *v1.Pod, containerName string
}

if len(badLogLines) != 0 {
log.Error().Msgf("%s container of pod %s contains bad logs", containerName, pod.Name)
log.Error().Msg(badLogLines)
return errors.Errorf("%s container of pod %s contains bad log lines: %s", containerName, pod.Name, badLogLines)
}

return nil
Expand Down
13 changes: 10 additions & 3 deletions pkg/osm/osm_controller_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"fmt"

"github.com/pkg/errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"

"k8s.io/client-go/kubernetes"

"github.com/openservicemesh/osm-health/pkg/common"
Expand Down Expand Up @@ -44,15 +45,21 @@ func (check NoBadOsmControllerLogsCheck) Run() error {
}
pods, err := check.client.CoreV1().Pods(check.osmControlPlaneNamespace).List(context.TODO(), listOptions)
if err != nil {
return fmt.Errorf("unable to list osm controller pods in namespace %s", check.osmControlPlaneNamespace)
return fmt.Errorf("unable to list %s pods in namespace %s", constants.OSMControllerName, check.osmControlPlaneNamespace)
}

osmControllerErrCount := 0
for i := range pods.Items {
if err := podhelper.HasNoBadLogs(check.client, &pods.Items[i], "osm-controller"); err != nil {
return err // TODO since we can have multiple osm-controller pods, should we return err on the first controller with bad logs?
osmControllerErrCount++
log.Error().Err(err)
}
}

if osmControllerErrCount != 0 {
return errors.Errorf("%s pods in namespace %s have %d errors", constants.OSMControllerName, check.osmControlPlaneNamespace, osmControllerErrCount)
}

return nil
}

Expand Down

0 comments on commit be6bea9

Please sign in to comment.