diff --git a/pkg/action/lint_test.go b/pkg/action/lint_test.go index 63b2f51ae..08329ad6c 100644 --- a/pkg/action/lint_test.go +++ b/pkg/action/lint_test.go @@ -75,6 +75,10 @@ func TestLintChart(t *testing.T) { name: "chart-with-schema-ref", chartPath: "testdata/charts/chart-with-schema-ref", }, + { + name: "archived-chart-with-schema-ref", + chartPath: "testdata/charts/chart-with-schema-ref.tgz", + }, { name: "chart-with-schema-negative", chartPath: "testdata/charts/chart-with-schema-negative", diff --git a/pkg/action/testdata/charts/chart-with-schema-ref.tgz b/pkg/action/testdata/charts/chart-with-schema-ref.tgz new file mode 100644 index 000000000..da12c8d09 Binary files /dev/null and b/pkg/action/testdata/charts/chart-with-schema-ref.tgz differ diff --git a/pkg/chart/common/util/jsonschema.go b/pkg/chart/common/util/jsonschema.go index 38ec632ae..752184c7d 100644 --- a/pkg/chart/common/util/jsonschema.go +++ b/pkg/chart/common/util/jsonschema.go @@ -86,20 +86,28 @@ func ValidateAgainstSchemaWithPath(ch chart.Charter, values map[string]any, char var absChartPath string if chartDir != "" { + var err error absChartPath, err = filepath.Abs(chartDir) - } else { - absChartPath, err = filepath.Abs(chrt.ChartFullPath()) - } - if err != nil { - return err + if err != nil { + return err + } } var sb strings.Builder if chrt.Schema() != nil { slog.Debug("chart name", "chart-name", chrt.Name()) - schemaPath := filepath.Join(absChartPath, "values.schema.json") - err = ValidateAgainstSingleSchemaWithPath(values, chrt.Schema(), schemaPath) + var schemaPath string + if absChartPath != "" { + // Use the chart directory for $ref resolution + schemaPath = filepath.Join(absChartPath, "values.schema.json") + } else { + // No chart directory (e.g., chart loaded from .tgz archive). + // Use a synthetic path - $ref resolution will not work, but main schema validation will. + schemaPath = "/values.schema.json" + } + + err := ValidateAgainstSingleSchemaWithPath(values, chrt.Schema(), schemaPath) if err != nil { fmt.Fprintf(&sb, "%s:\n", chrt.Name()) sb.WriteString(err.Error()) @@ -126,7 +134,11 @@ func ValidateAgainstSchemaWithPath(ch chart.Charter, values map[string]any, char continue } - subchartPath := filepath.Join(absChartPath, "charts", sub.Name()) + var subchartPath string + if absChartPath != "" { + subchartPath = filepath.Join(absChartPath, "charts", sub.Name()) + } + // If absChartPath is empty (archived chart), pass empty string to disable $ref resolution for subcharts too if err := ValidateAgainstSchemaWithPath(subchart, subchartValues, subchartPath); err != nil { sb.WriteString(err.Error()) } diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go index e52bfcc71..d36cd9e34 100644 --- a/pkg/cmd/install.go +++ b/pkg/cmd/install.go @@ -247,7 +247,6 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options if err != nil { return nil, err } - client.ChartDir = cp slog.Debug("Chart path", "path", cp) diff --git a/pkg/cmd/install_test.go b/pkg/cmd/install_test.go index 3a88a9aa6..5fa3c1340 100644 --- a/pkg/cmd/install_test.go +++ b/pkg/cmd/install_test.go @@ -231,11 +231,6 @@ 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", diff --git a/pkg/cmd/template_test.go b/pkg/cmd/template_test.go index 6bfa29743..5bcccf5d0 100644 --- a/pkg/cmd/template_test.go +++ b/pkg/cmd/template_test.go @@ -166,11 +166,6 @@ 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) } diff --git a/pkg/cmd/testdata/output/schema-ref.txt b/pkg/cmd/testdata/output/schema-ref.txt deleted file mode 100644 index fa6015315..000000000 --- a/pkg/cmd/testdata/output/schema-ref.txt +++ /dev/null @@ -1,7 +0,0 @@ -NAME: reftest -LAST DEPLOYED: Fri Sep 2 22:04:05 1977 -NAMESPACE: default -STATUS: deployed -REVISION: 1 -DESCRIPTION: Install complete -TEST SUITE: None diff --git a/pkg/cmd/testdata/output/template-schema-ref.txt b/pkg/cmd/testdata/output/template-schema-ref.txt deleted file mode 100644 index 8b1378917..000000000 --- a/pkg/cmd/testdata/output/template-schema-ref.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/pkg/cmd/testdata/output/upgrade-schema-ref.txt b/pkg/cmd/testdata/output/upgrade-schema-ref.txt deleted file mode 100644 index cceed6919..000000000 --- a/pkg/cmd/testdata/output/upgrade-schema-ref.txt +++ /dev/null @@ -1,8 +0,0 @@ -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 diff --git a/pkg/cmd/testdata/testcharts/chart-with-schema-ref/Chart.yaml b/pkg/cmd/testdata/testcharts/chart-with-schema-ref/Chart.yaml deleted file mode 100644 index c344a04d9..000000000 --- a/pkg/cmd/testdata/testcharts/chart-with-schema-ref/Chart.yaml +++ /dev/null @@ -1,3 +0,0 @@ -apiVersion: v2 -name: chart-with-schema-ref -version: 0.1.0 diff --git a/pkg/cmd/testdata/testcharts/chart-with-schema-ref/name.schema.json b/pkg/cmd/testdata/testcharts/chart-with-schema-ref/name.schema.json deleted file mode 100644 index 290e9cca5..000000000 --- a/pkg/cmd/testdata/testcharts/chart-with-schema-ref/name.schema.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string" -} diff --git a/pkg/cmd/testdata/testcharts/chart-with-schema-ref/values.schema.json b/pkg/cmd/testdata/testcharts/chart-with-schema-ref/values.schema.json deleted file mode 100644 index e253c4c7e..000000000 --- a/pkg/cmd/testdata/testcharts/chart-with-schema-ref/values.schema.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "properties": { - "name": { "$ref": "name.schema.json" } - } -} diff --git a/pkg/cmd/testdata/testcharts/chart-with-schema-ref/values.yaml b/pkg/cmd/testdata/testcharts/chart-with-schema-ref/values.yaml deleted file mode 100644 index 0b9fc7e3a..000000000 --- a/pkg/cmd/testdata/testcharts/chart-with-schema-ref/values.yaml +++ /dev/null @@ -1 +0,0 @@ -name: "test" diff --git a/pkg/cmd/upgrade.go b/pkg/cmd/upgrade.go index 8aea8be50..b71c4ae2d 100644 --- a/pkg/cmd/upgrade.go +++ b/pkg/cmd/upgrade.go @@ -186,7 +186,6 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } - client.ChartDir = chartPath p := getter.All(settings) vals, err := valueOpts.MergeValues(p) diff --git a/pkg/cmd/upgrade_test.go b/pkg/cmd/upgrade_test.go index 0c7ef5671..0ae1e3561 100644 --- a/pkg/cmd/upgrade_test.go +++ b/pkg/cmd/upgrade_test.go @@ -190,12 +190,6 @@ 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) }