Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(techdebt): make table report errors #21

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/charm/models/panels/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Table struct {
mutex *sync.Mutex
rows map[types.UID]tbl.Row
columns []buoytypes.Column
err error
}

func NewTable(name string, table tbl.Model, columns []buoytypes.Column) *Table {
Expand All @@ -42,6 +43,9 @@ func (m *Table) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m *Table) View() string {
if m.err != nil {
return m.err.Error()
}
return m.table.View()
}

Expand Down Expand Up @@ -74,3 +78,7 @@ func (m *Table) Columns() []buoytypes.Column {
func (m *Table) Name() string {
return m.name
}

func (m *Table) SetError(err error) {
m.err = err
}
25 changes: 8 additions & 17 deletions pkg/paneler/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"strings"
"sync"

"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -39,7 +38,7 @@ func modelWrapperForLogPanel(kc *kubernetes.Clientset, logsPanel types.Logs) *pa
return vpw
}

func streamLogs(kc *kubernetes.Clientset, logsPanel types.Logs, logItem *panels.Logs) error {
func streamLogs(kc *kubernetes.Clientset, logsPanel types.Logs, logItem *panels.Logs) {
//TODO: expand this beyond just a pod
req := kc.CoreV1().Pods(logsPanel.Key.Namespace).GetLogs(logsPanel.Key.Name, &v1.PodLogOptions{
Container: logsPanel.Container,
Expand All @@ -48,24 +47,16 @@ func streamLogs(kc *kubernetes.Clientset, logsPanel types.Logs, logItem *panels.

rc, err := req.Stream(context.Background())
if err != nil {
return fmt.Errorf("fetching logs for %s/%s: %w", logsPanel.Key.Namespace, logsPanel.Key.Name, err)
logItem.AddContent(fmt.Errorf("fetching logs for %s/%s: %w", logsPanel.Key.Namespace, logsPanel.Key.Name, err).Error())
return
}
defer rc.Close()

wg := sync.WaitGroup{}
wg.Add(1)

go func() {
defer wg.Done()
scanner := bufio.NewScanner(rc)
for scanner.Scan() {
logs := wrapLogs(scanner.Bytes())
logItem.AddContent(logs)
}
}()

wg.Wait()
return nil
scanner := bufio.NewScanner(rc)
for scanner.Scan() {
logs := wrapLogs(scanner.Bytes())
logItem.AddContent(logs)
}
}

func wrapLogs(logs []byte) string {
Expand Down
16 changes: 8 additions & 8 deletions pkg/paneler/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ func (t *Table) runInformerForTable(tablePanel buoytypes.Table, tw *panels.Table
for _, column := range tw.Columns() {
val, err := getDotNotationValue(u.Object, column.Path)
if err != nil {
//TODO: Log some kind of info here
continue
tw.SetError(err)
break
}
switch val := val.(type) {
case string:
row = append(row, val)
case map[string]interface{}:
data, err := json.Marshal(val)
if err != nil {
//TODO: log some kind of info here
continue
tw.SetError(err)
break
}
row = append(row, string(data))
default:
Expand All @@ -123,17 +123,17 @@ func (t *Table) runInformerForTable(tablePanel buoytypes.Table, tw *panels.Table
for _, column := range tw.Columns() {
val, err := getDotNotationValue(u.Object, column.Path)
if err != nil {
//TODO: Log some kind of info here
continue
tw.SetError(err)
break
}
switch val := val.(type) {
case string:
row = append(row, val)
case map[string]interface{}:
data, err := json.Marshal(val)
if err != nil {
//TODO: log some kind of info here
continue
tw.SetError(err)
break
}
row = append(row, string(data))
default:
Expand Down