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
…26)

* (feature): add support for reading dashboard configuration from YAML

Signed-off-by: Bryce Palmer <everettraven@gmail.com>

* add test.yaml

Signed-off-by: Bryce Palmer <everettraven@gmail.com>

---------

Signed-off-by: Bryce Palmer <everettraven@gmail.com>
  • Loading branch information
everettraven committed Nov 15, 2023
1 parent 512d6d9 commit 89a37a5
Show file tree
Hide file tree
Showing 5 changed files with 113 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"`
}
84 changes: 84 additions & 0 deletions test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
panels:
- name: All Pods
group: ""
version: v1
kind: Pod
type: table
columns:
- header: Namespace
path: metadata.namespace
- header: Name
path: metadata.name
- header: Labels
path: metadata.labels
- header: Ready Condition
path: status.conditions.#(type==Ready)
- header: Phase
path: status.phase
- header: Containers
path: spec.containers.#.name
- name: Kube-System Pods with label tier=control-plane
group: ""
version: v1
kind: Pod
type: table
namespace: kube-system
labelSelector:
tier: control-plane
columns:
- header: Namespace
path: metadata.namespace
- header: Name
path: metadata.name
- header: Phase
path: status.phase
- header: PodIP
path: status.podIP
- header: Start Time
path: status.startTime
- header: UID
path: metadata.uid
- name: Deployments
group: apps
version: v1
kind: Deployment
type: table
columns:
- header: Namespace
path: metadata.namespace
- header: Name
path: metadata.name
- header: Replicas
path: status.replicas
- name: Kube API Server
group: ""
version: v1
kind: Pod
type: item
key:
namespace: kube-system
name: kube-apiserver-kind-control-plane
- name: Kube API Server Logs
group: ""
version: v1
kind: Pod
type: logs
key:
namespace: kube-system
name: kube-apiserver-kind-control-plane
- name: Namespaces
group: ""
version: v1
kind: Namespace
type: table
columns:
- header: Name
path: metadata.name
- name: CoreDNS Deployment Logs
group: apps
version: v1
kind: Deployment
type: logs
key:
namespace: kube-system
name: coredns

0 comments on commit 89a37a5

Please sign in to comment.