diff --git a/src/config/lang/english.go b/src/config/lang/english.go index 6ead05cdd7..4c074861e1 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -698,6 +698,8 @@ const ( PkgValidateErrComponentNameNotUnique = "component name %q is not unique" PkgValidateErrComponentReqDefault = "component %q cannot be both required and default" PkgValidateErrComponentReqGrouped = "component %q cannot be both required and grouped" + PkgValidateErrChartNamespaceMissing = "chart %q must include a namespace" + PkgValidateErrChartVersion = "chart %q must include a chart version" PkgValidateErrGroupMultipleDefaults = "group %q has multiple defaults (%q, %q)" PkgValidateErrGroupOneComponent = "group %q only has one component (%q)" PkgValidateErrConstant = "invalid package constant: %w" diff --git a/src/types/component.go b/src/types/component.go index 48c5458efd..562ca924dd 100644 --- a/src/types/component.go +++ b/src/types/component.go @@ -116,12 +116,12 @@ type ZarfFile struct { // ZarfChart defines a helm chart to be deployed. type ZarfChart struct { Name string `json:"name" jsonschema:"description=The name of the chart within Zarf; note that this must be unique and does not need to be the same as the name in the chart repo"` - Version string `json:"version" jsonschema:"description=The version of the chart to deploy; for git-based charts this is also the tag of the git repo by default (when not using the '@' syntax for 'repos')"` + Version string `json:"version,omitempty" jsonschema:"description=The version of the chart to deploy; for git-based charts this is also the tag of the git repo by default (when not using the '@' syntax for 'repos')"` URL string `json:"url,omitempty" jsonschema:"example=OCI registry: oci://ghcr.io/stefanprodan/charts/podinfo,example=helm chart repo: https://stefanprodan.github.io/podinfo,example=git repo: https://github.com/stefanprodan/podinfo (note the '@' syntax for 'repos' is supported here too)" jsonschema_description:"The URL of the OCI registry, chart repository, or git repo where the helm chart is stored"` RepoName string `json:"repoName,omitempty" jsonschema:"description=The name of a chart within a Helm repository (defaults to the Zarf name of the chart)"` GitPath string `json:"gitPath,omitempty" jsonschema:"description=(git repo only) The sub directory to the chart within a git repo,example=charts/your-chart"` LocalPath string `json:"localPath,omitempty" jsonschema:"description=The path to a local chart's folder or .tgz archive"` - Namespace string `json:"namespace" jsonschema:"description=The namespace to deploy the chart to"` + Namespace string `json:"namespace,omitempty" jsonschema:"description=The namespace to deploy the chart to"` ReleaseName string `json:"releaseName,omitempty" jsonschema:"description=The name of the Helm release to create (defaults to the Zarf name of the chart)"` NoWait bool `json:"noWait,omitempty" jsonschema:"description=Whether to not wait for chart resources to be ready before continuing"` ValuesFiles []string `json:"valuesFiles,omitempty" jsonschema:"description=List of local values file paths or remote URLs to include in the package; these will be merged together when deployed"` diff --git a/src/types/validate.go b/src/types/validate.go index 6b87bb2642..ea90d4e634 100644 --- a/src/types/validate.go +++ b/src/types/validate.go @@ -261,6 +261,14 @@ func (chart ZarfChart) Validate() error { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrChartName, chart.Name, ZarfMaxChartNameLength)) } + if chart.Version == "" { + err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrChartVersion, chart.Name)) + } + + if chart.Namespace == "" { + err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrChartNamespaceMissing, chart.Name)) + } + // Must have a url or localPath (and not both) if chart.URL != "" && chart.LocalPath != "" { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrChartURLOrPath, chart.Name)) diff --git a/src/types/validate_test.go b/src/types/validate_test.go index bea69c7860..eea97ec097 100644 --- a/src/types/validate_test.go +++ b/src/types/validate_test.go @@ -196,26 +196,28 @@ func TestValidateChart(t *testing.T) { }{ { name: "valid", - chart: ZarfChart{Name: "chart1", URL: "http://whatever"}, + chart: ZarfChart{Name: "chart1", Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0"}, expectedErrs: nil, }, { name: "long name", - chart: ZarfChart{Name: longName, URL: "http://whatever"}, + chart: ZarfChart{Name: longName, Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0"}, expectedErrs: []string{ fmt.Sprintf(lang.PkgValidateErrChartName, longName, ZarfMaxChartNameLength), }, }, { - name: "no url or local path", + name: "no url, local path, version, or namespace", chart: ZarfChart{Name: "invalid"}, expectedErrs: []string{ + fmt.Sprintf(lang.PkgValidateErrChartNamespaceMissing, "invalid"), fmt.Sprintf(lang.PkgValidateErrChartURLOrPath, "invalid"), + fmt.Sprintf(lang.PkgValidateErrChartVersion, "invalid"), }, }, { name: "both url and local path", - chart: ZarfChart{Name: "invalid", URL: "http://whatever", LocalPath: "wherever"}, + chart: ZarfChart{Name: "invalid", Namespace: "whatever", URL: "http://whatever", LocalPath: "wherever", Version: "v1.0.0"}, expectedErrs: []string{ fmt.Sprintf(lang.PkgValidateErrChartURLOrPath, "invalid"), }, diff --git a/zarf.schema.json b/zarf.schema.json index 9ff37da5f5..04b4da7e76 100644 --- a/zarf.schema.json +++ b/zarf.schema.json @@ -382,9 +382,7 @@ "additionalProperties": false, "type": "object", "required": [ - "name", - "version", - "namespace" + "name" ], "patternProperties": { "^x-": {}