Skip to content

Commit

Permalink
(feature): add support for reading dashboard configuration from YAML
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce Palmer <everettraven@gmail.com>
  • Loading branch information
everettraven committed Nov 15, 2023
1 parent 512d6d9 commit 1db4ad1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ kind create cluster

The `test.json` file contains samples for each of the different panel types that `buoy` currently supports. As this is a hobby project very early in the development cycle there are some limitations and things are bound to not work as expected.

`buoy` uses https://github.com/tidwall/gjson for the path evaluation and extracting of values from resources. Please consult their documentation for valid path syntax
`test.yaml` results in the exact same dashboard as `test.json` and exists to show YAML support.

`buoy` uses https://github.com/tidwall/gjson for the path evaluation and extracting of values from resources. Please consult their documentation for valid path syntax.

## Controls
- `ctrl+c`, `q`, `esc` will quit the program and exit the tui
Expand Down
12 changes: 10 additions & 2 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"fmt"
"log"
"os"
"path/filepath"

tea "github.com/charmbracelet/bubbletea"
"github.com/everettraven/buoy/pkg/charm/models"
"github.com/everettraven/buoy/pkg/paneler"
"github.com/everettraven/buoy/pkg/types"
"github.com/spf13/cobra"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/yaml"
)

var rootCommand = &cobra.Command{
Expand All @@ -28,13 +30,19 @@ func init() {
}

func run(file string) error {
rawJson, err := os.ReadFile(file)
ext := filepath.Ext(file)
raw, err := os.ReadFile(file)
if err != nil {
log.Fatalf("reading file: %s", err)
}

fmt.Println(ext)
dash := &types.Dashboard{}
err = json.Unmarshal(rawJson, dash)
if ext == ".yaml" {
err = yaml.Unmarshal(raw, dash)
} else {
err = json.Unmarshal(raw, dash)
}
if err != nil {
log.Fatalf("unmarshalling dashboard: %s", err)
}
Expand Down
30 changes: 15 additions & 15 deletions pkg/types/panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ const (
)

type PanelBase struct {
Name string `json:"name"`
Group string `json:"group"`
Version string `json:"version"`
Kind string `json:"kind"`
Type string `json:"type"`
Name string `json:"name" yaml:"name"`
Group string `json:"group" yaml:"group"`
Version string `json:"version" yaml:"version"`
Kind string `json:"kind" yaml:"kind"`
Type string `json:"type" yaml:"type"`
}

type Panel struct {
PanelBase
Blob json.RawMessage `json:"blob"`
Blob json.RawMessage `json:"blob" yaml:"blob"`
}

func (p *Panel) UnmarshalJSON(data []byte) error {
Expand All @@ -37,24 +37,24 @@ func (p *Panel) UnmarshalJSON(data []byte) error {

type Table struct {
PanelBase
Columns []Column `json:"columns"`
Namespace string `json:"namespace"`
LabelSelector map[string]string `json:"labelSelector"`
Columns []Column `json:"columns" yaml:"columns"`
Namespace string `json:"namespace" yaml:"namespace"`
LabelSelector map[string]string `json:"labelSelector" yaml:"labelSelector"`
}

type Column struct {
Header string `json:"header"`
Width int `json:"width"`
Path string `json:"path"`
Header string `json:"header" yaml:"header"`
Width int `json:"width" yaml:"width"`
Path string `json:"path" yaml:"path"`
}

type Item struct {
PanelBase
Key types.NamespacedName
Key types.NamespacedName `json:"key" yaml:"key"`
}

type Logs struct {
PanelBase
Key types.NamespacedName
Container string `json:"container"`
Key types.NamespacedName `json:"key" yaml:"key"`
Container string `json:"container" yaml:"container"`
}
2 changes: 1 addition & 1 deletion pkg/types/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package types

type Dashboard struct {
Panels []Panel `json:"panels"`
Panels []Panel `json:"panels" yaml:"panels"`
}

0 comments on commit 1db4ad1

Please sign in to comment.