mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
fix(schema): enable $ref resolution for directory charts
Set ChartDir only for directory-based charts to enable $ref resolution in JSON schemas. Archived charts (.tgz) are loaded into memory without filesystem extraction, so $ref resolution is not supported for them. This fixes the original issue where `helm template .` and `helm install .` failed to validate schemas with relative $ref references. Fixes #31260 Signed-off-by: Benoit Tigeot <benoit.tigeot@lifen.fr>
This commit is contained in:
parent
dd0b8f40ba
commit
088959aae9
12 changed files with 61 additions and 0 deletions
|
|
@ -248,6 +248,13 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Only set ChartDir for directory-based charts to enable $ref resolution.
|
||||
// Archived charts (.tgz) are loaded into memory without filesystem extraction,
|
||||
// so $ref resolution is not supported for them.
|
||||
if fi, err := os.Stat(cp); err == nil && fi.IsDir() {
|
||||
client.ChartDir = cp
|
||||
}
|
||||
|
||||
slog.Debug("Chart path", "path", cp)
|
||||
|
||||
p := getter.All(settings)
|
||||
|
|
|
|||
|
|
@ -231,6 +231,11 @@ func TestInstall(t *testing.T) {
|
|||
cmd: "install schema testdata/testcharts/chart-with-schema-and-subchart --set lastname=doe --set subchart-with-schema.age=-25 --skip-schema-validation",
|
||||
golden: "output/schema.txt",
|
||||
},
|
||||
{
|
||||
name: "install with schema file containing $ref",
|
||||
cmd: "install reftest testdata/testcharts/chart-with-schema-ref",
|
||||
golden: "output/schema-ref.txt",
|
||||
},
|
||||
// Install deprecated chart
|
||||
{
|
||||
name: "install with warning about deprecated chart",
|
||||
|
|
|
|||
|
|
@ -166,6 +166,11 @@ func TestTemplateCmd(t *testing.T) {
|
|||
cmd: fmt.Sprintf("template '%s' -f %s/extra_values.yaml", chartPath, chartPath),
|
||||
golden: "output/template-subchart-cm-set-file.txt",
|
||||
},
|
||||
{
|
||||
name: "template with schema file containing $ref",
|
||||
cmd: "template reftest testdata/testcharts/chart-with-schema-ref",
|
||||
golden: "output/template-schema-ref.txt",
|
||||
},
|
||||
}
|
||||
runTestCmd(t, tests)
|
||||
}
|
||||
|
|
|
|||
7
pkg/cmd/testdata/output/schema-ref.txt
vendored
Normal file
7
pkg/cmd/testdata/output/schema-ref.txt
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
NAME: reftest
|
||||
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
|
||||
NAMESPACE: default
|
||||
STATUS: deployed
|
||||
REVISION: 1
|
||||
DESCRIPTION: Install complete
|
||||
TEST SUITE: None
|
||||
1
pkg/cmd/testdata/output/template-schema-ref.txt
vendored
Normal file
1
pkg/cmd/testdata/output/template-schema-ref.txt
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
8
pkg/cmd/testdata/output/upgrade-schema-ref.txt
vendored
Normal file
8
pkg/cmd/testdata/output/upgrade-schema-ref.txt
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Release "reftest" has been upgraded. Happy Helming!
|
||||
NAME: reftest
|
||||
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
|
||||
NAMESPACE: default
|
||||
STATUS: deployed
|
||||
REVISION: 2
|
||||
DESCRIPTION: Upgrade complete
|
||||
TEST SUITE: None
|
||||
3
pkg/cmd/testdata/testcharts/chart-with-schema-ref/Chart.yaml
vendored
Normal file
3
pkg/cmd/testdata/testcharts/chart-with-schema-ref/Chart.yaml
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
apiVersion: v2
|
||||
name: chart-with-schema-ref
|
||||
version: 0.1.0
|
||||
4
pkg/cmd/testdata/testcharts/chart-with-schema-ref/name.schema.json
vendored
Normal file
4
pkg/cmd/testdata/testcharts/chart-with-schema-ref/name.schema.json
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "string"
|
||||
}
|
||||
7
pkg/cmd/testdata/testcharts/chart-with-schema-ref/values.schema.json
vendored
Normal file
7
pkg/cmd/testdata/testcharts/chart-with-schema-ref/values.schema.json
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": { "$ref": "name.schema.json" }
|
||||
}
|
||||
}
|
||||
1
pkg/cmd/testdata/testcharts/chart-with-schema-ref/values.yaml
vendored
Normal file
1
pkg/cmd/testdata/testcharts/chart-with-schema-ref/values.yaml
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
name: "test"
|
||||
|
|
@ -187,6 +187,13 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|||
return err
|
||||
}
|
||||
|
||||
// Only set ChartDir for directory-based charts to enable $ref resolution.
|
||||
// Archived charts (.tgz) are loaded into memory without filesystem extraction,
|
||||
// so $ref resolution is not supported for them.
|
||||
if fi, err := os.Stat(chartPath); err == nil && fi.IsDir() {
|
||||
client.ChartDir = chartPath
|
||||
}
|
||||
|
||||
p := getter.All(settings)
|
||||
vals, err := valueOpts.MergeValues(p)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -190,6 +190,12 @@ func TestUpgradeCmd(t *testing.T) {
|
|||
golden: "output/upgrade-uninstalled-with-keep-history.txt",
|
||||
rels: []*release.Release{relWithStatusMock("funny-bunny", 2, ch, rcommon.StatusUninstalled)},
|
||||
},
|
||||
{
|
||||
name: "upgrade with schema file containing $ref",
|
||||
cmd: "upgrade reftest testdata/testcharts/chart-with-schema-ref",
|
||||
golden: "output/upgrade-schema-ref.txt",
|
||||
rels: []*release.Release{relMock("reftest", 1, ch)},
|
||||
},
|
||||
}
|
||||
runTestCmd(t, tests)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue