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

Ship should show human readable messages when running in headless #289

Merged
merged 2 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/lifecycle/daemon/headless/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ func (d *HeadlessDaemon) HeadlessResolve(ctx context.Context, release *api.Relea
}

func (d *HeadlessDaemon) SetProgress(progress daemontypes.Progress) {
d.UI.Output(progress.Detail)
if progress.Type == "string" {
d.UI.Output(progress.Detail)
}
}

func (d *HeadlessDaemon) ClearProgress() {}
2 changes: 2 additions & 0 deletions pkg/lifecycle/helmValues/helmValues.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func (h *helmValues) Execute(ctx context.Context, release *api.Release, step *ap
return errors.Wrap(err, "read file values.yaml")
}

h.Daemon.SetProgress(daemontypes.StringProgress("helmValues", "generating installable application manifests"))

h.Daemon.PushHelmValuesStep(ctx, daemontypes.HelmValues{
Values: string(bytes),
}, daemon.HelmValuesActions())
Expand Down
23 changes: 10 additions & 13 deletions pkg/lifecycle/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ import (
)

var (
ProgressLoad = daemontypes.StringProgress("render", "load")
ProgressResolve = daemontypes.StringProgress("render", "resolve")
ProgressBuild = daemontypes.StringProgress("render", "build")
ProgressBackup = daemontypes.StringProgress("render", "backup")
ProgressExecute = daemontypes.StringProgress("render", "execute")
ProgressCommit = daemontypes.StringProgress("render", "commit")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opted to merge these into a few human-readable messages. However, they have been preserved through debug logs below!

ProgressRead = daemontypes.StringProgress("render", "reading application release")
ProgressRender = daemontypes.StringProgress("render", "rendering assets and configuration values")
)

// A renderer takes a resolved spec, collects config values, and renders assets
Expand All @@ -48,34 +44,35 @@ func (r *renderer) Execute(ctx context.Context, release *api.Release, step *api.
debug := level.Debug(log.With(r.Logger, "step.type", "render"))
debug.Log("event", "step.execute")

r.StatusReceiver.SetProgress(ProgressLoad)
debug.Log("event", "try.load")
previousState, err := r.StateManager.TryLoad()
if err != nil {
return err
}

r.StatusReceiver.SetProgress(ProgressResolve)
r.StatusReceiver.SetProgress(ProgressRead)

debug.Log("event", "resolve.config")
templateContext, err := r.ConfigResolver.ResolveConfig(ctx, release, previousState.CurrentConfig())
if err != nil {
return errors.Wrap(err, "resolve config")
}

r.StatusReceiver.SetProgress(ProgressRender)

debug.Log("event", "render.plan")
r.StatusReceiver.SetProgress(ProgressBuild)
pln, err := r.Planner.Build(release.Spec.Assets.V1, release.Spec.Config.V1, release.Metadata, templateContext)
if err != nil {
return errors.Wrap(err, "build plan")

}

debug.Log("event", "backup.start")
r.StatusReceiver.SetProgress(ProgressBackup)
err = r.backupIfPresent(constants.InstallerPrefixPath)
if err != nil {
return errors.Wrapf(err, "backup existing install directory %s", constants.InstallerPrefixPath)
}

r.StatusReceiver.SetProgress(ProgressExecute)
debug.Log("event", "execute.plan")
r.StatusReceiver.SetStepName(ctx, daemontypes.StepNameConfirm)
err = r.Planner.Execute(ctx, pln)
if err != nil {
Expand All @@ -97,7 +94,7 @@ func (r *renderer) Execute(ctx context.Context, release *api.Release, step *api.
stateTemplateContext = templateContext
}

r.StatusReceiver.SetProgress(ProgressCommit)
debug.Log("event", "commit")
if err := r.StateManager.SerializeConfig(release.Spec.Assets.V1, release.Metadata, stateTemplateContext); err != nil {
return errors.Wrap(err, "serialize state")
}
Expand Down
8 changes: 2 additions & 6 deletions pkg/lifecycle/render/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,9 @@ func TestRender(t *testing.T) {
V: viper.New(),
}

prog := mockDaemon.EXPECT().SetProgress(ProgressLoad)
prog = mockDaemon.EXPECT().SetProgress(ProgressResolve).After(prog)
prog = mockDaemon.EXPECT().SetProgress(ProgressBuild).After(prog)
prog = mockDaemon.EXPECT().SetProgress(ProgressBackup).After(prog)
prog = mockDaemon.EXPECT().SetProgress(ProgressExecute).After(prog)
prog := mockDaemon.EXPECT().SetProgress(ProgressRead)
prog = mockDaemon.EXPECT().SetProgress(ProgressRender).After(prog)
prog = mockDaemon.EXPECT().SetStepName(ctx, daemontypes.StepNameConfirm).After(prog)
prog = mockDaemon.EXPECT().SetProgress(ProgressCommit).After(prog)
mockDaemon.EXPECT().ClearProgress().After(prog)

renderer.StatusReceiver = mockDaemon
Expand Down
4 changes: 4 additions & 0 deletions pkg/ship/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/replicatedhq/libyaml"
"github.com/replicatedhq/ship/pkg/api"
"github.com/replicatedhq/ship/pkg/constants"
"github.com/replicatedhq/ship/pkg/lifecycle/daemon/daemontypes"
"github.com/replicatedhq/ship/pkg/state"
)

Expand Down Expand Up @@ -56,6 +57,8 @@ func (s *Ship) Update(ctx context.Context) error {
// does a state file exist on disk?
existingState, err := s.State.TryLoad()

s.Daemon.SetProgress(daemontypes.StringProgress("kustomize", `loading state from `+constants.StatePath))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinherro should this be the viper flag, not the constant?


if _, noExistingState := existingState.(state.Empty); noExistingState {
debug.Log("event", "state.missing")
return errors.New(`No state file found at ` + s.Viper.GetString("state-file") + `, please run "ship init"`)
Expand All @@ -68,6 +71,7 @@ func (s *Ship) Update(ctx context.Context) error {
}

debug.Log("event", "fetch latest chart")
s.Daemon.SetProgress(daemontypes.StringProgress("kustomize", `downloading latest from upstream `+helmChartPath))
helmChartMetadata, err := s.Resolver.ResolveChartMetadata(context.Background(), string(helmChartPath))
if err != nil {
return errors.Wrapf(err, "resolve helm chart metadata for %s", helmChartPath)
Expand Down