-
Notifications
You must be signed in to change notification settings - Fork 70
Refactor Helm template file writing logic #385
Refactor Helm template file writing logic #385
Conversation
- Fix #373 by creating base destination directory - Unify app/init file-writing logic
@@ -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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 TempDir
s. 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops, my bad
pkg/lifecycle/render/helm/fetch.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#392 (comment)
lol
) error { | ||
debug := level.Debug(log.With(f.Logger, "method", "cleanUpAndOutputRenderedFiles")) | ||
|
||
subChartsDirName := "charts" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
pkg/specs/chart.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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
This reverts commit bb62a7a.
This reverts commit 4cc5ccb.
What I Did
Fixes #373 by refactoring how we write a rendered Helm asset to its destination.
How I Did it
app
command now removes nested helm template chart dir, writes rendered templates in dest rootnoconfig.go
to properly pass Root parameterHow to verify it
Unit and integration tests were updated to verify that this issue is addressed.
Description for the Changelog
Picture of a Boat (not required but encouraged)