Permalink
Browse files

Implement devspace list package and fix several problems

  • Loading branch information...
FabianKramm committed Sep 25, 2018
1 parent 6da94a6 commit 3a036dc79eac936d20d59d2e86a76417c4a143cf
Showing with 135 additions and 16 deletions.
  1. +1 −0 .gitignore
  2. +2 −2 .vscode/launch.json
  3. +37 −14 cmd/add.go
  4. +60 −0 cmd/list.go
  5. +19 −0 cmd/remove.go
  6. +12 −0 pkg/devspace/clients/helm/client.go
  7. +4 −0 pkg/util/log/log.go
View
@@ -17,3 +17,4 @@
devspace
debug
.DS_STORE
View
@@ -9,10 +9,10 @@
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"cwd": "${workspaceFolder}/examples/nodejs",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/main.go",
"env": {},
"args": [""],
"args": ["list", "package"],
"showLog": true
}
]
View
@@ -2,11 +2,14 @@ package cmd
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/covexo/devspace/pkg/util/yamlutil"
helmClient "github.com/covexo/devspace/pkg/devspace/clients/helm"
"github.com/covexo/devspace/pkg/devspace/clients/kubectl"
"github.com/covexo/devspace/pkg/devspace/config/configutil"
@@ -175,9 +178,6 @@ func (cmd *AddCmd) RunAddPackage(cobraCmd *cobra.Command, args []string) {
}
log.Done("Chart found")
entry := "- name: \"" + version.GetName() + "\"\n" +
" version: \"" + version.GetVersion() + "\"\n" +
" repository: \"" + repo.URL + "\"\n"
cwd, err := os.Getwd()
if err != nil {
@@ -188,22 +188,45 @@ func (cmd *AddCmd) RunAddPackage(cobraCmd *cobra.Command, args []string) {
_, err = os.Stat(requirementsFile)
if os.IsNotExist(err) {
entry = "dependencies:\n" + entry
}
entry := "dependencies:\n" +
"- name: \"" + version.GetName() + "\"\n" +
" version: \"" + version.GetVersion() + "\"\n" +
" repository: \"" + repo.URL + "\"\n"
f, err := os.OpenFile(requirementsFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile(requirementsFile, []byte(entry), 0600)
if err != nil {
log.Fatal(err)
}
} else {
yamlContents := map[interface{}]interface{}{}
err = yamlutil.ReadYamlFromFile(requirementsFile, yamlContents)
if err != nil {
log.Fatalf("Error parsing %s: %v", requirementsFile, err)
}
defer f.Close()
dependenciesArr := []interface{}{}
if dependencies, ok := yamlContents["dependencies"]; ok {
dependenciesArr, ok = dependencies.([]interface{})
if ok == false {
log.Fatalf("Error parsing %s: Key dependencies is not an array", requirementsFile)
}
}
if _, err = f.WriteString(entry); err != nil {
log.Fatal(err)
dependenciesArr = append(dependenciesArr, map[interface{}]interface{}{
"name": version.GetName(),
"version": version.GetVersion(),
"repository": repo.URL,
})
yamlContents["dependencies"] = dependenciesArr
err = yamlutil.WriteYamlToFile(yamlContents, requirementsFile)
if err != nil {
log.Fatal(err)
}
}
log.StartWait("Building chart")
err = helm.BuildDependencies(filepath.Join(cwd, "chart"))
log.StartWait("Update chart dependencies")
err = helm.UpdateDependencies(filepath.Join(cwd, "chart"))
log.StopWait()
if err != nil {
View
@@ -1,10 +1,13 @@
package cmd
import (
"os"
"path/filepath"
"strconv"
"github.com/covexo/devspace/pkg/devspace/config/configutil"
"github.com/covexo/devspace/pkg/util/log"
"github.com/covexo/devspace/pkg/util/yamlutil"
"github.com/spf13/cobra"
)
@@ -72,6 +75,63 @@ func init() {
}
listCmd.AddCommand(listPortCmd)
listPackageCmd := &cobra.Command{
Use: "package",
Short: "Lists all added packages",
Long: `
#######################################################
############### devspace list package #################
#######################################################
Lists the packages that were added to the devspace
#######################################################
`,
Args: cobra.NoArgs,
Run: cmd.RunListPackage,
}
listCmd.AddCommand(listPackageCmd)
}
// RunListPackage runs the list sync command logic
func (cmd *ListCmd) RunListPackage(cobraCmd *cobra.Command, args []string) {
headerColumnNames := []string{
"Name",
"Version",
"Repository",
}
values := [][]string{}
cwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
requirementsFile := filepath.Join(cwd, "chart", "requirements.yaml")
_, err = os.Stat(requirementsFile)
if os.IsNotExist(err) == false {
yamlContents := map[interface{}]interface{}{}
err = yamlutil.ReadYamlFromFile(requirementsFile, yamlContents)
if err != nil {
log.Fatalf("Error parsing %s: %v", requirementsFile, err)
}
if dependencies, ok := yamlContents["dependencies"]; ok {
if dependenciesArr, ok := dependencies.([]interface{}); ok {
for _, dependency := range dependenciesArr {
if dependencyMap, ok := dependency.(map[interface{}]interface{}); ok {
values = append(values, []string{
dependencyMap["name"].(string),
dependencyMap["version"].(string),
dependencyMap["repository"].(string),
})
}
}
}
}
}
log.PrintTable(headerColumnNames, values)
}
// RunListSync runs the list sync command logic
View
@@ -6,6 +6,8 @@ import (
"strconv"
"strings"
helmClient "github.com/covexo/devspace/pkg/devspace/clients/helm"
"github.com/covexo/devspace/pkg/devspace/clients/kubectl"
"github.com/covexo/devspace/pkg/devspace/config/configutil"
"github.com/covexo/devspace/pkg/devspace/config/v1"
"github.com/covexo/devspace/pkg/util/log"
@@ -162,6 +164,23 @@ func (cmd *RemoveCmd) RunRemovePackage(cobraCmd *cobra.Command, args []string) {
}
// Rebuild dependencies
kubectl, err := kubectl.NewClient()
if err != nil {
log.Fatalf("Unable to create new kubectl client: %v", err)
}
helm, err := helmClient.NewClient(kubectl, false)
if err != nil {
log.Fatalf("Error initializing helm client: %v", err)
}
log.StartWait("Update chart dependencies")
err = helm.UpdateDependencies(filepath.Join(cwd, "chart"))
log.StopWait()
if err != nil {
log.Fatal(err)
}
break
}
@@ -754,6 +754,18 @@ func (helmClientWrapper *HelmClientWrapper) BuildDependencies(chartPath string)
return man.Build()
}
// UpdateDependencies updates the dependencies
func (helmClientWrapper *HelmClientWrapper) UpdateDependencies(chartPath string) error {
man := &helmdownloader.Manager{
Out: ioutil.Discard,
ChartPath: chartPath,
HelmHome: helmClientWrapper.Settings.Home,
Getters: getter.All(*helmClientWrapper.Settings),
}
return man.Update()
}
// DeleteRelease deletes a helm release and optionally purges it
func (helmClientWrapper *HelmClientWrapper) DeleteRelease(releaseName string, purge bool) (*rls.UninstallReleaseResponse, error) {
return helmClientWrapper.Client.DeleteRelease(releaseName, k8shelm.DeletePurge(purge))
View
@@ -181,6 +181,10 @@ func PrintTable(header []string, values [][]string) {
Write("\n")
if len(values) == 0 {
Write(" No entries found\n")
}
// Print Values
for _, v := range values {
for key, value := range v {

0 comments on commit 3a036dc

Please sign in to comment.