Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
roll back rm state changes, the logic is a little wrong
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dexhorthy committed Aug 21, 2018
1 parent 883741e commit 843b1a5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions integration/init_app/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
21 changes: 8 additions & 13 deletions pkg/ship/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,27 @@ 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)
}
}

// 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
Expand Down
12 changes: 6 additions & 6 deletions pkg/ship/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (

"strings"

"os"

"fmt"

"github.com/go-kit/kit/log"
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion pkg/ship/ship.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,3 @@ func (s *Ship) execute(ctx context.Context, release *api.Release, selector *repl
return result
}
}

0 comments on commit 843b1a5

Please sign in to comment.