Skip to content

Commit

Permalink
add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Nov 30, 2018
1 parent e09e803 commit 785b047
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -57,15 +56,15 @@ func run(cmd *cobra.Command, args []string) error {

// Backup performs a backup of all releases from provided namespace
func Backup(namespace string) error {
log.Println("getting Tiller storage")
log.Println("getting tiller storage")
storage := utils.GetTillerStorage(tillerNamespace)
log.Printf("found Tiller storage: %s", storage)
log.Printf("getting releases in namespace %s", namespace)
log.Printf("found tiller storage: \"%s\"", storage)
log.Printf("getting releases in namespace \"%s\"", namespace)
inReleases, err := utils.ListReleaseNamesInNamespace(namespace)
if err != nil {
return err
}
log.Printf("found relases: %s", inReleases)
log.Printf("found relases: %s", prettyPrint(inReleases))
backupCmd := []string{
"kubectl",
"--namespace", tillerNamespace,
Expand Down Expand Up @@ -97,7 +96,7 @@ func Backup(namespace string) error {
}
os.Remove(manifestsFileName)
os.Remove(releasesFileName)
fmt.Printf("backup of namespace \"%s\" to file %s complete (found releases: %s)\n", namespace, tarGzName, strings.Replace(inReleases, ",", ", ", -1))
log.Printf("backup of namespace \"%s\" to file %s complete (found releases: %s)\n", namespace, tarGzName, prettyPrint(inReleases))
return nil
}

Expand All @@ -108,9 +107,11 @@ func Restore(namespace string) error {
releasesFileName := untarDir + "/releases"
os.RemoveAll(untarDir)
tarGzName := getTarGzFileName(namespace)
log.Printf("extracting backup from file %s", tarGzName)
if err := archiver.TarGz.Open(tarGzName, untarDir); err != nil {
return err
}
log.Println("reading backup data")
releasesToRestore, err := ioutil.ReadFile(releasesFileName)
if err != nil {
return err
Expand All @@ -120,16 +121,18 @@ func Restore(namespace string) error {
"--namespace", tillerNamespace,
"apply", "-f", manifestsFileName,
}
log.Println("applying backup data to tiller")
output := utils.Execute(restoreCmd)
fmt.Print((string)(output))
log.Print((string)(output))

label += ",STATUS=DEPLOYED"
for _, r := range strings.Split((string)(releasesToRestore), ",") {
log.Printf("restoring release \"%s\"", r)
helm_restore.Restore(r, tillerNamespace, label)
}

os.RemoveAll(untarDir)
fmt.Printf("restore file %s to namespace \"%s\" complete (found releases: %s)\n", tarGzName, namespace, strings.Replace((string)(releasesToRestore), ",", ", ", -1))
log.Printf("restore file %s to namespace \"%s\" complete (found releases: %s)\n", tarGzName, namespace, prettyPrint(releasesToRestore))
return nil
}

Expand All @@ -144,3 +147,7 @@ func getTarGzFileName(namespace string) string {

return tarGzName
}

func prettyPrint(in string) string {
return strings.Replace(in, ",", ", ", -1)
}

0 comments on commit 785b047

Please sign in to comment.