diff --git a/compose/compose.go b/compose/compose.go index aea0c8505..77253ae2d 100644 --- a/compose/compose.go +++ b/compose/compose.go @@ -18,12 +18,6 @@ type ComposeProject struct { Name string `yaml:"-" json:"-"` } -type ComposeResult struct { - Info string - Status string - Descriptin string -} - func Load(name string, configpaths []string) (*ComposeProject, error) { if name == "" { name = "docker-compose" @@ -68,3 +62,7 @@ func (cp *ComposeProject) Install(name, path string) error { func (cp *ComposeProject) Uninstall(name string) error { return cp.helm.Uninstall(name) } + +func (cp *ComposeProject) List() (map[string]interface{}, error) { + return cp.helm.ListReleases() +} diff --git a/compose/internal/env.go b/compose/internal/env.go index 8397ac0f8..72075138b 100644 --- a/compose/internal/env.go +++ b/compose/internal/env.go @@ -11,34 +11,11 @@ import ( "github.com/docker/helm-prototype/pkg/compose/internal/utils" chart "helm.sh/helm/v3/pkg/chart" util "helm.sh/helm/v3/pkg/chartutil" + helmenv "helm.sh/helm/v3/pkg/cli" ) -// Kind is "kubernetes" or "docker" -type Kind string - -const ( - // Kubernetes specifies to use a kubernetes cluster. - Kubernetes Kind = "kubernetes" - // Docker specifies to use Docker engine. - DockerEngine Kind = "docker" -) - -type Engine struct { - Namespace string - - Kind Kind - - Config string - // Context is the name of the kubeconfig/docker context. - Context string - // Token used for authentication (kubernetes) - Token string - // Kubernetes API Server Endpoint for authentication - APIServer string -} - -func GetDefault() *Engine { - return &Engine{Kind: Kubernetes} +func GetDefault() *helmenv.EnvSettings { + return helmenv.New() } func Environment() map[string]string { diff --git a/compose/internal/helm/helm.go b/compose/internal/helm/helm.go index 288e34884..60cb39df0 100644 --- a/compose/internal/helm/helm.go +++ b/compose/internal/helm/helm.go @@ -95,3 +95,21 @@ func (hc *HelmActions) Get(name string) (*release.Release, error) { actGet := action.NewGet(hc.Config) return actGet.Run(name) } + +func (hc *HelmActions) ListReleases() (map[string]interface{}, error) { + hc.initKubeClient() + + actList := action.NewList(hc.Config) + releases, err := actList.Run() + if err != nil { + return map[string]interface{}{}, err + } + result := map[string]interface{}{} + for _, rel := range releases { + result[rel.Name] = map[string]string{ + "Status": string(rel.Info.Status), + "Description": rel.Info.Description, + } + } + return result, nil +}