cleaning up
parent
1f2c159aa6
commit
65ee532784
2
go.mod
2
go.mod
|
|
@ -2,8 +2,6 @@ module github.com/derailed/k9s
|
||||||
|
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
replace helm.sh/helm/v3 => /Users/fernand/go_wk/derailed/src/github.com/derailed/tmp/helm
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/atotto/clipboard v0.1.2
|
github.com/atotto/clipboard v0.1.2
|
||||||
github.com/derailed/popeye v0.8.1
|
github.com/derailed/popeye v0.8.1
|
||||||
|
|
|
||||||
|
|
@ -1,124 +1,124 @@
|
||||||
package dao
|
package dao
|
||||||
|
|
||||||
// BOZO!! v1.18.0
|
// BOZO!! v1.18.0
|
||||||
import (
|
// import (
|
||||||
"context"
|
// "context"
|
||||||
"fmt"
|
// "fmt"
|
||||||
"os"
|
// "os"
|
||||||
|
|
||||||
"github.com/derailed/k9s/internal/client"
|
// "github.com/derailed/k9s/internal/client"
|
||||||
"github.com/derailed/k9s/internal/render"
|
// "github.com/derailed/k9s/internal/render"
|
||||||
"github.com/rs/zerolog/log"
|
// "github.com/rs/zerolog/log"
|
||||||
"helm.sh/helm/v3/pkg/action"
|
// "helm.sh/helm/v3/pkg/action"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
// "k8s.io/apimachinery/pkg/runtime"
|
||||||
)
|
// )
|
||||||
|
|
||||||
var (
|
// var (
|
||||||
_ Accessor = (*Chart)(nil)
|
// _ Accessor = (*Chart)(nil)
|
||||||
_ Nuker = (*Chart)(nil)
|
// _ Nuker = (*Chart)(nil)
|
||||||
_ Describer = (*Chart)(nil)
|
// _ Describer = (*Chart)(nil)
|
||||||
)
|
// )
|
||||||
|
|
||||||
// Chart represents a helm chart.
|
// // Chart represents a helm chart.
|
||||||
type Chart struct {
|
// type Chart struct {
|
||||||
NonResource
|
// NonResource
|
||||||
}
|
// }
|
||||||
|
|
||||||
// List returns a collection of resources.
|
// // List returns a collection of resources.
|
||||||
func (c *Chart) List(ctx context.Context, ns string) ([]runtime.Object, error) {
|
// func (c *Chart) List(ctx context.Context, ns string) ([]runtime.Object, error) {
|
||||||
cfg, err := c.EnsureHelmConfig(ns)
|
// cfg, err := c.EnsureHelmConfig(ns)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
|
|
||||||
rr, err := action.NewList(cfg).Run()
|
// rr, err := action.NewList(cfg).Run()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
|
|
||||||
oo := make([]runtime.Object, 0, len(rr))
|
// oo := make([]runtime.Object, 0, len(rr))
|
||||||
for _, r := range rr {
|
// for _, r := range rr {
|
||||||
oo = append(oo, render.ChartRes{Release: r})
|
// oo = append(oo, render.ChartRes{Release: r})
|
||||||
}
|
// }
|
||||||
|
|
||||||
return oo, nil
|
// return oo, nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Get returns a resource.
|
// // Get returns a resource.
|
||||||
func (c *Chart) Get(_ context.Context, path string) (runtime.Object, error) {
|
// func (c *Chart) Get(_ context.Context, path string) (runtime.Object, error) {
|
||||||
ns, n := client.Namespaced(path)
|
// ns, n := client.Namespaced(path)
|
||||||
cfg, err := c.EnsureHelmConfig(ns)
|
// cfg, err := c.EnsureHelmConfig(ns)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
resp, err := action.NewGet(cfg).Run(n)
|
// resp, err := action.NewGet(cfg).Run(n)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
|
|
||||||
return render.ChartRes{Release: resp}, nil
|
// return render.ChartRes{Release: resp}, nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Describe returns the chart notes.
|
// // Describe returns the chart notes.
|
||||||
func (c *Chart) Describe(path string) (string, error) {
|
// func (c *Chart) Describe(path string) (string, error) {
|
||||||
ns, n := client.Namespaced(path)
|
// ns, n := client.Namespaced(path)
|
||||||
cfg, err := c.EnsureHelmConfig(ns)
|
// cfg, err := c.EnsureHelmConfig(ns)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return "", err
|
// return "", err
|
||||||
}
|
// }
|
||||||
resp, err := action.NewGet(cfg).Run(n)
|
// resp, err := action.NewGet(cfg).Run(n)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return "", err
|
// return "", err
|
||||||
}
|
// }
|
||||||
|
|
||||||
return resp.Info.Notes, nil
|
// return resp.Info.Notes, nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
// ToYAML returns the chart manifest.
|
// // ToYAML returns the chart manifest.
|
||||||
func (c *Chart) ToYAML(path string) (string, error) {
|
// func (c *Chart) ToYAML(path string) (string, error) {
|
||||||
ns, n := client.Namespaced(path)
|
// ns, n := client.Namespaced(path)
|
||||||
cfg, err := c.EnsureHelmConfig(ns)
|
// cfg, err := c.EnsureHelmConfig(ns)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return "", err
|
// return "", err
|
||||||
}
|
// }
|
||||||
resp, err := action.NewGet(cfg).Run(n)
|
// resp, err := action.NewGet(cfg).Run(n)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return "", err
|
// return "", err
|
||||||
}
|
// }
|
||||||
|
|
||||||
return resp.Manifest, nil
|
// return resp.Manifest, nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Delete uninstall a Chart.
|
// // Delete uninstall a Chart.
|
||||||
func (c *Chart) Delete(path string, cascade, force bool) error {
|
// func (c *Chart) Delete(path string, cascade, force bool) error {
|
||||||
ns, n := client.Namespaced(path)
|
// ns, n := client.Namespaced(path)
|
||||||
cfg, err := c.EnsureHelmConfig(ns)
|
// cfg, err := c.EnsureHelmConfig(ns)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
res, err := action.NewUninstall(cfg).Run(n)
|
// res, err := action.NewUninstall(cfg).Run(n)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
if res != nil && res.Info != "" {
|
// if res != nil && res.Info != "" {
|
||||||
return fmt.Errorf("%s", res.Info)
|
// return fmt.Errorf("%s", res.Info)
|
||||||
}
|
// }
|
||||||
|
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
// EnsureHelmConfig return a new configuration.
|
// // EnsureHelmConfig return a new configuration.
|
||||||
func (c *Chart) EnsureHelmConfig(ns string) (*action.Configuration, error) {
|
// func (c *Chart) EnsureHelmConfig(ns string) (*action.Configuration, error) {
|
||||||
cfg := new(action.Configuration)
|
// cfg := new(action.Configuration)
|
||||||
flags := c.Client().Config().Flags()
|
// flags := c.Client().Config().Flags()
|
||||||
if err := cfg.Init(flags, ns, os.Getenv("HELM_DRIVER"), helmLogger); err != nil {
|
// if err := cfg.Init(flags, ns, os.Getenv("HELM_DRIVER"), helmLogger); err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
return cfg, nil
|
// return cfg, nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
func helmLogger(s string, args ...interface{}) {
|
// func helmLogger(s string, args ...interface{}) {
|
||||||
log.Debug().Msgf("%s %v", s, args)
|
// log.Debug().Msgf("%s %v", s, args)
|
||||||
}
|
// }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue