Skip to content

Commit

Permalink
update package
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Aug 2, 2024
1 parent ff08442 commit 105ecdc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 33 deletions.
20 changes: 2 additions & 18 deletions src/api/v1alpha1/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 2 additions & 15 deletions src/api/v1alpha1/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package v1alpha1

import (
"github.com/invopop/jsonschema"
"github.com/zarf-dev/zarf/src/pkg/variables"
)

Expand All @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 105ecdc

Please sign in to comment.