From 105ecdca4264f9adc17914ad50b43739b0f70723 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Fri, 2 Aug 2024 16:51:43 +0000 Subject: [PATCH] update package Signed-off-by: Austin Abro --- src/api/v1alpha1/component.go | 20 ++------------------ src/api/v1alpha1/package.go | 17 ++--------------- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/src/api/v1alpha1/component.go b/src/api/v1alpha1/component.go index 3c00a325f6..2cf0019b14 100644 --- a/src/api/v1alpha1/component.go +++ b/src/api/v1alpha1/component.go @@ -107,23 +107,13 @@ func (c ZarfComponent) IsRequired() bool { // ZarfComponentOnlyTarget filters a component to only show it for a given local OS and cluster. type ZarfComponentOnlyTarget struct { // Only deploy component to specified OS. - LocalOS string `json:"localOS,omitempty"` + LocalOS string `json:"localOS,omitempty" jsonschema:"enum=linux,enum=darwin,enum=windows"` // Only deploy component to specified clusters. Cluster ZarfComponentOnlyCluster `json:"cluster,omitempty"` // Only include this component when a matching '--flavor' is specified on 'zarf package create'. Flavor string `json:"flavor,omitempty"` } -// JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` -func (ZarfComponentOnlyTarget) JSONSchemaExtend(schema *jsonschema.Schema) { - kind, _ := schema.Properties.Get("localOS") - supportOSEnum := []any{} - for _, os := range supportedOS { - supportOSEnum = append(supportOSEnum, os) - } - kind.Enum = supportOSEnum -} - // ZarfComponentOnlyCluster represents the architecture and K8s cluster distribution to filter on. type ZarfComponentOnlyCluster struct { // Only create and deploy to clusters of the given architecture. @@ -177,19 +167,13 @@ type ZarfChart struct { // ZarfChartVariable represents a variable that can be set for a Helm chart overrides. type ZarfChartVariable struct { // The name of the variable. - Name string `json:"name"` + Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"` // A brief description of what the variable controls. Description string `json:"description"` // The path within the Helm chart values where this variable applies. Path string `json:"path"` } -// JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` -func (ZarfChartVariable) JSONSchemaExtend(schema *jsonschema.Schema) { - name, _ := schema.Properties.Get("name") - name.Pattern = variables.UppercaseNumberUnderscorePattern -} - // ZarfManifest defines raw manifests Zarf will deploy as a helm chart. type ZarfManifest struct { // A name to give this collection of manifests; this will become the name of the dynamically-created helm chart. diff --git a/src/api/v1alpha1/package.go b/src/api/v1alpha1/package.go index 02bfd719c9..89e27c9826 100644 --- a/src/api/v1alpha1/package.go +++ b/src/api/v1alpha1/package.go @@ -5,7 +5,6 @@ package v1alpha1 import ( - "github.com/invopop/jsonschema" "github.com/zarf-dev/zarf/src/pkg/variables" ) @@ -27,14 +26,12 @@ const ( ZarfPackageConfig ZarfPackageKind = "ZarfPackageConfig" ) -const apiVersion = "zarf.dev/v1alpha1" - // ZarfPackage the top-level structure of a Zarf config file. type ZarfPackage struct { // The API version of the Zarf package. - ApiVersion string `json:"apiVersion,omitempty"` + ApiVersion string `json:"apiVersion,omitempty," jsonschema:"enum=zarf.dev/v1alpha1"` // The kind of Zarf package. - Kind ZarfPackageKind `json:"kind"` + Kind ZarfPackageKind `json:"kind" jsonschema:"enum=ZarfInitConfig,enum=ZarfPackageConfig"` // Package metadata. Metadata ZarfMetadata `json:"metadata,omitempty"` // Zarf-generated package build data. @@ -47,16 +44,6 @@ type ZarfPackage struct { Variables []variables.InteractiveVariable `json:"variables,omitempty"` } -// JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` -func (ZarfPackage) JSONSchemaExtend(schema *jsonschema.Schema) { - kind, _ := schema.Properties.Get("kind") - kind.Enum = []interface{}{ZarfInitConfig, ZarfPackageConfig} - kind.Default = ZarfPackageConfig - - apiVersionSchema, _ := schema.Properties.Get("apiVersion") - apiVersionSchema.Enum = []interface{}{apiVersion} -} - // IsInitConfig returns whether a Zarf package is an init config. func (pkg ZarfPackage) IsInitConfig() bool { return pkg.Kind == ZarfInitConfig