fix: version path issue (#1344)
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
parent
5da9bc2c1e
commit
43fec2d599
|
|
@ -3568,7 +3568,7 @@ func (st *HelmState) getOCIChart(release *ReleaseSpec, tempDir string, helm helm
|
||||||
pathElems = append(pathElems, release.KubeContext)
|
pathElems = append(pathElems, release.KubeContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
pathElems = append(pathElems, release.Name, chartName, chartVersion)
|
pathElems = append(pathElems, release.Name, chartName, safeVersionPath(chartVersion))
|
||||||
|
|
||||||
chartPath := filepath.Join(pathElems...)
|
chartPath := filepath.Join(pathElems...)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -71,3 +72,10 @@ func getBuildDepsFlags(cpr *chartPrepareResult) []string {
|
||||||
|
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// safePath returns a clean path
|
||||||
|
func safeVersionPath(version string) string {
|
||||||
|
c := regexp.MustCompile(`=|>|<|!|\||~|\^| |,|\*`)
|
||||||
|
sp := c.ReplaceAll([]byte(version), []byte("_"))
|
||||||
|
return string(sp)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package state
|
package state
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestIsLocalChart(t *testing.T) {
|
func TestIsLocalChart(t *testing.T) {
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
|
|
@ -151,3 +153,64 @@ func TestNormalizeChart(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func TestSafeVersionPath(t *testing.T) {
|
||||||
|
testcases := []struct {
|
||||||
|
input string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
input: "=1.2.3",
|
||||||
|
expected: "_1.2.3",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: ">1.0.0",
|
||||||
|
expected: "_1.0.0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "<=2.3.4",
|
||||||
|
expected: "__2.3.4",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "!3.4.5",
|
||||||
|
expected: "_3.4.5",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "|4.5.6",
|
||||||
|
expected: "_4.5.6",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "~5.6.7",
|
||||||
|
expected: "_5.6.7",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "^6.7.8",
|
||||||
|
expected: "_6.7.8",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: " 7.8.9",
|
||||||
|
expected: "_7.8.9",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: ",9.10.11",
|
||||||
|
expected: "_9.10.11",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "<= 1.2.3, >= 1.4",
|
||||||
|
expected: "___1.2.3_____1.4",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "*",
|
||||||
|
expected: "_",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range testcases {
|
||||||
|
testcase := testcases[i]
|
||||||
|
|
||||||
|
actual := safeVersionPath(testcase.input)
|
||||||
|
|
||||||
|
if testcase.expected != actual {
|
||||||
|
t.Errorf("unexpected result: safeVersionPath(\"%s\"): expected=%v, got=%v", testcase.input, testcase.expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue