From 23fd02efefd3c027fab7a6cbd5d73b1faf05efe1 Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Wed, 21 Feb 2024 15:55:45 -0500 Subject: [PATCH] left-pad helm chart filenames with 0s to fix sorting Signed-off-by: Andrew Lavery --- pkg/apis/k0s/v1beta1/extensions.go | 2 +- pkg/apis/k0s/v1beta1/extenstions_test.go | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/apis/k0s/v1beta1/extensions.go b/pkg/apis/k0s/v1beta1/extensions.go index 0ef163466fe4..598afb1ac317 100644 --- a/pkg/apis/k0s/v1beta1/extensions.go +++ b/pkg/apis/k0s/v1beta1/extensions.go @@ -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 diff --git a/pkg/apis/k0s/v1beta1/extenstions_test.go b/pkg/apis/k0s/v1beta1/extenstions_test.go index 752c773e22bc..90d46d9416ac 100644 --- a/pkg/apis/k0s/v1beta1/extenstions_test.go +++ b/pkg/apis/k0s/v1beta1/extenstions_test.go @@ -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") }) }