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

Revert "[chore] Update output tables" #118

Merged
merged 1 commit into from
Oct 16, 2024
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/docker/buildx v0.16.0
github.com/enescakir/emoji v1.0.0
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/jedib0t/go-pretty/v6 v6.6.0
github.com/jedib0t/go-pretty v4.3.0+incompatible
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213
github.com/moby/buildkit v0.15.1
github.com/project-copacetic/copacetic v0.7.1-0.20240723231147-beb8c86673a8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,8 @@ github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jedib0t/go-pretty/v6 v6.6.0 h1:wmZVuAcEkZRT+Aq1xXpE8IGat4vE5WXOMmBpbQqERXw=
github.com/jedib0t/go-pretty/v6 v6.6.0/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/jedib0t/go-pretty v4.3.0+incompatible h1:CGs8AVhEKg/n9YbUenWmNStRW2PHJzaeDodcfvRAbIo=
github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag=
github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267 h1:TMtDYDHKYY15rFihtRfck/bfFqNfvcabqvXAFQfAUpY=
github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267/go.mod h1:h1nSAbGFqGVzn6Jyl1R/iCcBUHN4g+gW1u9CoBTrb9E=
github.com/jellydator/ttlcache/v3 v3.3.0 h1:BdoC9cE81qXfrxeb9eoJi9dWrdhSuwXMAnHTbnBm4Wc=
Expand Down
98 changes: 13 additions & 85 deletions internal/output/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package output

import (
"context"
"fmt"
"log/slog"
"os"
"strings"
Expand All @@ -16,22 +15,21 @@ import (
"github.com/ChristofferNissen/helmper/pkg/util/file"
"github.com/ChristofferNissen/helmper/pkg/util/state"
"github.com/ChristofferNissen/helmper/pkg/util/terminal"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/table"
)

var sc counter.SafeCounter = counter.NewSafeCounter()

// create a new table.writer with header and os.Stdout output mirror
func newTable(title string, header table.Row) table.Writer {
func newTable(row table.Row) table.Writer {
t := table.NewWriter()
t.SetTitle(title)
t.SetOutputMirror(os.Stdout)
t.AppendHeader(header)
t.AppendHeader(row)
return t
}

func renderChartTable(rows []table.Row) {
t := newTable("Charts", table.Row{"#", "Type", "Chart", "Version", "Latest Version", "Latest", "Values", "SubChart", "Version", "Condition", "Enabled"})
t := newTable(table.Row{"#", "Type", "Chart", "Version", "Latest Version", "Latest", "Values", "SubChart", "Version", "Condition", "Enabled"})
t.AppendRows(rows)
t.SortBy([]table.SortBy{
{Number: 1, Mode: table.AscNumeric},
Expand Down Expand Up @@ -113,13 +111,13 @@ func RenderChartTable(charts *helm.ChartCollection, setters ...Option) {

func RenderHelmValuePathToImageTable(chartImageHelmValuesMap map[helm.Chart]map[*registry.Image][]string) {
// Print Helm values to be set for each chart
t := newTable("Helm Values Paths Per Image", table.Row{"#", "Helm Chart", "Chart Version", "Image", "Helm Value Path(s)"})
t := newTable(table.Row{"#", "Helm Chart", "Chart Version", "Helm Value Path", "Image"})
id := 0
for c, v := range chartImageHelmValuesMap {
for i, paths := range v {
ref, _ := i.String()
noSHA := strings.SplitN(ref, "@", 2)[0]
t.AppendRow(table.Row{id, c.Name, c.Version, noSHA, strings.Join(paths, "\n")})
t.AppendRow(table.Row{id, c.Name, c.Version, strings.Join(paths, "\n"), noSHA})
id = id + 1
}
}
Expand Down Expand Up @@ -152,7 +150,7 @@ func getImportTableRows(ctx context.Context, viper *viper.Viper, registries []re
// Create collection of registry names as keys for iterating registries
keys := make([]string, 0)
for _, r := range registries {
keys = append(keys, r.URL)
keys = append(keys, r.GetName())
}

// Combine results
Expand All @@ -165,12 +163,8 @@ func getImportTableRows(ctx context.Context, viper *viper.Viper, registries []re
// make sure we don't parse again
seenImages = append(seenImages, *i)

name, err := i.ImageName()
if err != nil {
return []table.Row{}, err
}
// check if image exists in registry
m := registry.Exists(ctx, name, i.Tag, registries)
m := registry.Exists(ctx, i, registries)

// add row to overview table
ref, _ := i.String()
Expand All @@ -184,6 +178,7 @@ func getImportTableRows(ctx context.Context, viper *viper.Viper, registries []re
}

func RenderImageOverviewTable(ctx context.Context, viper *viper.Viper, missing int, registries []registry.Registry, chartImageValuesMap map[helm.Chart]map[*registry.Image][]string) error {

rows, err := getImportTableRows(ctx, viper, registries, chartImageValuesMap)
if err != nil {
return err
Expand All @@ -200,86 +195,19 @@ func RenderImageOverviewTable(ctx context.Context, viper *viper.Viper, missing i

// dynamic number of registries
for _, r := range registries {
header = append(header, r.GetName())
footer = append(footer, "")

if ic.Import.Enabled {
// second static part of header
header = append(header, "import")
footer = append(footer, sc.Value(r.URL))
}
}

// construct tab"test"le
t := newTable("Registry Overview For Charts", header)
t.AppendRows(rows)
t.AppendFooter(footer)
t.Render()

return nil
}

func RenderChartOverviewTable(ctx context.Context, viper *viper.Viper, missing int, registries []registry.Registry, charts helm.ChartCollection) error {

// Create collection of registry names as keys for iterating registries
keys := make([]string, 0)
for _, r := range registries {
keys = append(keys, r.URL)
}

// Combine results
rows := make([]table.Row, 0)
for _, c := range charts.Charts {
// check if image exists in registry
m := registry.Exists(ctx, fmt.Sprintf("charts/%s", c.Name), c.Version, registries)

// add row to overview table
row := func() table.Row {
row := table.Row{}
row = append(row, sc.Value("index_import_charts"), c.Name, c.Version)

for _, key := range keys {
row = append(row, terminal.StatusEmoji(m[key]))
ic := state.GetValue[bootstrap.ImportConfigSection](viper, "importConfig")
if ic.Import.Enabled {
b := state.GetValue[bool](viper, "all") || !m[key]
if b {
sc.Inc(key + "charts")
}
row = append(row, terminal.StatusEmoji(b))
}
}

sc.Inc("index_import_charts")
return row
}()

rows = append(rows, row)
}

header := table.Row{}
footer := table.Row{}

// first static part of header
header = append(header, "#", "Helm Chart", "Chart Version")
footer = append(footer, "", "", "")

ic := state.GetValue[bootstrap.ImportConfigSection](viper, "importConfig")

// dynamic number of registries
for _, r := range registries {
header = append(header, r.GetName())
name := r.GetName()
header = append(header, name)
footer = append(footer, "")

if ic.Import.Enabled {
// second static part of header
header = append(header, "import")
footer = append(footer, sc.Value(r.URL+"charts"))
footer = append(footer, sc.Value(r.GetName()))
}
}

// construct table
t := newTable("Registry Overview For Images", header)
t := newTable(header)
t.AppendRows(rows)
t.AppendFooter(footer)
t.Render()
Expand Down
Loading
Loading