Skip to content

Commit

Permalink
feat: display container env
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillich committed Jan 25, 2024
1 parent ef9338d commit eac4b41
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 15 deletions.
25 changes: 24 additions & 1 deletion behavior/detail_behavior.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,30 @@ func (b *DetailBehaviour) onObjectChange(object client.Object) {
props = append(props, ObjectProperty{Name: "Command", Value: strings.Join(container.Command, " ")})
}

// TODO env
prop := ObjectProperty{Name: "Env"}
for _, env := range container.Env {
if from := env.ValueFrom; from != nil {
if ref := from.ConfigMapKeyRef; ref != nil {
var cm corev1.ConfigMap
if err := b.client.Get(context.TODO(), types.NamespacedName{Name: ref.Name, Namespace: object.Namespace}, &cm); err != nil {
prop.Children = append(prop.Children, ObjectProperty{Name: env.Name, Value: fmt.Sprintf("error: %v", err)})
} else {
prop.Children = append(prop.Children, ObjectProperty{Name: env.Name, Value: cm.Data[ref.Key]})
}
} else if ref := from.SecretKeyRef; ref != nil {
var secret corev1.Secret
if err := b.client.Get(context.TODO(), types.NamespacedName{Name: ref.Name, Namespace: object.Namespace}, &secret); err != nil {
prop.Children = append(prop.Children, ObjectProperty{Name: env.Name, Value: fmt.Sprintf("error: %v", err)})
} else {
prop.Children = append(prop.Children, ObjectProperty{Name: env.Name, Value: string(secret.Data[ref.Key])})
}
}
// TODO field refs
} else {
prop.Children = append(prop.Children, ObjectProperty{Name: env.Name, Value: env.Value})
}
}
props = append(props, prop)

if metrics != nil {
if cpu := metrics.Usage.Cpu(); cpu != nil {
Expand Down
7 changes: 7 additions & 0 deletions style/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ columnview>listview>row:selected {

.navigation-sidebar {
opacity: 0.9;
}

label.badge {
background-color: @window_bg_color;
padding: .3em 0 .3em 0;
border-radius: .6rem;
font-size: 0.9em;
}
52 changes: 38 additions & 14 deletions ui/detail_view.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ui

import (
"fmt"

"github.com/diamondburned/gotk4-adwaita/pkg/adw"
"github.com/diamondburned/gotk4-sourceview/pkg/gtksource/v5"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
Expand Down Expand Up @@ -63,23 +65,45 @@ func (d *DetailView) onPropertiesChange(properties []behavior.ObjectProperty) {
d.groups = append(d.groups, g)
for _, p2 := range p1.Children {
if len(p2.Children) > 0 {
parent := adw.NewExpanderRow()
parent.SetTitle(p2.Name)
g.Add(parent)
r2 := adw.NewExpanderRow()
r2.SetTitle(p2.Name)
g.Add(r2)
for _, p3 := range p2.Children {
child := adw.NewActionRow()
child.SetTitle(p3.Name)
child.SetSubtitle(p3.Value)
child.AddCSSClass("property")
parent.AddRow(child)
if len(p3.Children) > 0 {
r3 := adw.NewActionRow()
r3.SetTitle(p2.Name)
r3.AddCSSClass("property")
r2.AddRow(r3)

box := gtk.NewFlowBox()
box.SetColumnSpacing(2)
box.SetRowSpacing(2)
r3.FirstChild().(*gtk.Box).FirstChild().(*gtk.Box).NextSibling().(*gtk.Image).NextSibling().(*gtk.Box).Append(box)

for _, p4 := range p3.Children {
label := gtk.NewLabel(fmt.Sprintf("%s: %s", p4.Name, p4.Value))
label.SetSelectable(true)
label.AddCSSClass("badge")
box.Insert(label, -1)
}
} else {
r3 := adw.NewActionRow()
r3.SetTitle(p3.Name)
r3.SetSubtitle(p3.Value)
r3.SetSubtitleSelectable(true)
r3.AddCSSClass("property")
r2.AddRow(r3)
}

}
d.extendRow([]string{p1.Name, p2.Name}, parent)
d.extendRow([]string{p1.Name, p2.Name}, r2)
} else {
r := adw.NewActionRow()
r.SetTitle(p2.Name)
r.SetSubtitle(p2.Value)
r.AddCSSClass("property")
g.Add(r)
r2 := adw.NewActionRow()
r2.SetTitle(p2.Name)
r2.SetSubtitle(p2.Value)
r2.SetSubtitleSelectable(true)
r2.AddCSSClass("property")
g.Add(r2)
}
}
}
Expand Down

0 comments on commit eac4b41

Please sign in to comment.