Skip to content

Commit

Permalink
left-pad helm chart filenames with 0s to fix sorting
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Lavery <[email protected]>
  • Loading branch information
laverya committed Feb 21, 2024
1 parent 76e3ce7 commit 23fd02e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/k0s/v1beta1/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type Chart struct {

// ManifestFileName returns filename to use for the crd manifest
func (c Chart) ManifestFileName() string {
return fmt.Sprintf("%d_helm_extension_%s.yaml", c.Order, c.Name)
return fmt.Sprintf("%9d_helm_extension_%s.yaml", c.Order, c.Name)
}

// Validate performs validation
Expand Down
14 changes: 11 additions & 3 deletions pkg/apis/k0s/v1beta1/extenstions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,17 @@ func TestValidation(t *testing.T) {
TargetNS: "default",
Order: 2,
}
assert.Equal(t, chart.ManifestFileName(), "0_helm_extension_release.yaml")
assert.Equal(t, chart1.ManifestFileName(), "1_helm_extension_release.yaml")
assert.Equal(t, chart2.ManifestFileName(), "2_helm_extension_release.yaml")

chart20 := Chart{
Name: "release",
ChartName: "k0s/chart",
TargetNS: "default",
Order: 20,
}
assert.Equal(t, chart.ManifestFileName(), "000000000_helm_extension_release.yaml")
assert.Equal(t, chart1.ManifestFileName(), "000000001_helm_extension_release.yaml")
assert.Equal(t, chart2.ManifestFileName(), "000000002_helm_extension_release.yaml")
assert.Equal(t, chart20.ManifestFileName(), "000000020_helm_extension_release.yaml")
})

}

0 comments on commit 23fd02e

Please sign in to comment.