Skip to content

Commit

Permalink
Merge pull request #8 from vmware-labs/appversion
Browse files Browse the repository at this point in the history
Added appVersion to lock file
  • Loading branch information
mpermar authored Aug 24, 2023
2 parents 1439dee + 460245c commit 7bf72d2
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 18 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ cat examples/mariadb/Images.lock
```

```yaml
apiversion: v0
apiVersion: v0
kind: ImagesLock
metadata:
generatedAt: "2023-08-04T13:36:09.398772Z"
Expand Down Expand Up @@ -225,7 +225,7 @@ helm dt images lock ../charts/jenkins --platform linux/amd64
If we now look at generated `Images.lock` we will notice that it contains only `linux/amd64` digests:

```yaml
apiversion: v0
apiVersion: v0
kind: ImagesLock
metadata:
generatedAt: "2023-08-04T14:24:18.515082Z"
Expand Down Expand Up @@ -384,7 +384,7 @@ It is also possible to get a YAML dump if the `Images.lock` in case you need to

```sh
helm dt info --yaml wordpress-16.1.24.wrap.tgz
apiversion: v0
apiVersion: v0
kind: ImagesLock
metadata:
generatedAt: "2023-08-18T12:52:55.824345304Z"
Expand Down Expand Up @@ -432,4 +432,4 @@ So as community adopts this new proposal and this plugin becomes more mature we

**What about chart-syncer? Will it continue to work?**

Yes, still support [chart-syncer](https://github.com/bitnami-labs/charts-syncer) and we don't have any short-term plans right now about it. But as this tool gains adoption, it becomes natural to think that it should be fairly straightforward to implement Helm chart syncing on top of it.
Yes, still support [chart-syncer](https://github.com/bitnami-labs/charts-syncer) and we don't have any short-term plans right now about it. But as this tool gains adoption, it becomes natural to think that it should be fairly straightforward to implement Helm chart syncing on top of it.
1 change: 1 addition & 0 deletions cmd/dt/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func newInfoCmd() *cobra.Command {
_ = l.Section("Wrap Information", func(l log.SectionLogger) error {
l.Printf("Chart: %s", lock.Chart.Name)
l.Printf("Version: %s", lock.Chart.Version)
l.Printf("App Version: %s", lock.Chart.AppVersion)
_ = l.Section("Metadata", func(l log.SectionLogger) error {
for k, v := range lock.Metadata {
l.Printf("- %s: %s", k, v)
Expand Down
7 changes: 4 additions & 3 deletions cmd/dt/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (suite *CmdSuite) TestInfoCommand() {
scenarioName := "complete-chart"
chartName := "test"
version := "1.0.0"
appVersion := "2.3.4"
scenarioDir := fmt.Sprintf("../../testdata/scenarios/%s", scenarioName)

dest := sb.TempFile()
Expand All @@ -35,7 +36,7 @@ func (suite *CmdSuite) TestInfoCommand() {
require.NoError(err)

require.NoError(tu.RenderScenario(scenarioDir, dest,
map[string]interface{}{"ServerURL": serverURL, "Images": images, "Name": chartName, "Version": version, "RepositoryURL": serverURL},
map[string]interface{}{"ServerURL": serverURL, "Images": images, "Name": chartName, "Version": version, "AppVersion": appVersion, "RepositoryURL": serverURL},
))

tarFile := sb.TempFile()
Expand All @@ -56,7 +57,7 @@ func (suite *CmdSuite) TestInfoCommand() {
imageURL := fmt.Sprintf("%s/%s:%s", serverURL, imageName, imageTag)

imageEntryRe := fmt.Sprintf(`%s\s+\(%s\)`, imageURL, strings.Join(archList, ", "))
assert.Regexp(fmt.Sprintf(`(?s).*Wrap Information.*Chart:.*%s\s*.*Version:.*%s.*Metadata.*Images.*%s`, chartName, version, imageEntryRe), res.stdout)
assert.Regexp(fmt.Sprintf(`(?s).*Wrap Information.*Chart:.*%s\s*.*Version:.*%s.*%s\s*.*Metadata.*Images.*%s`, chartName, version, appVersion, imageEntryRe), res.stdout)
})
t.Run("Detailed info", func(t *testing.T) {
res := dt("info", "--detailed", inputChart)
Expand All @@ -73,7 +74,7 @@ func (suite *CmdSuite) TestInfoCommand() {
res := dt("info", "--yaml", inputChart)
res.AssertSuccess(t)
data, err := tu.RenderTemplateFile(filepath.Join(scenarioDir, "imagelock.partial.tmpl"),
map[string]interface{}{"ServerURL": serverURL, "Images": images, "Name": chartName, "Version": version},
map[string]interface{}{"ServerURL": serverURL, "Images": images, "Name": chartName, "Version": version, "AppVersion": appVersion},
)
require.NoError(err)

Expand Down
8 changes: 5 additions & 3 deletions imagelock/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ const DefaultAnnotationsKey = "images"

// ImagesLock represents the lock file containing information about the included images.
type ImagesLock struct {
APIVersion string // The version of the API used for the lock file.
APIVersion string `yaml:"apiVersion"` // The version of the API used for the lock file.
Kind string // The type of object represented by the lock file.
Metadata map[string]string // Additional metadata associated with the lock file.

Chart struct {
Name string // The name of the chart.
Version string // The version of the chart.
Name string // The name of the chart.
Version string // The version of the chart.
AppVersion string `yaml:"appVersion"` // The version of the app contained in the chart
} // Information about the chart associated with the lock file.

Images ImageList // List of included images
Expand Down Expand Up @@ -130,6 +131,7 @@ func GenerateFromChart(chartPath string, opts ...Option) (*ImagesLock, error) {

imgLock.Chart.Name = chart.Name()
imgLock.Chart.Version = chart.Metadata.Version
imgLock.Chart.AppVersion = chart.Metadata.AppVersion

if err := populateImagesFromChart(imgLock, chart, cfg); err != nil {
return nil, err
Expand Down
11 changes: 8 additions & 3 deletions imagelock/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (suite *ImageLockTestSuite) TestGenerateFromChart() {

chartName := "wordpress"
chartVersion := "1.0.0"
appVersion := "6.7.8"
serverURL := suite.testServer.ServerURL

sampleImages, err := suite.testServer.LoadImagesFromFile("../testdata/images.json")
Expand All @@ -149,6 +150,7 @@ func (suite *ImageLockTestSuite) TestGenerateFromChart() {

referenceLock.Chart.Name = chartName
referenceLock.Chart.Version = chartVersion
referenceLock.Chart.AppVersion = appVersion

imgs, err := suite.getCustomizedReferenceImages(referenceLock.Chart.Name,
"wordpress", "bitnami-shell", "apache-exporter")
Expand All @@ -161,7 +163,7 @@ func (suite *ImageLockTestSuite) TestGenerateFromChart() {

require.NoError(tu.RenderScenario(scenarioDir, dest,
map[string]interface{}{
"ServerURL": serverURL, "Images": imgs, "Name": chartName, "Version": chartVersion,
"ServerURL": serverURL, "Images": imgs, "Name": chartName, "Version": chartVersion, "AppVersion": appVersion,
},
))

Expand Down Expand Up @@ -244,12 +246,13 @@ func (suite *ImageLockTestSuite) TestGenerateFromChart() {
scenarioName := "custom-chart"
chartName := "test"
chartVersion := "1.0.0"
appVersion := "2.2.0"
scenarioDir := fmt.Sprintf("../testdata/scenarios/%s", scenarioName)

dest := sb.TempFile()

require.NoError(tu.RenderScenario(scenarioDir, dest,
map[string]interface{}{"ServerURL": serverURL, "Images": images, "Name": chartName, "Version": chartVersion},
map[string]interface{}{"ServerURL": serverURL, "Images": images, "Name": chartName, "Version": chartVersion, "AppVersion": appVersion},
))
chartDir := filepath.Join(dest, scenarioName)

Expand All @@ -258,6 +261,7 @@ func (suite *ImageLockTestSuite) TestGenerateFromChart() {
})
expectedLock.Chart.Name = chartName
expectedLock.Chart.Version = chartVersion
expectedLock.Chart.AppVersion = appVersion
expectedLock.Metadata["generatedAt"] = ""

lock, err := GenerateFromChart(chartDir, WithInsecure(true))
Expand Down Expand Up @@ -452,14 +456,15 @@ func (suite *ImageLockTestSuite) TestYAML() {
},
}

expected := fmt.Sprintf(`apiversion: v0
expected := fmt.Sprintf(`apiVersion: v0
kind: ImagesLock
metadata:
generatedAt: "%s"
generatedBy: Distribution Tooling for Helm
chart:
name: test
version: 1.0.0
appVersion: ""
images:
- name: test
image: ""
Expand Down
3 changes: 2 additions & 1 deletion testdata/scenarios/chart1/Images.lock.tmpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
apiversion: v0
apiVersion: v0
kind: ImagesLock
metadata:
generatedAt: "2023-07-13T16:30:33.284125307Z"
generatedBy: Distribution Tooling for Helm
chart:
name: wordpress
version: 1.0.0
appVersion: ""
images:
{{include "lock_images.partial.tmpl" . | indent 2 }}
2 changes: 1 addition & 1 deletion testdata/scenarios/complete-chart/Chart.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ annotations:
licenses: Apache-2.0
{{if .AnnotationsKey}}{{.AnnotationsKey}}{{else}}images{{end}}: |
{{- include "images.partial.tmpl" . | indent 6 }}
appVersion: 6.2.2
appVersion: {{if .AppVersion}}{{.AppVersion}}{{else}}6.2.2{{end}}
{{if .Dependencies }}
{{if gt (len .Dependencies) 0 }}
dependencies:
Expand Down
3 changes: 2 additions & 1 deletion testdata/scenarios/complete-chart/imagelock.partial.tmpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
apiversion: v0
apiVersion: v0
kind: ImagesLock
metadata:
generatedAt: "2023-07-13T16:30:33.284125307Z"
generatedBy: Distribution Tooling for Helm
chart:
name: {{.Name}}
version: 1.0.0
appVersion: {{if .AppVersion}}{{.AppVersion}}{{else}}6.2.2{{end}}
images:
{{- $p := . -}}
{{- range $idx, $elem := .Images}}
Expand Down
2 changes: 1 addition & 1 deletion testdata/scenarios/custom-chart/Chart.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ annotations:
licenses: Apache-2.0
{{if .AnnotationsKey}}{{.AnnotationsKey}}{{else}}images{{end}}: |
{{- include "images.partial.tmpl" . | indent 6 }}
appVersion: 6.2.2
appVersion: {{if .AppVersion}}{{.AppVersion}}{{else}}6.2.2{{end}}
{{if .Dependencies }}
{{if gt (len .Dependencies) 0 }}
dependencies:
Expand Down
3 changes: 2 additions & 1 deletion testdata/scenarios/custom-chart/imagelock.partial.tmpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
apiversion: v0
apiVersion: v0
kind: ImagesLock
metadata:
generatedAt: "2023-07-13T16:30:33.284125307Z"
generatedBy: Distribution Tooling for Helm
chart:
name: {{.Name}}
version: 1.0.0
appVersion: {{if .AppVersion}}{{.AppVersion}}{{else}}6.2.2{{end}}
images:
{{- $p := . -}}
{{- range $idx, $elem := .Images}}
Expand Down

0 comments on commit 7bf72d2

Please sign in to comment.