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

Refactor Helm template file writing logic #385

Merged
merged 23 commits into from
Aug 20, 2018
Merged

Refactor Helm template file writing logic #385

merged 23 commits into from
Aug 20, 2018

Conversation

ebramanti
Copy link
Contributor

@ebramanti ebramanti commented Aug 17, 2018

What I Did

Fixes #373 by refactoring how we write a rendered Helm asset to its destination.

How I Did it

  • Create base destination directory before renaming rendered folders
  • Unify app/init file-writing logic by refactoring to use rootFs
    • app command now removes nested helm template chart dir, writes rendered templates in dest root
  • Fix noconfig.go to properly pass Root parameter
  • Add additional integration test for Helm charts with sub-charts
  • Improve messaging and errors around templating

How to verify it

Unit and integration tests were updated to verify that this issue is addressed.

Description for the Changelog

  • Helm asset rendering now writes base destination directory

Picture of a Boat (not required but encouraged)

- Fix #373 by creating base destination directory
- Unify app/init file-writing logic
@ebramanti ebramanti requested review from laverya and dexhorthy August 17, 2018 00:13
@ebramanti ebramanti added the wip Work in progress label Aug 17, 2018
@ebramanti ebramanti removed the wip Work in progress label Aug 17, 2018
@@ -19,7 +19,7 @@ const ReleasePath = ".ship/release.yml"
const KustomizeHelmPath = "chart"

// RenderedHelmTempPath is the path where the `helm template` command writes to
const RenderedHelmTempPath = ".ship/tmp-rendered"
const RenderedHelmTempPath = "tmp-rendered"
Copy link
Member

Choose a reason for hiding this comment

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

why is this no longer in .ship? I think that's where we're putting all of our temp directories

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@laverya Change of plans on this because of rootFs, to be consistent in the filesystem instance we use we are writing them to the Lifecycle Root and then cleaning up after ourselves.

Copy link
Member

Choose a reason for hiding this comment

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

Can you remind me why we did this? Is this an issue with moving things in/out of rootFs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dexhorthy We did this because of how BasePathFs works with TempDirs. We would have to use 2 FS' (one for temporary, one for root) to manage this

@@ -1,3 +1,3 @@
disable_online: true

skip_cleanup: true
skip_cleanup: false
Copy link
Member

Choose a reason for hiding this comment

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

whoops, my bad

@@ -87,7 +87,7 @@ func (f *ClientFetcher) FetchChart(
}

// find the path that the chart was fetched to
chartDir, err := util.FindOnlySubdir(checkoutDir, f.FS)
chartDir, err := util.FindOnlySubdir(checkoutDir, f.FS.Fs)
Copy link
Member

Choose a reason for hiding this comment

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

holy mother of stutter
(unavoidable though)

return path.Join(constants.RenderedHelmTempPath, meta.HelmChartMetadata.Name), nil
}

return util.FindOnlySubdir(constants.RenderedHelmTempPath, rootFs.Fs)
Copy link
Member

Choose a reason for hiding this comment

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

) error {
debug := level.Debug(log.With(f.Logger, "method", "cleanUpAndOutputRenderedFiles"))

subChartsDirName := "charts"
Copy link
Member

Choose a reason for hiding this comment

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

seems like we're using a lot of constants/paths that are pretty ship init <chart> specific

Copy link
Member

Choose a reason for hiding this comment

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

I checked out the changes to integration test expected and they look good though. I like that we're stripping off templates/ everywhere now and just dropping the rendered stuff at Dest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dexhorthy This is no longer ship init-specific, I unified the logic for helm templating

@@ -138,10 +140,15 @@ func TestForkTemplater(t *testing.T) {
mockCommands.EXPECT().DependencyUpdate(chartRoot).Return(nil)
mockCommands.EXPECT().Template(chartRoot, templateArgs).Return(nil)

mockFolderPathToCreate := path.Join(constants.RenderedHelmTempPath, expectedChannelName, "templates")
if err := mockFs.MkdirAll(mockFolderPathToCreate, 0755); err != nil {
req.Error(err, "failed to make temp dir")
Copy link
Member

Choose a reason for hiding this comment

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

req.Error asserts that an error is present. I think you want req.NoError

Copy link
Member

Choose a reason for hiding this comment

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

You can also skip the if, require will essentially panic and abort the test if the assertion fails

@@ -20,14 +20,17 @@ func (f *Fs) TempDir(prefix, name string) (string, error) {
}

// NewRootFS initializes a Fs struct with a base path of root
func NewRootFS(root string) Fs {
func NewRootFS(fs afero.Afero, root string) Fs {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -396,7 +396,7 @@ func (r *Resolver) fetchUnpack(chartRef, repoURL, version, dest, home string) (s
return out, err
}

subdir, err := util.FindOnlySubdir(tmpDest, r.FS)
subdir, err := util.FindOnlySubdir(tmpDest, r.FS.Fs)
Copy link
Member

Choose a reason for hiding this comment

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

it seems a little strange to me that we strip off the fs here, just to make a new Afero with it down below. Why not just pass through the Afero instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how it was originally, but it seemed weird having to initialize a new afero.Afero in some cases.

Copy link
Contributor Author

@ebramanti ebramanti Aug 20, 2018

Choose a reason for hiding this comment

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

I'm going to put it back

Copy link
Member

@dexhorthy dexhorthy left a comment

Choose a reason for hiding this comment

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

approved but a few small things to tweak

@ebramanti ebramanti merged commit bb62a7a into replicatedhq:master Aug 20, 2018
@ebramanti ebramanti deleted the helm-template-dest-directory branch August 20, 2018 17:05
ebramanti added a commit that referenced this pull request Aug 20, 2018
ebramanti added a commit that referenced this pull request Aug 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants