Skip to content

Commit

Permalink
take some validations out of chart schema because importing :/
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinAbro321 committed Jun 12, 2024
1 parent cb82744 commit 84d42d7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/types/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
8 changes: 8 additions & 0 deletions src/types/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 6 additions & 4 deletions src/types/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
Expand Down
4 changes: 1 addition & 3 deletions zarf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,7 @@
"additionalProperties": false,
"type": "object",
"required": [
"name",
"version",
"namespace"
"name"
],
"patternProperties": {
"^x-": {}
Expand Down

0 comments on commit 84d42d7

Please sign in to comment.