From 843b1a536ee45afa2b9466afcc16d591949c636d Mon Sep 17 00:00:00 2001 From: Dex Date: Tue, 21 Aug 2018 08:33:40 -0700 Subject: [PATCH] roll back rm state changes, the logic is a little wrong What I Did ------------ roll back rm state changes, the logic is a little wrong How I Did it ------------ - remove an if os.Getenv check - clean up ExitWithWarn, no messaging about error logs or antyhing - Improve prompt for "start from scratch" so it doesn't put the cursor on the next line How to verify it ------------ `ship init ...; ship init ...;`, see state warning Description for the Changelog ------------ None, this was a regression since 0.13.2 --- Makefile | 6 +----- integration/init_app/integration_test.go | 10 +++++----- pkg/ship/exit.go | 21 ++++++++------------- pkg/ship/kustomize.go | 12 ++++++------ pkg/ship/ship.go | 1 - 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index ae2e83852..3b470e7e8 100644 --- a/Makefile +++ b/Makefile @@ -237,11 +237,7 @@ bin/ship: $(FULLSRC) # tests base "ship" cli integration-test: - ginkgo -p -stream integration/base - -# tests "ship kustomize" -integration-test-update: - ginkgo -p -stream integration/update + ginkgo -p -stream -r integration goreleaser: .state/goreleaser diff --git a/integration/init_app/integration_test.go b/integration/init_app/integration_test.go index 4cc242322..6143e48cd 100644 --- a/integration/init_app/integration_test.go +++ b/integration/init_app/integration_test.go @@ -87,13 +87,13 @@ var _ = Describe("ship init replicated.app/...", func() { testMetadata = readMetadata(testPath) // if a token is provided, try to ensure the release matches what we have here in the repo - - if vendorToken != "" { - channelName := fmt.Sprintf("integration replicated.app %s", filepath.Base(testPath)) - installationID = createRelease(vendorEndpoint, vendorToken, testInputPath, testMetadata, channelName) + if vendorToken == "" { + Fail("Please set SHIP_INTEGRATION_VENDOR_TOKEN to run the init_app test suite") } - close(done) + channelName := fmt.Sprintf("integration replicated.app %s", filepath.Base(testPath)) + installationID = createRelease(vendorEndpoint, vendorToken, testInputPath, testMetadata, channelName) + close(done) }, 20) AfterEach(func() { diff --git a/pkg/ship/exit.go b/pkg/ship/exit.go index 73e25a855..1dede9170 100644 --- a/pkg/ship/exit.go +++ b/pkg/ship/exit.go @@ -12,11 +12,16 @@ import ( // ExitWithError can be called if something goes wrong to print some friendly output func (s *Ship) ExitWithError(err error) { - s.printAndLogError(err, s.UI.Error) + if s.Viper.GetString("log-level") == "debug" { + s.UI.Error(fmt.Sprintf("There was an unexpected error! %+v", err)) + } else { + s.UI.Error(fmt.Sprintf("There was an unexpected error! %v", err)) + } + level.Warn(s.Logger).Log("event", "exit.withErr", "errorWithStack", fmt.Sprintf("%+v", err)) + s.UI.Output("") time.Sleep(100 * time.Millisecond) // hack, need to wait for flush output from above s.preserveDebugLogsOrRequestReRun() - // we want to avoid exiting in certain integration testing scenarios if !s.Viper.GetBool("no-os-exit") { os.Exit(1) } @@ -24,20 +29,10 @@ func (s *Ship) ExitWithError(err error) { // ExitWithWarn can be called if something goes wrong to print some friendly output func (s *Ship) ExitWithWarn(err error) { - s.printAndLogError(err, s.UI.Warn) + s.UI.Warn(fmt.Sprintf("%v", err)) os.Exit(1) } -func (s *Ship) printAndLogError(err error, uiOutput func(string)) { - if s.Viper.GetString("log-level") == "debug" { - uiOutput(fmt.Sprintf("There was an unexpected error! %+v", err)) - } else { - uiOutput(fmt.Sprintf("There was an unexpected error! %v", err)) - } - level.Warn(s.Logger).Log("event", "exit.withErr", "errorWithStack", fmt.Sprintf("%+v", err)) - s.UI.Output("") -} - func (s *Ship) preserveDebugLogsOrRequestReRun() { debugLogFile := path.Join(constants.ShipPathInternalLog) // make sure it exists diff --git a/pkg/ship/kustomize.go b/pkg/ship/kustomize.go index 25277b765..53ff7ab07 100644 --- a/pkg/ship/kustomize.go +++ b/pkg/ship/kustomize.go @@ -6,8 +6,6 @@ import ( "strings" - "os" - "fmt" "github.com/go-kit/kit/log" @@ -146,13 +144,15 @@ func (s *Ship) Init(ctx context.Context) error { } // does a state file exist on disk? - if s.stateFileExists(ctx) && os.Getenv("RM_STATE") != "" { + if s.stateFileExists(ctx) { debug.Log("event", "state.exists") - useUpdate, err := s.UI.Ask(` + s.UI.Warn(` An existing .ship directory was found. If you are trying to update this application, run "ship update". -Continuing will delete this state, would you like to continue? There is no undo. (y/N) -`) +Continuing will delete this state, would you like to continue? There is no undo.`) + + useUpdate, err := s.UI.Ask(` + Start from scratch? (y/N): `) if err != nil { return err } diff --git a/pkg/ship/ship.go b/pkg/ship/ship.go index cc821dab1..95e3be113 100644 --- a/pkg/ship/ship.go +++ b/pkg/ship/ship.go @@ -207,4 +207,3 @@ func (s *Ship) execute(ctx context.Context, release *api.Release, selector *repl return result } } -