Skip to content

Commit

Permalink
Don't overwrite kdk config on restart
Browse files Browse the repository at this point in the history
- Add `force` param to Destroy method to avoid prompting user during
  restart
  • Loading branch information
Ryan Luckie authored and rtluckie committed Feb 28, 2019
1 parent e73f166 commit bf203db
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cmd/kdk/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var destroyCmd = &cobra.Command{
Short: "Destroy the running KDK container",
Long: `Destroy the running KDK container`,
Run: func(cmd *cobra.Command, args []string) {
kdk.Destroy(CurrentKdkEnvConfig)
kdk.Destroy(CurrentKdkEnvConfig, false)
},
}

Expand Down
22 changes: 12 additions & 10 deletions pkg/kdk/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
log "github.com/sirupsen/logrus"
)

func Destroy(cfg KdkEnvConfig) error {
func Destroy(cfg KdkEnvConfig, force bool) error {

var containerIds []string

Expand All @@ -42,15 +42,17 @@ func Destroy(cfg KdkEnvConfig) error {
if len(containerIds) > 0 {
log.Info("Destroying KDK container(s)...")
for _, containerId := range containerIds {
fmt.Printf("Delete KDK container [%s][%v]\n", cfg.ConfigFile.AppConfig.Name, containerId[:8])
prmpt := prompt.Prompt{
Text: "Continue? [y/n] ",
Loop: true,
Validate: prompt.ValidateYorN,
}
if result, err := prmpt.Run(); err != nil || result == "n" {
log.Error("KDK container deletion canceled or invalid input.")
return nil
if !force {
fmt.Printf("Delete KDK container [%s][%v]\n", cfg.ConfigFile.AppConfig.Name, containerId[:8])
prmpt := prompt.Prompt{
Text: "Continue? [y/n] ",
Loop: true,
Validate: prompt.ValidateYorN,
}
if result, err := prmpt.Run(); err != nil || result == "n" {
log.Error("KDK container deletion canceled or invalid input.")
return nil
}
}
if err := cfg.DockerClient.ContainerRemove(cfg.Ctx, containerId, types.ContainerRemoveOptions{Force: true}); err != nil {
log.WithField("error", err).Fatal("Failed to remove KDK container")
Expand Down
12 changes: 1 addition & 11 deletions pkg/kdk/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
package kdk

import (
"github.com/ghodss/yaml"
log "github.com/sirupsen/logrus"
"io/ioutil"
"strings"
)

Expand All @@ -32,20 +30,12 @@ func Restart(cfg KdkEnvConfig) {
}

// Destroy running KDK container
Destroy(cfg)
Destroy(cfg, true)

// Save config with snapshot image tag
cfg.ConfigFile.AppConfig.ImageTag = strings.Split(snapshotName, ":")[1]
cfg.ConfigFile.ContainerConfig.Image = snapshotName
y, err := yaml.Marshal(cfg.ConfigFile)
if err != nil {
log.WithField("error", err).Error("Failed to create YAML string of configuration")
}

err = ioutil.WriteFile(cfg.ConfigPath(), y, 0600)
if err != nil {
log.WithField("error", err).Error("Failed to write new config file")
}
// Start KDK container with snapshot image
cfg.Start()
log.Info("KDK container restarted")
Expand Down
1 change: 0 additions & 1 deletion pkg/kdk/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func WarnIfUpdateAvailable(cfg *KdkEnvConfig) {
log.Warn("Upgrade Available\n" + strings.Join([]string{
"***************************************",
"Some KDK components are out of date.",
"It is safe to ignore updates if you are using a custom image (from snapshot or restart).",
" Latest Version: " + latestReleaseVersion,
" Binary Version: " + Version,
" Image Tag: " + cfg.ConfigFile.AppConfig.ImageTag,
Expand Down

0 comments on commit bf203db

Please sign in to comment.