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

Commit

Permalink
correct way to persist chart url (#218)
Browse files Browse the repository at this point in the history
* correct way to persist chart url

* todo

* todo error
  • Loading branch information
kherroWisc authored Jul 31, 2018
1 parent c7c6476 commit 7460121
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
13 changes: 5 additions & 8 deletions pkg/ship/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func (s *Ship) Update(ctx context.Context) error {

// does a state file exist on disk?
existingState, err := s.State.TryLoad()
if err != nil {

if _, noExistingState := existingState.(state.Empty); noExistingState {
debug.Log("event", "state.missing")
return errors.New(`No state file found at ` + constants.StatePath + `, please run "ship init"`)
}
Expand All @@ -63,10 +64,11 @@ func (s *Ship) Update(ctx context.Context) error {

release := s.buildRelease(helmChartMetadata)

// log to compile, will remove later
// log for compile. will adjust later
debug.Log("event", "build release", "release", release)

return errors.New(`Implement me`)
// TODO IMPLEMENT
return errors.New("Not implemented")
}

func (s *Ship) Init(ctx context.Context) error {
Expand Down Expand Up @@ -104,11 +106,6 @@ func (s *Ship) Init(ctx context.Context) error {
return errors.Wrapf(err, "resolve helm metadata for %s", helmChartPath)
}

// persist after resolve as to not persist a bad chart URL
if err := s.State.BlowAwayStateAndSetChartURL(helmChartPath); err != nil {
return errors.Wrapf(err, "persist helm chart URL to %s", constants.StatePath)
}

release := s.buildRelease(helmChartMetadata)

return s.execute(ctx, release, nil, true)
Expand Down
18 changes: 6 additions & 12 deletions pkg/state/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func (s *Manager) SerializeHelmValues(values string) error {
debug.Log("event", "emptyState")
isEmpty := currentState == Empty{}
if isEmpty {
toSerialize := VersionedState{V1: &V1{HelmValues: values}}
toSerialize := VersionedState{V1: &V1{HelmValues: values,
ChartURL: s.V.GetString("chart")}}
return s.serializeAndWriteState(toSerialize)
}

Expand All @@ -60,19 +61,11 @@ func (s *Manager) SerializeHelmValues(values string) error {
return s.serializeAndWriteState(toSerialize)
}

// BlowAwayStateAndSetChartURL takes the URL of the helm chart and serializes a state file to disk
func (s *Manager) BlowAwayStateAndSetChartURL(URL string) error {
debug := level.Debug(log.With(s.Logger, "method", "BlowAwayStateAndSetChartURL"))

debug.Log("event", "serializeAndWriteState", "serialize", "helmChartURL")
toSerialize := VersionedState{V1: &V1{ChartURL: URL}}

return s.serializeAndWriteState(toSerialize)
}

// Serialize takes the application data and input params and serializes a state file to disk
func (s *Manager) Serialize(assets []api.Asset, meta api.ReleaseMetadata, templateContext map[string]interface{}) error {
toSerialize := VersionedState{V1: &V1{Config: templateContext}}
toSerialize := VersionedState{V1: &V1{
Config: templateContext,
ChartURL: s.V.GetString("chart")}}
return s.serializeAndWriteState(toSerialize)
}

Expand Down Expand Up @@ -142,6 +135,7 @@ func (m *Manager) SaveKustomize(kustomize *Kustomize) error {

newState := VersionedState{
V1: &V1{
ChartURL: m.V.GetString("chart"),
Config: state.CurrentConfig(),
Kustomize: kustomize,
},
Expand Down

0 comments on commit 7460121

Please sign in to comment.