-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embed Helm chart templates in CLI (#757)
- Loading branch information
1 parent
7788630
commit eb86243
Showing
10 changed files
with
135 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package charts | ||
|
||
import "embed" | ||
|
||
// ConsulHelmChart embeds the Consul Helm Chart files into an exported variable from this package. Changes to the chart | ||
// files referenced below will be reflected in the embedded templates in the CLI at CLI compile time. | ||
// | ||
// This is currently only meant to be used by the consul-k8s CLI within this repository. Importing this package from the | ||
// CLI allows us to embed the templates at compilation time. Since this is in a monorepo, we can directly reference this | ||
// charts module as relative to the CLI module (with a replace directive), which allows us to not need to bump the | ||
// charts module dependency manually or as part of a Makefile. | ||
// | ||
// The embed directive does not include files with underscores unless explicitly listed, which is why _helpers.tpl is | ||
// explicitly embedded. | ||
//go:embed consul/Chart.yaml consul/values.yaml consul/templates consul/templates/_helpers.tpl | ||
var ConsulHelmChart embed.FS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/hashicorp/consul-k8s/charts | ||
|
||
go 1.16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
chart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
helpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package common | ||
|
||
import ( | ||
"embed" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
//go:embed fixtures/consul/* fixtures/consul/templates/_helpers.tpl | ||
var testChart embed.FS | ||
|
||
func TestReadChartFiles(t *testing.T) { | ||
files, err := ReadChartFiles(testChart, "fixtures/consul") | ||
require.NoError(t, err) | ||
var foundChart, foundValues, foundTemplate, foundHelper bool | ||
for _, f := range files { | ||
if f.Name == "Chart.yaml" { | ||
require.Equal(t, "chart", string(f.Data)) | ||
foundChart = true | ||
} | ||
if f.Name == "values.yaml" { | ||
require.Equal(t, "values", string(f.Data)) | ||
foundValues = true | ||
} | ||
if f.Name == "templates/foo.yaml" { | ||
require.Equal(t, "foo", string(f.Data)) | ||
foundTemplate = true | ||
} | ||
if f.Name == "templates/_helpers.tpl" { | ||
require.Equal(t, "helpers", string(f.Data)) | ||
foundHelper = true | ||
} | ||
} | ||
require.True(t, foundChart) | ||
require.True(t, foundValues) | ||
require.True(t, foundTemplate) | ||
require.True(t, foundHelper) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters