diff --git a/cmd/kdk/destroy.go b/cmd/kdk/destroy.go index 12ba145..3ae865b 100644 --- a/cmd/kdk/destroy.go +++ b/cmd/kdk/destroy.go @@ -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) }, } diff --git a/pkg/kdk/destroy.go b/pkg/kdk/destroy.go index 10c0bab..c7c313a 100644 --- a/pkg/kdk/destroy.go +++ b/pkg/kdk/destroy.go @@ -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 @@ -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") diff --git a/pkg/kdk/restart.go b/pkg/kdk/restart.go index 6a91879..0d0ed49 100644 --- a/pkg/kdk/restart.go +++ b/pkg/kdk/restart.go @@ -15,9 +15,7 @@ package kdk import ( - "github.com/ghodss/yaml" log "github.com/sirupsen/logrus" - "io/ioutil" "strings" ) @@ -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") diff --git a/pkg/kdk/update.go b/pkg/kdk/update.go index 66d46bf..7b8212e 100644 --- a/pkg/kdk/update.go +++ b/pkg/kdk/update.go @@ -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,