From 2d57404436df1884f3f9def8f1a1fe856cfa89f6 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 29 Jul 2024 16:49:33 +0000 Subject: [PATCH 01/34] switching json description to go comments Signed-off-by: Austin Abro --- src/cmd/internal.go | 4 ++ src/types/component.go | 79 +++++++++++++++++---------------- src/types/extensions/bigbang.go | 2 +- src/types/package.go | 18 +++++--- zarf.schema.json | 23 ++++++++++ 5 files changed, 80 insertions(+), 46 deletions(-) diff --git a/src/cmd/internal.go b/src/cmd/internal.go index 907125688d..290f2082bd 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -162,6 +162,10 @@ var genConfigSchemaCmd = &cobra.Command{ Short: lang.CmdInternalConfigSchemaShort, RunE: func(_ *cobra.Command, _ []string) error { reflector := jsonschema.Reflector(jsonschema.Reflector{ExpandedStruct: true}) + typePackagePath := filepath.Join("src", "types") + if err := reflector.AddGoComments("github.com/zarf-dev/zarf", typePackagePath); err != nil { + return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) + } schema := reflector.Reflect(&types.ZarfPackage{}) output, err := json.MarshalIndent(schema, "", " ") if err != nil { diff --git a/src/types/component.go b/src/types/component.go index 4ccf392970..2dd801ed1a 100644 --- a/src/types/component.go +++ b/src/types/component.go @@ -13,58 +13,56 @@ import ( // ZarfComponent is the primary functional grouping of assets to deploy by Zarf. type ZarfComponent struct { - // Name is the unique identifier for this component - Name string `json:"name" jsonschema:"description=The name of the component,pattern=^[a-z0-9][a-z0-9\\-]*$"` + // The name of the component + Name string `json:"name" jsonschema:"pattern=^[a-z0-9][a-z0-9\\-]*$"` - // Description is a message given to a user when deciding to enable this component or not - Description string `json:"description,omitempty" jsonschema:"description=Message to include during package deploy describing the purpose of this component"` + // Message to include during package deploy describing the purpose of this component + Description string `json:"description,omitempty"` - // Default changes the default option when deploying this component - Default bool `json:"default,omitempty" jsonschema:"description=Determines the default Y/N state for installing this component on package deploy"` + // Determines the default Y/N state for installing this component on package deploy + Default bool `json:"default,omitempty"` - // Required makes this component mandatory for package deployment - Required *bool `json:"required,omitempty" jsonschema:"description=Do not prompt user to install this component, always install on package deploy."` + // Do not prompt user to install this component + Required *bool `json:"required,omitempty"` - // Only include compatible components during package deployment - Only ZarfComponentOnlyTarget `json:"only,omitempty" jsonschema:"description=Filter when this component is included in package creation or deployment"` + // Filter when this component is included in package creation or deployment + Only ZarfComponentOnlyTarget `json:"only,omitempty"` - // DeprecatedGroup is a key to match other components to produce a user selector field, used to create a BOOLEAN XOR for a set of components - // - // Note: ignores default and required flags - DeprecatedGroup string `json:"group,omitempty" jsonschema:"description=[Deprecated] Create a user selector field based on all components in the same group. This will be removed in Zarf v1.0.0. Consider using 'only.flavor' instead.,deprecated=true"` + // [Deprecated] Create a user selector field based on all components in the same group. This will be removed in Zarf v1.0.0. Consider using 'only.flavor' instead. + DeprecatedGroup string `json:"group,omitempty" jsonschema:"deprecated=true"` - // DeprecatedCosignKeyPath to cosign public key for signed online resources - DeprecatedCosignKeyPath string `json:"cosignKeyPath,omitempty" jsonschema:"description=[Deprecated] Specify a path to a public key to validate signed online resources. This will be removed in Zarf v1.0.0.,deprecated=true"` + // [Deprecated] Specify a path to a public key to validate signed online resources. This will be removed in Zarf v1.0.0. + DeprecatedCosignKeyPath string `json:"cosignKeyPath,omitempty" jsonschema:"deprecated=true"` - // Import refers to another zarf.yaml package component. - Import ZarfComponentImport `json:"import,omitempty" jsonschema:"description=Import a component from another Zarf package"` + // Import a component from another Zarf package + Import ZarfComponentImport `json:"import,omitempty"` - // Manifests are raw manifests that get converted into zarf-generated helm charts during deploy - Manifests []ZarfManifest `json:"manifests,omitempty" jsonschema:"description=Kubernetes manifests to be included in a generated Helm chart on package deploy"` + // Kubernetes manifests to be included in a generated Helm chart on package deploy + Manifests []ZarfManifest `json:"manifests,omitempty"` - // Charts are helm charts to install during package deploy - Charts []ZarfChart `json:"charts,omitempty" jsonschema:"description=Helm charts to install during package deploy"` + // Helm charts to install during package deploy + Charts []ZarfChart `json:"charts,omitempty"` - // Data packages to push into a running cluster - DataInjections []ZarfDataInjection `json:"dataInjections,omitempty" jsonschema:"description=Datasets to inject into a container in the target cluster"` + // Datasets to inject into a container in the target cluster + DataInjections []ZarfDataInjection `json:"dataInjections,omitempty"` - // Files are files to place on disk during deploy - Files []ZarfFile `json:"files,omitempty" jsonschema:"description=Files or folders to place on disk during package deployment"` + // Files or folders to place on disk during package deployment + Files []ZarfFile `json:"files,omitempty"` - // Images are the online images needed to be included in the zarf package - Images []string `json:"images,omitempty" jsonschema:"description=List of OCI images to include in the package"` + // List of OCI images to include in the package + Images []string `json:"images,omitempty"` - // Repos are any git repos that need to be pushed into the git server - Repos []string `json:"repos,omitempty" jsonschema:"description=List of git repos to include in the package"` + // List of git repos to include in the package + Repos []string `json:"repos,omitempty"` - // Extensions provide additional functionality to a component - Extensions extensions.ZarfComponentExtensions `json:"extensions,omitempty" jsonschema:"description=Extend component functionality with additional features"` + // Extend component functionality with additional features + Extensions extensions.ZarfComponentExtensions `json:"extensions,omitempty"` - // DeprecatedScripts are custom commands that run before or after package deployment - DeprecatedScripts DeprecatedZarfComponentScripts `json:"scripts,omitempty" jsonschema:"description=[Deprecated] (replaced by actions) Custom commands to run before or after package deployment. This will be removed in Zarf v1.0.0.,deprecated=true"` + // [Deprecated] (replaced by actions) Custom commands to run before or after package deployment. This will be removed in Zarf v1.0.0. + DeprecatedScripts DeprecatedZarfComponentScripts `json:"scripts,omitempty" jsonschema:"deprecated=true"` - // Replaces scripts, fine-grained control over commands to run at various stages of a package lifecycle - Actions ZarfComponentActions `json:"actions,omitempty" jsonschema:"description=Custom commands to run at various stages of a package lifecycle"` + // Custom commands to run at various stages of a package lifecycle + Actions ZarfComponentActions `json:"actions,omitempty"` } // RequiresCluster returns if the component requires a cluster connection to deploy @@ -93,9 +91,12 @@ func (c ZarfComponent) IsRequired() bool { // ZarfComponentOnlyTarget filters a component to only show it for a given local OS and cluster. type ZarfComponentOnlyTarget struct { - LocalOS string `json:"localOS,omitempty" jsonschema:"description=Only deploy component to specified OS,enum=linux,enum=darwin,enum=windows"` - Cluster ZarfComponentOnlyCluster `json:"cluster,omitempty" jsonschema:"description=Only deploy component to specified clusters"` - Flavor string `json:"flavor,omitempty" jsonschema:"description=Only include this component when a matching '--flavor' is specified on 'zarf package create'"` + // Only deploy component to specified OS + 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"` } // ZarfComponentOnlyCluster represents the architecture and K8s cluster distribution to filter on. diff --git a/src/types/extensions/bigbang.go b/src/types/extensions/bigbang.go index 8078e0be04..1ac7c4385b 100644 --- a/src/types/extensions/bigbang.go +++ b/src/types/extensions/bigbang.go @@ -4,7 +4,7 @@ // Package extensions contains the types for all official extensions. package extensions -// BigBang defines a file to deploy. +// BigBang holds the configuration for the Big Bang extension type BigBang struct { Version string `json:"version" jsonschema:"description=The version of Big Bang to use"` Repo string `json:"repo,omitempty" jsonschema:"description=Override repo to pull Big Bang from instead of Repo One"` diff --git a/src/types/package.go b/src/types/package.go index cb097d6e42..0afb3aa2af 100644 --- a/src/types/package.go +++ b/src/types/package.go @@ -18,12 +18,18 @@ const ( // ZarfPackage the top-level structure of a Zarf config file. type ZarfPackage struct { - Kind ZarfPackageKind `json:"kind" jsonschema:"description=The kind of Zarf package,enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` - Metadata ZarfMetadata `json:"metadata,omitempty" jsonschema:"description=Package metadata"` - Build ZarfBuildData `json:"build,omitempty" jsonschema:"description=Zarf-generated package build data"` - Components []ZarfComponent `json:"components" jsonschema:"description=List of components to deploy in this package,minItems=1"` - Constants []variables.Constant `json:"constants,omitempty" jsonschema:"description=Constant template values applied on deploy for K8s resources"` - Variables []variables.InteractiveVariable `json:"variables,omitempty" jsonschema:"description=Variable template values applied on deploy for K8s resources"` + // The kind of Zarf package + Kind ZarfPackageKind `json:"kind" jsonschema:"enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` + // Package metadata + Metadata ZarfMetadata `json:"metadata,omitempty"` + // Zarf-generated package build data + Build ZarfBuildData `json:"build,omitempty"` + // List of components to deploy in this package + Components []ZarfComponent `json:"components" jsonschema:"minItems=1"` + // Constant template values applied on deploy for K8s resources + Constants []variables.Constant `json:"constants,omitempty"` + // Variable template values applied on deploy for K8s resources + Variables []variables.InteractiveVariable `json:"variables,omitempty"` } // IsInitConfig returns whether a Zarf package is an init config. diff --git a/zarf.schema.json b/zarf.schema.json index b5c7a971d4..008d94aeeb 100644 --- a/zarf.schema.json +++ b/zarf.schema.json @@ -36,6 +36,7 @@ "required": [ "version" ], + "description": "BigBang holds the configuration for the Big Bang extension", "patternProperties": { "^x-": {} } @@ -112,6 +113,7 @@ }, "additionalProperties": false, "type": "object", + "description": "DeprecatedZarfComponentScripts are scripts that run before or after a component is deployed", "patternProperties": { "^x-": {} } @@ -314,6 +316,7 @@ "timestamp", "version" ], + "description": "ZarfBuildData is written during the packager.Create() operation to track details of the created package.", "patternProperties": { "^x-": {} } @@ -384,6 +387,7 @@ "required": [ "name" ], + "description": "ZarfChart defines a helm chart to be deployed.", "patternProperties": { "^x-": {} } @@ -411,6 +415,7 @@ "description", "path" ], + "description": "ZarfChartVariable represents a variable that can be set for a Helm chart overrides.", "patternProperties": { "^x-": {} } @@ -510,6 +515,7 @@ "required": [ "name" ], + "description": "ZarfComponent is the primary functional grouping of assets to deploy by Zarf.", "patternProperties": { "^x-": {} } @@ -570,6 +576,7 @@ }, "additionalProperties": false, "type": "object", + "description": "ZarfComponentAction represents a single action to run during a zarf package operation", "patternProperties": { "^x-": {} } @@ -606,6 +613,7 @@ }, "additionalProperties": false, "type": "object", + "description": "ZarfComponentActionDefaults sets the default configs for child actions", "patternProperties": { "^x-": {} } @@ -647,6 +655,7 @@ }, "additionalProperties": false, "type": "object", + "description": "ZarfComponentActionSet is a set of actions to run during a zarf package operation", "patternProperties": { "^x-": {} } @@ -664,6 +673,7 @@ }, "additionalProperties": false, "type": "object", + "description": "ZarfComponentActionWait specifies a condition to wait for before continuing", "patternProperties": { "^x-": {} } @@ -705,6 +715,7 @@ "kind", "name" ], + "description": "ZarfComponentActionWaitCluster specifies a condition to wait for before continuing", "patternProperties": { "^x-": {} } @@ -743,6 +754,7 @@ "protocol", "address" ], + "description": "ZarfComponentActionWaitNetwork specifies a condition to wait for before continuing", "patternProperties": { "^x-": {} } @@ -764,6 +776,7 @@ }, "additionalProperties": false, "type": "object", + "description": "ZarfComponentActions are ActionSets that map to different zarf package operations", "patternProperties": { "^x-": {} } @@ -777,6 +790,7 @@ }, "additionalProperties": false, "type": "object", + "description": "ZarfComponentExtensions is a struct that contains all the official extensions", "patternProperties": { "^x-": {} } @@ -805,6 +819,7 @@ }, "additionalProperties": false, "type": "object", + "description": "ZarfComponentImport structure for including imported Zarf components.", "patternProperties": { "^x-": {} } @@ -833,6 +848,7 @@ }, "additionalProperties": false, "type": "object", + "description": "ZarfComponentOnlyCluster represents the architecture and K8s cluster distribution to filter on.", "patternProperties": { "^x-": {} } @@ -859,6 +875,7 @@ }, "additionalProperties": false, "type": "object", + "description": "ZarfComponentOnlyTarget filters a component to only show it for a given local OS and cluster.", "patternProperties": { "^x-": {} } @@ -893,6 +910,7 @@ "container", "path" ], + "description": "ZarfContainerTarget defines the destination info for a ZarfData target", "patternProperties": { "^x-": {} } @@ -918,6 +936,7 @@ "source", "target" ], + "description": "ZarfDataInjection is a data-injection definition.", "patternProperties": { "^x-": {} } @@ -958,6 +977,7 @@ "source", "target" ], + "description": "ZarfFile defines a file to deploy.", "patternProperties": { "^x-": {} } @@ -1000,6 +1020,7 @@ "required": [ "name" ], + "description": "ZarfManifest defines raw manifests Zarf will deploy as a helm chart.", "patternProperties": { "^x-": {} } @@ -1072,6 +1093,7 @@ "required": [ "name" ], + "description": "ZarfMetadata lists information about the current ZarfPackage.", "patternProperties": { "^x-": {} } @@ -1124,6 +1146,7 @@ "kind", "components" ], + "description": "ZarfPackage the top-level structure of a Zarf config file.", "patternProperties": { "^x-": {} } From e466577340d46141dfd6645d1cb4dd6a2cc20fd4 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 29 Jul 2024 17:07:40 +0000 Subject: [PATCH 02/34] switching json description to go comments Signed-off-by: Austin Abro --- src/types/component.go | 66 ++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/src/types/component.go b/src/types/component.go index 2dd801ed1a..ccf2905a00 100644 --- a/src/types/component.go +++ b/src/types/component.go @@ -101,40 +101,62 @@ type ZarfComponentOnlyTarget struct { // ZarfComponentOnlyCluster represents the architecture and K8s cluster distribution to filter on. type ZarfComponentOnlyCluster struct { - Architecture string `json:"architecture,omitempty" jsonschema:"description=Only create and deploy to clusters of the given architecture,enum=amd64,enum=arm64"` - Distros []string `json:"distros,omitempty" jsonschema:"description=A list of kubernetes distros this package works with (Reserved for future use),example=k3s,example=eks"` + // Only create and deploy to clusters of the given architecture + Architecture string `json:"architecture,omitempty" jsonschema:"enum=amd64,enum=arm64"` + // A list of kubernetes distros this package works with (Reserved for future use) + Distros []string `json:"distros,omitempty" jsonschema:"example=k3s,example=eks"` } // ZarfFile defines a file to deploy. type ZarfFile struct { - Source string `json:"source" jsonschema:"description=Local folder or file path or remote URL to pull into the package"` - Shasum string `json:"shasum,omitempty" jsonschema:"description=(files only) Optional SHA256 checksum of the file"` - Target string `json:"target" jsonschema:"description=The absolute or relative path where the file or folder should be copied to during package deploy"` - Executable bool `json:"executable,omitempty" jsonschema:"description=(files only) Determines if the file should be made executable during package deploy"` - Symlinks []string `json:"symlinks,omitempty" jsonschema:"description=List of symlinks to create during package deploy"` - ExtractPath string `json:"extractPath,omitempty" jsonschema:"description=Local folder or file to be extracted from a 'source' archive"` + // Local folder or file path or remote URL to pull into the package + Source string `json:"source"` + // (files only) Optional SHA256 checksum of the file + Shasum string `json:"shasum,omitempty"` + // The absolute or relative path where the file or folder should be copied to during package deploy + Target string `json:"target"` + // (files only) Determines if the file should be made executable during package deploy + Executable bool `json:"executable,omitempty"` + // List of symlinks to create during package deploy + Symlinks []string `json:"symlinks,omitempty"` + // Local folder or file to be extracted from a 'source' archive + ExtractPath string `json:"extractPath,omitempty"` } // 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,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,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"` - Variables []ZarfChartVariable `json:"variables,omitempty" jsonschema:"description=[alpha] List of variables to set in the Helm chart"` + // 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 + Name string `json:"name"` + // 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"` + // The URL of the OCI registry, chart repository, or git repo where the helm chart is stored + 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)"` + // The name of a chart within a Helm repository (defaults to the Zarf name of the chart) + RepoName string `json:"repoName,omitempty"` + // (git repo only) The sub directory to the chart within a git repo + GitPath string `json:"gitPath,omitempty" jsonschema:"example=charts/your-chart"` + // The path to a local chart's folder or .tgz archive + LocalPath string `json:"localPath,omitempty"` + // The namespace to deploy the chart to + Namespace string `json:"namespace,omitempty"` + // The name of the Helm release to create (defaults to the Zarf name of the chart) + ReleaseName string `json:"releaseName,omitempty"` + // Whether to not wait for chart resources to be ready before continuing + NoWait bool `json:"noWait,omitempty"` + // List of local values file paths or remote URLs to include in the package; these will be merged together when deployed + ValuesFiles []string `json:"valuesFiles,omitempty"` + // [alpha] List of variables to set in the Helm chart + Variables []ZarfChartVariable `json:"variables,omitempty"` } // ZarfChartVariable represents a variable that can be set for a Helm chart overrides. type ZarfChartVariable struct { - Name string `json:"name" jsonschema:"description=The name of the variable,pattern=^[A-Z0-9_]+$"` - Description string `json:"description" jsonschema:"description=A brief description of what the variable controls"` - Path string `json:"path" jsonschema:"description=The path within the Helm chart values where this variable applies"` + // The name of the variable + 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"` } // ZarfManifest defines raw manifests Zarf will deploy as a helm chart. From a54b4d69934edc69c8345908442ab534a2720646 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 29 Jul 2024 17:30:13 +0000 Subject: [PATCH 03/34] switching json description to go comments Signed-off-by: Austin Abro --- src/types/component.go | 170 +++++++++++++++++++++++++++-------------- src/types/k8s.go | 5 +- zarf.schema.json | 12 +-- 3 files changed, 120 insertions(+), 67 deletions(-) diff --git a/src/types/component.go b/src/types/component.go index ccf2905a00..b2aedf9ba7 100644 --- a/src/types/component.go +++ b/src/types/component.go @@ -161,108 +161,162 @@ type ZarfChartVariable struct { // ZarfManifest defines raw manifests Zarf will deploy as a helm chart. type ZarfManifest struct { - Name string `json:"name" jsonschema:"description=A name to give this collection of manifests; this will become the name of the dynamically-created helm chart"` - Namespace string `json:"namespace,omitempty" jsonschema:"description=The namespace to deploy the manifests to"` - Files []string `json:"files,omitempty" jsonschema:"description=List of local K8s YAML files or remote URLs to deploy (in order)"` - KustomizeAllowAnyDirectory bool `json:"kustomizeAllowAnyDirectory,omitempty" jsonschema:"description=Allow traversing directory above the current directory if needed for kustomization"` - Kustomizations []string `json:"kustomizations,omitempty" jsonschema:"description=List of local kustomization paths or remote URLs to include in the package"` - NoWait bool `json:"noWait,omitempty" jsonschema:"description=Whether to not wait for manifest resources to be ready before continuing"` + // A name to give this collection of manifests; this will become the name of the dynamically-created helm chart + Name string `json:"name"` + // The namespace to deploy the manifests to + Namespace string `json:"namespace,omitempty"` + // List of local K8s YAML files or remote URLs to deploy (in order) + Files []string `json:"files,omitempty"` + // Allow traversing directory above the current directory if needed for kustomization + KustomizeAllowAnyDirectory bool `json:"kustomizeAllowAnyDirectory,omitempty"` + // List of local kustomization paths or remote URLs to include in the package + Kustomizations []string `json:"kustomizations,omitempty"` + // Whether to not wait for manifest resources to be ready before continuing + NoWait bool `json:"noWait,omitempty"` } // DeprecatedZarfComponentScripts are scripts that run before or after a component is deployed type DeprecatedZarfComponentScripts struct { - ShowOutput bool `json:"showOutput,omitempty" jsonschema:"description=Show the output of the script during package deployment"` - TimeoutSeconds int `json:"timeoutSeconds,omitempty" jsonschema:"description=Timeout in seconds for the script"` - Retry bool `json:"retry,omitempty" jsonschema:"description=Retry the script if it fails"` - Prepare []string `json:"prepare,omitempty" jsonschema:"description=Scripts to run before the component is added during package create"` - Before []string `json:"before,omitempty" jsonschema:"description=Scripts to run before the component is deployed"` - After []string `json:"after,omitempty" jsonschema:"description=Scripts to run after the component successfully deploys"` + // Show the output of the script during package deployment + ShowOutput bool `json:"showOutput,omitempty"` + // Timeout in seconds for the script + TimeoutSeconds int `json:"timeoutSeconds,omitempty"` + // Retry the script if it fails + Retry bool `json:"retry,omitempty"` + // Scripts to run before the component is added during package create + Prepare []string `json:"prepare,omitempty"` + // Scripts to run before the component is deployed + Before []string `json:"before,omitempty"` + // Scripts to run after the component successfully deploys + After []string `json:"after,omitempty" jsonschema:"description="` } // ZarfComponentActions are ActionSets that map to different zarf package operations type ZarfComponentActions struct { - OnCreate ZarfComponentActionSet `json:"onCreate,omitempty" jsonschema:"description=Actions to run during package creation"` - OnDeploy ZarfComponentActionSet `json:"onDeploy,omitempty" jsonschema:"description=Actions to run during package deployment"` - OnRemove ZarfComponentActionSet `json:"onRemove,omitempty" jsonschema:"description=Actions to run during package removal"` + // Actions to run during package creation + OnCreate ZarfComponentActionSet `json:"onCreate,omitempty"` + // Actions to run during package deployment + OnDeploy ZarfComponentActionSet `json:"onDeploy,omitempty"` + // Actions to run during package removal + OnRemove ZarfComponentActionSet `json:"onRemove,omitempty"` } // ZarfComponentActionSet is a set of actions to run during a zarf package operation type ZarfComponentActionSet struct { - Defaults ZarfComponentActionDefaults `json:"defaults,omitempty" jsonschema:"description=Default configuration for all actions in this set"` - Before []ZarfComponentAction `json:"before,omitempty" jsonschema:"description=Actions to run at the start of an operation"` - After []ZarfComponentAction `json:"after,omitempty" jsonschema:"description=Actions to run at the end of an operation"` - OnSuccess []ZarfComponentAction `json:"onSuccess,omitempty" jsonschema:"description=Actions to run if all operations succeed"` - OnFailure []ZarfComponentAction `json:"onFailure,omitempty" jsonschema:"description=Actions to run if all operations fail"` + // Default configuration for all actions in this set + Defaults ZarfComponentActionDefaults `json:"defaults,omitempty"` + // Actions to run at the start of an operation + Before []ZarfComponentAction `json:"before,omitempty"` + // Actions to run at the end of an operation + After []ZarfComponentAction `json:"after,omitempty"` + // Actions to run if all operations succeed + OnSuccess []ZarfComponentAction `json:"onSuccess,omitempty"` + // Actions to run if all operations fail + OnFailure []ZarfComponentAction `json:"onFailure,omitempty"` } // ZarfComponentActionDefaults sets the default configs for child actions type ZarfComponentActionDefaults struct { - Mute bool `json:"mute,omitempty" jsonschema:"description=Hide the output of commands during execution (default false)"` - MaxTotalSeconds int `json:"maxTotalSeconds,omitempty" jsonschema:"description=Default timeout in seconds for commands (default to 0, no timeout)"` - MaxRetries int `json:"maxRetries,omitempty" jsonschema:"description=Retry commands given number of times if they fail (default 0)"` - Dir string `json:"dir,omitempty" jsonschema:"description=Working directory for commands (default CWD)"` - Env []string `json:"env,omitempty" jsonschema:"description=Additional environment variables for commands"` - Shell exec.Shell `json:"shell,omitempty" jsonschema:"description=(cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems"` + // Hide the output of commands during execution (default false) + Mute bool `json:"mute,omitempty"` + // Default timeout in seconds for commands (default to 0, no timeout) + MaxTotalSeconds int `json:"maxTotalSeconds,omitempty"` + // Retry commands given number of times if they fail (default 0) + MaxRetries int `json:"maxRetries,omitempty"` + // Working directory for commands (default CWD) + Dir string `json:"dir,omitempty"` + // Additional environment variables for commands + Env []string `json:"env,omitempty"` + // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems + Shell exec.Shell `json:"shell,omitempty"` } // ZarfComponentAction represents a single action to run during a zarf package operation type ZarfComponentAction struct { - Mute *bool `json:"mute,omitempty" jsonschema:"description=Hide the output of the command during package deployment (default false)"` - MaxTotalSeconds *int `json:"maxTotalSeconds,omitempty" jsonschema:"description=Timeout in seconds for the command (default to 0, no timeout for cmd actions and 300, 5 minutes for wait actions)"` - MaxRetries *int `json:"maxRetries,omitempty" jsonschema:"description=Retry the command if it fails up to given number of times (default 0)"` - Dir *string `json:"dir,omitempty" jsonschema:"description=The working directory to run the command in (default is CWD)"` - Env []string `json:"env,omitempty" jsonschema:"description=Additional environment variables to set for the command"` - Cmd string `json:"cmd,omitempty" jsonschema:"description=The command to run. Must specify either cmd or wait for the action to do anything."` - Shell *exec.Shell `json:"shell,omitempty" jsonschema:"description=(cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems"` - DeprecatedSetVariable string `json:"setVariable,omitempty" jsonschema:"description=[Deprecated] (replaced by setVariables) (onDeploy/cmd only) The name of a variable to update with the output of the command. This variable will be available to all remaining actions and components in the package. This will be removed in Zarf v1.0.0,pattern=^[A-Z0-9_]+$"` - SetVariables []variables.Variable `json:"setVariables,omitempty" jsonschema:"description=(onDeploy/cmd only) An array of variables to update with the output of the command. These variables will be available to all remaining actions and components in the package."` - Description string `json:"description,omitempty" jsonschema:"description=Description of the action to be displayed during package execution instead of the command"` - Wait *ZarfComponentActionWait `json:"wait,omitempty" jsonschema:"description=Wait for a condition to be met before continuing. Must specify either cmd or wait for the action. See the 'zarf tools wait-for' command for more info."` + // Hide the output of the command during package deployment (default false) + Mute *bool `json:"mute,omitempty"` + // Timeout in seconds for the command (default to 0, no timeout for cmd actions and 300, 5 minutes for wait actions) + MaxTotalSeconds *int `json:"maxTotalSeconds,omitempty"` + // Retry the command if it fails up to given number of times (default 0) + MaxRetries *int `json:"maxRetries,omitempty"` + // The working directory to run the command in (default is CWD) + Dir *string `json:"dir,omitempty"` + // Additional environment variables to set for the command + Env []string `json:"env,omitempty"` + // The command to run. Must specify either cmd or wait for the action to do anything. + Cmd string `json:"cmd,omitempty"` + // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems + Shell *exec.Shell `json:"shell,omitempty"` + // [Deprecated] (replaced by setVariables) (onDeploy/cmd only) The name of a variable to update with the output of the command. This variable will be available to all remaining actions and components in the package. This will be removed in Zarf v1.0.0 + DeprecatedSetVariable string `json:"setVariable,omitempty" jsonschema:"pattern=^[A-Z0-9_]+$"` + // (onDeploy/cmd only) An array of variables to update with the output of the command. These variables will be available to all remaining actions and components in the package. + SetVariables []variables.Variable `json:"setVariables,omitempty"` + // Description of the action to be displayed during package execution instead of the command + Description string `json:"description,omitempty"` + // Wait for a condition to be met before continuing. Must specify either cmd or wait for the action. See the 'zarf tools wait-for' command for more info. + Wait *ZarfComponentActionWait `json:"wait,omitempty"` } // ZarfComponentActionWait specifies a condition to wait for before continuing type ZarfComponentActionWait struct { - Cluster *ZarfComponentActionWaitCluster `json:"cluster,omitempty" jsonschema:"description=Wait for a condition to be met in the cluster before continuing. Only one of cluster or network can be specified."` - Network *ZarfComponentActionWaitNetwork `json:"network,omitempty" jsonschema:"description=Wait for a condition to be met on the network before continuing. Only one of cluster or network can be specified."` + // Wait for a condition to be met in the cluster before continuing. Only one of cluster or network can be specified. + Cluster *ZarfComponentActionWaitCluster `json:"cluster,omitempty"` + // Wait for a condition to be met on the network before continuing. Only one of cluster or network can be specified. + Network *ZarfComponentActionWaitNetwork `json:"network,omitempty"` } // ZarfComponentActionWaitCluster specifies a condition to wait for before continuing type ZarfComponentActionWaitCluster struct { - Kind string `json:"kind" jsonschema:"description=The kind of resource to wait for,example=Pod,example=Deployment)"` - Identifier string `json:"name" jsonschema:"description=The name of the resource or selector to wait for,example=podinfo,example=app=podinfo"` - Namespace string `json:"namespace,omitempty" jsonschema:"description=The namespace of the resource to wait for"` - Condition string `json:"condition,omitempty" jsonschema:"description=The condition or jsonpath state to wait for; defaults to exist, a special condition that will wait for the resource to exist,example=Ready,example=Available,'{.status.availableReplicas}'=23"` + // The kind of resource to wait for + Kind string `json:"kind" jsonschema:"example=Pod,example=Deployment)"` + // The name of the resource or selector to wait for + Identifier string `json:"name" jsonschema:"example=podinfo,example=app=podinfo"` + // The namespace of the resource to wait for + Namespace string `json:"namespace,omitempty"` + // The condition or jsonpath state to wait for; defaults to exist, a special condition that will wait for the resource to exist + Condition string `json:"condition,omitempty" jsonschema:"example=Ready,example=Available,'{.status.availableReplicas}'=23"` } // ZarfComponentActionWaitNetwork specifies a condition to wait for before continuing type ZarfComponentActionWaitNetwork struct { - Protocol string `json:"protocol" jsonschema:"description=The protocol to wait for,enum=tcp,enum=http,enum=https"` - Address string `json:"address" jsonschema:"description=The address to wait for,example=localhost:8080,example=1.1.1.1"` - Code int `json:"code,omitempty" jsonschema:"description=The HTTP status code to wait for if using http or https,example=200,example=404"` + // The protocol to wait for + Protocol string `json:"protocol" jsonschema:"enum=tcp,enum=http,enum=https"` + // The address to wait for + Address string `json:"address" jsonschema:"example=localhost:8080,example=1.1.1.1"` + // The HTTP status code to wait for if using http or https + Code int `json:"code,omitempty" jsonschema:"example=200,example=404"` } // ZarfContainerTarget defines the destination info for a ZarfData target type ZarfContainerTarget struct { - Namespace string `json:"namespace" jsonschema:"description=The namespace to target for data injection"` - Selector string `json:"selector" jsonschema:"description=The K8s selector to target for data injection,example=app=data-injection"` - Container string `json:"container" jsonschema:"description=The container name to target for data injection"` - Path string `json:"path" jsonschema:"description=The path within the container to copy the data into"` + // The namespace to target for data injection + Namespace string `json:"namespace"` + // The K8s selector to target for data injection + Selector string `json:"selector" jsonschema:"example=app=data-injection"` + // The container name to target for data injection + Container string `json:"container"` + // The path within the container to copy the data into + Path string `json:"path"` } // ZarfDataInjection is a data-injection definition. type ZarfDataInjection struct { - Source string `json:"source" jsonschema:"description=Either a path to a local folder/file or a remote URL of a file to inject into the given target pod + container"` - Target ZarfContainerTarget `json:"target" jsonschema:"description=The target pod + container to inject the data into"` - Compress bool `json:"compress,omitempty" jsonschema:"description=Compress the data before transmitting using gzip. Note: this requires support for tar/gzip locally and in the target image."` + // Either a path to a local folder/file or a remote URL of a file to inject into the given target pod + container + Source string `json:"source"` + // The target pod + container to inject the data into + Target ZarfContainerTarget `json:"target"` + // Compress the data before transmitting using gzip. Note: this requires support for tar/gzip locally and in the target image. + Compress bool `json:"compress,omitempty"` } // ZarfComponentImport structure for including imported Zarf components. type ZarfComponentImport struct { - ComponentName string `json:"name,omitempty" jsonschema:"description=The name of the component to import from the referenced zarf.yaml"` - // For further explanation see https://regex101.com/r/nxX8vx/1 - Path string `json:"path,omitempty" jsonschema:"description=The relative path to a directory containing a zarf.yaml to import from"` - // For further explanation see https://regex101.com/r/nxX8vx/1 - URL string `json:"url,omitempty" jsonschema:"description=[beta] The URL to a Zarf package to import via OCI,pattern=^oci://.*$"` + // The name of the component to import from the referenced zarf.yaml + ComponentName string `json:"name,omitempty"` + // The path to the directory containing a zarf.yaml to import + Path string `json:"path,omitempty"` + // [beta] The URL to a Zarf package to import via OCI + URL string `json:"url,omitempty" jsonschema:"pattern=^oci://.*$"` } // JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` diff --git a/src/types/k8s.go b/src/types/k8s.go index a8f61856ce..dd8d792e9a 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -153,9 +153,8 @@ func (gs *GitServerInfo) FillInEmptyValues() error { // ArtifactServerInfo contains information Zarf uses to communicate with a artifact registry to push/pull repositories to. type ArtifactServerInfo struct { - PushUsername string `json:"pushUsername" jsonschema:"description=Username of a user with push access to the artifact registry"` - PushToken string `json:"pushPassword" jsonschema:"description=Password of a user with push access to the artifact registry"` - + PushUsername string `json:"pushUsername" jsonschema:"description=Username of a user with push access to the artifact registry"` + PushToken string `json:"pushPassword" jsonschema:"description=Password of a user with push access to the artifact registry"` Address string `json:"address" jsonschema:"description=URL address of the artifact registry"` InternalServer bool `json:"internalServer" jsonschema:"description=Indicates if we are using a artifact registry that Zarf is directly managing"` } diff --git a/zarf.schema.json b/zarf.schema.json index 008d94aeeb..d7d2b5adc6 100644 --- a/zarf.schema.json +++ b/zarf.schema.json @@ -528,7 +528,7 @@ }, "maxTotalSeconds": { "type": "integer", - "description": "Timeout in seconds for the command (default to 0" + "description": "Timeout in seconds for the command (default to 0, no timeout for cmd actions and 300, 5 minutes for wait actions)" }, "maxRetries": { "type": "integer", @@ -589,7 +589,7 @@ }, "maxTotalSeconds": { "type": "integer", - "description": "Default timeout in seconds for commands (default to 0" + "description": "Default timeout in seconds for commands (default to 0, no timeout)" }, "maxRetries": { "type": "integer", @@ -702,7 +702,7 @@ }, "condition": { "type": "string", - "description": "The condition or jsonpath state to wait for; defaults to exist", + "description": "The condition or jsonpath state to wait for; defaults to exist, a special condition that will wait for the resource to exist", "examples": [ "Ready", "Available" @@ -806,7 +806,7 @@ "pattern": "###ZARF_PKG_TMPL_" }, "type": "string", - "description": "The relative path to a directory containing a zarf.yaml to import from" + "description": "For further explanation see https://regex101.com/r/nxX8vx/1" }, "url": { "not": { @@ -814,7 +814,7 @@ }, "type": "string", "pattern": "^oci://.*$", - "description": "[beta] The URL to a Zarf package to import via OCI" + "description": "For further explanation see https://regex101.com/r/nxX8vx/1\n[beta] The URL to a Zarf package to import via OCI" } }, "additionalProperties": false, @@ -927,7 +927,7 @@ }, "compress": { "type": "boolean", - "description": "Compress the data before transmitting using gzip. Note: this requires support for tar/gzip locally and in the target image." + "description": "Compress the data before transmitting using gzip. Note: this requires support for tar/gzip locally and in the target image." } }, "additionalProperties": false, From d7460671b5facbadf2ae99ff5961ff554ad4bc85 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 29 Jul 2024 18:44:43 +0000 Subject: [PATCH 04/34] switching json description to go comments Signed-off-by: Austin Abro --- go.mod | 1 + go.sum | 2 + src/cmd/internal.go | 8 ++ src/extensions/bigbang/bigbang.go | 10 +- src/pkg/packager/actions/actions.go | 2 +- src/pkg/packager/composer/list.go | 4 +- src/pkg/packager/publish.go | 4 +- src/pkg/variables/types.go | 47 ++++--- src/types/component.go | 198 ++++++++++++++-------------- src/types/extensions/bigbang.go | 15 ++- src/types/k8s.go | 126 +++++++++++------- src/types/package.go | 89 ++++++++----- src/types/runtime.go | 197 +++++++++++++++------------ zarf.schema.json | 24 ++-- 14 files changed, 416 insertions(+), 311 deletions(-) diff --git a/go.mod b/go.mod index db29e4a620..a3e73c68b4 100644 --- a/go.mod +++ b/go.mod @@ -43,6 +43,7 @@ require ( github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.18.2 + github.com/stoewer/go-strcase v1.2.0 github.com/stretchr/testify v1.9.0 github.com/xeipuuv/gojsonschema v1.2.0 golang.org/x/crypto v0.24.0 diff --git a/go.sum b/go.sum index 23759f5ede..9ee894aa29 100644 --- a/go.sum +++ b/go.sum @@ -1594,6 +1594,8 @@ github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= github.com/spiffe/go-spiffe/v2 v2.1.7 h1:VUkM1yIyg/x8X7u1uXqSRVRCdMdfRIEdFBzpqoeASGk= github.com/spiffe/go-spiffe/v2 v2.1.7/go.mod h1:QJDGdhXllxjxvd5B+2XnhhXB/+rC8gr+lNrtOryiWeE= +github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU= +github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= diff --git a/src/cmd/internal.go b/src/cmd/internal.go index 290f2082bd..824d803788 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -17,6 +17,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/cobra/doc" "github.com/spf13/pflag" + strcase "github.com/stoewer/go-strcase" "github.com/zarf-dev/zarf/src/cmd/common" "github.com/zarf-dev/zarf/src/config/lang" "github.com/zarf-dev/zarf/src/internal/agent" @@ -166,6 +167,13 @@ var genConfigSchemaCmd = &cobra.Command{ if err := reflector.AddGoComments("github.com/zarf-dev/zarf", typePackagePath); err != nil { return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) } + varPackagePath := filepath.Join("src", "pkg", "variables") + if err := reflector.AddGoComments("github.com/zarf-dev/zarf", varPackagePath); err != nil { + return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) + } + + reflector.KeyNamer = strcase.LowerCamelCase + reflector.RequiredFromJSONSchemaTags = true schema := reflector.Reflect(&types.ZarfPackage{}) output, err := json.MarshalIndent(schema, "", " ") if err != nil { diff --git a/src/extensions/bigbang/bigbang.go b/src/extensions/bigbang/bigbang.go index 7eedf66255..951ae88ccf 100644 --- a/src/extensions/bigbang/bigbang.go +++ b/src/extensions/bigbang/bigbang.go @@ -154,10 +154,10 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c type MaxTotalSeconds: &maxTotalSeconds, Wait: &types.ZarfComponentActionWait{ Cluster: &types.ZarfComponentActionWaitCluster{ - Kind: "HelmRelease", - Identifier: hr.Metadata.Name, - Namespace: hr.Metadata.Namespace, - Condition: "ready", + Kind: "HelmRelease", + Name: hr.Metadata.Name, + Namespace: hr.Metadata.Namespace, + Condition: "ready", }, }, } @@ -171,7 +171,7 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c type action.Wait.Cluster = &types.ZarfComponentActionWaitCluster{ Kind: "APIService", // https://github.com/kubernetes-sigs/metrics-server#compatibility-matrix - Identifier: "v1beta1.metrics.k8s.io", + Name: "v1beta1.metrics.k8s.io", } } diff --git a/src/pkg/packager/actions/actions.go b/src/pkg/packager/actions/actions.go index 250e7bf100..ee66b84c39 100644 --- a/src/pkg/packager/actions/actions.go +++ b/src/pkg/packager/actions/actions.go @@ -183,7 +183,7 @@ func convertWaitToCmd(wait types.ZarfComponentActionWait, timeout *int) (string, // Build a call to the zarf tools wait-for command. return fmt.Sprintf("./zarf tools wait-for %s %s %s %s %s", - cluster.Kind, cluster.Identifier, cluster.Condition, ns, timeoutString), nil + cluster.Kind, cluster.Name, cluster.Condition, ns, timeoutString), nil } network := wait.Network diff --git a/src/pkg/packager/composer/list.go b/src/pkg/packager/composer/list.go index 06f67ec816..0edb04d448 100644 --- a/src/pkg/packager/composer/list.go +++ b/src/pkg/packager/composer/list.go @@ -71,8 +71,8 @@ func (n *Node) Prev() *Node { // otherwise the name of the component will be used func (n *Node) ImportName() string { name := n.ZarfComponent.Name - if n.Import.ComponentName != "" { - name = n.Import.ComponentName + if n.Import.Name != "" { + name = n.Import.Name } return name } diff --git a/src/pkg/packager/publish.go b/src/pkg/packager/publish.go index bf664f2739..4cefc1d872 100644 --- a/src/pkg/packager/publish.go +++ b/src/pkg/packager/publish.go @@ -112,8 +112,8 @@ func (p *Packager) Publish(ctx context.Context) (err error) { ex = append(ex, types.ZarfComponent{ Name: fmt.Sprintf("import-%s", c.Name), Import: types.ZarfComponentImport{ - ComponentName: c.Name, - URL: helpers.OCIURLPrefix + remote.Repo().Reference.String(), + Name: c.Name, + URL: helpers.OCIURLPrefix + remote.Repo().Reference.String(), }, }) } diff --git a/src/pkg/variables/types.go b/src/pkg/variables/types.go index b106e911fa..c4b5e14e8d 100644 --- a/src/pkg/variables/types.go +++ b/src/pkg/variables/types.go @@ -29,35 +29,48 @@ var ( // Variable represents a variable that has a value set programmatically type Variable struct { - Name string `json:"name" jsonschema:"description=The name to be used for the variable,pattern=^[A-Z0-9_]+$"` - Sensitive bool `json:"sensitive,omitempty" jsonschema:"description=Whether to mark this variable as sensitive to not print it in the log"` - AutoIndent bool `json:"autoIndent,omitempty" jsonschema:"description=Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_."` - Pattern string `json:"pattern,omitempty" jsonschema:"description=An optional regex pattern that a variable value must match before a package deployment can continue."` - Type VariableType `json:"type,omitempty" jsonschema:"description=Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB),enum=raw,enum=file"` + // The name to be used for the variable + Name string `jsonschema:"required,pattern=^[A-Z0-9_]+$"` + // Whether to mark this variable as sensitive to not print it in the log + Sensitive bool + // Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_. + AutoIndent bool + // An optional regex pattern that a variable value must match before a package deployment can continue. + Pattern string + // Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB) + Type VariableType `jsonschema:"enum=raw,enum=file"` } // InteractiveVariable is a variable that can be used to prompt a user for more information type InteractiveVariable struct { - Variable `json:",inline"` - Description string `json:"description,omitempty" jsonschema:"description=A description of the variable to be used when prompting the user a value"` - Default string `json:"default,omitempty" jsonschema:"description=The default value to use for the variable"` - Prompt bool `json:"prompt,omitempty" jsonschema:"description=Whether to prompt the user for input for this variable"` + Variable + // A description of the variable to be used when prompting the user a value + Description string + // The default value to use for the variable + Default string + // Whether to prompt the user for input for this variable + Prompt bool } // Constant are constants that can be used to dynamically template K8s resources or run in actions. type Constant struct { - Name string `json:"name" jsonschema:"description=The name to be used for the constant,pattern=^[A-Z0-9_]+$"` - Value string `json:"value" jsonschema:"description=The value to set for the constant during deploy"` - // Include a description that will only be displayed during package create/deploy confirm prompts - Description string `json:"description,omitempty" jsonschema:"description=A description of the constant to explain its purpose on package create or deploy confirmation prompts"` - AutoIndent bool `json:"autoIndent,omitempty" jsonschema:"description=Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_."` - Pattern string `json:"pattern,omitempty" jsonschema:"description=An optional regex pattern that a constant value must match before a package can be created."` + // The name to be used for the constant + Name string `jsonschema:"required,pattern=^[A-Z0-9_]+$"` + // The value to set for the constant during deploy + Value string `jsonschema:"required"` + // A description of the constant to explain its purpose on package create or deploy confirmation prompts + Description string + // Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_. + AutoIndent bool + // An optional regex pattern that a constant value must match before a package can be created. + Pattern string } // SetVariable tracks internal variables that have been set during this run of Zarf type SetVariable struct { - Variable `json:",inline"` - Value string `json:"value" jsonschema:"description=The value the variable is currently set with"` + Variable + // The value the variable is currently set with + Value string `jsonschema:"required"` } // Validate runs all validation checks on a package constant. diff --git a/src/types/component.go b/src/types/component.go index b2aedf9ba7..b9dc2df3ca 100644 --- a/src/types/component.go +++ b/src/types/component.go @@ -14,55 +14,55 @@ import ( // ZarfComponent is the primary functional grouping of assets to deploy by Zarf. type ZarfComponent struct { // The name of the component - Name string `json:"name" jsonschema:"pattern=^[a-z0-9][a-z0-9\\-]*$"` + Name string `jsonschema:"required,pattern=^[a-z0-9][a-z0-9\\-]*$"` // Message to include during package deploy describing the purpose of this component - Description string `json:"description,omitempty"` + Description string // Determines the default Y/N state for installing this component on package deploy - Default bool `json:"default,omitempty"` + Default bool // Do not prompt user to install this component - Required *bool `json:"required,omitempty"` + Required *bool // Filter when this component is included in package creation or deployment - Only ZarfComponentOnlyTarget `json:"only,omitempty"` + Only ZarfComponentOnlyTarget // [Deprecated] Create a user selector field based on all components in the same group. This will be removed in Zarf v1.0.0. Consider using 'only.flavor' instead. - DeprecatedGroup string `json:"group,omitempty" jsonschema:"deprecated=true"` + DeprecatedGroup string `json:"group" jsonschema:"deprecated=true"` // [Deprecated] Specify a path to a public key to validate signed online resources. This will be removed in Zarf v1.0.0. - DeprecatedCosignKeyPath string `json:"cosignKeyPath,omitempty" jsonschema:"deprecated=true"` + DeprecatedCosignKeyPath string `json:"cosignKeyPath" jsonschema:"deprecated=true"` // Import a component from another Zarf package - Import ZarfComponentImport `json:"import,omitempty"` + Import ZarfComponentImport // Kubernetes manifests to be included in a generated Helm chart on package deploy - Manifests []ZarfManifest `json:"manifests,omitempty"` + Manifests []ZarfManifest // Helm charts to install during package deploy - Charts []ZarfChart `json:"charts,omitempty"` + Charts []ZarfChart // Datasets to inject into a container in the target cluster - DataInjections []ZarfDataInjection `json:"dataInjections,omitempty"` + DataInjections []ZarfDataInjection // Files or folders to place on disk during package deployment - Files []ZarfFile `json:"files,omitempty"` + Files []ZarfFile // List of OCI images to include in the package - Images []string `json:"images,omitempty"` + Images []string // List of git repos to include in the package - Repos []string `json:"repos,omitempty"` + Repos []string // Extend component functionality with additional features - Extensions extensions.ZarfComponentExtensions `json:"extensions,omitempty"` + Extensions extensions.ZarfComponentExtensions - // [Deprecated] (replaced by actions) Custom commands to run before or after package deployment. This will be removed in Zarf v1.0.0. - DeprecatedScripts DeprecatedZarfComponentScripts `json:"scripts,omitempty" jsonschema:"deprecated=true"` + // [Deprecated] (replaced by actions) Custom commands to run before or after package deployment. This will be removed in Zarf v1.0.0. + DeprecatedScripts DeprecatedZarfComponentScripts `json:"scripts" jsonschema:"deprecated=true"` // Custom commands to run at various stages of a package lifecycle - Actions ZarfComponentActions `json:"actions,omitempty"` + Actions ZarfComponentActions } // RequiresCluster returns if the component requires a cluster connection to deploy @@ -92,231 +92,231 @@ 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" jsonschema:"enum=linux,enum=darwin,enum=windows"` + LocalOS string `json:"localOS" jsonschema:"enum=linux,enum=darwin,enum=windows"` // Only deploy component to specified clusters - Cluster ZarfComponentOnlyCluster `json:"cluster,omitempty"` + Cluster ZarfComponentOnlyCluster // Only include this component when a matching '--flavor' is specified on 'zarf package create' - Flavor string `json:"flavor,omitempty"` + Flavor string } // ZarfComponentOnlyCluster represents the architecture and K8s cluster distribution to filter on. type ZarfComponentOnlyCluster struct { // Only create and deploy to clusters of the given architecture - Architecture string `json:"architecture,omitempty" jsonschema:"enum=amd64,enum=arm64"` + Architecture string `jsonschema:"enum=amd64,enum=arm64"` // A list of kubernetes distros this package works with (Reserved for future use) - Distros []string `json:"distros,omitempty" jsonschema:"example=k3s,example=eks"` + Distros []string `jsonschema:"example=k3s,example=eks"` } // ZarfFile defines a file to deploy. type ZarfFile struct { // Local folder or file path or remote URL to pull into the package - Source string `json:"source"` + Source string `jsonschema:"required"` // (files only) Optional SHA256 checksum of the file - Shasum string `json:"shasum,omitempty"` + Shasum string // The absolute or relative path where the file or folder should be copied to during package deploy - Target string `json:"target"` + Target string `jsonschema:"required"` // (files only) Determines if the file should be made executable during package deploy - Executable bool `json:"executable,omitempty"` + Executable bool // List of symlinks to create during package deploy - Symlinks []string `json:"symlinks,omitempty"` + Symlinks []string // Local folder or file to be extracted from a 'source' archive - ExtractPath string `json:"extractPath,omitempty"` + ExtractPath string } // ZarfChart defines a helm chart to be deployed. type ZarfChart struct { // 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 - Name string `json:"name"` + Name string `jsonschema:"required"` // 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"` + Version string // The URL of the OCI registry, chart repository, or git repo where the helm chart is stored - 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)"` + URL string `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)"` // The name of a chart within a Helm repository (defaults to the Zarf name of the chart) - RepoName string `json:"repoName,omitempty"` + RepoName string // (git repo only) The sub directory to the chart within a git repo - GitPath string `json:"gitPath,omitempty" jsonschema:"example=charts/your-chart"` + GitPath string `jsonschema:"example=charts/your-chart"` // The path to a local chart's folder or .tgz archive - LocalPath string `json:"localPath,omitempty"` + LocalPath string // The namespace to deploy the chart to - Namespace string `json:"namespace,omitempty"` + Namespace string // The name of the Helm release to create (defaults to the Zarf name of the chart) - ReleaseName string `json:"releaseName,omitempty"` + ReleaseName string // Whether to not wait for chart resources to be ready before continuing - NoWait bool `json:"noWait,omitempty"` + NoWait bool // List of local values file paths or remote URLs to include in the package; these will be merged together when deployed - ValuesFiles []string `json:"valuesFiles,omitempty"` + ValuesFiles []string // [alpha] List of variables to set in the Helm chart - Variables []ZarfChartVariable `json:"variables,omitempty"` + Variables []ZarfChartVariable } // 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" jsonschema:"pattern=^[A-Z0-9_]+$"` + Name string `jsonschema:"required,pattern=^[A-Z0-9_]+$"` // A brief description of what the variable controls - Description string `json:"description"` + Description string `jsonschema:"required"` // The path within the Helm chart values where this variable applies - Path string `json:"path"` + Path string `jsonschema:"required"` } // 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 - Name string `json:"name"` + Name string `jsonschema:"required"` // The namespace to deploy the manifests to - Namespace string `json:"namespace,omitempty"` + Namespace string // List of local K8s YAML files or remote URLs to deploy (in order) - Files []string `json:"files,omitempty"` + Files []string // Allow traversing directory above the current directory if needed for kustomization - KustomizeAllowAnyDirectory bool `json:"kustomizeAllowAnyDirectory,omitempty"` + KustomizeAllowAnyDirectory bool // List of local kustomization paths or remote URLs to include in the package - Kustomizations []string `json:"kustomizations,omitempty"` + Kustomizations []string // Whether to not wait for manifest resources to be ready before continuing - NoWait bool `json:"noWait,omitempty"` + NoWait bool } // DeprecatedZarfComponentScripts are scripts that run before or after a component is deployed type DeprecatedZarfComponentScripts struct { // Show the output of the script during package deployment - ShowOutput bool `json:"showOutput,omitempty"` + ShowOutput bool // Timeout in seconds for the script - TimeoutSeconds int `json:"timeoutSeconds,omitempty"` + TimeoutSeconds int // Retry the script if it fails - Retry bool `json:"retry,omitempty"` + Retry bool // Scripts to run before the component is added during package create - Prepare []string `json:"prepare,omitempty"` + Prepare []string // Scripts to run before the component is deployed - Before []string `json:"before,omitempty"` + Before []string // Scripts to run after the component successfully deploys - After []string `json:"after,omitempty" jsonschema:"description="` + After []string } // ZarfComponentActions are ActionSets that map to different zarf package operations type ZarfComponentActions struct { // Actions to run during package creation - OnCreate ZarfComponentActionSet `json:"onCreate,omitempty"` + OnCreate ZarfComponentActionSet // Actions to run during package deployment - OnDeploy ZarfComponentActionSet `json:"onDeploy,omitempty"` + OnDeploy ZarfComponentActionSet // Actions to run during package removal - OnRemove ZarfComponentActionSet `json:"onRemove,omitempty"` + OnRemove ZarfComponentActionSet } // ZarfComponentActionSet is a set of actions to run during a zarf package operation type ZarfComponentActionSet struct { // Default configuration for all actions in this set - Defaults ZarfComponentActionDefaults `json:"defaults,omitempty"` + Defaults ZarfComponentActionDefaults // Actions to run at the start of an operation - Before []ZarfComponentAction `json:"before,omitempty"` + Before []ZarfComponentAction // Actions to run at the end of an operation - After []ZarfComponentAction `json:"after,omitempty"` + After []ZarfComponentAction // Actions to run if all operations succeed - OnSuccess []ZarfComponentAction `json:"onSuccess,omitempty"` + OnSuccess []ZarfComponentAction // Actions to run if all operations fail - OnFailure []ZarfComponentAction `json:"onFailure,omitempty"` + OnFailure []ZarfComponentAction } // ZarfComponentActionDefaults sets the default configs for child actions type ZarfComponentActionDefaults struct { // Hide the output of commands during execution (default false) - Mute bool `json:"mute,omitempty"` + Mute bool // Default timeout in seconds for commands (default to 0, no timeout) - MaxTotalSeconds int `json:"maxTotalSeconds,omitempty"` + MaxTotalSeconds int // Retry commands given number of times if they fail (default 0) - MaxRetries int `json:"maxRetries,omitempty"` + MaxRetries int // Working directory for commands (default CWD) - Dir string `json:"dir,omitempty"` + Dir string // Additional environment variables for commands - Env []string `json:"env,omitempty"` + Env []string // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems - Shell exec.Shell `json:"shell,omitempty"` + Shell exec.Shell } // ZarfComponentAction represents a single action to run during a zarf package operation type ZarfComponentAction struct { // Hide the output of the command during package deployment (default false) - Mute *bool `json:"mute,omitempty"` + Mute *bool // Timeout in seconds for the command (default to 0, no timeout for cmd actions and 300, 5 minutes for wait actions) - MaxTotalSeconds *int `json:"maxTotalSeconds,omitempty"` + MaxTotalSeconds *int // Retry the command if it fails up to given number of times (default 0) - MaxRetries *int `json:"maxRetries,omitempty"` + MaxRetries *int // The working directory to run the command in (default is CWD) - Dir *string `json:"dir,omitempty"` + Dir *string // Additional environment variables to set for the command - Env []string `json:"env,omitempty"` + Env []string // The command to run. Must specify either cmd or wait for the action to do anything. - Cmd string `json:"cmd,omitempty"` + Cmd string // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems - Shell *exec.Shell `json:"shell,omitempty"` + Shell *exec.Shell // [Deprecated] (replaced by setVariables) (onDeploy/cmd only) The name of a variable to update with the output of the command. This variable will be available to all remaining actions and components in the package. This will be removed in Zarf v1.0.0 - DeprecatedSetVariable string `json:"setVariable,omitempty" jsonschema:"pattern=^[A-Z0-9_]+$"` + DeprecatedSetVariable string `json:"setVariable" jsonschema:"pattern=^[A-Z0-9_]+$"` // (onDeploy/cmd only) An array of variables to update with the output of the command. These variables will be available to all remaining actions and components in the package. - SetVariables []variables.Variable `json:"setVariables,omitempty"` + SetVariables []variables.Variable // Description of the action to be displayed during package execution instead of the command - Description string `json:"description,omitempty"` + Description string // Wait for a condition to be met before continuing. Must specify either cmd or wait for the action. See the 'zarf tools wait-for' command for more info. - Wait *ZarfComponentActionWait `json:"wait,omitempty"` + Wait *ZarfComponentActionWait } // ZarfComponentActionWait specifies a condition to wait for before continuing type ZarfComponentActionWait struct { // Wait for a condition to be met in the cluster before continuing. Only one of cluster or network can be specified. - Cluster *ZarfComponentActionWaitCluster `json:"cluster,omitempty"` + Cluster *ZarfComponentActionWaitCluster // Wait for a condition to be met on the network before continuing. Only one of cluster or network can be specified. - Network *ZarfComponentActionWaitNetwork `json:"network,omitempty"` + Network *ZarfComponentActionWaitNetwork } // ZarfComponentActionWaitCluster specifies a condition to wait for before continuing type ZarfComponentActionWaitCluster struct { // The kind of resource to wait for - Kind string `json:"kind" jsonschema:"example=Pod,example=Deployment)"` + Kind string `jsonschema:"required,example=Pod,example=Deployment"` // The name of the resource or selector to wait for - Identifier string `json:"name" jsonschema:"example=podinfo,example=app=podinfo"` + Name string `jsonschema:"required,example=podinfo,example=app=podinfo"` // The namespace of the resource to wait for - Namespace string `json:"namespace,omitempty"` + Namespace string // The condition or jsonpath state to wait for; defaults to exist, a special condition that will wait for the resource to exist - Condition string `json:"condition,omitempty" jsonschema:"example=Ready,example=Available,'{.status.availableReplicas}'=23"` + Condition string `jsonschema:"example=Ready,example=Available,'{.status.availableReplicas}'=23"` } // ZarfComponentActionWaitNetwork specifies a condition to wait for before continuing type ZarfComponentActionWaitNetwork struct { // The protocol to wait for - Protocol string `json:"protocol" jsonschema:"enum=tcp,enum=http,enum=https"` + Protocol string `jsonschema:"required,enum=tcp,enum=http,enum=https"` // The address to wait for - Address string `json:"address" jsonschema:"example=localhost:8080,example=1.1.1.1"` + Address string `jsonschema:"required,example=localhost:8080,example=1.1.1.1"` // The HTTP status code to wait for if using http or https - Code int `json:"code,omitempty" jsonschema:"example=200,example=404"` + Code int `jsonschema:"required,example=200,example=404"` } // ZarfContainerTarget defines the destination info for a ZarfData target type ZarfContainerTarget struct { // The namespace to target for data injection - Namespace string `json:"namespace"` + Namespace string `jsonschema:"required"` // The K8s selector to target for data injection - Selector string `json:"selector" jsonschema:"example=app=data-injection"` + Selector string `jsonschema:"required,example=app=data-injection"` // The container name to target for data injection - Container string `json:"container"` + Container string `jsonschema:"required"` // The path within the container to copy the data into - Path string `json:"path"` + Path string `jsonschema:"required"` } // ZarfDataInjection is a data-injection definition. type ZarfDataInjection struct { // Either a path to a local folder/file or a remote URL of a file to inject into the given target pod + container - Source string `json:"source"` + Source string `jsonschema:"required"` // The target pod + container to inject the data into - Target ZarfContainerTarget `json:"target"` + Target ZarfContainerTarget `jsonschema:"required"` // Compress the data before transmitting using gzip. Note: this requires support for tar/gzip locally and in the target image. - Compress bool `json:"compress,omitempty"` + Compress bool } // ZarfComponentImport structure for including imported Zarf components. type ZarfComponentImport struct { // The name of the component to import from the referenced zarf.yaml - ComponentName string `json:"name,omitempty"` + Name string // The path to the directory containing a zarf.yaml to import - Path string `json:"path,omitempty"` + Path string // [beta] The URL to a Zarf package to import via OCI - URL string `json:"url,omitempty" jsonschema:"pattern=^oci://.*$"` + URL string `jsonschema:"pattern=^oci://.*$"` } // JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` diff --git a/src/types/extensions/bigbang.go b/src/types/extensions/bigbang.go index 1ac7c4385b..2119fac542 100644 --- a/src/types/extensions/bigbang.go +++ b/src/types/extensions/bigbang.go @@ -6,9 +6,14 @@ package extensions // BigBang holds the configuration for the Big Bang extension type BigBang struct { - Version string `json:"version" jsonschema:"description=The version of Big Bang to use"` - Repo string `json:"repo,omitempty" jsonschema:"description=Override repo to pull Big Bang from instead of Repo One"` - ValuesFiles []string `json:"valuesFiles,omitempty" jsonschema:"description=The list of values files to pass to Big Bang; these will be merged together"` - SkipFlux bool `json:"skipFlux,omitempty" jsonschema:"description=Whether to skip deploying flux; Defaults to false"` - FluxPatchFiles []string `json:"fluxPatchFiles,omitempty" jsonschema:"description=Optional paths to Flux kustomize strategic merge patch files"` + // The version of Big Bang to use + Version string `jsonschema:"required"` + // Override repo to pull Big Bang from instead of Repo One + Repo string + // The list of values files to pass to Big Bang; these will be merged together + ValuesFiles []string + // Whether to skip deploying flux; Defaults to false + SkipFlux bool + // Optional paths to Flux kustomize strategic merge patch files + FluxPatchFiles []string } diff --git a/src/types/k8s.go b/src/types/k8s.go index dd8d792e9a..c1ca6d0005 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -51,67 +51,81 @@ const ( // GeneratedPKI is a struct for storing generated PKI data. type GeneratedPKI struct { - CA []byte `json:"ca"` - Cert []byte `json:"cert"` - Key []byte `json:"key"` + CA []byte + Cert []byte + Key []byte } // ZarfState is maintained as a secret in the Zarf namespace to track Zarf init data. type ZarfState struct { - ZarfAppliance bool `json:"zarfAppliance" jsonschema:"description=Indicates if Zarf was initialized while deploying its own k8s cluster"` - Distro string `json:"distro" jsonschema:"description=K8s distribution of the cluster Zarf was deployed to"` - Architecture string `json:"architecture" jsonschema:"description=Machine architecture of the k8s node(s)"` - StorageClass string `json:"storageClass" jsonschema:"Default StorageClass value Zarf uses for variable templating"` - AgentTLS GeneratedPKI `json:"agentTLS" jsonschema:"PKI certificate information for the agent pods Zarf manages"` - - GitServer GitServerInfo `json:"gitServer" jsonschema:"description=Information about the repository Zarf is configured to use"` - RegistryInfo RegistryInfo `json:"registryInfo" jsonschema:"description=Information about the container registry Zarf is configured to use"` - ArtifactServer ArtifactServerInfo `json:"artifactServer" jsonschema:"description=Information about the artifact registry Zarf is configured to use"` + // Indicates if Zarf was initialized while deploying its own k8s cluster + ZarfAppliance bool + // K8s distribution of the cluster Zarf was deployed to + Distro string + // Machine architecture of the k8s node(s) + Architecture string + // Default StorageClass value Zarf uses for variable templating + StorageClass string + // PKI certificate information for the agent pods Zarf manages + AgentTLS GeneratedPKI + + // Information about the repository Zarf is configured to use + GitServer GitServerInfo + // Information about the container registry Zarf is configured to use + RegistryInfo RegistryInfo + // Information about the artifact registry Zarf is configured to use + ArtifactServer ArtifactServerInfo } // DeployedPackage contains information about a Zarf Package that has been deployed to a cluster // This object is saved as the data of a k8s secret within the 'Zarf' namespace (not as part of the ZarfState secret). type DeployedPackage struct { - Name string `json:"name"` - Data ZarfPackage `json:"data"` - CLIVersion string `json:"cliVersion"` - Generation int `json:"generation"` - DeployedComponents []DeployedComponent `json:"deployedComponents"` - ComponentWebhooks map[string]map[string]Webhook `json:"componentWebhooks,omitempty"` - ConnectStrings ConnectStrings `json:"connectStrings,omitempty"` + Name string + Data ZarfPackage + CLIVersion string + Generation int + DeployedComponents []DeployedComponent + ComponentWebhooks map[string]map[string]Webhook `jsonschema:"required"` + ConnectStrings ConnectStrings `jsonschema:"required"` } // DeployedComponent contains information about a Zarf Package Component that has been deployed to a cluster. type DeployedComponent struct { - Name string `json:"name"` - InstalledCharts []InstalledChart `json:"installedCharts"` - Status ComponentStatus `json:"status"` - ObservedGeneration int `json:"observedGeneration"` + Name string + InstalledCharts []InstalledChart + Status ComponentStatus + ObservedGeneration int } // Webhook contains information about a Component Webhook operating on a Zarf package secret. type Webhook struct { - Name string `json:"name"` - WaitDurationSeconds int `json:"waitDurationSeconds,omitempty"` - Status WebhookStatus `json:"status"` - ObservedGeneration int `json:"observedGeneration"` + Name string + WaitDurationSeconds int `jsonschema:"required"` + Status WebhookStatus + ObservedGeneration int } // InstalledChart contains information about a Helm Chart that has been deployed to a cluster. type InstalledChart struct { - Namespace string `json:"namespace"` - ChartName string `json:"chartName"` + Namespace string + ChartName string } // GitServerInfo contains information Zarf uses to communicate with a git repository to push/pull repositories to. type GitServerInfo struct { - PushUsername string `json:"pushUsername" jsonschema:"description=Username of a user with push access to the git repository"` - PushPassword string `json:"pushPassword" jsonschema:"description=Password of a user with push access to the git repository"` - PullUsername string `json:"pullUsername" jsonschema:"description=Username of a user with pull-only access to the git repository. If not provided for an external repository then the push-user is used"` - PullPassword string `json:"pullPassword" jsonschema:"description=Password of a user with pull-only access to the git repository. If not provided for an external repository then the push-user is used"` - - Address string `json:"address" jsonschema:"description=URL address of the git server"` - InternalServer bool `json:"internalServer" jsonschema:"description=Indicates if we are using a git server that Zarf is directly managing"` + // Username of a user with push access to the git repository + PushUsername string + // Password of a user with push access to the git repository + PushPassword string + // Username of a user with pull-only access to the git repository. If not provided for an external repository then the push-user is used + PullUsername string + // Password of a user with pull-only access to the git repository. If not provided for an external repository then the push-user is used + PullPassword string + + // URL address of the git server + Address string + // Indicates if we are using a git server that Zarf is directly managing + InternalServer bool } // FillInEmptyValues sets every necessary value that's currently empty to a reasonable default @@ -153,10 +167,14 @@ func (gs *GitServerInfo) FillInEmptyValues() error { // ArtifactServerInfo contains information Zarf uses to communicate with a artifact registry to push/pull repositories to. type ArtifactServerInfo struct { - PushUsername string `json:"pushUsername" jsonschema:"description=Username of a user with push access to the artifact registry"` - PushToken string `json:"pushPassword" jsonschema:"description=Password of a user with push access to the artifact registry"` - Address string `json:"address" jsonschema:"description=URL address of the artifact registry"` - InternalServer bool `json:"internalServer" jsonschema:"description=Indicates if we are using a artifact registry that Zarf is directly managing"` + // Username of a user with push access to the artifact registry + PushUsername string + // Password of a user with push access to the artifact registry + PushToken string + // URL address of the artifact registry + Address string + // Indicates if we are using a artifact registry that Zarf is directly managing + InternalServer bool } // FillInEmptyValues sets every necessary value that's currently empty to a reasonable default @@ -175,16 +193,24 @@ func (as *ArtifactServerInfo) FillInEmptyValues() { // RegistryInfo contains information Zarf uses to communicate with a container registry to push/pull images. type RegistryInfo struct { - PushUsername string `json:"pushUsername" jsonschema:"description=Username of a user with push access to the registry"` - PushPassword string `json:"pushPassword" jsonschema:"description=Password of a user with push access to the registry"` - PullUsername string `json:"pullUsername" jsonschema:"description=Username of a user with pull-only access to the registry. If not provided for an external registry than the push-user is used"` - PullPassword string `json:"pullPassword" jsonschema:"description=Password of a user with pull-only access to the registry. If not provided for an external registry than the push-user is used"` - - Address string `json:"address" jsonschema:"description=URL address of the registry"` - NodePort int `json:"nodePort" jsonschema:"description=Nodeport of the registry. Only needed if the registry is running inside the kubernetes cluster"` - InternalRegistry bool `json:"internalRegistry" jsonschema:"description=Indicates if we are using a registry that Zarf is directly managing"` - - Secret string `json:"secret" jsonschema:"description=Secret value that the registry was seeded with"` + // Username of a user with push access to the registry + PushUsername string + // Password of a user with push access to the registry + PushPassword string + // Username of a user with pull-only access to the registry. If not provided for an external registry than the push-user is used + PullUsername string + // Password of a user with pull-only access to the registry. If not provided for an external registry than the push-user is used + PullPassword string + + // URL address of the registry + Address string + // Nodeport of the registry. Only needed if the registry is running inside the kubernetes cluster + NodePort int + // Indicates if we are using a registry that Zarf is directly managing + InternalRegistry bool + + // Secret value that the registry was seeded with + Secret string } // FillInEmptyValues sets every necessary value not already set to a reasonable default diff --git a/src/types/package.go b/src/types/package.go index 0afb3aa2af..c31330eba3 100644 --- a/src/types/package.go +++ b/src/types/package.go @@ -19,17 +19,17 @@ const ( // ZarfPackage the top-level structure of a Zarf config file. type ZarfPackage struct { // The kind of Zarf package - Kind ZarfPackageKind `json:"kind" jsonschema:"enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` + Kind ZarfPackageKind `jsonschema:"required,enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` // Package metadata - Metadata ZarfMetadata `json:"metadata,omitempty"` + Metadata ZarfMetadata // Zarf-generated package build data - Build ZarfBuildData `json:"build,omitempty"` + Build ZarfBuildData // List of components to deploy in this package - Components []ZarfComponent `json:"components" jsonschema:"minItems=1"` + Components []ZarfComponent `jsonschema:"required,minItems=1"` // Constant template values applied on deploy for K8s resources - Constants []variables.Constant `json:"constants,omitempty"` + Constants []variables.Constant // Variable template values applied on deploy for K8s resources - Variables []variables.InteractiveVariable `json:"variables,omitempty"` + Variables []variables.InteractiveVariable } // IsInitConfig returns whether a Zarf package is an init config. @@ -49,35 +49,58 @@ func (pkg ZarfPackage) IsSBOMAble() bool { // ZarfMetadata lists information about the current ZarfPackage. type ZarfMetadata struct { - // The Name regex permits lowercase letters, numbers, and hyphens not at the start - // https://regex101.com/r/FLdG9G/2 - Name string `json:"name" jsonschema:"description=Name to identify this Zarf package,pattern=^[a-z0-9][a-z0-9\\-]*$"` - Description string `json:"description,omitempty" jsonschema:"description=Additional information about this package"` - Version string `json:"version,omitempty" jsonschema:"description=Generic string set by a package author to track the package version (Note: ZarfInitConfigs will always be versioned to the CLIVersion they were created with)"` - URL string `json:"url,omitempty" jsonschema:"description=Link to package information when online"` - Image string `json:"image,omitempty" jsonschema:"description=An image URL to embed in this package (Reserved for future use in Zarf UI)"` - Uncompressed bool `json:"uncompressed,omitempty" jsonschema:"description=Disable compression of this package"` - Architecture string `json:"architecture,omitempty" jsonschema:"description=The target cluster architecture for this package,example=arm64,example=amd64"` - YOLO bool `json:"yolo,omitempty" jsonschema:"description=Yaml OnLy Online (YOLO): True enables deploying a Zarf package without first running zarf init against the cluster. This is ideal for connected environments where you want to use existing VCS and container registries."` - Authors string `json:"authors,omitempty" jsonschema:"description=Comma-separated list of package authors (including contact info),example=Doug <hello@defenseunicorns.com>, Pepr <hello@defenseunicorns.com>"` - Documentation string `json:"documentation,omitempty" jsonschema:"description=Link to package documentation when online"` - Source string `json:"source,omitempty" jsonschema:"description=Link to package source code when online"` - Vendor string `json:"vendor,omitempty" jsonschema_description:"Name of the distributing entity, organization or individual."` - AggregateChecksum string `json:"aggregateChecksum,omitempty" jsonschema:"description=Checksum of a checksums.txt file that contains checksums all the layers within the package."` + // Name to identify this Zarf package + Name string `jsonschema:"required,pattern=^[a-z0-9][a-z0-9\\-]*$"` + // Additional information about this package + Description string + // Generic string set by a package author to track the package version (Note: ZarfInitConfigs will always be versioned to the CLIVersion they were created with) + Version string + // Link to package information when online + URL string + // An image URL to embed in this package (Reserved for future use in Zarf UI) + Image string + // Disable compression of this package + Uncompressed bool + // The target cluster architecture for this package + Architecture string `jsonschema:"example=arm64,example=amd64"` + // Yaml OnLy Online (YOLO): True enables deploying a Zarf package without first running zarf init against the cluster. This is ideal for connected environments where you want to use existing VCS and container registries. + YOLO bool + // Comma-separated list of package authors (including contact info) + Authors string `jsonschema:"example=Doug <hello@defenseunicorns.com>, Pepr <hello@defenseunicorns.com>"` + // Link to package documentation when online + Documentation string + // Link to package source code when online + Source string + // Name of the distributing entity, organization or individual + Vendor string + // Checksum of a checksums.txt file that contains checksums all the layers within the package + AggregateChecksum string } // ZarfBuildData is written during the packager.Create() operation to track details of the created package. type ZarfBuildData struct { - Terminal string `json:"terminal" jsonschema:"description=The machine name that created this package"` - User string `json:"user" jsonschema:"description=The username who created this package"` - Architecture string `json:"architecture" jsonschema:"description=The architecture this package was created on"` - Timestamp string `json:"timestamp" jsonschema:"description=The timestamp when this package was created"` - Version string `json:"version" jsonschema:"description=The version of Zarf used to build this package"` - Migrations []string `json:"migrations,omitempty" jsonschema:"description=Any migrations that have been run on this package"` - RegistryOverrides map[string]string `json:"registryOverrides,omitempty" jsonschema:"description=Any registry domains that were overridden on package create when pulling images"` - Differential bool `json:"differential,omitempty" jsonschema:"description=Whether this package was created with differential components"` - DifferentialPackageVersion string `json:"differentialPackageVersion,omitempty" jsonschema:"description=Version of a previously built package used as the basis for creating this differential package"` - DifferentialMissing []string `json:"differentialMissing,omitempty" jsonschema:"description=List of components that were not included in this package due to differential packaging"` - LastNonBreakingVersion string `json:"lastNonBreakingVersion,omitempty" jsonschema:"description=The minimum version of Zarf that does not have breaking package structure changes"` - Flavor string `json:"flavor,omitempty" jsonschema:"description=The flavor of Zarf used to build this package"` + // The machine name that created this package + Terminal string `jsonschema:"required"` + // The username who created this package + User string `jsonschema:"required"` + // The architecture this package was created on + Architecture string `jsonschema:"required"` + // The timestamp when this package was created + Timestamp string `jsonschema:"required"` + // The version of Zarf used to build this package + Version string `jsonschema:"required"` + // Any migrations that have been run on this package + Migrations []string + // Any registry domains that were overridden on package create when pulling images + RegistryOverrides map[string]string + // Whether this package was created with differential components + Differential bool + // Version of a previously built package used as the basis for creating this differential package + DifferentialPackageVersion string + // List of components that were not included in this package due to differential packaging + DifferentialMissing []string + // The minimum version of Zarf that does not have breaking package structure changes + LastNonBreakingVersion string + // The flavor of Zarf used to build this package + Flavor string } diff --git a/src/types/runtime.go b/src/types/runtime.go index b4a7d44ad2..6587ff3aa0 100644 --- a/src/types/runtime.go +++ b/src/types/runtime.go @@ -18,22 +18,34 @@ const ( // ZarfCommonOptions tracks the user-defined preferences used across commands. type ZarfCommonOptions struct { - Confirm bool `json:"confirm" jsonschema:"description=Verify that Zarf should perform an action"` - Insecure bool `json:"insecure" jsonschema:"description=Allow insecure connections for remote packages"` - CachePath string `json:"cachePath" jsonschema:"description=Path to use to cache images and git repos on package create"` - TempDirectory string `json:"tempDirectory" jsonschema:"description=Location Zarf should use as a staging ground when managing files and images for package creation and deployment"` - OCIConcurrency int `jsonschema:"description=Number of concurrent layer operations to perform when interacting with a remote package"` + // Verify that Zarf should perform an action + Confirm bool + // Allow insecure connections for remote packages + Insecure bool + // Path to use to cache images and git repos on package create + CachePath string + // Location Zarf should use as a staging ground when managing files and images for package creation and deployment + TempDirectory string + // Number of concurrent layer operations to perform when interacting with a remote package + OCIConcurrency int } // ZarfPackageOptions tracks the user-defined preferences during common package operations. type ZarfPackageOptions struct { - Shasum string `json:"shasum" jsonschema:"description=The SHA256 checksum of the package"` - PackageSource string `json:"packageSource" jsonschema:"description=Location where a Zarf package can be found"` - OptionalComponents string `json:"optionalComponents" jsonschema:"description=Comma separated list of optional components"` - SGetKeyPath string `json:"sGetKeyPath" jsonschema:"description=Location where the public key component of a cosign key-pair can be found"` - SetVariables map[string]string `json:"setVariables" jsonschema:"description=Key-Value map of variable names and their corresponding values that will be used to template manifests and files in the Zarf package"` - PublicKeyPath string `json:"publicKeyPath" jsonschema:"description=Location where the public key component of a cosign key-pair can be found"` - Retries int `json:"retries" jsonschema:"description=The number of retries to perform for Zarf deploy operations like image pushes or Helm installs"` + // The SHA256 checksum of the package + Shasum string + // Location where a Zarf package can be found + PackageSource string + // Comma separated list of optional components + OptionalComponents string + // Location where the public key component of a cosign key-pair can be found + SGetKeyPath string + // Key-Value map of variable names and their corresponding values that will be used to template manifests and files in the Zarf package + SetVariables map[string]string + // Location where the public key component of a cosign key-pair can be found + PublicKeyPath string + // The number of retries to perform for Zarf deploy operations like image pushes or Helm installs + Retries int } // ZarfInspectOptions tracks the user-defined preferences during a package inspection. @@ -48,91 +60,128 @@ type ZarfInspectOptions struct { // ZarfFindImagesOptions tracks the user-defined preferences during a prepare find-images search. type ZarfFindImagesOptions struct { - RepoHelmChartPath string `json:"repoHelmChartPath" jsonschema:"description=Path to the helm chart directory"` - KubeVersionOverride string `json:"kubeVersionOverride" jsonschema:"description=Kubernetes version to use for the helm chart"` - RegistryURL string `json:"registryURL" jsonschema:"description=Manual override for ###ZARF_REGISTRY###"` - Why string `json:"why" jsonschema:"description=Find the location of the image given as an argument and print it to the console"` - SkipCosign bool `json:"skip-cosign" jsonschema:"description=Optionally skip lookup of cosign artifacts when finding images"` + // Path to the helm chart directory + RepoHelmChartPath string + // Kubernetes version to use for the helm chart + KubeVersionOverride string + // Manual override for ###ZARF_REGISTRY### + RegistryURL string + // Find the location of the image given as an argument and print it to the console + Why string + // Optionally skip lookup of cosign artifacts when finding images + SkipCosign bool } // ZarfDeployOptions tracks the user-defined preferences during a package deploy. type ZarfDeployOptions struct { - AdoptExistingResources bool `json:"adoptExistingResources" jsonschema:"description=Whether to adopt any pre-existing K8s resources into the Helm charts managed by Zarf"` - SkipWebhooks bool `json:"componentWebhooks" jsonschema:"description=Skip waiting for external webhooks to execute as each package component is deployed"` - Timeout time.Duration `json:"timeout" jsonschema:"description=Timeout for performing Helm operations"` - - // TODO (@WSTARR): This is a library only addition to Zarf and should be refactored in the future (potentially to utilize component composability). As is it should NOT be exposed directly on the CLI - ValuesOverridesMap map[string]map[string]map[string]interface{} `json:"valuesOverridesMap" jsonschema:"description=[Library Only] A map of component names to chart names containing Helm Chart values to override values on deploy"` + // Whether to adopt any pre-existing K8s resources into the Helm charts managed by Zarf + AdoptExistingResources bool + // Skip waiting for external webhooks to execute as each package component is deployed + SkipWebhooks bool + // Timeout for performing Helm operations + Timeout time.Duration + // [Library Only] A map of component names to chart names containing Helm Chart values to override values on deploy + ValuesOverridesMap map[string]map[string]map[string]interface{} } // ZarfMirrorOptions tracks the user-defined preferences during a package mirror. type ZarfMirrorOptions struct { - NoImgChecksum bool `json:"noImgChecksum" jsonschema:"description=Whether to skip adding a Zarf checksum to image references."` + // Whether to skip adding a Zarf checksum to image references + NoImgChecksum bool } // ZarfPublishOptions tracks the user-defined preferences during a package publish. type ZarfPublishOptions struct { - PackageDestination string `json:"packageDestination" jsonschema:"description=Location where the Zarf package will be published to"` - SigningKeyPassword string `json:"signingKeyPassword" jsonschema:"description=Password to the private key signature file that will be used to sign the published package"` - SigningKeyPath string `json:"signingKeyPath" jsonschema:"description=Location where the private key component of a cosign key-pair can be found"` + // Location where the Zarf package will be published to + PackageDestination string + // Password to the private key signature file that will be used to sign the published package + SigningKeyPassword string + // Location where the private key component of a cosign key-pair can be found + SigningKeyPath string } // ZarfPullOptions tracks the user-defined preferences during a package pull. type ZarfPullOptions struct { - OutputDirectory string `json:"outputDirectory" jsonschema:"description=Location where the pulled Zarf package will be placed"` + // Location where the pulled Zarf package will be placed + OutputDirectory string } // ZarfGenerateOptions tracks the user-defined options during package generation. type ZarfGenerateOptions struct { - Name string `json:"name" jsonschema:"description=Name of the package being generated"` - URL string `json:"url" jsonschema:"description=URL to the source git repository"` - Version string `json:"version" jsonschema:"description=Version of the chart to use"` - GitPath string `json:"gitPath" jsonschema:"description=Relative path to the chart in the git repository"` - Output string `json:"output" jsonschema:"description=Location where the finalized zarf.yaml will be placed"` + // Name of the package being generated + Name string + // URL to the source git repository + URL string + // Version of the chart to use + Version string + // Relative path to the chart in the git repository + GitPath string + // Location where the finalized zarf.yaml will be placed + Output string } // ZarfInitOptions tracks the user-defined options during cluster initialization. type ZarfInitOptions struct { - // Zarf init is installing the k3s component - ApplianceMode bool `json:"applianceMode" jsonschema:"description=Indicates if Zarf was initialized while deploying its own k8s cluster"` - - // Using alternative services - GitServer GitServerInfo `json:"gitServer" jsonschema:"description=Information about the repository Zarf is going to be using"` - RegistryInfo RegistryInfo `json:"registryInfo" jsonschema:"description=Information about the container registry Zarf is going to be using"` - ArtifactServer ArtifactServerInfo `json:"artifactServer" jsonschema:"description=Information about the artifact registry Zarf is going to be using"` - - StorageClass string `json:"storageClass" jsonschema:"description=StorageClass of the k8s cluster Zarf is initializing"` + // Indicates if Zarf was initialized while deploying its own k8s cluster + ApplianceMode bool + // Information about the repository Zarf is going to be using + GitServer GitServerInfo + // Information about the container registry Zarf is going to be using + RegistryInfo RegistryInfo + // Information about the artifact registry Zarf is going to be using + ArtifactServer ArtifactServerInfo + // StorageClass of the k8s cluster Zarf is initializing + StorageClass string } // ZarfCreateOptions tracks the user-defined options used to create the package. type ZarfCreateOptions struct { - SkipSBOM bool `json:"skipSBOM" jsonschema:"description=Disable the generation of SBOM materials during package creation"` - BaseDir string `json:"baseDir" jsonschema:"description=Location where the Zarf package will be created from"` - Output string `json:"output" jsonschema:"description=Location where the finalized Zarf package will be placed"` - ViewSBOM bool `json:"sbom" jsonschema:"description=Whether to pause to allow for viewing the SBOM post-creation"` - SBOMOutputDir string `json:"sbomOutput" jsonschema:"description=Location to output an SBOM into after package creation"` - SetVariables map[string]string `json:"setVariables" jsonschema:"description=Key-Value map of variable names and their corresponding values that will be used to template against the Zarf package being used"` - MaxPackageSizeMB int `json:"maxPackageSizeMB" jsonschema:"description=Size of chunks to use when splitting a zarf package into multiple files in megabytes"` - SigningKeyPath string `json:"signingKeyPath" jsonschema:"description=Location where the private key component of a cosign key-pair can be found"` - SigningKeyPassword string `json:"signingKeyPassword" jsonschema:"description=Password to the private key signature file that will be used to sigh the created package"` - DifferentialPackagePath string `json:"differentialPackagePath" jsonschema:"description=Path to a previously built package used as the basis for creating a differential package"` - RegistryOverrides map[string]string `json:"registryOverrides" jsonschema:"description=A map of domains to override on package create when pulling images"` - Flavor string `json:"flavor" jsonschema:"description=An optional variant that controls which components will be included in a package"` - IsSkeleton bool `json:"isSkeleton" jsonschema:"description=Whether to create a skeleton package"` - NoYOLO bool `json:"noYOLO" jsonschema:"description=Whether to create a YOLO package"` + // Disable the generation of SBOM materials during package creation + SkipSBOM bool + // Location where the Zarf package will be created from + BaseDir string + // Location where the finalized Zarf package will be placed + Output string + // Whether to pause to allow for viewing the SBOM post-creation + ViewSBOM bool + // Location to output an SBOM into after package creation + SBOMOutputDir string + // Key-Value map of variable names and their corresponding values that will be used to template against the Zarf package being used + SetVariables map[string]string + // Size of chunks to use when splitting a zarf package into multiple files in megabytes + MaxPackageSizeMB int + // Location where the private key component of a cosign key-pair can be found + SigningKeyPath string + // Password to the private key signature file that will be used to sigh the created package + SigningKeyPassword string + // Path to a previously built package used as the basis for creating a differential package + DifferentialPackagePath string + // A map of domains to override on package create when pulling images + RegistryOverrides map[string]string + // An optional variant that controls which components will be included in a package + Flavor string + // Whether to create a skeleton package + IsSkeleton bool + // Whether to create a YOLO package + NoYOLO bool } // ZarfSplitPackageData contains info about a split package. type ZarfSplitPackageData struct { - Sha256Sum string `json:"sha256Sum" jsonschema:"description=The sha256sum of the package"` - Bytes int64 `json:"bytes" jsonschema:"description=The size of the package in bytes"` - Count int `json:"count" jsonschema:"description=The number of parts the package is split into"` + // The sha256sum of the package + Sha256Sum string + // The size of the package in bytes + Bytes int64 + // The number of parts the package is split into + Count int } // ConnectString contains information about a connection made with Zarf connect. type ConnectString struct { - Description string `json:"description" jsonschema:"description=Descriptive text that explains what the resource you would be connecting to is used for"` - URL string `json:"url" jsonschema:"description=URL path that gets appended to the k8s port-forward result"` + // Descriptive text that explains what the resource you would be connecting to is used for + Description string + // URL path that gets appended to the k8s port-forward result + URL string } // ConnectStrings is a map of connect names to connection information. @@ -144,29 +193,3 @@ type DifferentialData struct { DifferentialRepos map[string]bool DifferentialPackageVersion string } - -// PackageFinding is a struct that contains a finding about something wrong with a package -type PackageFinding struct { - // YqPath is the path to the key where the error originated from, this is sometimes empty in the case of a general error - YqPath string - Description string - // Item is the value of a key that is causing an error, for example a bad image name - Item string - // PackageNameOverride shows the name of the package that the error originated from - // If it is not set the base package will be used when displaying the error - PackageNameOverride string - // PackagePathOverride shows the path to the package that the error originated from - // If it is not set the base package will be used when displaying the error - PackagePathOverride string - Severity Severity -} - -// Severity is the type of package error -// Either Err or Warning -type Severity int - -// different severities of package errors -const ( - SevErr Severity = iota + 1 - SevWarn -) diff --git a/zarf.schema.json b/zarf.schema.json index d7d2b5adc6..09596b024e 100644 --- a/zarf.schema.json +++ b/zarf.schema.json @@ -71,6 +71,7 @@ "name", "value" ], + "description": "Constant are constants that can be used to dynamically template K8s resources or run in actions.", "patternProperties": { "^x-": {} } @@ -163,6 +164,7 @@ "required": [ "name" ], + "description": "InteractiveVariable is a variable that can be used to prompt a user for more information", "patternProperties": { "^x-": {} } @@ -243,6 +245,7 @@ "required": [ "name" ], + "description": "Variable represents a variable that has a value set programmatically", "patternProperties": { "^x-": {} } @@ -503,7 +506,7 @@ }, "scripts": { "$ref": "#/$defs/DeprecatedZarfComponentScripts", - "description": "[Deprecated] (replaced by actions) Custom commands to run before or after package deployment. This will be removed in Zarf v1.0.0." + "description": "[Deprecated] (replaced by actions) Custom commands to run before or after package deployment. This will be removed in Zarf v1.0.0." }, "actions": { "$ref": "#/$defs/ZarfComponentActions", @@ -685,7 +688,7 @@ "description": "The kind of resource to wait for", "examples": [ "Pod", - "Deployment)" + "Deployment" ] }, "name": { @@ -693,7 +696,7 @@ "description": "The name of the resource or selector to wait for", "examples": [ "podinfo", - "app=podinfo" + "app=podinfo" ] }, "namespace": { @@ -752,7 +755,8 @@ "type": "object", "required": [ "protocol", - "address" + "address", + "code" ], "description": "ZarfComponentActionWaitNetwork specifies a condition to wait for before continuing", "patternProperties": { @@ -806,7 +810,7 @@ "pattern": "###ZARF_PKG_TMPL_" }, "type": "string", - "description": "For further explanation see https://regex101.com/r/nxX8vx/1" + "description": "The path to the directory containing a zarf.yaml to import" }, "url": { "not": { @@ -814,7 +818,7 @@ }, "type": "string", "pattern": "^oci://.*$", - "description": "For further explanation see https://regex101.com/r/nxX8vx/1\n[beta] The URL to a Zarf package to import via OCI" + "description": "[beta] The URL to a Zarf package to import via OCI" } }, "additionalProperties": false, @@ -855,7 +859,7 @@ }, "ZarfComponentOnlyTarget": { "properties": { - "localOS": { + "localOs": { "type": "string", "enum": [ "linux", @@ -890,7 +894,7 @@ "type": "string", "description": "The K8s selector to target for data injection", "examples": [ - "app=data-injection" + "app=data-injection" ] }, "container": { @@ -1081,11 +1085,11 @@ }, "vendor": { "type": "string", - "description": "Name of the distributing entity, organization or individual." + "description": "Name of the distributing entity, organization or individual" }, "aggregateChecksum": { "type": "string", - "description": "Checksum of a checksums.txt file that contains checksums all the layers within the package." + "description": "Checksum of a checksums.txt file that contains checksums all the layers within the package" } }, "additionalProperties": false, From 7e168604137d0f54545321dccdd936b209e6d369 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 29 Jul 2024 19:21:00 +0000 Subject: [PATCH 05/34] make gen types work again Signed-off-by: Austin Abro --- src/cmd/internal.go | 14 +++++++++++++- src/types/component.go | 11 ++++++++++- src/types/k8s.go | 8 +++----- zarf.schema.json | 18 +++++++++--------- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/cmd/internal.go b/src/cmd/internal.go index 824d803788..45ab28c04c 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -195,7 +195,19 @@ var genTypesSchemaCmd = &cobra.Command{ Aliases: []string{"gt"}, Short: lang.CmdInternalTypesSchemaShort, RunE: func(_ *cobra.Command, _ []string) error { - schema := jsonschema.Reflect(&zarfTypes{}) + reflector := jsonschema.Reflector(jsonschema.Reflector{ExpandedStruct: true}) + typePackagePath := filepath.Join("src", "types") + if err := reflector.AddGoComments("github.com/zarf-dev/zarf", typePackagePath); err != nil { + return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) + } + varPackagePath := filepath.Join("src", "pkg", "variables") + if err := reflector.AddGoComments("github.com/zarf-dev/zarf", varPackagePath); err != nil { + return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) + } + + reflector.KeyNamer = strcase.LowerCamelCase + reflector.RequiredFromJSONSchemaTags = true + schema := reflector.Reflect(&zarfTypes{}) output, err := json.MarshalIndent(schema, "", " ") if err != nil { return fmt.Errorf("unable to generate the JSON schema for the Zarf types DeployedPackage, ZarfPackage, and ZarfState: %w", err) diff --git a/src/types/component.go b/src/types/component.go index b9dc2df3ca..eb0779e002 100644 --- a/src/types/component.go +++ b/src/types/component.go @@ -92,13 +92,22 @@ 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" jsonschema:"enum=linux,enum=darwin,enum=windows"` + LocalOS string `jsonschema:"enum=linux,enum=darwin,enum=windows"` // Only deploy component to specified clusters Cluster ZarfComponentOnlyCluster // Only include this component when a matching '--flavor' is specified on 'zarf package create' Flavor string } +// JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` +func (ZarfComponentOnlyTarget) JSONSchemaExtend(schema *jsonschema.Schema) { + // Need this since it auto camel cases the acronym + localOS := schema.Properties.GetPair("localOs") + localOS.Key = "localOS" + schema.Properties.Delete("localOs") + schema.Properties.AddPairs(*localOS) +} + // ZarfComponentOnlyCluster represents the architecture and K8s cluster distribution to filter on. type ZarfComponentOnlyCluster struct { // Only create and deploy to clusters of the given architecture diff --git a/src/types/k8s.go b/src/types/k8s.go index c1ca6d0005..96ff246638 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -85,8 +85,8 @@ type DeployedPackage struct { CLIVersion string Generation int DeployedComponents []DeployedComponent - ComponentWebhooks map[string]map[string]Webhook `jsonschema:"required"` - ConnectStrings ConnectStrings `jsonschema:"required"` + ComponentWebhooks map[string]map[string]Webhook + ConnectStrings ConnectStrings } // DeployedComponent contains information about a Zarf Package Component that has been deployed to a cluster. @@ -100,7 +100,7 @@ type DeployedComponent struct { // Webhook contains information about a Component Webhook operating on a Zarf package secret. type Webhook struct { Name string - WaitDurationSeconds int `jsonschema:"required"` + WaitDurationSeconds int Status WebhookStatus ObservedGeneration int } @@ -201,14 +201,12 @@ type RegistryInfo struct { PullUsername string // Password of a user with pull-only access to the registry. If not provided for an external registry than the push-user is used PullPassword string - // URL address of the registry Address string // Nodeport of the registry. Only needed if the registry is running inside the kubernetes cluster NodePort int // Indicates if we are using a registry that Zarf is directly managing InternalRegistry bool - // Secret value that the registry was seeded with Secret string } diff --git a/zarf.schema.json b/zarf.schema.json index 09596b024e..ebf4e729d3 100644 --- a/zarf.schema.json +++ b/zarf.schema.json @@ -859,15 +859,6 @@ }, "ZarfComponentOnlyTarget": { "properties": { - "localOs": { - "type": "string", - "enum": [ - "linux", - "darwin", - "windows" - ], - "description": "Only deploy component to specified OS" - }, "cluster": { "$ref": "#/$defs/ZarfComponentOnlyCluster", "description": "Only deploy component to specified clusters" @@ -875,6 +866,15 @@ "flavor": { "type": "string", "description": "Only include this component when a matching '--flavor' is specified on 'zarf package create'" + }, + "localOS": { + "type": "string", + "enum": [ + "linux", + "darwin", + "windows" + ], + "description": "Only deploy component to specified OS" } }, "additionalProperties": false, From 8dfe1a51b7b707f5cfbc9da0872f39a2e67cf2d3 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 29 Jul 2024 19:49:58 +0000 Subject: [PATCH 06/34] wording Signed-off-by: Austin Abro --- src/types/component.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/component.go b/src/types/component.go index eb0779e002..5b01afa18b 100644 --- a/src/types/component.go +++ b/src/types/component.go @@ -322,7 +322,7 @@ type ZarfDataInjection struct { type ZarfComponentImport struct { // The name of the component to import from the referenced zarf.yaml Name string - // The path to the directory containing a zarf.yaml to import + // The path to the directory containing the zarf.yaml to import Path string // [beta] The URL to a Zarf package to import via OCI URL string `jsonschema:"pattern=^oci://.*$"` From be388f8f70cb31927cec1d4a2ebe9510bc38736f Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 29 Jul 2024 20:20:13 +0000 Subject: [PATCH 07/34] add json tags back Signed-off-by: Austin Abro --- src/cmd/internal.go | 3 - src/types/component.go | 197 ++++++++++++++++++++--------------------- src/types/k8s.go | 92 +++++++++---------- src/types/package.go | 62 ++++++------- src/types/runtime.go | 122 ++++++++++++------------- zarf.schema.json | 152 +++++++++++++++---------------- 6 files changed, 308 insertions(+), 320 deletions(-) diff --git a/src/cmd/internal.go b/src/cmd/internal.go index 45ab28c04c..5f0f3f6ee8 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -17,7 +17,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/cobra/doc" "github.com/spf13/pflag" - strcase "github.com/stoewer/go-strcase" "github.com/zarf-dev/zarf/src/cmd/common" "github.com/zarf-dev/zarf/src/config/lang" "github.com/zarf-dev/zarf/src/internal/agent" @@ -172,7 +171,6 @@ var genConfigSchemaCmd = &cobra.Command{ return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) } - reflector.KeyNamer = strcase.LowerCamelCase reflector.RequiredFromJSONSchemaTags = true schema := reflector.Reflect(&types.ZarfPackage{}) output, err := json.MarshalIndent(schema, "", " ") @@ -205,7 +203,6 @@ var genTypesSchemaCmd = &cobra.Command{ return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) } - reflector.KeyNamer = strcase.LowerCamelCase reflector.RequiredFromJSONSchemaTags = true schema := reflector.Reflect(&zarfTypes{}) output, err := json.MarshalIndent(schema, "", " ") diff --git a/src/types/component.go b/src/types/component.go index 5b01afa18b..893224f06f 100644 --- a/src/types/component.go +++ b/src/types/component.go @@ -14,19 +14,19 @@ import ( // ZarfComponent is the primary functional grouping of assets to deploy by Zarf. type ZarfComponent struct { // The name of the component - Name string `jsonschema:"required,pattern=^[a-z0-9][a-z0-9\\-]*$"` + Name string `json:"name" jsonschema:"required,pattern=^[a-z0-9][a-z0-9\\-]*$"` // Message to include during package deploy describing the purpose of this component - Description string + Description string `json:"description"` // Determines the default Y/N state for installing this component on package deploy - Default bool + Default bool `json:"default"` // Do not prompt user to install this component - Required *bool + Required *bool `json:"required"` // Filter when this component is included in package creation or deployment - Only ZarfComponentOnlyTarget + Only ZarfComponentOnlyTarget `json:"only"` // [Deprecated] Create a user selector field based on all components in the same group. This will be removed in Zarf v1.0.0. Consider using 'only.flavor' instead. DeprecatedGroup string `json:"group" jsonschema:"deprecated=true"` @@ -35,34 +35,34 @@ type ZarfComponent struct { DeprecatedCosignKeyPath string `json:"cosignKeyPath" jsonschema:"deprecated=true"` // Import a component from another Zarf package - Import ZarfComponentImport + Import ZarfComponentImport `json:"import"` // Kubernetes manifests to be included in a generated Helm chart on package deploy - Manifests []ZarfManifest + Manifests []ZarfManifest `json:"manifests"` // Helm charts to install during package deploy - Charts []ZarfChart + Charts []ZarfChart `json:"charts"` // Datasets to inject into a container in the target cluster - DataInjections []ZarfDataInjection + DataInjections []ZarfDataInjection `json:"dataInjections"` // Files or folders to place on disk during package deployment - Files []ZarfFile + Files []ZarfFile `json:"files"` // List of OCI images to include in the package - Images []string + Images []string `json:"images"` // List of git repos to include in the package - Repos []string + Repos []string `json:"repos"` // Extend component functionality with additional features - Extensions extensions.ZarfComponentExtensions + Extensions extensions.ZarfComponentExtensions `json:"extensions"` // [Deprecated] (replaced by actions) Custom commands to run before or after package deployment. This will be removed in Zarf v1.0.0. DeprecatedScripts DeprecatedZarfComponentScripts `json:"scripts" jsonschema:"deprecated=true"` // Custom commands to run at various stages of a package lifecycle - Actions ZarfComponentActions + Actions ZarfComponentActions `json:"actions"` } // RequiresCluster returns if the component requires a cluster connection to deploy @@ -92,240 +92,231 @@ 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 `jsonschema:"enum=linux,enum=darwin,enum=windows"` + LocalOS string `json:"localOS" jsonschema:"enum=linux,enum=darwin,enum=windows"` // Only deploy component to specified clusters - Cluster ZarfComponentOnlyCluster + Cluster ZarfComponentOnlyCluster `json:"cluster"` // Only include this component when a matching '--flavor' is specified on 'zarf package create' - Flavor string -} - -// JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` -func (ZarfComponentOnlyTarget) JSONSchemaExtend(schema *jsonschema.Schema) { - // Need this since it auto camel cases the acronym - localOS := schema.Properties.GetPair("localOs") - localOS.Key = "localOS" - schema.Properties.Delete("localOs") - schema.Properties.AddPairs(*localOS) + Flavor string `json:"flavor"` } // ZarfComponentOnlyCluster represents the architecture and K8s cluster distribution to filter on. type ZarfComponentOnlyCluster struct { // Only create and deploy to clusters of the given architecture - Architecture string `jsonschema:"enum=amd64,enum=arm64"` + Architecture string `json:"architecture" jsonschema:"enum=amd64,enum=arm64"` // A list of kubernetes distros this package works with (Reserved for future use) - Distros []string `jsonschema:"example=k3s,example=eks"` + Distros []string `json:"distros" jsonschema:"example=k3s,example=eks"` } // ZarfFile defines a file to deploy. type ZarfFile struct { // Local folder or file path or remote URL to pull into the package - Source string `jsonschema:"required"` + Source string `json:"source" jsonschema:"required"` // (files only) Optional SHA256 checksum of the file - Shasum string + Shasum string `json:"shasum"` // The absolute or relative path where the file or folder should be copied to during package deploy - Target string `jsonschema:"required"` + Target string `json:"target" jsonschema:"required"` // (files only) Determines if the file should be made executable during package deploy - Executable bool + Executable bool `json:"executable"` // List of symlinks to create during package deploy - Symlinks []string + Symlinks []string `json:"symlinks"` // Local folder or file to be extracted from a 'source' archive - ExtractPath string + ExtractPath string `json:"extractPath"` } // ZarfChart defines a helm chart to be deployed. type ZarfChart struct { // 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 - Name string `jsonschema:"required"` + Name string `json:"name" jsonschema:"required"` // 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 + Version string `json:"version"` // The URL of the OCI registry, chart repository, or git repo where the helm chart is stored - URL string `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)"` + URL string `json:"url" 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)"` // The name of a chart within a Helm repository (defaults to the Zarf name of the chart) - RepoName string + RepoName string `json:"repoName"` // (git repo only) The sub directory to the chart within a git repo - GitPath string `jsonschema:"example=charts/your-chart"` + GitPath string `json:"gitPath" jsonschema:"example=charts/your-chart"` // The path to a local chart's folder or .tgz archive - LocalPath string + LocalPath string `json:"localPath"` // The namespace to deploy the chart to - Namespace string + Namespace string `json:"namespace"` // The name of the Helm release to create (defaults to the Zarf name of the chart) - ReleaseName string + ReleaseName string `json:"releaseName"` // Whether to not wait for chart resources to be ready before continuing - NoWait bool + NoWait bool `json:"noWait"` // List of local values file paths or remote URLs to include in the package; these will be merged together when deployed - ValuesFiles []string + ValuesFiles []string `json:"valuesFiles"` // [alpha] List of variables to set in the Helm chart - Variables []ZarfChartVariable + Variables []ZarfChartVariable `json:"variables"` } // ZarfChartVariable represents a variable that can be set for a Helm chart overrides. type ZarfChartVariable struct { // The name of the variable - Name string `jsonschema:"required,pattern=^[A-Z0-9_]+$"` + Name string `json:"name" jsonschema:"required,pattern=^[A-Z0-9_]+$"` // A brief description of what the variable controls - Description string `jsonschema:"required"` + Description string `json:"description" jsonschema:"required"` // The path within the Helm chart values where this variable applies - Path string `jsonschema:"required"` + Path string `json:"path" jsonschema:"required"` } // 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 - Name string `jsonschema:"required"` + Name string `json:"name" jsonschema:"required"` // The namespace to deploy the manifests to - Namespace string + Namespace string `json:"namespace"` // List of local K8s YAML files or remote URLs to deploy (in order) - Files []string + Files []string `json:"files"` // Allow traversing directory above the current directory if needed for kustomization - KustomizeAllowAnyDirectory bool + KustomizeAllowAnyDirectory bool `json:"kustomizeAllowAnyDirectory"` // List of local kustomization paths or remote URLs to include in the package - Kustomizations []string + Kustomizations []string `json:"kustomizations"` // Whether to not wait for manifest resources to be ready before continuing - NoWait bool + NoWait bool `json:"noWait"` } // DeprecatedZarfComponentScripts are scripts that run before or after a component is deployed type DeprecatedZarfComponentScripts struct { // Show the output of the script during package deployment - ShowOutput bool + ShowOutput bool `json:"showOutput"` // Timeout in seconds for the script - TimeoutSeconds int + TimeoutSeconds int `json:"timeoutSeconds"` // Retry the script if it fails - Retry bool + Retry bool `json:"retry"` // Scripts to run before the component is added during package create - Prepare []string + Prepare []string `json:"prepare"` // Scripts to run before the component is deployed - Before []string + Before []string `json:"before"` // Scripts to run after the component successfully deploys - After []string + After []string `json:"after"` } // ZarfComponentActions are ActionSets that map to different zarf package operations type ZarfComponentActions struct { // Actions to run during package creation - OnCreate ZarfComponentActionSet + OnCreate ZarfComponentActionSet `json:"onCreate"` // Actions to run during package deployment - OnDeploy ZarfComponentActionSet + OnDeploy ZarfComponentActionSet `json:"onDeploy"` // Actions to run during package removal - OnRemove ZarfComponentActionSet + OnRemove ZarfComponentActionSet `json:"onRemove"` } // ZarfComponentActionSet is a set of actions to run during a zarf package operation type ZarfComponentActionSet struct { // Default configuration for all actions in this set - Defaults ZarfComponentActionDefaults + Defaults ZarfComponentActionDefaults `json:"defaults"` // Actions to run at the start of an operation - Before []ZarfComponentAction + Before []ZarfComponentAction `json:"before"` // Actions to run at the end of an operation - After []ZarfComponentAction + After []ZarfComponentAction `json:"after"` // Actions to run if all operations succeed - OnSuccess []ZarfComponentAction + OnSuccess []ZarfComponentAction `json:"onSuccess"` // Actions to run if all operations fail - OnFailure []ZarfComponentAction + OnFailure []ZarfComponentAction `json:"onFailure"` } // ZarfComponentActionDefaults sets the default configs for child actions type ZarfComponentActionDefaults struct { // Hide the output of commands during execution (default false) - Mute bool + Mute bool `json:"mute"` // Default timeout in seconds for commands (default to 0, no timeout) - MaxTotalSeconds int + MaxTotalSeconds int `json:"maxTotalSeconds"` // Retry commands given number of times if they fail (default 0) - MaxRetries int + MaxRetries int `json:"maxRetries"` // Working directory for commands (default CWD) - Dir string + Dir string `json:"dir"` // Additional environment variables for commands - Env []string + Env []string `json:"env"` // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems - Shell exec.Shell + Shell exec.Shell `json:"shell"` } // ZarfComponentAction represents a single action to run during a zarf package operation type ZarfComponentAction struct { // Hide the output of the command during package deployment (default false) - Mute *bool + Mute *bool `json:"mute"` // Timeout in seconds for the command (default to 0, no timeout for cmd actions and 300, 5 minutes for wait actions) - MaxTotalSeconds *int + MaxTotalSeconds *int `json:"maxTotalSeconds"` // Retry the command if it fails up to given number of times (default 0) - MaxRetries *int + MaxRetries *int `json:"maxRetries"` // The working directory to run the command in (default is CWD) - Dir *string + Dir *string `json:"dir"` // Additional environment variables to set for the command - Env []string + Env []string `json:"env"` // The command to run. Must specify either cmd or wait for the action to do anything. - Cmd string + Cmd string `json:"cmd"` // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems - Shell *exec.Shell + Shell *exec.Shell `json:"shell"` // [Deprecated] (replaced by setVariables) (onDeploy/cmd only) The name of a variable to update with the output of the command. This variable will be available to all remaining actions and components in the package. This will be removed in Zarf v1.0.0 DeprecatedSetVariable string `json:"setVariable" jsonschema:"pattern=^[A-Z0-9_]+$"` // (onDeploy/cmd only) An array of variables to update with the output of the command. These variables will be available to all remaining actions and components in the package. - SetVariables []variables.Variable + SetVariables []variables.Variable `json:"setVariables"` // Description of the action to be displayed during package execution instead of the command - Description string + Description string `json:"description"` // Wait for a condition to be met before continuing. Must specify either cmd or wait for the action. See the 'zarf tools wait-for' command for more info. - Wait *ZarfComponentActionWait + Wait *ZarfComponentActionWait `json:"wait"` } // ZarfComponentActionWait specifies a condition to wait for before continuing type ZarfComponentActionWait struct { // Wait for a condition to be met in the cluster before continuing. Only one of cluster or network can be specified. - Cluster *ZarfComponentActionWaitCluster + Cluster *ZarfComponentActionWaitCluster `json:"cluster"` // Wait for a condition to be met on the network before continuing. Only one of cluster or network can be specified. - Network *ZarfComponentActionWaitNetwork + Network *ZarfComponentActionWaitNetwork `json:"network"` } // ZarfComponentActionWaitCluster specifies a condition to wait for before continuing type ZarfComponentActionWaitCluster struct { // The kind of resource to wait for - Kind string `jsonschema:"required,example=Pod,example=Deployment"` + Kind string `json:"kind" jsonschema:"required,example=Pod,example=Deployment"` // The name of the resource or selector to wait for - Name string `jsonschema:"required,example=podinfo,example=app=podinfo"` + Name string `json:"name" jsonschema:"required,example=podinfo,example=app=podinfo"` // The namespace of the resource to wait for - Namespace string + Namespace string `json:"namespace"` // The condition or jsonpath state to wait for; defaults to exist, a special condition that will wait for the resource to exist - Condition string `jsonschema:"example=Ready,example=Available,'{.status.availableReplicas}'=23"` + Condition string `json:"condition" jsonschema:"example=Ready,example=Available,'{.status.availableReplicas}'=23"` } // ZarfComponentActionWaitNetwork specifies a condition to wait for before continuing type ZarfComponentActionWaitNetwork struct { // The protocol to wait for - Protocol string `jsonschema:"required,enum=tcp,enum=http,enum=https"` + Protocol string `json:"protocol" jsonschema:"required,enum=tcp,enum=http,enum=https"` // The address to wait for - Address string `jsonschema:"required,example=localhost:8080,example=1.1.1.1"` + Address string `json:"address" jsonschema:"required,example=localhost:8080,example=1.1.1.1"` // The HTTP status code to wait for if using http or https - Code int `jsonschema:"required,example=200,example=404"` + Code int `json:"code" jsonschema:"required,example=200,example=404"` } // ZarfContainerTarget defines the destination info for a ZarfData target type ZarfContainerTarget struct { // The namespace to target for data injection - Namespace string `jsonschema:"required"` + Namespace string `json:"namespace" jsonschema:"required"` // The K8s selector to target for data injection - Selector string `jsonschema:"required,example=app=data-injection"` + Selector string `json:"selector" jsonschema:"required,example=app=data-injection"` // The container name to target for data injection - Container string `jsonschema:"required"` + Container string `json:"container" jsonschema:"required"` // The path within the container to copy the data into - Path string `jsonschema:"required"` + Path string `json:"path" jsonschema:"required"` } // ZarfDataInjection is a data-injection definition. type ZarfDataInjection struct { // Either a path to a local folder/file or a remote URL of a file to inject into the given target pod + container - Source string `jsonschema:"required"` + Source string `json:"source" jsonschema:"required"` // The target pod + container to inject the data into - Target ZarfContainerTarget `jsonschema:"required"` + Target ZarfContainerTarget `json:"target" jsonschema:"required"` // Compress the data before transmitting using gzip. Note: this requires support for tar/gzip locally and in the target image. - Compress bool + Compress bool `json:"compress"` } // ZarfComponentImport structure for including imported Zarf components. type ZarfComponentImport struct { // The name of the component to import from the referenced zarf.yaml - Name string + Name string `json:"name"` // The path to the directory containing the zarf.yaml to import - Path string + Path string `json:"path"` // [beta] The URL to a Zarf package to import via OCI - URL string `jsonschema:"pattern=^oci://.*$"` + URL string `json:"url" jsonschema:"pattern=^oci://.*$"` } // JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` diff --git a/src/types/k8s.go b/src/types/k8s.go index 96ff246638..9711b8f516 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -51,81 +51,81 @@ const ( // GeneratedPKI is a struct for storing generated PKI data. type GeneratedPKI struct { - CA []byte - Cert []byte - Key []byte + CA []byte `json:"ca"` + Cert []byte `json:"cert"` + Key []byte `json:"key"` } // ZarfState is maintained as a secret in the Zarf namespace to track Zarf init data. type ZarfState struct { // Indicates if Zarf was initialized while deploying its own k8s cluster - ZarfAppliance bool + ZarfAppliance bool `json:"zarfAppliance"` // K8s distribution of the cluster Zarf was deployed to - Distro string + Distro string `json:"distro"` // Machine architecture of the k8s node(s) - Architecture string + Architecture string `json:"architecture"` // Default StorageClass value Zarf uses for variable templating - StorageClass string + StorageClass string `json:"storageClass"` // PKI certificate information for the agent pods Zarf manages - AgentTLS GeneratedPKI + AgentTLS GeneratedPKI `json:"agentTLS"` // Information about the repository Zarf is configured to use - GitServer GitServerInfo + GitServer GitServerInfo `json:"gitServer"` // Information about the container registry Zarf is configured to use - RegistryInfo RegistryInfo + RegistryInfo RegistryInfo `json:"registryInfo"` // Information about the artifact registry Zarf is configured to use - ArtifactServer ArtifactServerInfo + ArtifactServer ArtifactServerInfo `json:"artifactServer"` } // DeployedPackage contains information about a Zarf Package that has been deployed to a cluster // This object is saved as the data of a k8s secret within the 'Zarf' namespace (not as part of the ZarfState secret). type DeployedPackage struct { - Name string - Data ZarfPackage - CLIVersion string - Generation int - DeployedComponents []DeployedComponent - ComponentWebhooks map[string]map[string]Webhook - ConnectStrings ConnectStrings + Name string `json:"name"` + Data ZarfPackage `json:"data"` + CLIVersion string `json:"cliVersion"` + Generation int `json:"generation"` + DeployedComponents []DeployedComponent `json:"deployedComponents"` + ComponentWebhooks map[string]map[string]Webhook `json:"componentWebhooks"` + ConnectStrings ConnectStrings `json:"connectStrings"` } // DeployedComponent contains information about a Zarf Package Component that has been deployed to a cluster. type DeployedComponent struct { - Name string - InstalledCharts []InstalledChart - Status ComponentStatus - ObservedGeneration int + Name string `json:"name"` + InstalledCharts []InstalledChart `json:"installedCharts"` + Status ComponentStatus `json:"status"` + ObservedGeneration int `json:"observedGeneration"` } // Webhook contains information about a Component Webhook operating on a Zarf package secret. type Webhook struct { - Name string - WaitDurationSeconds int - Status WebhookStatus - ObservedGeneration int + Name string `json:"name"` + WaitDurationSeconds int `json:"waitDurationSeconds"` + Status WebhookStatus `json:"status"` + ObservedGeneration int `json:"observedGeneration"` } // InstalledChart contains information about a Helm Chart that has been deployed to a cluster. type InstalledChart struct { - Namespace string - ChartName string + Namespace string `json:"namespace"` + ChartName string `json:"chartName"` } // GitServerInfo contains information Zarf uses to communicate with a git repository to push/pull repositories to. type GitServerInfo struct { // Username of a user with push access to the git repository - PushUsername string + PushUsername string `json:"pushUsername"` // Password of a user with push access to the git repository - PushPassword string + PushPassword string `json:"pushPassword"` // Username of a user with pull-only access to the git repository. If not provided for an external repository then the push-user is used - PullUsername string + PullUsername string `json:"pullUsername"` // Password of a user with pull-only access to the git repository. If not provided for an external repository then the push-user is used - PullPassword string + PullPassword string `json:"pullPassword"` // URL address of the git server - Address string + Address string `json:"address"` // Indicates if we are using a git server that Zarf is directly managing - InternalServer bool + InternalServer bool `json:"internalServer"` } // FillInEmptyValues sets every necessary value that's currently empty to a reasonable default @@ -168,13 +168,13 @@ func (gs *GitServerInfo) FillInEmptyValues() error { // ArtifactServerInfo contains information Zarf uses to communicate with a artifact registry to push/pull repositories to. type ArtifactServerInfo struct { // Username of a user with push access to the artifact registry - PushUsername string + PushUsername string `json:"pushUsername"` // Password of a user with push access to the artifact registry - PushToken string + PushToken string `json:"pushToken"` // URL address of the artifact registry - Address string + Address string `json:"address"` // Indicates if we are using a artifact registry that Zarf is directly managing - InternalServer bool + InternalServer bool `json:"internalServer"` } // FillInEmptyValues sets every necessary value that's currently empty to a reasonable default @@ -194,21 +194,21 @@ func (as *ArtifactServerInfo) FillInEmptyValues() { // RegistryInfo contains information Zarf uses to communicate with a container registry to push/pull images. type RegistryInfo struct { // Username of a user with push access to the registry - PushUsername string + PushUsername string `json:"pushUsername"` // Password of a user with push access to the registry - PushPassword string + PushPassword string `json:"pushPassword"` // Username of a user with pull-only access to the registry. If not provided for an external registry than the push-user is used - PullUsername string + PullUsername string `json:"pullUsername"` // Password of a user with pull-only access to the registry. If not provided for an external registry than the push-user is used - PullPassword string + PullPassword string `json:"pullPassword"` // URL address of the registry - Address string + Address string `json:"address"` // Nodeport of the registry. Only needed if the registry is running inside the kubernetes cluster - NodePort int + NodePort int `json:"nodePort"` // Indicates if we are using a registry that Zarf is directly managing - InternalRegistry bool + InternalRegistry bool `json:"internalRegistry"` // Secret value that the registry was seeded with - Secret string + Secret string `json:"secret"` } // FillInEmptyValues sets every necessary value not already set to a reasonable default diff --git a/src/types/package.go b/src/types/package.go index c31330eba3..0a7e5f52be 100644 --- a/src/types/package.go +++ b/src/types/package.go @@ -19,17 +19,17 @@ const ( // ZarfPackage the top-level structure of a Zarf config file. type ZarfPackage struct { // The kind of Zarf package - Kind ZarfPackageKind `jsonschema:"required,enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` + Kind ZarfPackageKind `json:"kind" jsonschema:"required,enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` // Package metadata - Metadata ZarfMetadata + Metadata ZarfMetadata `json:"metadata"` // Zarf-generated package build data - Build ZarfBuildData + Build ZarfBuildData `json:"build"` // List of components to deploy in this package - Components []ZarfComponent `jsonschema:"required,minItems=1"` + Components []ZarfComponent `json:"components" jsonschema:"required,minItems=1"` // Constant template values applied on deploy for K8s resources - Constants []variables.Constant + Constants []variables.Constant `json:"constants"` // Variable template values applied on deploy for K8s resources - Variables []variables.InteractiveVariable + Variables []variables.InteractiveVariable `json:"variables"` } // IsInitConfig returns whether a Zarf package is an init config. @@ -50,57 +50,57 @@ func (pkg ZarfPackage) IsSBOMAble() bool { // ZarfMetadata lists information about the current ZarfPackage. type ZarfMetadata struct { // Name to identify this Zarf package - Name string `jsonschema:"required,pattern=^[a-z0-9][a-z0-9\\-]*$"` + Name string `json:"name" jsonschema:"required,pattern=^[a-z0-9][a-z0-9\\-]*$"` // Additional information about this package - Description string + Description string `json:"description"` // Generic string set by a package author to track the package version (Note: ZarfInitConfigs will always be versioned to the CLIVersion they were created with) - Version string + Version string `json:"version"` // Link to package information when online - URL string + URL string `json:"url"` // An image URL to embed in this package (Reserved for future use in Zarf UI) - Image string + Image string `json:"image"` // Disable compression of this package - Uncompressed bool + Uncompressed bool `json:"uncompressed"` // The target cluster architecture for this package - Architecture string `jsonschema:"example=arm64,example=amd64"` + Architecture string `json:"architecture" jsonschema:"example=arm64,example=amd64"` // Yaml OnLy Online (YOLO): True enables deploying a Zarf package without first running zarf init against the cluster. This is ideal for connected environments where you want to use existing VCS and container registries. - YOLO bool + YOLO bool `json:"yolo"` // Comma-separated list of package authors (including contact info) - Authors string `jsonschema:"example=Doug <hello@defenseunicorns.com>, Pepr <hello@defenseunicorns.com>"` + Authors string `json:"authors" jsonschema:"example=Doug <hello@defenseunicorns.com>, Pepr <hello@defenseunicorns.com>"` // Link to package documentation when online - Documentation string + Documentation string `json:"documentation"` // Link to package source code when online - Source string + Source string `json:"source"` // Name of the distributing entity, organization or individual - Vendor string + Vendor string `json:"vendor"` // Checksum of a checksums.txt file that contains checksums all the layers within the package - AggregateChecksum string + AggregateChecksum string `json:"aggregateChecksum"` } // ZarfBuildData is written during the packager.Create() operation to track details of the created package. type ZarfBuildData struct { // The machine name that created this package - Terminal string `jsonschema:"required"` + Terminal string `json:"terminal" jsonschema:"required"` // The username who created this package - User string `jsonschema:"required"` + User string `json:"user" jsonschema:"required"` // The architecture this package was created on - Architecture string `jsonschema:"required"` + Architecture string `json:"architecture" jsonschema:"required"` // The timestamp when this package was created - Timestamp string `jsonschema:"required"` + Timestamp string `json:"timestamp" jsonschema:"required"` // The version of Zarf used to build this package - Version string `jsonschema:"required"` + Version string `json:"version" jsonschema:"required"` // Any migrations that have been run on this package - Migrations []string + Migrations []string `json:"migrations"` // Any registry domains that were overridden on package create when pulling images - RegistryOverrides map[string]string + RegistryOverrides map[string]string `json:"registryOverrides"` // Whether this package was created with differential components - Differential bool + Differential bool `json:"differential"` // Version of a previously built package used as the basis for creating this differential package - DifferentialPackageVersion string + DifferentialPackageVersion string `json:"differentialPackageVersion"` // List of components that were not included in this package due to differential packaging - DifferentialMissing []string + DifferentialMissing []string `json:"differentialMissing"` // The minimum version of Zarf that does not have breaking package structure changes - LastNonBreakingVersion string + LastNonBreakingVersion string `json:"lastNonBreakingVersion"` // The flavor of Zarf used to build this package - Flavor string + Flavor string `json:"flavor"` } diff --git a/src/types/runtime.go b/src/types/runtime.go index 6587ff3aa0..b3b2f7c8f3 100644 --- a/src/types/runtime.go +++ b/src/types/runtime.go @@ -19,169 +19,169 @@ const ( // ZarfCommonOptions tracks the user-defined preferences used across commands. type ZarfCommonOptions struct { // Verify that Zarf should perform an action - Confirm bool + Confirm bool `json:"confirm"` // Allow insecure connections for remote packages - Insecure bool + Insecure bool `json:"insecure"` // Path to use to cache images and git repos on package create - CachePath string + CachePath string `json:"cachePath"` // Location Zarf should use as a staging ground when managing files and images for package creation and deployment - TempDirectory string + TempDirectory string `json:"tempDirectory"` // Number of concurrent layer operations to perform when interacting with a remote package - OCIConcurrency int + OCIConcurrency int `json:"ociConcurrency"` } // ZarfPackageOptions tracks the user-defined preferences during common package operations. type ZarfPackageOptions struct { // The SHA256 checksum of the package - Shasum string + Shasum string `json:"shasum"` // Location where a Zarf package can be found - PackageSource string + PackageSource string `json:"packageSource"` // Comma separated list of optional components - OptionalComponents string + OptionalComponents string `json:"optionalComponents"` // Location where the public key component of a cosign key-pair can be found - SGetKeyPath string + SGetKeyPath string `json:"sGetKeyPath"` // Key-Value map of variable names and their corresponding values that will be used to template manifests and files in the Zarf package - SetVariables map[string]string + SetVariables map[string]string `json:"setVariables"` // Location where the public key component of a cosign key-pair can be found - PublicKeyPath string + PublicKeyPath string `json:"publicKeyPath"` // The number of retries to perform for Zarf deploy operations like image pushes or Helm installs - Retries int + Retries int `json:"retries"` } // ZarfInspectOptions tracks the user-defined preferences during a package inspection. type ZarfInspectOptions struct { // View SBOM contents while inspecting the package - ViewSBOM bool + ViewSBOM bool `json:"viewSBOM"` // Location to output an SBOM into after package inspection - SBOMOutputDir string + SBOMOutputDir string `json:"sbomOutputDir"` // ListImages will list the images in the package - ListImages bool + ListImages bool `json:"listImages"` } // ZarfFindImagesOptions tracks the user-defined preferences during a prepare find-images search. type ZarfFindImagesOptions struct { // Path to the helm chart directory - RepoHelmChartPath string + RepoHelmChartPath string `json:"repoHelmChartPath"` // Kubernetes version to use for the helm chart - KubeVersionOverride string + KubeVersionOverride string `json:"kubeVersionOverride"` // Manual override for ###ZARF_REGISTRY### - RegistryURL string + RegistryURL string `json:"registryUrl"` // Find the location of the image given as an argument and print it to the console - Why string + Why string `json:"why"` // Optionally skip lookup of cosign artifacts when finding images - SkipCosign bool + SkipCosign bool `json:"skipCosign"` } // ZarfDeployOptions tracks the user-defined preferences during a package deploy. type ZarfDeployOptions struct { // Whether to adopt any pre-existing K8s resources into the Helm charts managed by Zarf - AdoptExistingResources bool + AdoptExistingResources bool `json:"adoptExistingResources"` // Skip waiting for external webhooks to execute as each package component is deployed - SkipWebhooks bool + SkipWebhooks bool `json:"skipWebhooks"` // Timeout for performing Helm operations - Timeout time.Duration + Timeout time.Duration `json:"timeout"` // [Library Only] A map of component names to chart names containing Helm Chart values to override values on deploy - ValuesOverridesMap map[string]map[string]map[string]interface{} + ValuesOverridesMap map[string]map[string]map[string]interface{} `json:"valuesOverridesMap"` } // ZarfMirrorOptions tracks the user-defined preferences during a package mirror. type ZarfMirrorOptions struct { // Whether to skip adding a Zarf checksum to image references - NoImgChecksum bool + NoImgChecksum bool `json:"noImgChecksum"` } // ZarfPublishOptions tracks the user-defined preferences during a package publish. type ZarfPublishOptions struct { // Location where the Zarf package will be published to - PackageDestination string + PackageDestination string `json:"packageDestination"` // Password to the private key signature file that will be used to sign the published package - SigningKeyPassword string + SigningKeyPassword string `json:"signingKeyPassword"` // Location where the private key component of a cosign key-pair can be found - SigningKeyPath string + SigningKeyPath string `json:"signingKeyPath"` } // ZarfPullOptions tracks the user-defined preferences during a package pull. type ZarfPullOptions struct { // Location where the pulled Zarf package will be placed - OutputDirectory string + OutputDirectory string `json:"outputDirectory"` } // ZarfGenerateOptions tracks the user-defined options during package generation. type ZarfGenerateOptions struct { // Name of the package being generated - Name string + Name string `json:"name"` // URL to the source git repository - URL string + URL string `json:"url"` // Version of the chart to use - Version string + Version string `json:"version"` // Relative path to the chart in the git repository - GitPath string + GitPath string `json:"gitPath"` // Location where the finalized zarf.yaml will be placed - Output string + Output string `json:"output"` } // ZarfInitOptions tracks the user-defined options during cluster initialization. type ZarfInitOptions struct { // Indicates if Zarf was initialized while deploying its own k8s cluster - ApplianceMode bool + ApplianceMode bool `json:"applianceMode"` // Information about the repository Zarf is going to be using - GitServer GitServerInfo + GitServer GitServerInfo `json:"gitServer"` // Information about the container registry Zarf is going to be using - RegistryInfo RegistryInfo + RegistryInfo RegistryInfo `json:"registryInfo"` // Information about the artifact registry Zarf is going to be using - ArtifactServer ArtifactServerInfo + ArtifactServer ArtifactServerInfo `json:"artifactServer"` // StorageClass of the k8s cluster Zarf is initializing - StorageClass string + StorageClass string `json:"storageClass"` } // ZarfCreateOptions tracks the user-defined options used to create the package. type ZarfCreateOptions struct { // Disable the generation of SBOM materials during package creation - SkipSBOM bool + SkipSBOM bool `json:"skipSBOM"` // Location where the Zarf package will be created from - BaseDir string + BaseDir string `json:"baseDir"` // Location where the finalized Zarf package will be placed - Output string + Output string `json:"output"` // Whether to pause to allow for viewing the SBOM post-creation - ViewSBOM bool + ViewSBOM bool `json:"viewSBOM"` // Location to output an SBOM into after package creation - SBOMOutputDir string + SBOMOutputDir string `json:"sbomOutputDir"` // Key-Value map of variable names and their corresponding values that will be used to template against the Zarf package being used - SetVariables map[string]string + SetVariables map[string]string `json:"setVariables"` // Size of chunks to use when splitting a zarf package into multiple files in megabytes - MaxPackageSizeMB int + MaxPackageSizeMB int `json:"maxPackageSizeMB"` // Location where the private key component of a cosign key-pair can be found - SigningKeyPath string + SigningKeyPath string `json:"signingKeyPath"` // Password to the private key signature file that will be used to sigh the created package - SigningKeyPassword string + SigningKeyPassword string `json:"signingKeyPassword"` // Path to a previously built package used as the basis for creating a differential package - DifferentialPackagePath string + DifferentialPackagePath string `json:"differentialPackagePath"` // A map of domains to override on package create when pulling images - RegistryOverrides map[string]string + RegistryOverrides map[string]string `json:"registryOverrides"` // An optional variant that controls which components will be included in a package - Flavor string + Flavor string `json:"flavor"` // Whether to create a skeleton package - IsSkeleton bool + IsSkeleton bool `json:"isSkeleton"` // Whether to create a YOLO package - NoYOLO bool + NoYOLO bool `json:"noYOLO"` } // ZarfSplitPackageData contains info about a split package. type ZarfSplitPackageData struct { // The sha256sum of the package - Sha256Sum string + Sha256Sum string `json:"sha256Sum"` // The size of the package in bytes - Bytes int64 + Bytes int64 `json:"bytes"` // The number of parts the package is split into - Count int + Count int `json:"count"` } // ConnectString contains information about a connection made with Zarf connect. type ConnectString struct { // Descriptive text that explains what the resource you would be connecting to is used for - Description string + Description string `json:"description"` // URL path that gets appended to the k8s port-forward result - URL string + URL string `json:"url"` } // ConnectStrings is a map of connect names to connection information. @@ -189,7 +189,7 @@ type ConnectStrings map[string]ConnectString // DifferentialData contains image and repository information about the package a Differential Package is Based on. type DifferentialData struct { - DifferentialImages map[string]bool - DifferentialRepos map[string]bool - DifferentialPackageVersion string + DifferentialImages map[string]bool `json:"differentialImages"` + DifferentialRepos map[string]bool `json:"differentialRepos"` + DifferentialPackageVersion string `json:"differentialPackageVersion"` } diff --git a/zarf.schema.json b/zarf.schema.json index ebf4e729d3..abf18b68e5 100644 --- a/zarf.schema.json +++ b/zarf.schema.json @@ -4,26 +4,26 @@ "$defs": { "BigBang": { "properties": { - "version": { + "Version": { "type": "string", "description": "The version of Big Bang to use" }, - "repo": { + "Repo": { "type": "string", "description": "Override repo to pull Big Bang from instead of Repo One" }, - "valuesFiles": { + "ValuesFiles": { "items": { "type": "string" }, "type": "array", "description": "The list of values files to pass to Big Bang; these will be merged together" }, - "skipFlux": { + "SkipFlux": { "type": "boolean", "description": "Whether to skip deploying flux; Defaults to false" }, - "fluxPatchFiles": { + "FluxPatchFiles": { "items": { "type": "string" }, @@ -34,7 +34,7 @@ "additionalProperties": false, "type": "object", "required": [ - "version" + "Version" ], "description": "BigBang holds the configuration for the Big Bang extension", "patternProperties": { @@ -43,24 +43,24 @@ }, "Constant": { "properties": { - "name": { + "Name": { "type": "string", "pattern": "^[A-Z0-9_]+$", "description": "The name to be used for the constant" }, - "value": { + "Value": { "type": "string", "description": "The value to set for the constant during deploy" }, - "description": { + "Description": { "type": "string", "description": "A description of the constant to explain its purpose on package create or deploy confirmation prompts" }, - "autoIndent": { + "AutoIndent": { "type": "boolean", "description": "Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_." }, - "pattern": { + "Pattern": { "type": "string", "description": "An optional regex pattern that a constant value must match before a package can be created." } @@ -68,8 +68,8 @@ "additionalProperties": false, "type": "object", "required": [ - "name", - "value" + "Name", + "Value" ], "description": "Constant are constants that can be used to dynamically template K8s resources or run in actions.", "patternProperties": { @@ -121,24 +121,24 @@ }, "InteractiveVariable": { "properties": { - "name": { + "Name": { "type": "string", "pattern": "^[A-Z0-9_]+$", "description": "The name to be used for the variable" }, - "sensitive": { + "Sensitive": { "type": "boolean", "description": "Whether to mark this variable as sensitive to not print it in the log" }, - "autoIndent": { + "AutoIndent": { "type": "boolean", "description": "Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_." }, - "pattern": { + "Pattern": { "type": "string", "description": "An optional regex pattern that a variable value must match before a package deployment can continue." }, - "type": { + "Type": { "type": "string", "enum": [ "raw", @@ -146,15 +146,15 @@ ], "description": "Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB)" }, - "description": { + "Description": { "type": "string", "description": "A description of the variable to be used when prompting the user a value" }, - "default": { + "Default": { "type": "string", "description": "The default value to use for the variable" }, - "prompt": { + "Prompt": { "type": "boolean", "description": "Whether to prompt the user for input for this variable" } @@ -162,7 +162,7 @@ "additionalProperties": false, "type": "object", "required": [ - "name" + "Name" ], "description": "InteractiveVariable is a variable that can be used to prompt a user for more information", "patternProperties": { @@ -214,24 +214,24 @@ }, "Variable": { "properties": { - "name": { + "Name": { "type": "string", "pattern": "^[A-Z0-9_]+$", "description": "The name to be used for the variable" }, - "sensitive": { + "Sensitive": { "type": "boolean", "description": "Whether to mark this variable as sensitive to not print it in the log" }, - "autoIndent": { + "AutoIndent": { "type": "boolean", "description": "Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_." }, - "pattern": { + "Pattern": { "type": "string", "description": "An optional regex pattern that a variable value must match before a package deployment can continue." }, - "type": { + "Type": { "type": "string", "enum": [ "raw", @@ -243,7 +243,7 @@ "additionalProperties": false, "type": "object", "required": [ - "name" + "Name" ], "description": "Variable represents a variable that has a value set programmatically", "patternProperties": { @@ -252,60 +252,60 @@ }, "ZarfBuildData": { "properties": { - "terminal": { + "Terminal": { "type": "string", "description": "The machine name that created this package" }, - "user": { + "User": { "type": "string", "description": "The username who created this package" }, - "architecture": { + "Architecture": { "type": "string", "description": "The architecture this package was created on" }, - "timestamp": { + "Timestamp": { "type": "string", "description": "The timestamp when this package was created" }, - "version": { + "Version": { "type": "string", "description": "The version of Zarf used to build this package" }, - "migrations": { + "Migrations": { "items": { "type": "string" }, "type": "array", "description": "Any migrations that have been run on this package" }, - "registryOverrides": { + "RegistryOverrides": { "additionalProperties": { "type": "string" }, "type": "object", "description": "Any registry domains that were overridden on package create when pulling images" }, - "differential": { + "Differential": { "type": "boolean", "description": "Whether this package was created with differential components" }, - "differentialPackageVersion": { + "DifferentialPackageVersion": { "type": "string", "description": "Version of a previously built package used as the basis for creating this differential package" }, - "differentialMissing": { + "DifferentialMissing": { "items": { "type": "string" }, "type": "array", "description": "List of components that were not included in this package due to differential packaging" }, - "lastNonBreakingVersion": { + "LastNonBreakingVersion": { "type": "string", "description": "The minimum version of Zarf that does not have breaking package structure changes" }, - "flavor": { + "Flavor": { "type": "string", "description": "The flavor of Zarf used to build this package" } @@ -313,11 +313,11 @@ "additionalProperties": false, "type": "object", "required": [ - "terminal", - "user", - "architecture", - "timestamp", - "version" + "Terminal", + "User", + "Architecture", + "Timestamp", + "Version" ], "description": "ZarfBuildData is written during the packager.Create() operation to track details of the created package.", "patternProperties": { @@ -810,7 +810,7 @@ "pattern": "###ZARF_PKG_TMPL_" }, "type": "string", - "description": "The path to the directory containing a zarf.yaml to import" + "description": "The path to the directory containing the zarf.yaml to import" }, "url": { "not": { @@ -859,14 +859,6 @@ }, "ZarfComponentOnlyTarget": { "properties": { - "cluster": { - "$ref": "#/$defs/ZarfComponentOnlyCluster", - "description": "Only deploy component to specified clusters" - }, - "flavor": { - "type": "string", - "description": "Only include this component when a matching '--flavor' is specified on 'zarf package create'" - }, "localOS": { "type": "string", "enum": [ @@ -875,6 +867,14 @@ "windows" ], "description": "Only deploy component to specified OS" + }, + "cluster": { + "$ref": "#/$defs/ZarfComponentOnlyCluster", + "description": "Only deploy component to specified clusters" + }, + "flavor": { + "type": "string", + "description": "Only include this component when a matching '--flavor' is specified on 'zarf package create'" } }, "additionalProperties": false, @@ -1031,32 +1031,32 @@ }, "ZarfMetadata": { "properties": { - "name": { + "Name": { "type": "string", "pattern": "^[a-z0-9][a-z0-9\\-]*$", "description": "Name to identify this Zarf package" }, - "description": { + "Description": { "type": "string", "description": "Additional information about this package" }, - "version": { + "Version": { "type": "string", "description": "Generic string set by a package author to track the package version (Note: ZarfInitConfigs will always be versioned to the CLIVersion they were created with)" }, - "url": { + "URL": { "type": "string", "description": "Link to package information when online" }, - "image": { + "Image": { "type": "string", "description": "An image URL to embed in this package (Reserved for future use in Zarf UI)" }, - "uncompressed": { + "Uncompressed": { "type": "boolean", "description": "Disable compression of this package" }, - "architecture": { + "Architecture": { "type": "string", "description": "The target cluster architecture for this package", "examples": [ @@ -1064,30 +1064,30 @@ "amd64" ] }, - "yolo": { + "YOLO": { "type": "boolean", "description": "Yaml OnLy Online (YOLO): True enables deploying a Zarf package without first running zarf init against the cluster. This is ideal for connected environments where you want to use existing VCS and container registries." }, - "authors": { + "Authors": { "type": "string", "description": "Comma-separated list of package authors (including contact info)", "examples": [ "Doug <hello@defenseunicorns.com>, Pepr <hello@defenseunicorns.com>" ] }, - "documentation": { + "Documentation": { "type": "string", "description": "Link to package documentation when online" }, - "source": { + "Source": { "type": "string", "description": "Link to package source code when online" }, - "vendor": { + "Vendor": { "type": "string", "description": "Name of the distributing entity, organization or individual" }, - "aggregateChecksum": { + "AggregateChecksum": { "type": "string", "description": "Checksum of a checksums.txt file that contains checksums all the layers within the package" } @@ -1095,7 +1095,7 @@ "additionalProperties": false, "type": "object", "required": [ - "name" + "Name" ], "description": "ZarfMetadata lists information about the current ZarfPackage.", "patternProperties": { @@ -1104,7 +1104,7 @@ } }, "properties": { - "kind": { + "Kind": { "type": "string", "enum": [ "ZarfInitConfig", @@ -1113,15 +1113,15 @@ "description": "The kind of Zarf package", "default": "ZarfPackageConfig" }, - "metadata": { + "Metadata": { "$ref": "#/$defs/ZarfMetadata", "description": "Package metadata" }, - "build": { + "Build": { "$ref": "#/$defs/ZarfBuildData", "description": "Zarf-generated package build data" }, - "components": { + "Components": { "items": { "$ref": "#/$defs/ZarfComponent" }, @@ -1129,14 +1129,14 @@ "minItems": 1, "description": "List of components to deploy in this package" }, - "constants": { + "Constants": { "items": { "$ref": "#/$defs/Constant" }, "type": "array", "description": "Constant template values applied on deploy for K8s resources" }, - "variables": { + "Variables": { "items": { "$ref": "#/$defs/InteractiveVariable" }, @@ -1147,8 +1147,8 @@ "additionalProperties": false, "type": "object", "required": [ - "kind", - "components" + "Kind", + "Components" ], "description": "ZarfPackage the top-level structure of a Zarf config file.", "patternProperties": { From 59bc21f238cd763ef4d547cb501e9340618e1dda Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 29 Jul 2024 20:25:50 +0000 Subject: [PATCH 08/34] add back json tags Signed-off-by: Austin Abro --- src/pkg/variables/types.go | 28 ++++----- zarf.schema.json | 122 ++++++++++++++++++------------------- 2 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/pkg/variables/types.go b/src/pkg/variables/types.go index c4b5e14e8d..57dbd6d1a8 100644 --- a/src/pkg/variables/types.go +++ b/src/pkg/variables/types.go @@ -30,47 +30,47 @@ var ( // Variable represents a variable that has a value set programmatically type Variable struct { // The name to be used for the variable - Name string `jsonschema:"required,pattern=^[A-Z0-9_]+$"` + Name string `json:"name" jsonschema:"required,pattern=^[A-Z0-9_]+$"` // Whether to mark this variable as sensitive to not print it in the log - Sensitive bool + Sensitive bool `json:"sensitive"` // Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_. - AutoIndent bool + AutoIndent bool `json:"autoIndent"` // An optional regex pattern that a variable value must match before a package deployment can continue. - Pattern string + Pattern string `json:"pattern"` // Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB) - Type VariableType `jsonschema:"enum=raw,enum=file"` + Type VariableType `json:"type" jsonschema:"enum=raw,enum=file"` } // InteractiveVariable is a variable that can be used to prompt a user for more information type InteractiveVariable struct { Variable // A description of the variable to be used when prompting the user a value - Description string + Description string `json:"description"` // The default value to use for the variable - Default string + Default string `json:"default"` // Whether to prompt the user for input for this variable - Prompt bool + Prompt bool `json:"prompt"` } // Constant are constants that can be used to dynamically template K8s resources or run in actions. type Constant struct { // The name to be used for the constant - Name string `jsonschema:"required,pattern=^[A-Z0-9_]+$"` + Name string `json:"name" jsonschema:"required,pattern=^[A-Z0-9_]+$"` // The value to set for the constant during deploy - Value string `jsonschema:"required"` + Value string `json:"value" jsonschema:"required"` // A description of the constant to explain its purpose on package create or deploy confirmation prompts - Description string + Description string `json:"description"` // Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_. - AutoIndent bool + AutoIndent bool `json:"autoIndent"` // An optional regex pattern that a constant value must match before a package can be created. - Pattern string + Pattern string `json:"pattern"` } // SetVariable tracks internal variables that have been set during this run of Zarf type SetVariable struct { Variable // The value the variable is currently set with - Value string `jsonschema:"required"` + Value string `json:"value" jsonschema:"required"` } // Validate runs all validation checks on a package constant. diff --git a/zarf.schema.json b/zarf.schema.json index abf18b68e5..57efbb6982 100644 --- a/zarf.schema.json +++ b/zarf.schema.json @@ -43,24 +43,24 @@ }, "Constant": { "properties": { - "Name": { + "name": { "type": "string", "pattern": "^[A-Z0-9_]+$", "description": "The name to be used for the constant" }, - "Value": { + "value": { "type": "string", "description": "The value to set for the constant during deploy" }, - "Description": { + "description": { "type": "string", "description": "A description of the constant to explain its purpose on package create or deploy confirmation prompts" }, - "AutoIndent": { + "autoIndent": { "type": "boolean", "description": "Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_." }, - "Pattern": { + "pattern": { "type": "string", "description": "An optional regex pattern that a constant value must match before a package can be created." } @@ -68,8 +68,8 @@ "additionalProperties": false, "type": "object", "required": [ - "Name", - "Value" + "name", + "value" ], "description": "Constant are constants that can be used to dynamically template K8s resources or run in actions.", "patternProperties": { @@ -121,24 +121,24 @@ }, "InteractiveVariable": { "properties": { - "Name": { + "name": { "type": "string", "pattern": "^[A-Z0-9_]+$", "description": "The name to be used for the variable" }, - "Sensitive": { + "sensitive": { "type": "boolean", "description": "Whether to mark this variable as sensitive to not print it in the log" }, - "AutoIndent": { + "autoIndent": { "type": "boolean", "description": "Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_." }, - "Pattern": { + "pattern": { "type": "string", "description": "An optional regex pattern that a variable value must match before a package deployment can continue." }, - "Type": { + "type": { "type": "string", "enum": [ "raw", @@ -146,15 +146,15 @@ ], "description": "Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB)" }, - "Description": { + "description": { "type": "string", "description": "A description of the variable to be used when prompting the user a value" }, - "Default": { + "default": { "type": "string", "description": "The default value to use for the variable" }, - "Prompt": { + "prompt": { "type": "boolean", "description": "Whether to prompt the user for input for this variable" } @@ -162,7 +162,7 @@ "additionalProperties": false, "type": "object", "required": [ - "Name" + "name" ], "description": "InteractiveVariable is a variable that can be used to prompt a user for more information", "patternProperties": { @@ -214,24 +214,24 @@ }, "Variable": { "properties": { - "Name": { + "name": { "type": "string", "pattern": "^[A-Z0-9_]+$", "description": "The name to be used for the variable" }, - "Sensitive": { + "sensitive": { "type": "boolean", "description": "Whether to mark this variable as sensitive to not print it in the log" }, - "AutoIndent": { + "autoIndent": { "type": "boolean", "description": "Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_." }, - "Pattern": { + "pattern": { "type": "string", "description": "An optional regex pattern that a variable value must match before a package deployment can continue." }, - "Type": { + "type": { "type": "string", "enum": [ "raw", @@ -243,7 +243,7 @@ "additionalProperties": false, "type": "object", "required": [ - "Name" + "name" ], "description": "Variable represents a variable that has a value set programmatically", "patternProperties": { @@ -252,60 +252,60 @@ }, "ZarfBuildData": { "properties": { - "Terminal": { + "terminal": { "type": "string", "description": "The machine name that created this package" }, - "User": { + "user": { "type": "string", "description": "The username who created this package" }, - "Architecture": { + "architecture": { "type": "string", "description": "The architecture this package was created on" }, - "Timestamp": { + "timestamp": { "type": "string", "description": "The timestamp when this package was created" }, - "Version": { + "version": { "type": "string", "description": "The version of Zarf used to build this package" }, - "Migrations": { + "migrations": { "items": { "type": "string" }, "type": "array", "description": "Any migrations that have been run on this package" }, - "RegistryOverrides": { + "registryOverrides": { "additionalProperties": { "type": "string" }, "type": "object", "description": "Any registry domains that were overridden on package create when pulling images" }, - "Differential": { + "differential": { "type": "boolean", "description": "Whether this package was created with differential components" }, - "DifferentialPackageVersion": { + "differentialPackageVersion": { "type": "string", "description": "Version of a previously built package used as the basis for creating this differential package" }, - "DifferentialMissing": { + "differentialMissing": { "items": { "type": "string" }, "type": "array", "description": "List of components that were not included in this package due to differential packaging" }, - "LastNonBreakingVersion": { + "lastNonBreakingVersion": { "type": "string", "description": "The minimum version of Zarf that does not have breaking package structure changes" }, - "Flavor": { + "flavor": { "type": "string", "description": "The flavor of Zarf used to build this package" } @@ -313,11 +313,11 @@ "additionalProperties": false, "type": "object", "required": [ - "Terminal", - "User", - "Architecture", - "Timestamp", - "Version" + "terminal", + "user", + "architecture", + "timestamp", + "version" ], "description": "ZarfBuildData is written during the packager.Create() operation to track details of the created package.", "patternProperties": { @@ -1031,32 +1031,32 @@ }, "ZarfMetadata": { "properties": { - "Name": { + "name": { "type": "string", "pattern": "^[a-z0-9][a-z0-9\\-]*$", "description": "Name to identify this Zarf package" }, - "Description": { + "description": { "type": "string", "description": "Additional information about this package" }, - "Version": { + "version": { "type": "string", "description": "Generic string set by a package author to track the package version (Note: ZarfInitConfigs will always be versioned to the CLIVersion they were created with)" }, - "URL": { + "url": { "type": "string", "description": "Link to package information when online" }, - "Image": { + "image": { "type": "string", "description": "An image URL to embed in this package (Reserved for future use in Zarf UI)" }, - "Uncompressed": { + "uncompressed": { "type": "boolean", "description": "Disable compression of this package" }, - "Architecture": { + "architecture": { "type": "string", "description": "The target cluster architecture for this package", "examples": [ @@ -1064,30 +1064,30 @@ "amd64" ] }, - "YOLO": { + "yolo": { "type": "boolean", "description": "Yaml OnLy Online (YOLO): True enables deploying a Zarf package without first running zarf init against the cluster. This is ideal for connected environments where you want to use existing VCS and container registries." }, - "Authors": { + "authors": { "type": "string", "description": "Comma-separated list of package authors (including contact info)", "examples": [ "Doug <hello@defenseunicorns.com>, Pepr <hello@defenseunicorns.com>" ] }, - "Documentation": { + "documentation": { "type": "string", "description": "Link to package documentation when online" }, - "Source": { + "source": { "type": "string", "description": "Link to package source code when online" }, - "Vendor": { + "vendor": { "type": "string", "description": "Name of the distributing entity, organization or individual" }, - "AggregateChecksum": { + "aggregateChecksum": { "type": "string", "description": "Checksum of a checksums.txt file that contains checksums all the layers within the package" } @@ -1095,7 +1095,7 @@ "additionalProperties": false, "type": "object", "required": [ - "Name" + "name" ], "description": "ZarfMetadata lists information about the current ZarfPackage.", "patternProperties": { @@ -1104,7 +1104,7 @@ } }, "properties": { - "Kind": { + "kind": { "type": "string", "enum": [ "ZarfInitConfig", @@ -1113,15 +1113,15 @@ "description": "The kind of Zarf package", "default": "ZarfPackageConfig" }, - "Metadata": { + "metadata": { "$ref": "#/$defs/ZarfMetadata", "description": "Package metadata" }, - "Build": { + "build": { "$ref": "#/$defs/ZarfBuildData", "description": "Zarf-generated package build data" }, - "Components": { + "components": { "items": { "$ref": "#/$defs/ZarfComponent" }, @@ -1129,14 +1129,14 @@ "minItems": 1, "description": "List of components to deploy in this package" }, - "Constants": { + "constants": { "items": { "$ref": "#/$defs/Constant" }, "type": "array", "description": "Constant template values applied on deploy for K8s resources" }, - "Variables": { + "variables": { "items": { "$ref": "#/$defs/InteractiveVariable" }, @@ -1147,8 +1147,8 @@ "additionalProperties": false, "type": "object", "required": [ - "Kind", - "Components" + "kind", + "components" ], "description": "ZarfPackage the top-level structure of a Zarf config file.", "patternProperties": { From cde411aeb83bb7865f8bf5a3946e50d653b33cc2 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 29 Jul 2024 21:21:55 +0000 Subject: [PATCH 09/34] inline Signed-off-by: Austin Abro --- go.mod | 1 - go.sum | 2 -- src/pkg/variables/types.go | 4 ++-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index a3e73c68b4..db29e4a620 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,6 @@ require ( github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.18.2 - github.com/stoewer/go-strcase v1.2.0 github.com/stretchr/testify v1.9.0 github.com/xeipuuv/gojsonschema v1.2.0 golang.org/x/crypto v0.24.0 diff --git a/go.sum b/go.sum index 9ee894aa29..23759f5ede 100644 --- a/go.sum +++ b/go.sum @@ -1594,8 +1594,6 @@ github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= github.com/spiffe/go-spiffe/v2 v2.1.7 h1:VUkM1yIyg/x8X7u1uXqSRVRCdMdfRIEdFBzpqoeASGk= github.com/spiffe/go-spiffe/v2 v2.1.7/go.mod h1:QJDGdhXllxjxvd5B+2XnhhXB/+rC8gr+lNrtOryiWeE= -github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU= -github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= diff --git a/src/pkg/variables/types.go b/src/pkg/variables/types.go index 57dbd6d1a8..4ca675850e 100644 --- a/src/pkg/variables/types.go +++ b/src/pkg/variables/types.go @@ -43,7 +43,7 @@ type Variable struct { // InteractiveVariable is a variable that can be used to prompt a user for more information type InteractiveVariable struct { - Variable + Variable `json:",inline"` // A description of the variable to be used when prompting the user a value Description string `json:"description"` // The default value to use for the variable @@ -68,7 +68,7 @@ type Constant struct { // SetVariable tracks internal variables that have been set during this run of Zarf type SetVariable struct { - Variable + Variable `json:",inline"` // The value the variable is currently set with Value string `json:"value" jsonschema:"required"` } From fd680fc2d098f820dbd649fc27f54a812f70e20f Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 30 Jul 2024 12:59:32 +0000 Subject: [PATCH 10/34] back to omitempty Signed-off-by: Austin Abro --- src/cmd/internal.go | 2 - src/pkg/lint/schema_test.go | 152 ++++++++++++------------- src/pkg/variables/types.go | 28 ++--- src/types/component.go | 196 ++++++++++++++++---------------- src/types/extensions/bigbang.go | 10 +- src/types/k8s.go | 86 +++++++------- src/types/package.go | 62 +++++----- zarf.schema.json | 15 ++- 8 files changed, 273 insertions(+), 278 deletions(-) diff --git a/src/cmd/internal.go b/src/cmd/internal.go index 5f0f3f6ee8..6d54bbdca1 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -171,7 +171,6 @@ var genConfigSchemaCmd = &cobra.Command{ return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) } - reflector.RequiredFromJSONSchemaTags = true schema := reflector.Reflect(&types.ZarfPackage{}) output, err := json.MarshalIndent(schema, "", " ") if err != nil { @@ -203,7 +202,6 @@ var genTypesSchemaCmd = &cobra.Command{ return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) } - reflector.RequiredFromJSONSchemaTags = true schema := reflector.Reflect(&zarfTypes{}) output, err := json.MarshalIndent(schema, "", " ") if err != nil { diff --git a/src/pkg/lint/schema_test.go b/src/pkg/lint/schema_test.go index bb6adde541..c30820aa9a 100644 --- a/src/pkg/lint/schema_test.go +++ b/src/pkg/lint/schema_test.go @@ -5,13 +5,11 @@ package lint import ( - "fmt" "os" "testing" goyaml "github.com/goccy/go-yaml" "github.com/stretchr/testify/require" - "github.com/zarf-dev/zarf/src/pkg/variables" "github.com/zarf-dev/zarf/src/types" ) @@ -40,81 +38,81 @@ func TestZarfSchema(t *testing.T) { }, expectedSchemaStrings: nil, }, - { - name: "no comp or kind", - pkg: types.ZarfPackage{ - Metadata: types.ZarfMetadata{ - Name: "no-comp-or-kind", - }, - Components: []types.ZarfComponent{}, - }, - expectedSchemaStrings: []string{ - "kind: kind must be one of the following: \"ZarfInitConfig\", \"ZarfPackageConfig\"", - "components: Array must have at least 1 items", - }, - }, - { - name: "invalid package", - pkg: types.ZarfPackage{ - Kind: types.ZarfInitConfig, - Metadata: types.ZarfMetadata{ - Name: "-invalid-name", - }, - Components: []types.ZarfComponent{ - { - Name: "invalid-name", - Only: types.ZarfComponentOnlyTarget{ - LocalOS: "unsupportedOS", - }, - Import: types.ZarfComponentImport{ - Path: fmt.Sprintf("start%send", types.ZarfPackageTemplatePrefix), - URL: fmt.Sprintf("oci://start%send", types.ZarfPackageTemplatePrefix), - }, - }, - { - Name: "actions", - Actions: types.ZarfComponentActions{ - OnCreate: types.ZarfComponentActionSet{ - Before: []types.ZarfComponentAction{ - { - Cmd: "echo 'invalid setVariable'", - SetVariables: []variables.Variable{{Name: "not_uppercase"}}, - }, - }, - }, - OnRemove: types.ZarfComponentActionSet{ - OnSuccess: []types.ZarfComponentAction{ - { - Cmd: "echo 'invalid setVariable'", - SetVariables: []variables.Variable{{Name: "not_uppercase"}}, - }, - }, - }, - }, - }, - }, - Variables: []variables.InteractiveVariable{ - { - Variable: variables.Variable{Name: "not_uppercase"}, - }, - }, - Constants: []variables.Constant{ - { - Name: "not_uppercase", - }, - }, - }, - expectedSchemaStrings: []string{ - "metadata.name: Does not match pattern '^[a-z0-9][a-z0-9\\-]*$'", - "variables.0.name: Does not match pattern '^[A-Z0-9_]+$'", - "constants.0.name: Does not match pattern '^[A-Z0-9_]+$'", - "components.0.only.localOS: components.0.only.localOS must be one of the following: \"linux\", \"darwin\", \"windows\"", - "components.1.actions.onCreate.before.0.setVariables.0.name: Does not match pattern '^[A-Z0-9_]+$'", - "components.1.actions.onRemove.onSuccess.0.setVariables.0.name: Does not match pattern '^[A-Z0-9_]+$'", - "components.0.import.path: Must not validate the schema (not)", - "components.0.import.url: Must not validate the schema (not)", - }, - }, + // { + // name: "no comp or kind", + // pkg: types.ZarfPackage{ + // Metadata: types.ZarfMetadata{ + // Name: "no-comp-or-kind", + // }, + // Components: []types.ZarfComponent{}, + // }, + // expectedSchemaStrings: []string{ + // "kind: kind must be one of the following: \"ZarfInitConfig\", \"ZarfPackageConfig\"", + // "components: Array must have at least 1 items", + // }, + // }, + // { + // name: "invalid package", + // pkg: types.ZarfPackage{ + // Kind: types.ZarfInitConfig, + // Metadata: types.ZarfMetadata{ + // Name: "-invalid-name", + // }, + // Components: []types.ZarfComponent{ + // { + // Name: "invalid-name", + // Only: types.ZarfComponentOnlyTarget{ + // LocalOS: "unsupportedOS", + // }, + // Import: types.ZarfComponentImport{ + // Path: fmt.Sprintf("start%send", types.ZarfPackageTemplatePrefix), + // URL: fmt.Sprintf("oci://start%send", types.ZarfPackageTemplatePrefix), + // }, + // }, + // { + // Name: "actions", + // Actions: types.ZarfComponentActions{ + // OnCreate: types.ZarfComponentActionSet{ + // Before: []types.ZarfComponentAction{ + // { + // Cmd: "echo 'invalid setVariable'", + // SetVariables: []variables.Variable{{Name: "not_uppercase"}}, + // }, + // }, + // }, + // OnRemove: types.ZarfComponentActionSet{ + // OnSuccess: []types.ZarfComponentAction{ + // { + // Cmd: "echo 'invalid setVariable'", + // SetVariables: []variables.Variable{{Name: "not_uppercase"}}, + // }, + // }, + // }, + // }, + // }, + // }, + // Variables: []variables.InteractiveVariable{ + // { + // Variable: variables.Variable{Name: "not_uppercase"}, + // }, + // }, + // Constants: []variables.Constant{ + // { + // Name: "not_uppercase", + // }, + // }, + // }, + // expectedSchemaStrings: []string{ + // "metadata.name: Does not match pattern '^[a-z0-9][a-z0-9\\-]*$'", + // "variables.0.name: Does not match pattern '^[A-Z0-9_]+$'", + // "constants.0.name: Does not match pattern '^[A-Z0-9_]+$'", + // "components.0.only.localOS: components.0.only.localOS must be one of the following: \"linux\", \"darwin\", \"windows\"", + // "components.1.actions.onCreate.before.0.setVariables.0.name: Does not match pattern '^[A-Z0-9_]+$'", + // "components.1.actions.onRemove.onSuccess.0.setVariables.0.name: Does not match pattern '^[A-Z0-9_]+$'", + // "components.0.import.path: Must not validate the schema (not)", + // "components.0.import.url: Must not validate the schema (not)", + // }, + // }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/src/pkg/variables/types.go b/src/pkg/variables/types.go index 4ca675850e..6b3be2863b 100644 --- a/src/pkg/variables/types.go +++ b/src/pkg/variables/types.go @@ -30,47 +30,47 @@ var ( // Variable represents a variable that has a value set programmatically type Variable struct { // The name to be used for the variable - Name string `json:"name" jsonschema:"required,pattern=^[A-Z0-9_]+$"` + Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"` // Whether to mark this variable as sensitive to not print it in the log - Sensitive bool `json:"sensitive"` + Sensitive bool `json:"sensitive,omitempty"` // Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_. - AutoIndent bool `json:"autoIndent"` + AutoIndent bool `json:"autoIndent,omitempty"` // An optional regex pattern that a variable value must match before a package deployment can continue. - Pattern string `json:"pattern"` + Pattern string `json:"pattern,omitempty"` // Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB) - Type VariableType `json:"type" jsonschema:"enum=raw,enum=file"` + Type VariableType `json:"type,omitempty" jsonschema:"enum=raw,enum=file"` } // InteractiveVariable is a variable that can be used to prompt a user for more information type InteractiveVariable struct { Variable `json:",inline"` // A description of the variable to be used when prompting the user a value - Description string `json:"description"` + Description string `json:"description,omitempty"` // The default value to use for the variable - Default string `json:"default"` + Default string `json:"default,omitempty"` // Whether to prompt the user for input for this variable - Prompt bool `json:"prompt"` + Prompt bool `json:"prompt,omitempty"` } // Constant are constants that can be used to dynamically template K8s resources or run in actions. type Constant struct { // The name to be used for the constant - Name string `json:"name" jsonschema:"required,pattern=^[A-Z0-9_]+$"` + Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"` // The value to set for the constant during deploy - Value string `json:"value" jsonschema:"required"` + Value string `json:"value"` // A description of the constant to explain its purpose on package create or deploy confirmation prompts - Description string `json:"description"` + Description string `json:"description,omitempty"` // Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_. - AutoIndent bool `json:"autoIndent"` + AutoIndent bool `json:"autoIndent,omitempty"` // An optional regex pattern that a constant value must match before a package can be created. - Pattern string `json:"pattern"` + Pattern string `json:"pattern,omitempty"` } // SetVariable tracks internal variables that have been set during this run of Zarf type SetVariable struct { Variable `json:",inline"` // The value the variable is currently set with - Value string `json:"value" jsonschema:"required"` + Value string `json:"value"` } // Validate runs all validation checks on a package constant. diff --git a/src/types/component.go b/src/types/component.go index 893224f06f..7eb744d764 100644 --- a/src/types/component.go +++ b/src/types/component.go @@ -14,55 +14,55 @@ import ( // ZarfComponent is the primary functional grouping of assets to deploy by Zarf. type ZarfComponent struct { // The name of the component - Name string `json:"name" jsonschema:"required,pattern=^[a-z0-9][a-z0-9\\-]*$"` + Name string `json:"name" jsonschema:"pattern=^[a-z0-9][a-z0-9\\-]*$"` // Message to include during package deploy describing the purpose of this component - Description string `json:"description"` + Description string `json:"description,omitempty"` // Determines the default Y/N state for installing this component on package deploy - Default bool `json:"default"` + Default bool `json:"default,omitempty"` // Do not prompt user to install this component - Required *bool `json:"required"` + Required *bool `json:"required,omitempty"` // Filter when this component is included in package creation or deployment - Only ZarfComponentOnlyTarget `json:"only"` + Only ZarfComponentOnlyTarget `json:"only,omitempty"` // [Deprecated] Create a user selector field based on all components in the same group. This will be removed in Zarf v1.0.0. Consider using 'only.flavor' instead. - DeprecatedGroup string `json:"group" jsonschema:"deprecated=true"` + DeprecatedGroup string `json:"group,omitempty" jsonschema:"deprecated=true"` // [Deprecated] Specify a path to a public key to validate signed online resources. This will be removed in Zarf v1.0.0. - DeprecatedCosignKeyPath string `json:"cosignKeyPath" jsonschema:"deprecated=true"` + DeprecatedCosignKeyPath string `json:"cosignKeyPath,omitempty" jsonschema:"deprecated=true"` // Import a component from another Zarf package - Import ZarfComponentImport `json:"import"` + Import ZarfComponentImport `json:"import,omitempty"` // Kubernetes manifests to be included in a generated Helm chart on package deploy - Manifests []ZarfManifest `json:"manifests"` + Manifests []ZarfManifest `json:"manifests,omitempty"` // Helm charts to install during package deploy - Charts []ZarfChart `json:"charts"` + Charts []ZarfChart `json:"charts,omitempty"` // Datasets to inject into a container in the target cluster - DataInjections []ZarfDataInjection `json:"dataInjections"` + DataInjections []ZarfDataInjection `json:"dataInjections,omitempty"` // Files or folders to place on disk during package deployment - Files []ZarfFile `json:"files"` + Files []ZarfFile `json:"files,omitempty"` // List of OCI images to include in the package - Images []string `json:"images"` + Images []string `json:"images,omitempty"` // List of git repos to include in the package - Repos []string `json:"repos"` + Repos []string `json:"repos,omitempty"` // Extend component functionality with additional features - Extensions extensions.ZarfComponentExtensions `json:"extensions"` + Extensions extensions.ZarfComponentExtensions `json:"extensions,omitempty"` // [Deprecated] (replaced by actions) Custom commands to run before or after package deployment. This will be removed in Zarf v1.0.0. - DeprecatedScripts DeprecatedZarfComponentScripts `json:"scripts" jsonschema:"deprecated=true"` + DeprecatedScripts DeprecatedZarfComponentScripts `json:"scripts,omitempty" jsonschema:"deprecated=true"` // Custom commands to run at various stages of a package lifecycle - Actions ZarfComponentActions `json:"actions"` + Actions ZarfComponentActions `json:"actions,omitempty"` } // RequiresCluster returns if the component requires a cluster connection to deploy @@ -92,231 +92,231 @@ 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" jsonschema:"enum=linux,enum=darwin,enum=windows"` + LocalOS string `json:"localOS,omitempty" jsonschema:"enum=linux,enum=darwin,enum=windows"` // Only deploy component to specified clusters - Cluster ZarfComponentOnlyCluster `json:"cluster"` + Cluster ZarfComponentOnlyCluster `json:"cluster,omitempty"` // Only include this component when a matching '--flavor' is specified on 'zarf package create' - Flavor string `json:"flavor"` + Flavor string `json:"flavor,omitempty"` } // ZarfComponentOnlyCluster represents the architecture and K8s cluster distribution to filter on. type ZarfComponentOnlyCluster struct { // Only create and deploy to clusters of the given architecture - Architecture string `json:"architecture" jsonschema:"enum=amd64,enum=arm64"` + Architecture string `json:"architecture,omitempty" jsonschema:"enum=amd64,enum=arm64"` // A list of kubernetes distros this package works with (Reserved for future use) - Distros []string `json:"distros" jsonschema:"example=k3s,example=eks"` + Distros []string `json:"distros,omitempty" jsonschema:"example=k3s,example=eks"` } // ZarfFile defines a file to deploy. type ZarfFile struct { // Local folder or file path or remote URL to pull into the package - Source string `json:"source" jsonschema:"required"` + Source string `json:"source"` // (files only) Optional SHA256 checksum of the file - Shasum string `json:"shasum"` + Shasum string `json:"shasum,omitempty"` // The absolute or relative path where the file or folder should be copied to during package deploy - Target string `json:"target" jsonschema:"required"` + Target string `json:"target"` // (files only) Determines if the file should be made executable during package deploy - Executable bool `json:"executable"` + Executable bool `json:"executable,omitempty"` // List of symlinks to create during package deploy - Symlinks []string `json:"symlinks"` + Symlinks []string `json:"symlinks,omitempty"` // Local folder or file to be extracted from a 'source' archive - ExtractPath string `json:"extractPath"` + ExtractPath string `json:"extractPath,omitempty"` } // ZarfChart defines a helm chart to be deployed. type ZarfChart struct { // 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 - Name string `json:"name" jsonschema:"required"` + Name string `json:"name"` // 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"` + Version string `json:"version,omitempty"` // The URL of the OCI registry, chart repository, or git repo where the helm chart is stored - URL string `json:"url" 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)"` + 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)"` // The name of a chart within a Helm repository (defaults to the Zarf name of the chart) - RepoName string `json:"repoName"` + RepoName string `json:"repoName,omitempty"` // (git repo only) The sub directory to the chart within a git repo - GitPath string `json:"gitPath" jsonschema:"example=charts/your-chart"` + GitPath string `json:"gitPath,omitempty" jsonschema:"example=charts/your-chart"` // The path to a local chart's folder or .tgz archive - LocalPath string `json:"localPath"` + LocalPath string `json:"localPath,omitempty"` // The namespace to deploy the chart to - Namespace string `json:"namespace"` + Namespace string `json:"namespace,omitempty"` // The name of the Helm release to create (defaults to the Zarf name of the chart) - ReleaseName string `json:"releaseName"` + ReleaseName string `json:"releaseName,omitempty"` // Whether to not wait for chart resources to be ready before continuing - NoWait bool `json:"noWait"` + NoWait bool `json:"noWait,omitempty"` // List of local values file paths or remote URLs to include in the package; these will be merged together when deployed - ValuesFiles []string `json:"valuesFiles"` + ValuesFiles []string `json:"valuesFiles,omitempty"` // [alpha] List of variables to set in the Helm chart - Variables []ZarfChartVariable `json:"variables"` + Variables []ZarfChartVariable `json:"variables,omitempty"` } // 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" jsonschema:"required,pattern=^[A-Z0-9_]+$"` + Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"` // A brief description of what the variable controls - Description string `json:"description" jsonschema:"required"` + Description string `json:"description"` // The path within the Helm chart values where this variable applies - Path string `json:"path" jsonschema:"required"` + Path string `json:"path"` } // 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 - Name string `json:"name" jsonschema:"required"` + Name string `json:"name"` // The namespace to deploy the manifests to - Namespace string `json:"namespace"` + Namespace string `json:"namespace,omitempty"` // List of local K8s YAML files or remote URLs to deploy (in order) - Files []string `json:"files"` + Files []string `json:"files,omitempty"` // Allow traversing directory above the current directory if needed for kustomization - KustomizeAllowAnyDirectory bool `json:"kustomizeAllowAnyDirectory"` + KustomizeAllowAnyDirectory bool `json:"kustomizeAllowAnyDirectory,omitempty"` // List of local kustomization paths or remote URLs to include in the package - Kustomizations []string `json:"kustomizations"` + Kustomizations []string `json:"kustomizations,omitempty"` // Whether to not wait for manifest resources to be ready before continuing - NoWait bool `json:"noWait"` + NoWait bool `json:"noWait,omitempty"` } // DeprecatedZarfComponentScripts are scripts that run before or after a component is deployed type DeprecatedZarfComponentScripts struct { // Show the output of the script during package deployment - ShowOutput bool `json:"showOutput"` + ShowOutput bool `json:"showOutput,omitempty"` // Timeout in seconds for the script - TimeoutSeconds int `json:"timeoutSeconds"` + TimeoutSeconds int `json:"timeoutSeconds,omitempty"` // Retry the script if it fails - Retry bool `json:"retry"` + Retry bool `json:"retry,omitempty"` // Scripts to run before the component is added during package create - Prepare []string `json:"prepare"` + Prepare []string `json:"prepare,omitempty"` // Scripts to run before the component is deployed - Before []string `json:"before"` + Before []string `json:"before,omitempty"` // Scripts to run after the component successfully deploys - After []string `json:"after"` + After []string `json:"after,omitempty"` } // ZarfComponentActions are ActionSets that map to different zarf package operations type ZarfComponentActions struct { // Actions to run during package creation - OnCreate ZarfComponentActionSet `json:"onCreate"` + OnCreate ZarfComponentActionSet `json:"onCreate,omitempty"` // Actions to run during package deployment - OnDeploy ZarfComponentActionSet `json:"onDeploy"` + OnDeploy ZarfComponentActionSet `json:"onDeploy,omitempty"` // Actions to run during package removal - OnRemove ZarfComponentActionSet `json:"onRemove"` + OnRemove ZarfComponentActionSet `json:"onRemove,omitempty"` } // ZarfComponentActionSet is a set of actions to run during a zarf package operation type ZarfComponentActionSet struct { // Default configuration for all actions in this set - Defaults ZarfComponentActionDefaults `json:"defaults"` + Defaults ZarfComponentActionDefaults `json:"defaults,omitempty"` // Actions to run at the start of an operation - Before []ZarfComponentAction `json:"before"` + Before []ZarfComponentAction `json:"before,omitempty"` // Actions to run at the end of an operation - After []ZarfComponentAction `json:"after"` + After []ZarfComponentAction `json:"after,omitempty"` // Actions to run if all operations succeed - OnSuccess []ZarfComponentAction `json:"onSuccess"` + OnSuccess []ZarfComponentAction `json:"onSuccess,omitempty"` // Actions to run if all operations fail - OnFailure []ZarfComponentAction `json:"onFailure"` + OnFailure []ZarfComponentAction `json:"onFailure,omitempty"` } // ZarfComponentActionDefaults sets the default configs for child actions type ZarfComponentActionDefaults struct { // Hide the output of commands during execution (default false) - Mute bool `json:"mute"` + Mute bool `json:"mute,omitempty"` // Default timeout in seconds for commands (default to 0, no timeout) - MaxTotalSeconds int `json:"maxTotalSeconds"` + MaxTotalSeconds int `json:"maxTotalSeconds,omitempty"` // Retry commands given number of times if they fail (default 0) - MaxRetries int `json:"maxRetries"` + MaxRetries int `json:"maxRetries,omitempty"` // Working directory for commands (default CWD) - Dir string `json:"dir"` + Dir string `json:"dir,omitempty"` // Additional environment variables for commands - Env []string `json:"env"` + Env []string `json:"env,omitempty"` // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems - Shell exec.Shell `json:"shell"` + Shell exec.Shell `json:"shell,omitempty"` } // ZarfComponentAction represents a single action to run during a zarf package operation type ZarfComponentAction struct { // Hide the output of the command during package deployment (default false) - Mute *bool `json:"mute"` + Mute *bool `json:"mute,omitempty"` // Timeout in seconds for the command (default to 0, no timeout for cmd actions and 300, 5 minutes for wait actions) - MaxTotalSeconds *int `json:"maxTotalSeconds"` + MaxTotalSeconds *int `json:"maxTotalSeconds,omitempty"` // Retry the command if it fails up to given number of times (default 0) - MaxRetries *int `json:"maxRetries"` + MaxRetries *int `json:"maxRetries,omitempty"` // The working directory to run the command in (default is CWD) - Dir *string `json:"dir"` + Dir *string `json:"dir,omitempty"` // Additional environment variables to set for the command - Env []string `json:"env"` + Env []string `json:"env,omitempty"` // The command to run. Must specify either cmd or wait for the action to do anything. - Cmd string `json:"cmd"` + Cmd string `json:"cmd,omitempty"` // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems - Shell *exec.Shell `json:"shell"` + Shell *exec.Shell `json:"shell,omitempty"` // [Deprecated] (replaced by setVariables) (onDeploy/cmd only) The name of a variable to update with the output of the command. This variable will be available to all remaining actions and components in the package. This will be removed in Zarf v1.0.0 - DeprecatedSetVariable string `json:"setVariable" jsonschema:"pattern=^[A-Z0-9_]+$"` + DeprecatedSetVariable string `json:"setVariable,omitempty" jsonschema:"pattern=^[A-Z0-9_]+$"` // (onDeploy/cmd only) An array of variables to update with the output of the command. These variables will be available to all remaining actions and components in the package. - SetVariables []variables.Variable `json:"setVariables"` + SetVariables []variables.Variable `json:"setVariables,omitempty"` // Description of the action to be displayed during package execution instead of the command - Description string `json:"description"` + Description string `json:"description,omitempty"` // Wait for a condition to be met before continuing. Must specify either cmd or wait for the action. See the 'zarf tools wait-for' command for more info. - Wait *ZarfComponentActionWait `json:"wait"` + Wait *ZarfComponentActionWait `json:"wait,omitempty"` } // ZarfComponentActionWait specifies a condition to wait for before continuing type ZarfComponentActionWait struct { // Wait for a condition to be met in the cluster before continuing. Only one of cluster or network can be specified. - Cluster *ZarfComponentActionWaitCluster `json:"cluster"` + Cluster *ZarfComponentActionWaitCluster `json:"cluster,omitempty"` // Wait for a condition to be met on the network before continuing. Only one of cluster or network can be specified. - Network *ZarfComponentActionWaitNetwork `json:"network"` + Network *ZarfComponentActionWaitNetwork `json:"network,omitempty"` } // ZarfComponentActionWaitCluster specifies a condition to wait for before continuing type ZarfComponentActionWaitCluster struct { // The kind of resource to wait for - Kind string `json:"kind" jsonschema:"required,example=Pod,example=Deployment"` + Kind string `json:"kind" jsonschema:"example=Pod,example=Deployment"` // The name of the resource or selector to wait for - Name string `json:"name" jsonschema:"required,example=podinfo,example=app=podinfo"` + Name string `json:"name" jsonschema:"example=podinfo,example=app=podinfo"` // The namespace of the resource to wait for - Namespace string `json:"namespace"` + Namespace string `json:"namespace,omitempty"` // The condition or jsonpath state to wait for; defaults to exist, a special condition that will wait for the resource to exist - Condition string `json:"condition" jsonschema:"example=Ready,example=Available,'{.status.availableReplicas}'=23"` + Condition string `json:"condition,omitempty" jsonschema:"example=Ready,example=Available,'{.status.availableReplicas}'=23"` } // ZarfComponentActionWaitNetwork specifies a condition to wait for before continuing type ZarfComponentActionWaitNetwork struct { // The protocol to wait for - Protocol string `json:"protocol" jsonschema:"required,enum=tcp,enum=http,enum=https"` + Protocol string `json:"protocol" jsonschema:"enum=tcp,enum=http,enum=https"` // The address to wait for - Address string `json:"address" jsonschema:"required,example=localhost:8080,example=1.1.1.1"` + Address string `json:"address" jsonschema:"example=localhost:8080,example=1.1.1.1"` // The HTTP status code to wait for if using http or https - Code int `json:"code" jsonschema:"required,example=200,example=404"` + Code int `json:"code,omitempty" jsonschema:"example=200,example=404"` } // ZarfContainerTarget defines the destination info for a ZarfData target type ZarfContainerTarget struct { // The namespace to target for data injection - Namespace string `json:"namespace" jsonschema:"required"` + Namespace string `json:"namespace"` // The K8s selector to target for data injection - Selector string `json:"selector" jsonschema:"required,example=app=data-injection"` + Selector string `json:"selector" jsonschema:"example=app=data-injection"` // The container name to target for data injection - Container string `json:"container" jsonschema:"required"` + Container string `json:"container"` // The path within the container to copy the data into - Path string `json:"path" jsonschema:"required"` + Path string `json:"path"` } // ZarfDataInjection is a data-injection definition. type ZarfDataInjection struct { // Either a path to a local folder/file or a remote URL of a file to inject into the given target pod + container - Source string `json:"source" jsonschema:"required"` + Source string `json:"source"` // The target pod + container to inject the data into - Target ZarfContainerTarget `json:"target" jsonschema:"required"` + Target ZarfContainerTarget `json:"target"` // Compress the data before transmitting using gzip. Note: this requires support for tar/gzip locally and in the target image. - Compress bool `json:"compress"` + Compress bool `json:"compress,omitempty"` } // ZarfComponentImport structure for including imported Zarf components. type ZarfComponentImport struct { // The name of the component to import from the referenced zarf.yaml - Name string `json:"name"` + Name string `json:"name,omitempty"` // The path to the directory containing the zarf.yaml to import - Path string `json:"path"` + Path string `json:"path,omitempty"` // [beta] The URL to a Zarf package to import via OCI - URL string `json:"url" jsonschema:"pattern=^oci://.*$"` + URL string `json:"url,omitempty" jsonschema:"pattern=^oci://.*$"` } // JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` diff --git a/src/types/extensions/bigbang.go b/src/types/extensions/bigbang.go index 2119fac542..aac84f340a 100644 --- a/src/types/extensions/bigbang.go +++ b/src/types/extensions/bigbang.go @@ -7,13 +7,13 @@ package extensions // BigBang holds the configuration for the Big Bang extension type BigBang struct { // The version of Big Bang to use - Version string `jsonschema:"required"` + Version string `json:"version" jsonschema:"required"` // Override repo to pull Big Bang from instead of Repo One - Repo string + Repo string `json:"repo,omitempty"` // The list of values files to pass to Big Bang; these will be merged together - ValuesFiles []string + ValuesFiles []string `json:"valuesFiles,omitempty"` // Whether to skip deploying flux; Defaults to false - SkipFlux bool + SkipFlux bool `json:"skipFlux,omitempty"` // Optional paths to Flux kustomize strategic merge patch files - FluxPatchFiles []string + FluxPatchFiles []string `json:"fluxPatchFiles,omitempty"` } diff --git a/src/types/k8s.go b/src/types/k8s.go index 9711b8f516..5919804c48 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -59,73 +59,73 @@ type GeneratedPKI struct { // ZarfState is maintained as a secret in the Zarf namespace to track Zarf init data. type ZarfState struct { // Indicates if Zarf was initialized while deploying its own k8s cluster - ZarfAppliance bool `json:"zarfAppliance"` + ZarfAppliance bool `json:"zarfAppliance,omitempty"` // K8s distribution of the cluster Zarf was deployed to - Distro string `json:"distro"` + Distro string `json:"distro,omitempty"` // Machine architecture of the k8s node(s) - Architecture string `json:"architecture"` + Architecture string `json:"architecture,omitempty"` // Default StorageClass value Zarf uses for variable templating - StorageClass string `json:"storageClass"` + StorageClass string `json:"storageClass,omitempty"` // PKI certificate information for the agent pods Zarf manages - AgentTLS GeneratedPKI `json:"agentTLS"` + AgentTLS GeneratedPKI `json:"agentTLS,omitempty"` // Information about the repository Zarf is configured to use - GitServer GitServerInfo `json:"gitServer"` + GitServer GitServerInfo `json:"gitServer,omitempty"` // Information about the container registry Zarf is configured to use - RegistryInfo RegistryInfo `json:"registryInfo"` + RegistryInfo RegistryInfo `json:"registryInfo,omitempty"` // Information about the artifact registry Zarf is configured to use - ArtifactServer ArtifactServerInfo `json:"artifactServer"` + ArtifactServer ArtifactServerInfo `json:"artifactServer,omitempty"` } // DeployedPackage contains information about a Zarf Package that has been deployed to a cluster // This object is saved as the data of a k8s secret within the 'Zarf' namespace (not as part of the ZarfState secret). type DeployedPackage struct { - Name string `json:"name"` - Data ZarfPackage `json:"data"` - CLIVersion string `json:"cliVersion"` - Generation int `json:"generation"` - DeployedComponents []DeployedComponent `json:"deployedComponents"` - ComponentWebhooks map[string]map[string]Webhook `json:"componentWebhooks"` - ConnectStrings ConnectStrings `json:"connectStrings"` + Name string `json:"name,omitempty"` + Data ZarfPackage `json:"data,omitempty"` + CLIVersion string `json:"cliVersion,omitempty"` + Generation int `json:"generation,omitempty"` + DeployedComponents []DeployedComponent `json:"deployedComponents,omitempty"` + ComponentWebhooks map[string]map[string]Webhook `json:"componentWebhooks,omitempty"` + ConnectStrings ConnectStrings `json:"connectStrings,omitempty"` } // DeployedComponent contains information about a Zarf Package Component that has been deployed to a cluster. type DeployedComponent struct { - Name string `json:"name"` - InstalledCharts []InstalledChart `json:"installedCharts"` - Status ComponentStatus `json:"status"` - ObservedGeneration int `json:"observedGeneration"` + Name string `json:"name,omitempty"` + InstalledCharts []InstalledChart `json:"installedCharts,omitempty"` + Status ComponentStatus `json:"status,omitempty"` + ObservedGeneration int `json:"observedGeneration,omitempty"` } // Webhook contains information about a Component Webhook operating on a Zarf package secret. type Webhook struct { - Name string `json:"name"` - WaitDurationSeconds int `json:"waitDurationSeconds"` - Status WebhookStatus `json:"status"` - ObservedGeneration int `json:"observedGeneration"` + Name string `json:"name,omitempty"` + WaitDurationSeconds int `json:"waitDurationSeconds,omitempty"` + Status WebhookStatus `json:"status,omitempty"` + ObservedGeneration int `json:"observedGeneration,omitempty"` } // InstalledChart contains information about a Helm Chart that has been deployed to a cluster. type InstalledChart struct { - Namespace string `json:"namespace"` - ChartName string `json:"chartName"` + Namespace string `json:"namespace,omitempty"` + ChartName string `json:"chartName,omitempty"` } // GitServerInfo contains information Zarf uses to communicate with a git repository to push/pull repositories to. type GitServerInfo struct { // Username of a user with push access to the git repository - PushUsername string `json:"pushUsername"` + PushUsername string `json:"pushUsername,omitempty"` // Password of a user with push access to the git repository - PushPassword string `json:"pushPassword"` + PushPassword string `json:"pushPassword,omitempty"` // Username of a user with pull-only access to the git repository. If not provided for an external repository then the push-user is used - PullUsername string `json:"pullUsername"` + PullUsername string `json:"pullUsername,omitempty"` // Password of a user with pull-only access to the git repository. If not provided for an external repository then the push-user is used - PullPassword string `json:"pullPassword"` + PullPassword string `json:"pullPassword,omitempty"` // URL address of the git server - Address string `json:"address"` + Address string `json:"address,omitempty"` // Indicates if we are using a git server that Zarf is directly managing - InternalServer bool `json:"internalServer"` + InternalServer bool `json:"internalServer,omitempty"` } // FillInEmptyValues sets every necessary value that's currently empty to a reasonable default @@ -168,13 +168,13 @@ func (gs *GitServerInfo) FillInEmptyValues() error { // ArtifactServerInfo contains information Zarf uses to communicate with a artifact registry to push/pull repositories to. type ArtifactServerInfo struct { // Username of a user with push access to the artifact registry - PushUsername string `json:"pushUsername"` + PushUsername string `json:"pushUsername,omitempty"` // Password of a user with push access to the artifact registry - PushToken string `json:"pushToken"` + PushToken string `json:"pushToken,omitempty"` // URL address of the artifact registry - Address string `json:"address"` + Address string `json:"address,omitempty"` // Indicates if we are using a artifact registry that Zarf is directly managing - InternalServer bool `json:"internalServer"` + InternalServer bool `json:"internalServer,omitempty"` } // FillInEmptyValues sets every necessary value that's currently empty to a reasonable default @@ -194,21 +194,21 @@ func (as *ArtifactServerInfo) FillInEmptyValues() { // RegistryInfo contains information Zarf uses to communicate with a container registry to push/pull images. type RegistryInfo struct { // Username of a user with push access to the registry - PushUsername string `json:"pushUsername"` + PushUsername string `json:"pushUsername,omitempty"` // Password of a user with push access to the registry - PushPassword string `json:"pushPassword"` + PushPassword string `json:"pushPassword,omitempty"` // Username of a user with pull-only access to the registry. If not provided for an external registry than the push-user is used - PullUsername string `json:"pullUsername"` + PullUsername string `json:"pullUsername,omitempty"` // Password of a user with pull-only access to the registry. If not provided for an external registry than the push-user is used - PullPassword string `json:"pullPassword"` + PullPassword string `json:"pullPassword,omitempty"` // URL address of the registry - Address string `json:"address"` + Address string `json:"address,omitempty"` // Nodeport of the registry. Only needed if the registry is running inside the kubernetes cluster - NodePort int `json:"nodePort"` + NodePort int `json:"nodePort,omitempty"` // Indicates if we are using a registry that Zarf is directly managing - InternalRegistry bool `json:"internalRegistry"` + InternalRegistry bool `json:"internalRegistry,omitempty"` // Secret value that the registry was seeded with - Secret string `json:"secret"` + Secret string `json:"secret,omitempty"` } // FillInEmptyValues sets every necessary value not already set to a reasonable default diff --git a/src/types/package.go b/src/types/package.go index 0a7e5f52be..27b708c7b8 100644 --- a/src/types/package.go +++ b/src/types/package.go @@ -19,17 +19,17 @@ const ( // ZarfPackage the top-level structure of a Zarf config file. type ZarfPackage struct { // The kind of Zarf package - Kind ZarfPackageKind `json:"kind" jsonschema:"required,enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` + Kind ZarfPackageKind `json:"kind" jsonschema:"enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` // Package metadata - Metadata ZarfMetadata `json:"metadata"` + Metadata ZarfMetadata `json:"metadata,omitempty"` // Zarf-generated package build data - Build ZarfBuildData `json:"build"` + Build ZarfBuildData `json:"build,omitempty"` // List of components to deploy in this package - Components []ZarfComponent `json:"components" jsonschema:"required,minItems=1"` + Components []ZarfComponent `json:"components" jsonschema:"minItems=1"` // Constant template values applied on deploy for K8s resources - Constants []variables.Constant `json:"constants"` + Constants []variables.Constant `json:"constants,omitempty"` // Variable template values applied on deploy for K8s resources - Variables []variables.InteractiveVariable `json:"variables"` + Variables []variables.InteractiveVariable `json:"variables,omitempty"` } // IsInitConfig returns whether a Zarf package is an init config. @@ -50,57 +50,57 @@ func (pkg ZarfPackage) IsSBOMAble() bool { // ZarfMetadata lists information about the current ZarfPackage. type ZarfMetadata struct { // Name to identify this Zarf package - Name string `json:"name" jsonschema:"required,pattern=^[a-z0-9][a-z0-9\\-]*$"` + Name string `json:"name" jsonschema:"pattern=^[a-z0-9][a-z0-9\\-]*$"` // Additional information about this package - Description string `json:"description"` + Description string `json:"description,omitempty"` // Generic string set by a package author to track the package version (Note: ZarfInitConfigs will always be versioned to the CLIVersion they were created with) - Version string `json:"version"` + Version string `json:"version,omitempty"` // Link to package information when online - URL string `json:"url"` + URL string `json:"url,omitempty"` // An image URL to embed in this package (Reserved for future use in Zarf UI) - Image string `json:"image"` + Image string `json:"image,omitempty"` // Disable compression of this package - Uncompressed bool `json:"uncompressed"` + Uncompressed bool `json:"uncompressed,omitempty"` // The target cluster architecture for this package - Architecture string `json:"architecture" jsonschema:"example=arm64,example=amd64"` + Architecture string `json:"architecture,omitempty" jsonschema:"example=arm64,example=amd64"` // Yaml OnLy Online (YOLO): True enables deploying a Zarf package without first running zarf init against the cluster. This is ideal for connected environments where you want to use existing VCS and container registries. - YOLO bool `json:"yolo"` + YOLO bool `json:"yolo,omitempty"` // Comma-separated list of package authors (including contact info) - Authors string `json:"authors" jsonschema:"example=Doug <hello@defenseunicorns.com>, Pepr <hello@defenseunicorns.com>"` + Authors string `json:"authors,omitempty" jsonschema:"example=Doug <hello@defenseunicorns.com>, Pepr <hello@defenseunicorns.com>"` // Link to package documentation when online - Documentation string `json:"documentation"` + Documentation string `json:"documentation,omitempty"` // Link to package source code when online - Source string `json:"source"` + Source string `json:"source,omitempty"` // Name of the distributing entity, organization or individual - Vendor string `json:"vendor"` + Vendor string `json:"vendor,omitempty"` // Checksum of a checksums.txt file that contains checksums all the layers within the package - AggregateChecksum string `json:"aggregateChecksum"` + AggregateChecksum string `json:"aggregateChecksum,omitempty"` } // ZarfBuildData is written during the packager.Create() operation to track details of the created package. type ZarfBuildData struct { // The machine name that created this package - Terminal string `json:"terminal" jsonschema:"required"` + Terminal string `json:"terminal"` // The username who created this package - User string `json:"user" jsonschema:"required"` + User string `json:"user"` // The architecture this package was created on - Architecture string `json:"architecture" jsonschema:"required"` + Architecture string `json:"architecture"` // The timestamp when this package was created - Timestamp string `json:"timestamp" jsonschema:"required"` + Timestamp string `json:"timestamp"` // The version of Zarf used to build this package - Version string `json:"version" jsonschema:"required"` + Version string `json:"version"` // Any migrations that have been run on this package - Migrations []string `json:"migrations"` + Migrations []string `json:"migrations,omitempty"` // Any registry domains that were overridden on package create when pulling images - RegistryOverrides map[string]string `json:"registryOverrides"` + RegistryOverrides map[string]string `json:"registryOverrides,omitempty"` // Whether this package was created with differential components - Differential bool `json:"differential"` + Differential bool `json:"differential,omitempty"` // Version of a previously built package used as the basis for creating this differential package - DifferentialPackageVersion string `json:"differentialPackageVersion"` + DifferentialPackageVersion string `json:"differentialPackageVersion,omitempty"` // List of components that were not included in this package due to differential packaging - DifferentialMissing []string `json:"differentialMissing"` + DifferentialMissing []string `json:"differentialMissing,omitempty"` // The minimum version of Zarf that does not have breaking package structure changes - LastNonBreakingVersion string `json:"lastNonBreakingVersion"` + LastNonBreakingVersion string `json:"lastNonBreakingVersion,omitempty"` // The flavor of Zarf used to build this package - Flavor string `json:"flavor"` + Flavor string `json:"flavor,omitempty"` } diff --git a/zarf.schema.json b/zarf.schema.json index 57efbb6982..af0138282d 100644 --- a/zarf.schema.json +++ b/zarf.schema.json @@ -4,26 +4,26 @@ "$defs": { "BigBang": { "properties": { - "Version": { + "version": { "type": "string", "description": "The version of Big Bang to use" }, - "Repo": { + "repo": { "type": "string", "description": "Override repo to pull Big Bang from instead of Repo One" }, - "ValuesFiles": { + "valuesFiles": { "items": { "type": "string" }, "type": "array", "description": "The list of values files to pass to Big Bang; these will be merged together" }, - "SkipFlux": { + "skipFlux": { "type": "boolean", "description": "Whether to skip deploying flux; Defaults to false" }, - "FluxPatchFiles": { + "fluxPatchFiles": { "items": { "type": "string" }, @@ -34,7 +34,7 @@ "additionalProperties": false, "type": "object", "required": [ - "Version" + "version" ], "description": "BigBang holds the configuration for the Big Bang extension", "patternProperties": { @@ -755,8 +755,7 @@ "type": "object", "required": [ "protocol", - "address", - "code" + "address" ], "description": "ZarfComponentActionWaitNetwork specifies a condition to wait for before continuing", "patternProperties": { From cbc25f23d0299cde0fa17e6db285d3faeb22463e Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 30 Jul 2024 13:00:18 +0000 Subject: [PATCH 11/34] add back test Signed-off-by: Austin Abro --- src/pkg/lint/schema_test.go | 152 ++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 75 deletions(-) diff --git a/src/pkg/lint/schema_test.go b/src/pkg/lint/schema_test.go index c30820aa9a..bb6adde541 100644 --- a/src/pkg/lint/schema_test.go +++ b/src/pkg/lint/schema_test.go @@ -5,11 +5,13 @@ package lint import ( + "fmt" "os" "testing" goyaml "github.com/goccy/go-yaml" "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/pkg/variables" "github.com/zarf-dev/zarf/src/types" ) @@ -38,81 +40,81 @@ func TestZarfSchema(t *testing.T) { }, expectedSchemaStrings: nil, }, - // { - // name: "no comp or kind", - // pkg: types.ZarfPackage{ - // Metadata: types.ZarfMetadata{ - // Name: "no-comp-or-kind", - // }, - // Components: []types.ZarfComponent{}, - // }, - // expectedSchemaStrings: []string{ - // "kind: kind must be one of the following: \"ZarfInitConfig\", \"ZarfPackageConfig\"", - // "components: Array must have at least 1 items", - // }, - // }, - // { - // name: "invalid package", - // pkg: types.ZarfPackage{ - // Kind: types.ZarfInitConfig, - // Metadata: types.ZarfMetadata{ - // Name: "-invalid-name", - // }, - // Components: []types.ZarfComponent{ - // { - // Name: "invalid-name", - // Only: types.ZarfComponentOnlyTarget{ - // LocalOS: "unsupportedOS", - // }, - // Import: types.ZarfComponentImport{ - // Path: fmt.Sprintf("start%send", types.ZarfPackageTemplatePrefix), - // URL: fmt.Sprintf("oci://start%send", types.ZarfPackageTemplatePrefix), - // }, - // }, - // { - // Name: "actions", - // Actions: types.ZarfComponentActions{ - // OnCreate: types.ZarfComponentActionSet{ - // Before: []types.ZarfComponentAction{ - // { - // Cmd: "echo 'invalid setVariable'", - // SetVariables: []variables.Variable{{Name: "not_uppercase"}}, - // }, - // }, - // }, - // OnRemove: types.ZarfComponentActionSet{ - // OnSuccess: []types.ZarfComponentAction{ - // { - // Cmd: "echo 'invalid setVariable'", - // SetVariables: []variables.Variable{{Name: "not_uppercase"}}, - // }, - // }, - // }, - // }, - // }, - // }, - // Variables: []variables.InteractiveVariable{ - // { - // Variable: variables.Variable{Name: "not_uppercase"}, - // }, - // }, - // Constants: []variables.Constant{ - // { - // Name: "not_uppercase", - // }, - // }, - // }, - // expectedSchemaStrings: []string{ - // "metadata.name: Does not match pattern '^[a-z0-9][a-z0-9\\-]*$'", - // "variables.0.name: Does not match pattern '^[A-Z0-9_]+$'", - // "constants.0.name: Does not match pattern '^[A-Z0-9_]+$'", - // "components.0.only.localOS: components.0.only.localOS must be one of the following: \"linux\", \"darwin\", \"windows\"", - // "components.1.actions.onCreate.before.0.setVariables.0.name: Does not match pattern '^[A-Z0-9_]+$'", - // "components.1.actions.onRemove.onSuccess.0.setVariables.0.name: Does not match pattern '^[A-Z0-9_]+$'", - // "components.0.import.path: Must not validate the schema (not)", - // "components.0.import.url: Must not validate the schema (not)", - // }, - // }, + { + name: "no comp or kind", + pkg: types.ZarfPackage{ + Metadata: types.ZarfMetadata{ + Name: "no-comp-or-kind", + }, + Components: []types.ZarfComponent{}, + }, + expectedSchemaStrings: []string{ + "kind: kind must be one of the following: \"ZarfInitConfig\", \"ZarfPackageConfig\"", + "components: Array must have at least 1 items", + }, + }, + { + name: "invalid package", + pkg: types.ZarfPackage{ + Kind: types.ZarfInitConfig, + Metadata: types.ZarfMetadata{ + Name: "-invalid-name", + }, + Components: []types.ZarfComponent{ + { + Name: "invalid-name", + Only: types.ZarfComponentOnlyTarget{ + LocalOS: "unsupportedOS", + }, + Import: types.ZarfComponentImport{ + Path: fmt.Sprintf("start%send", types.ZarfPackageTemplatePrefix), + URL: fmt.Sprintf("oci://start%send", types.ZarfPackageTemplatePrefix), + }, + }, + { + Name: "actions", + Actions: types.ZarfComponentActions{ + OnCreate: types.ZarfComponentActionSet{ + Before: []types.ZarfComponentAction{ + { + Cmd: "echo 'invalid setVariable'", + SetVariables: []variables.Variable{{Name: "not_uppercase"}}, + }, + }, + }, + OnRemove: types.ZarfComponentActionSet{ + OnSuccess: []types.ZarfComponentAction{ + { + Cmd: "echo 'invalid setVariable'", + SetVariables: []variables.Variable{{Name: "not_uppercase"}}, + }, + }, + }, + }, + }, + }, + Variables: []variables.InteractiveVariable{ + { + Variable: variables.Variable{Name: "not_uppercase"}, + }, + }, + Constants: []variables.Constant{ + { + Name: "not_uppercase", + }, + }, + }, + expectedSchemaStrings: []string{ + "metadata.name: Does not match pattern '^[a-z0-9][a-z0-9\\-]*$'", + "variables.0.name: Does not match pattern '^[A-Z0-9_]+$'", + "constants.0.name: Does not match pattern '^[A-Z0-9_]+$'", + "components.0.only.localOS: components.0.only.localOS must be one of the following: \"linux\", \"darwin\", \"windows\"", + "components.1.actions.onCreate.before.0.setVariables.0.name: Does not match pattern '^[A-Z0-9_]+$'", + "components.1.actions.onRemove.onSuccess.0.setVariables.0.name: Does not match pattern '^[A-Z0-9_]+$'", + "components.0.import.path: Must not validate the schema (not)", + "components.0.import.url: Must not validate the schema (not)", + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From da9ea4856967ac5823b93b4e07a57e268ff7ab02 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 30 Jul 2024 13:28:40 +0000 Subject: [PATCH 12/34] removing json options Signed-off-by: Austin Abro --- src/types/runtime.go | 122 +++++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/src/types/runtime.go b/src/types/runtime.go index b3b2f7c8f3..6587ff3aa0 100644 --- a/src/types/runtime.go +++ b/src/types/runtime.go @@ -19,169 +19,169 @@ const ( // ZarfCommonOptions tracks the user-defined preferences used across commands. type ZarfCommonOptions struct { // Verify that Zarf should perform an action - Confirm bool `json:"confirm"` + Confirm bool // Allow insecure connections for remote packages - Insecure bool `json:"insecure"` + Insecure bool // Path to use to cache images and git repos on package create - CachePath string `json:"cachePath"` + CachePath string // Location Zarf should use as a staging ground when managing files and images for package creation and deployment - TempDirectory string `json:"tempDirectory"` + TempDirectory string // Number of concurrent layer operations to perform when interacting with a remote package - OCIConcurrency int `json:"ociConcurrency"` + OCIConcurrency int } // ZarfPackageOptions tracks the user-defined preferences during common package operations. type ZarfPackageOptions struct { // The SHA256 checksum of the package - Shasum string `json:"shasum"` + Shasum string // Location where a Zarf package can be found - PackageSource string `json:"packageSource"` + PackageSource string // Comma separated list of optional components - OptionalComponents string `json:"optionalComponents"` + OptionalComponents string // Location where the public key component of a cosign key-pair can be found - SGetKeyPath string `json:"sGetKeyPath"` + SGetKeyPath string // Key-Value map of variable names and their corresponding values that will be used to template manifests and files in the Zarf package - SetVariables map[string]string `json:"setVariables"` + SetVariables map[string]string // Location where the public key component of a cosign key-pair can be found - PublicKeyPath string `json:"publicKeyPath"` + PublicKeyPath string // The number of retries to perform for Zarf deploy operations like image pushes or Helm installs - Retries int `json:"retries"` + Retries int } // ZarfInspectOptions tracks the user-defined preferences during a package inspection. type ZarfInspectOptions struct { // View SBOM contents while inspecting the package - ViewSBOM bool `json:"viewSBOM"` + ViewSBOM bool // Location to output an SBOM into after package inspection - SBOMOutputDir string `json:"sbomOutputDir"` + SBOMOutputDir string // ListImages will list the images in the package - ListImages bool `json:"listImages"` + ListImages bool } // ZarfFindImagesOptions tracks the user-defined preferences during a prepare find-images search. type ZarfFindImagesOptions struct { // Path to the helm chart directory - RepoHelmChartPath string `json:"repoHelmChartPath"` + RepoHelmChartPath string // Kubernetes version to use for the helm chart - KubeVersionOverride string `json:"kubeVersionOverride"` + KubeVersionOverride string // Manual override for ###ZARF_REGISTRY### - RegistryURL string `json:"registryUrl"` + RegistryURL string // Find the location of the image given as an argument and print it to the console - Why string `json:"why"` + Why string // Optionally skip lookup of cosign artifacts when finding images - SkipCosign bool `json:"skipCosign"` + SkipCosign bool } // ZarfDeployOptions tracks the user-defined preferences during a package deploy. type ZarfDeployOptions struct { // Whether to adopt any pre-existing K8s resources into the Helm charts managed by Zarf - AdoptExistingResources bool `json:"adoptExistingResources"` + AdoptExistingResources bool // Skip waiting for external webhooks to execute as each package component is deployed - SkipWebhooks bool `json:"skipWebhooks"` + SkipWebhooks bool // Timeout for performing Helm operations - Timeout time.Duration `json:"timeout"` + Timeout time.Duration // [Library Only] A map of component names to chart names containing Helm Chart values to override values on deploy - ValuesOverridesMap map[string]map[string]map[string]interface{} `json:"valuesOverridesMap"` + ValuesOverridesMap map[string]map[string]map[string]interface{} } // ZarfMirrorOptions tracks the user-defined preferences during a package mirror. type ZarfMirrorOptions struct { // Whether to skip adding a Zarf checksum to image references - NoImgChecksum bool `json:"noImgChecksum"` + NoImgChecksum bool } // ZarfPublishOptions tracks the user-defined preferences during a package publish. type ZarfPublishOptions struct { // Location where the Zarf package will be published to - PackageDestination string `json:"packageDestination"` + PackageDestination string // Password to the private key signature file that will be used to sign the published package - SigningKeyPassword string `json:"signingKeyPassword"` + SigningKeyPassword string // Location where the private key component of a cosign key-pair can be found - SigningKeyPath string `json:"signingKeyPath"` + SigningKeyPath string } // ZarfPullOptions tracks the user-defined preferences during a package pull. type ZarfPullOptions struct { // Location where the pulled Zarf package will be placed - OutputDirectory string `json:"outputDirectory"` + OutputDirectory string } // ZarfGenerateOptions tracks the user-defined options during package generation. type ZarfGenerateOptions struct { // Name of the package being generated - Name string `json:"name"` + Name string // URL to the source git repository - URL string `json:"url"` + URL string // Version of the chart to use - Version string `json:"version"` + Version string // Relative path to the chart in the git repository - GitPath string `json:"gitPath"` + GitPath string // Location where the finalized zarf.yaml will be placed - Output string `json:"output"` + Output string } // ZarfInitOptions tracks the user-defined options during cluster initialization. type ZarfInitOptions struct { // Indicates if Zarf was initialized while deploying its own k8s cluster - ApplianceMode bool `json:"applianceMode"` + ApplianceMode bool // Information about the repository Zarf is going to be using - GitServer GitServerInfo `json:"gitServer"` + GitServer GitServerInfo // Information about the container registry Zarf is going to be using - RegistryInfo RegistryInfo `json:"registryInfo"` + RegistryInfo RegistryInfo // Information about the artifact registry Zarf is going to be using - ArtifactServer ArtifactServerInfo `json:"artifactServer"` + ArtifactServer ArtifactServerInfo // StorageClass of the k8s cluster Zarf is initializing - StorageClass string `json:"storageClass"` + StorageClass string } // ZarfCreateOptions tracks the user-defined options used to create the package. type ZarfCreateOptions struct { // Disable the generation of SBOM materials during package creation - SkipSBOM bool `json:"skipSBOM"` + SkipSBOM bool // Location where the Zarf package will be created from - BaseDir string `json:"baseDir"` + BaseDir string // Location where the finalized Zarf package will be placed - Output string `json:"output"` + Output string // Whether to pause to allow for viewing the SBOM post-creation - ViewSBOM bool `json:"viewSBOM"` + ViewSBOM bool // Location to output an SBOM into after package creation - SBOMOutputDir string `json:"sbomOutputDir"` + SBOMOutputDir string // Key-Value map of variable names and their corresponding values that will be used to template against the Zarf package being used - SetVariables map[string]string `json:"setVariables"` + SetVariables map[string]string // Size of chunks to use when splitting a zarf package into multiple files in megabytes - MaxPackageSizeMB int `json:"maxPackageSizeMB"` + MaxPackageSizeMB int // Location where the private key component of a cosign key-pair can be found - SigningKeyPath string `json:"signingKeyPath"` + SigningKeyPath string // Password to the private key signature file that will be used to sigh the created package - SigningKeyPassword string `json:"signingKeyPassword"` + SigningKeyPassword string // Path to a previously built package used as the basis for creating a differential package - DifferentialPackagePath string `json:"differentialPackagePath"` + DifferentialPackagePath string // A map of domains to override on package create when pulling images - RegistryOverrides map[string]string `json:"registryOverrides"` + RegistryOverrides map[string]string // An optional variant that controls which components will be included in a package - Flavor string `json:"flavor"` + Flavor string // Whether to create a skeleton package - IsSkeleton bool `json:"isSkeleton"` + IsSkeleton bool // Whether to create a YOLO package - NoYOLO bool `json:"noYOLO"` + NoYOLO bool } // ZarfSplitPackageData contains info about a split package. type ZarfSplitPackageData struct { // The sha256sum of the package - Sha256Sum string `json:"sha256Sum"` + Sha256Sum string // The size of the package in bytes - Bytes int64 `json:"bytes"` + Bytes int64 // The number of parts the package is split into - Count int `json:"count"` + Count int } // ConnectString contains information about a connection made with Zarf connect. type ConnectString struct { // Descriptive text that explains what the resource you would be connecting to is used for - Description string `json:"description"` + Description string // URL path that gets appended to the k8s port-forward result - URL string `json:"url"` + URL string } // ConnectStrings is a map of connect names to connection information. @@ -189,7 +189,7 @@ type ConnectStrings map[string]ConnectString // DifferentialData contains image and repository information about the package a Differential Package is Based on. type DifferentialData struct { - DifferentialImages map[string]bool `json:"differentialImages"` - DifferentialRepos map[string]bool `json:"differentialRepos"` - DifferentialPackageVersion string `json:"differentialPackageVersion"` + DifferentialImages map[string]bool + DifferentialRepos map[string]bool + DifferentialPackageVersion string } From e8a11ac4d8bd08a0033f73af538112f05aeb52d0 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 30 Jul 2024 13:48:14 +0000 Subject: [PATCH 13/34] add back json data Signed-off-by: Austin Abro --- src/types/k8s.go | 81 ++++++++++++++++++++++---------------------- src/types/runtime.go | 4 +-- 2 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/types/k8s.go b/src/types/k8s.go index 5919804c48..2dbc92b0c2 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -59,73 +59,72 @@ type GeneratedPKI struct { // ZarfState is maintained as a secret in the Zarf namespace to track Zarf init data. type ZarfState struct { // Indicates if Zarf was initialized while deploying its own k8s cluster - ZarfAppliance bool `json:"zarfAppliance,omitempty"` + ZarfAppliance bool `json:"zarfAppliance"` // K8s distribution of the cluster Zarf was deployed to - Distro string `json:"distro,omitempty"` + Distro string `json:"distro"` // Machine architecture of the k8s node(s) - Architecture string `json:"architecture,omitempty"` + Architecture string `json:"architecture"` // Default StorageClass value Zarf uses for variable templating - StorageClass string `json:"storageClass,omitempty"` + StorageClass string `json:"storageClass"` // PKI certificate information for the agent pods Zarf manages - AgentTLS GeneratedPKI `json:"agentTLS,omitempty"` + AgentTLS GeneratedPKI `json:"agentTLS"` // Information about the repository Zarf is configured to use - GitServer GitServerInfo `json:"gitServer,omitempty"` + GitServer GitServerInfo `json:"gitServer"` // Information about the container registry Zarf is configured to use - RegistryInfo RegistryInfo `json:"registryInfo,omitempty"` + RegistryInfo RegistryInfo `json:"registryInfo"` // Information about the artifact registry Zarf is configured to use - ArtifactServer ArtifactServerInfo `json:"artifactServer,omitempty"` + ArtifactServer ArtifactServerInfo `json:"artifactServer"` } // DeployedPackage contains information about a Zarf Package that has been deployed to a cluster // This object is saved as the data of a k8s secret within the 'Zarf' namespace (not as part of the ZarfState secret). type DeployedPackage struct { - Name string `json:"name,omitempty"` - Data ZarfPackage `json:"data,omitempty"` - CLIVersion string `json:"cliVersion,omitempty"` - Generation int `json:"generation,omitempty"` - DeployedComponents []DeployedComponent `json:"deployedComponents,omitempty"` + Name string `json:"name"` + Data ZarfPackage `json:"data"` + CLIVersion string `json:"cliVersion"` + Generation int `json:"generation"` + DeployedComponents []DeployedComponent `json:"deployedComponents"` ComponentWebhooks map[string]map[string]Webhook `json:"componentWebhooks,omitempty"` ConnectStrings ConnectStrings `json:"connectStrings,omitempty"` } // DeployedComponent contains information about a Zarf Package Component that has been deployed to a cluster. type DeployedComponent struct { - Name string `json:"name,omitempty"` - InstalledCharts []InstalledChart `json:"installedCharts,omitempty"` - Status ComponentStatus `json:"status,omitempty"` - ObservedGeneration int `json:"observedGeneration,omitempty"` + Name string `json:"name"` + InstalledCharts []InstalledChart `json:"installedCharts"` + Status ComponentStatus `json:"status"` + ObservedGeneration int `json:"observedGeneration"` } // Webhook contains information about a Component Webhook operating on a Zarf package secret. type Webhook struct { - Name string `json:"name,omitempty"` + Name string `json:"name"` WaitDurationSeconds int `json:"waitDurationSeconds,omitempty"` - Status WebhookStatus `json:"status,omitempty"` - ObservedGeneration int `json:"observedGeneration,omitempty"` + Status WebhookStatus `json:"status"` + ObservedGeneration int `json:"observedGeneration"` } // InstalledChart contains information about a Helm Chart that has been deployed to a cluster. type InstalledChart struct { - Namespace string `json:"namespace,omitempty"` - ChartName string `json:"chartName,omitempty"` + Namespace string `json:"namespace"` + ChartName string `json:"chartName"` } // GitServerInfo contains information Zarf uses to communicate with a git repository to push/pull repositories to. type GitServerInfo struct { // Username of a user with push access to the git repository - PushUsername string `json:"pushUsername,omitempty"` + PushUsername string `json:"pushUsername"` // Password of a user with push access to the git repository - PushPassword string `json:"pushPassword,omitempty"` + PushPassword string `json:"pushPassword"` // Username of a user with pull-only access to the git repository. If not provided for an external repository then the push-user is used - PullUsername string `json:"pullUsername,omitempty"` + PullUsername string `json:"pullUsername"` // Password of a user with pull-only access to the git repository. If not provided for an external repository then the push-user is used - PullPassword string `json:"pullPassword,omitempty"` - + PullPassword string `json:"pullPassword"` // URL address of the git server - Address string `json:"address,omitempty"` + Address string `json:"address"` // Indicates if we are using a git server that Zarf is directly managing - InternalServer bool `json:"internalServer,omitempty"` + InternalServer bool `json:"internalServer"` } // FillInEmptyValues sets every necessary value that's currently empty to a reasonable default @@ -168,13 +167,13 @@ func (gs *GitServerInfo) FillInEmptyValues() error { // ArtifactServerInfo contains information Zarf uses to communicate with a artifact registry to push/pull repositories to. type ArtifactServerInfo struct { // Username of a user with push access to the artifact registry - PushUsername string `json:"pushUsername,omitempty"` + PushUsername string `json:"pushUsername"` // Password of a user with push access to the artifact registry - PushToken string `json:"pushToken,omitempty"` + PushToken string `json:"pushPassword"` // URL address of the artifact registry - Address string `json:"address,omitempty"` + Address string `json:"address"` // Indicates if we are using a artifact registry that Zarf is directly managing - InternalServer bool `json:"internalServer,omitempty"` + InternalServer bool `json:"internalServer"` } // FillInEmptyValues sets every necessary value that's currently empty to a reasonable default @@ -194,21 +193,21 @@ func (as *ArtifactServerInfo) FillInEmptyValues() { // RegistryInfo contains information Zarf uses to communicate with a container registry to push/pull images. type RegistryInfo struct { // Username of a user with push access to the registry - PushUsername string `json:"pushUsername,omitempty"` + PushUsername string `json:"pushUsername"` // Password of a user with push access to the registry - PushPassword string `json:"pushPassword,omitempty"` + PushPassword string `json:"pushPassword"` // Username of a user with pull-only access to the registry. If not provided for an external registry than the push-user is used - PullUsername string `json:"pullUsername,omitempty"` + PullUsername string `json:"pullUsername"` // Password of a user with pull-only access to the registry. If not provided for an external registry than the push-user is used - PullPassword string `json:"pullPassword,omitempty"` + PullPassword string `json:"pullPassword"` // URL address of the registry - Address string `json:"address,omitempty"` + Address string `json:"address"` // Nodeport of the registry. Only needed if the registry is running inside the kubernetes cluster - NodePort int `json:"nodePort,omitempty"` + NodePort int `json:"nodePort"` // Indicates if we are using a registry that Zarf is directly managing - InternalRegistry bool `json:"internalRegistry,omitempty"` + InternalRegistry bool `json:"internalRegistry"` // Secret value that the registry was seeded with - Secret string `json:"secret,omitempty"` + Secret string `json:"secret"` } // FillInEmptyValues sets every necessary value not already set to a reasonable default diff --git a/src/types/runtime.go b/src/types/runtime.go index 6587ff3aa0..5a4cf728c1 100644 --- a/src/types/runtime.go +++ b/src/types/runtime.go @@ -179,9 +179,9 @@ type ZarfSplitPackageData struct { // ConnectString contains information about a connection made with Zarf connect. type ConnectString struct { // Descriptive text that explains what the resource you would be connecting to is used for - Description string + Description string `json:"description"` // URL path that gets appended to the k8s port-forward result - URL string + URL string `json:"url"` } // ConnectStrings is a map of connect names to connection information. From de0bd7c1ccd88b2ef29928d1a90c6f5f09e7b726 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 30 Jul 2024 13:49:04 +0000 Subject: [PATCH 14/34] bb required Signed-off-by: Austin Abro --- src/types/extensions/bigbang.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/extensions/bigbang.go b/src/types/extensions/bigbang.go index aac84f340a..67a8a71446 100644 --- a/src/types/extensions/bigbang.go +++ b/src/types/extensions/bigbang.go @@ -7,7 +7,7 @@ package extensions // BigBang holds the configuration for the Big Bang extension type BigBang struct { // The version of Big Bang to use - Version string `json:"version" jsonschema:"required"` + Version string `json:"version"` // Override repo to pull Big Bang from instead of Repo One Repo string `json:"repo,omitempty"` // The list of values files to pass to Big Bang; these will be merged together From 96d703d95d335caed5373ec66a89b31f367362b1 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 30 Jul 2024 14:07:56 +0000 Subject: [PATCH 15/34] de-dup Signed-off-by: Austin Abro --- src/cmd/internal.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/cmd/internal.go b/src/cmd/internal.go index 6d54bbdca1..3d77c01190 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -7,6 +7,7 @@ package cmd import ( "context" "encoding/json" + "errors" "fmt" "os" "path/filepath" @@ -156,19 +157,28 @@ tableOfContents: false }, } +func addGoComments(reflector *jsonschema.Reflector) error { + addCommentErr := errors.New("this command must be called from the root of the Zarf repo") + + typePackagePath := filepath.Join("src", "types") + if err := reflector.AddGoComments("github.com/zarf-dev/zarf", typePackagePath); err != nil { + return fmt.Errorf("%w: %w", addCommentErr, err) + } + varPackagePath := filepath.Join("src", "pkg", "variables") + if err := reflector.AddGoComments("github.com/zarf-dev/zarf", varPackagePath); err != nil { + return fmt.Errorf("%w: %w", addCommentErr, err) + } + return nil +} + var genConfigSchemaCmd = &cobra.Command{ Use: "gen-config-schema", Aliases: []string{"gc"}, Short: lang.CmdInternalConfigSchemaShort, RunE: func(_ *cobra.Command, _ []string) error { reflector := jsonschema.Reflector(jsonschema.Reflector{ExpandedStruct: true}) - typePackagePath := filepath.Join("src", "types") - if err := reflector.AddGoComments("github.com/zarf-dev/zarf", typePackagePath); err != nil { - return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) - } - varPackagePath := filepath.Join("src", "pkg", "variables") - if err := reflector.AddGoComments("github.com/zarf-dev/zarf", varPackagePath); err != nil { - return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) + if err := addGoComments(&reflector); err != nil { + return err } schema := reflector.Reflect(&types.ZarfPackage{}) @@ -193,13 +203,8 @@ var genTypesSchemaCmd = &cobra.Command{ Short: lang.CmdInternalTypesSchemaShort, RunE: func(_ *cobra.Command, _ []string) error { reflector := jsonschema.Reflector(jsonschema.Reflector{ExpandedStruct: true}) - typePackagePath := filepath.Join("src", "types") - if err := reflector.AddGoComments("github.com/zarf-dev/zarf", typePackagePath); err != nil { - return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) - } - varPackagePath := filepath.Join("src", "pkg", "variables") - if err := reflector.AddGoComments("github.com/zarf-dev/zarf", varPackagePath); err != nil { - return fmt.Errorf("this command must be called from the root of the Zarf repo: %w", err) + if err := addGoComments(&reflector); err != nil { + return err } schema := reflector.Reflect(&zarfTypes{}) From 380d2e7413ab8a4a2d07999ea5e08eaedf604e67 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 30 Jul 2024 15:13:25 +0000 Subject: [PATCH 16/34] add period to json descriptions Signed-off-by: Austin Abro --- src/types/component.go | 190 +++++++++++------------ src/types/extensions/bigbang.go | 12 +- src/types/extensions/common.go | 6 +- src/types/k8s.go | 11 ++ src/types/package.go | 60 ++++---- src/types/runtime.go | 11 -- zarf.schema.json | 264 ++++++++++++++++---------------- 7 files changed, 277 insertions(+), 277 deletions(-) diff --git a/src/types/component.go b/src/types/component.go index 7eb744d764..b43493ad0a 100644 --- a/src/types/component.go +++ b/src/types/component.go @@ -13,19 +13,19 @@ import ( // ZarfComponent is the primary functional grouping of assets to deploy by Zarf. type ZarfComponent struct { - // The name of the component + // The name of the component. Name string `json:"name" jsonschema:"pattern=^[a-z0-9][a-z0-9\\-]*$"` - // Message to include during package deploy describing the purpose of this component + // Message to include during package deploy describing the purpose of this component. Description string `json:"description,omitempty"` - // Determines the default Y/N state for installing this component on package deploy + // Determines the default Y/N state for installing this component on package deploy. Default bool `json:"default,omitempty"` - // Do not prompt user to install this component + // Do not prompt user to install this component. Required *bool `json:"required,omitempty"` - // Filter when this component is included in package creation or deployment + // Filter when this component is included in package creation or deployment. Only ZarfComponentOnlyTarget `json:"only,omitempty"` // [Deprecated] Create a user selector field based on all components in the same group. This will be removed in Zarf v1.0.0. Consider using 'only.flavor' instead. @@ -34,38 +34,38 @@ type ZarfComponent struct { // [Deprecated] Specify a path to a public key to validate signed online resources. This will be removed in Zarf v1.0.0. DeprecatedCosignKeyPath string `json:"cosignKeyPath,omitempty" jsonschema:"deprecated=true"` - // Import a component from another Zarf package + // Import a component from another Zarf package. Import ZarfComponentImport `json:"import,omitempty"` - // Kubernetes manifests to be included in a generated Helm chart on package deploy + // Kubernetes manifests to be included in a generated Helm chart on package deploy. Manifests []ZarfManifest `json:"manifests,omitempty"` - // Helm charts to install during package deploy + // Helm charts to install during package deploy. Charts []ZarfChart `json:"charts,omitempty"` - // Datasets to inject into a container in the target cluster + // Datasets to inject into a container in the target cluster. DataInjections []ZarfDataInjection `json:"dataInjections,omitempty"` - // Files or folders to place on disk during package deployment + // Files or folders to place on disk during package deployment. Files []ZarfFile `json:"files,omitempty"` - // List of OCI images to include in the package + // List of OCI images to include in the package. Images []string `json:"images,omitempty"` - // List of git repos to include in the package + // List of git repos to include in the package. Repos []string `json:"repos,omitempty"` - // Extend component functionality with additional features + // Extend component functionality with additional features. Extensions extensions.ZarfComponentExtensions `json:"extensions,omitempty"` // [Deprecated] (replaced by actions) Custom commands to run before or after package deployment. This will be removed in Zarf v1.0.0. DeprecatedScripts DeprecatedZarfComponentScripts `json:"scripts,omitempty" jsonschema:"deprecated=true"` - // Custom commands to run at various stages of a package lifecycle + // Custom commands to run at various stages of a package lifecycle. Actions ZarfComponentActions `json:"actions,omitempty"` } -// RequiresCluster returns if the component requires a cluster connection to deploy +// RequiresCluster returns if the component requires a cluster connection to deploy. func (c ZarfComponent) RequiresCluster() bool { hasImages := len(c.Images) > 0 hasCharts := len(c.Charts) > 0 @@ -91,167 +91,167 @@ 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 + // Only deploy component to specified OS. LocalOS string `json:"localOS,omitempty" jsonschema:"enum=linux,enum=darwin,enum=windows"` - // Only deploy component to specified clusters + // 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' + // Only include this component when a matching '--flavor' is specified on 'zarf package create'. Flavor string `json:"flavor,omitempty"` } // ZarfComponentOnlyCluster represents the architecture and K8s cluster distribution to filter on. type ZarfComponentOnlyCluster struct { - // Only create and deploy to clusters of the given architecture + // Only create and deploy to clusters of the given architecture. Architecture string `json:"architecture,omitempty" jsonschema:"enum=amd64,enum=arm64"` - // A list of kubernetes distros this package works with (Reserved for future use) + // A list of kubernetes distros this package works with (Reserved for future use). Distros []string `json:"distros,omitempty" jsonschema:"example=k3s,example=eks"` } // ZarfFile defines a file to deploy. type ZarfFile struct { - // Local folder or file path or remote URL to pull into the package + // Local folder or file path or remote URL to pull into the package. Source string `json:"source"` - // (files only) Optional SHA256 checksum of the file + // (files only) Optional SHA256 checksum of the file. Shasum string `json:"shasum,omitempty"` - // The absolute or relative path where the file or folder should be copied to during package deploy + // The absolute or relative path where the file or folder should be copied to during package deploy. Target string `json:"target"` - // (files only) Determines if the file should be made executable during package deploy + // (files only) Determines if the file should be made executable during package deploy. Executable bool `json:"executable,omitempty"` - // List of symlinks to create during package deploy + // List of symlinks to create during package deploy. Symlinks []string `json:"symlinks,omitempty"` - // Local folder or file to be extracted from a 'source' archive + // Local folder or file to be extracted from a 'source' archive. ExtractPath string `json:"extractPath,omitempty"` } // ZarfChart defines a helm chart to be deployed. type ZarfChart struct { - // 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 + // 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. Name string `json:"name"` - // 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') + // 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"` - // The URL of the OCI registry, chart repository, or git repo where the helm chart is stored + // The URL of the OCI registry, chart repository, or git repo where the helm chart is stored. 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)"` - // The name of a chart within a Helm repository (defaults to the Zarf name of the chart) + // The name of a chart within a Helm repository (defaults to the Zarf name of the chart). RepoName string `json:"repoName,omitempty"` - // (git repo only) The sub directory to the chart within a git repo + // (git repo only) The sub directory to the chart within a git repo. GitPath string `json:"gitPath,omitempty" jsonschema:"example=charts/your-chart"` - // The path to a local chart's folder or .tgz archive + // The path to a local chart's folder or .tgz archive. LocalPath string `json:"localPath,omitempty"` - // The namespace to deploy the chart to + // The namespace to deploy the chart to. Namespace string `json:"namespace,omitempty"` - // The name of the Helm release to create (defaults to the Zarf name of the chart) + // The name of the Helm release to create (defaults to the Zarf name of the chart). ReleaseName string `json:"releaseName,omitempty"` - // Whether to not wait for chart resources to be ready before continuing + // Whether to not wait for chart resources to be ready before continuing. NoWait bool `json:"noWait,omitempty"` - // List of local values file paths or remote URLs to include in the package; these will be merged together when deployed + // List of local values file paths or remote URLs to include in the package; these will be merged together when deployed. ValuesFiles []string `json:"valuesFiles,omitempty"` - // [alpha] List of variables to set in the Helm chart + // [alpha] List of variables to set in the Helm chart. Variables []ZarfChartVariable `json:"variables,omitempty"` } // ZarfChartVariable represents a variable that can be set for a Helm chart overrides. type ZarfChartVariable struct { - // The name of the variable + // The name of the variable. Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"` - // A brief description of what the variable controls + // A brief description of what the variable controls. Description string `json:"description"` - // The path within the Helm chart values where this variable applies + // The path within the Helm chart values where this variable applies. Path string `json:"path"` } // 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 + // A name to give this collection of manifests; this will become the name of the dynamically-created helm chart. Name string `json:"name"` - // The namespace to deploy the manifests to + // The namespace to deploy the manifests to. Namespace string `json:"namespace,omitempty"` - // List of local K8s YAML files or remote URLs to deploy (in order) + // List of local K8s YAML files or remote URLs to deploy (in order). Files []string `json:"files,omitempty"` - // Allow traversing directory above the current directory if needed for kustomization + // Allow traversing directory above the current directory if needed for kustomization. KustomizeAllowAnyDirectory bool `json:"kustomizeAllowAnyDirectory,omitempty"` - // List of local kustomization paths or remote URLs to include in the package + // List of local kustomization paths or remote URLs to include in the package. Kustomizations []string `json:"kustomizations,omitempty"` - // Whether to not wait for manifest resources to be ready before continuing + // Whether to not wait for manifest resources to be ready before continuing. NoWait bool `json:"noWait,omitempty"` } -// DeprecatedZarfComponentScripts are scripts that run before or after a component is deployed +// DeprecatedZarfComponentScripts are scripts that run before or after a component is deployed. type DeprecatedZarfComponentScripts struct { - // Show the output of the script during package deployment + // Show the output of the script during package deployment. ShowOutput bool `json:"showOutput,omitempty"` - // Timeout in seconds for the script + // Timeout in seconds for the script. TimeoutSeconds int `json:"timeoutSeconds,omitempty"` - // Retry the script if it fails + // Retry the script if it fails. Retry bool `json:"retry,omitempty"` - // Scripts to run before the component is added during package create + // Scripts to run before the component is added during package create. Prepare []string `json:"prepare,omitempty"` - // Scripts to run before the component is deployed + // Scripts to run before the component is deployed. Before []string `json:"before,omitempty"` - // Scripts to run after the component successfully deploys + // Scripts to run after the component successfully deploys. After []string `json:"after,omitempty"` } -// ZarfComponentActions are ActionSets that map to different zarf package operations +// ZarfComponentActions are ActionSets that map to different zarf package operations. type ZarfComponentActions struct { - // Actions to run during package creation + // Actions to run during package creation. OnCreate ZarfComponentActionSet `json:"onCreate,omitempty"` - // Actions to run during package deployment + // Actions to run during package deployment. OnDeploy ZarfComponentActionSet `json:"onDeploy,omitempty"` - // Actions to run during package removal + // Actions to run during package removal. OnRemove ZarfComponentActionSet `json:"onRemove,omitempty"` } -// ZarfComponentActionSet is a set of actions to run during a zarf package operation +// ZarfComponentActionSet is a set of actions to run during a zarf package operation. type ZarfComponentActionSet struct { - // Default configuration for all actions in this set + // Default configuration for all actions in this set. Defaults ZarfComponentActionDefaults `json:"defaults,omitempty"` - // Actions to run at the start of an operation + // Actions to run at the start of an operation. Before []ZarfComponentAction `json:"before,omitempty"` - // Actions to run at the end of an operation + // Actions to run at the end of an operation. After []ZarfComponentAction `json:"after,omitempty"` - // Actions to run if all operations succeed + // Actions to run if all operations succeed. OnSuccess []ZarfComponentAction `json:"onSuccess,omitempty"` - // Actions to run if all operations fail + // Actions to run if all operations fail. OnFailure []ZarfComponentAction `json:"onFailure,omitempty"` } -// ZarfComponentActionDefaults sets the default configs for child actions +// ZarfComponentActionDefaults sets the default configs for child actions. type ZarfComponentActionDefaults struct { - // Hide the output of commands during execution (default false) + // Hide the output of commands during execution (default false). Mute bool `json:"mute,omitempty"` - // Default timeout in seconds for commands (default to 0, no timeout) + // Default timeout in seconds for commands (default to 0, no timeout). MaxTotalSeconds int `json:"maxTotalSeconds,omitempty"` - // Retry commands given number of times if they fail (default 0) + // Retry commands given number of times if they fail (default 0). MaxRetries int `json:"maxRetries,omitempty"` - // Working directory for commands (default CWD) + // Working directory for commands (default CWD). Dir string `json:"dir,omitempty"` - // Additional environment variables for commands + // Additional environment variables for commands. Env []string `json:"env,omitempty"` - // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems + // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems. Shell exec.Shell `json:"shell,omitempty"` } -// ZarfComponentAction represents a single action to run during a zarf package operation +// ZarfComponentAction represents a single action to run during a zarf package operation. type ZarfComponentAction struct { - // Hide the output of the command during package deployment (default false) + // Hide the output of the command during package deployment (default false). Mute *bool `json:"mute,omitempty"` - // Timeout in seconds for the command (default to 0, no timeout for cmd actions and 300, 5 minutes for wait actions) + // Timeout in seconds for the command (default to 0, no timeout for cmd actions and 300, 5 minutes for wait actions). MaxTotalSeconds *int `json:"maxTotalSeconds,omitempty"` - // Retry the command if it fails up to given number of times (default 0) + // Retry the command if it fails up to given number of times (default 0). MaxRetries *int `json:"maxRetries,omitempty"` - // The working directory to run the command in (default is CWD) + // The working directory to run the command in (default is CWD). Dir *string `json:"dir,omitempty"` - // Additional environment variables to set for the command + // Additional environment variables to set for the command. Env []string `json:"env,omitempty"` // The command to run. Must specify either cmd or wait for the action to do anything. Cmd string `json:"cmd,omitempty"` - // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems + // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems. Shell *exec.Shell `json:"shell,omitempty"` - // [Deprecated] (replaced by setVariables) (onDeploy/cmd only) The name of a variable to update with the output of the command. This variable will be available to all remaining actions and components in the package. This will be removed in Zarf v1.0.0 + // [Deprecated] (replaced by setVariables) (onDeploy/cmd only) The name of a variable to update with the output of the command. This variable will be available to all remaining actions and components in the package. This will be removed in Zarf v1.0.0. DeprecatedSetVariable string `json:"setVariable,omitempty" jsonschema:"pattern=^[A-Z0-9_]+$"` // (onDeploy/cmd only) An array of variables to update with the output of the command. These variables will be available to all remaining actions and components in the package. SetVariables []variables.Variable `json:"setVariables,omitempty"` - // Description of the action to be displayed during package execution instead of the command + // Description of the action to be displayed during package execution instead of the command. Description string `json:"description,omitempty"` // Wait for a condition to be met before continuing. Must specify either cmd or wait for the action. See the 'zarf tools wait-for' command for more info. Wait *ZarfComponentActionWait `json:"wait,omitempty"` @@ -267,43 +267,43 @@ type ZarfComponentActionWait struct { // ZarfComponentActionWaitCluster specifies a condition to wait for before continuing type ZarfComponentActionWaitCluster struct { - // The kind of resource to wait for + // The kind of resource to wait for. Kind string `json:"kind" jsonschema:"example=Pod,example=Deployment"` - // The name of the resource or selector to wait for + // The name of the resource or selector to wait for. Name string `json:"name" jsonschema:"example=podinfo,example=app=podinfo"` - // The namespace of the resource to wait for + // The namespace of the resource to wait for. Namespace string `json:"namespace,omitempty"` - // The condition or jsonpath state to wait for; defaults to exist, a special condition that will wait for the resource to exist + // The condition or jsonpath state to wait for; defaults to exist, a special condition that will wait for the resource to exist. Condition string `json:"condition,omitempty" jsonschema:"example=Ready,example=Available,'{.status.availableReplicas}'=23"` } // ZarfComponentActionWaitNetwork specifies a condition to wait for before continuing type ZarfComponentActionWaitNetwork struct { - // The protocol to wait for + // The protocol to wait for. Protocol string `json:"protocol" jsonschema:"enum=tcp,enum=http,enum=https"` - // The address to wait for + // The address to wait for. Address string `json:"address" jsonschema:"example=localhost:8080,example=1.1.1.1"` - // The HTTP status code to wait for if using http or https + // The HTTP status code to wait for if using http or https. Code int `json:"code,omitempty" jsonschema:"example=200,example=404"` } // ZarfContainerTarget defines the destination info for a ZarfData target type ZarfContainerTarget struct { - // The namespace to target for data injection + // The namespace to target for data injection. Namespace string `json:"namespace"` - // The K8s selector to target for data injection + // The K8s selector to target for data injection. Selector string `json:"selector" jsonschema:"example=app=data-injection"` - // The container name to target for data injection + // The container name to target for data injection. Container string `json:"container"` - // The path within the container to copy the data into + // The path within the container to copy the data into. Path string `json:"path"` } // ZarfDataInjection is a data-injection definition. type ZarfDataInjection struct { - // Either a path to a local folder/file or a remote URL of a file to inject into the given target pod + container + // Either a path to a local folder/file or a remote URL of a file to inject into the given target pod + container. Source string `json:"source"` - // The target pod + container to inject the data into + // The target pod + container to inject the data into. Target ZarfContainerTarget `json:"target"` // Compress the data before transmitting using gzip. Note: this requires support for tar/gzip locally and in the target image. Compress bool `json:"compress,omitempty"` @@ -311,11 +311,11 @@ type ZarfDataInjection struct { // ZarfComponentImport structure for including imported Zarf components. type ZarfComponentImport struct { - // The name of the component to import from the referenced zarf.yaml + // The name of the component to import from the referenced zarf.yaml. Name string `json:"name,omitempty"` - // The path to the directory containing the zarf.yaml to import + // The path to the directory containing the zarf.yaml to import. Path string `json:"path,omitempty"` - // [beta] The URL to a Zarf package to import via OCI + // [beta] The URL to a Zarf package to import via OCI. URL string `json:"url,omitempty" jsonschema:"pattern=^oci://.*$"` } diff --git a/src/types/extensions/bigbang.go b/src/types/extensions/bigbang.go index 67a8a71446..af357d5990 100644 --- a/src/types/extensions/bigbang.go +++ b/src/types/extensions/bigbang.go @@ -4,16 +4,16 @@ // Package extensions contains the types for all official extensions. package extensions -// BigBang holds the configuration for the Big Bang extension +// BigBang holds the configuration for the Big Bang extension. type BigBang struct { - // The version of Big Bang to use + // The version of Big Bang to use. Version string `json:"version"` - // Override repo to pull Big Bang from instead of Repo One + // Override repo to pull Big Bang from instead of Repo One. Repo string `json:"repo,omitempty"` - // The list of values files to pass to Big Bang; these will be merged together + // The list of values files to pass to Big Bang; these will be merged together. ValuesFiles []string `json:"valuesFiles,omitempty"` - // Whether to skip deploying flux; Defaults to false + // Whether to skip deploying flux; Defaults to false. SkipFlux bool `json:"skipFlux,omitempty"` - // Optional paths to Flux kustomize strategic merge patch files + // Optional paths to Flux kustomize strategic merge patch files. FluxPatchFiles []string `json:"fluxPatchFiles,omitempty"` } diff --git a/src/types/extensions/common.go b/src/types/extensions/common.go index e84091e339..1df82730ab 100644 --- a/src/types/extensions/common.go +++ b/src/types/extensions/common.go @@ -4,8 +4,8 @@ // Package extensions contains the types for all official extensions. package extensions -// ZarfComponentExtensions is a struct that contains all the official extensions +// ZarfComponentExtensions is a struct that contains all the official extensions. type ZarfComponentExtensions struct { - // Big Bang Configurations - BigBang *BigBang `json:"bigbang,omitempty" jsonschema:"description=Configurations for installing Big Bang and Flux in the cluster"` + // Configurations for installing Big Bang and Flux in the cluster. + BigBang *BigBang `json:"bigbang,omitempty"` } diff --git a/src/types/k8s.go b/src/types/k8s.go index 2dbc92b0c2..6804de17ee 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -89,6 +89,17 @@ type DeployedPackage struct { ConnectStrings ConnectStrings `json:"connectStrings,omitempty"` } +// ConnectString contains information about a connection made with Zarf connect. +type ConnectString struct { + // Descriptive text that explains what the resource you would be connecting to is used for + Description string `json:"description"` + // URL path that gets appended to the k8s port-forward result + URL string `json:"url"` +} + +// ConnectStrings is a map of connect names to connection information. +type ConnectStrings map[string]ConnectString + // DeployedComponent contains information about a Zarf Package Component that has been deployed to a cluster. type DeployedComponent struct { Name string `json:"name"` diff --git a/src/types/package.go b/src/types/package.go index 27b708c7b8..bb4b0edc0a 100644 --- a/src/types/package.go +++ b/src/types/package.go @@ -18,17 +18,17 @@ const ( // ZarfPackage the top-level structure of a Zarf config file. type ZarfPackage struct { - // The kind of Zarf package + // The kind of Zarf package. Kind ZarfPackageKind `json:"kind" jsonschema:"enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` - // Package metadata + // Package metadata. Metadata ZarfMetadata `json:"metadata,omitempty"` - // Zarf-generated package build data + // Zarf-generated package build data. Build ZarfBuildData `json:"build,omitempty"` - // List of components to deploy in this package + // List of components to deploy in this package. Components []ZarfComponent `json:"components" jsonschema:"minItems=1"` - // Constant template values applied on deploy for K8s resources + // Constant template values applied on deploy for K8s resources. Constants []variables.Constant `json:"constants,omitempty"` - // Variable template values applied on deploy for K8s resources + // Variable template values applied on deploy for K8s resources. Variables []variables.InteractiveVariable `json:"variables,omitempty"` } @@ -49,58 +49,58 @@ func (pkg ZarfPackage) IsSBOMAble() bool { // ZarfMetadata lists information about the current ZarfPackage. type ZarfMetadata struct { - // Name to identify this Zarf package + // Name to identify this Zarf package. Name string `json:"name" jsonschema:"pattern=^[a-z0-9][a-z0-9\\-]*$"` - // Additional information about this package + // Additional information about this package. Description string `json:"description,omitempty"` - // Generic string set by a package author to track the package version (Note: ZarfInitConfigs will always be versioned to the CLIVersion they were created with) + // Generic string set by a package author to track the package version (Note: ZarfInitConfigs will always be versioned to the CLIVersion they were created with). Version string `json:"version,omitempty"` - // Link to package information when online + // Link to package information when online. URL string `json:"url,omitempty"` - // An image URL to embed in this package (Reserved for future use in Zarf UI) + // An image URL to embed in this package (Reserved for future use in Zarf UI). Image string `json:"image,omitempty"` - // Disable compression of this package + // Disable compression of this package. Uncompressed bool `json:"uncompressed,omitempty"` - // The target cluster architecture for this package + // The target cluster architecture for this package. Architecture string `json:"architecture,omitempty" jsonschema:"example=arm64,example=amd64"` // Yaml OnLy Online (YOLO): True enables deploying a Zarf package without first running zarf init against the cluster. This is ideal for connected environments where you want to use existing VCS and container registries. YOLO bool `json:"yolo,omitempty"` - // Comma-separated list of package authors (including contact info) + // Comma-separated list of package authors (including contact info). Authors string `json:"authors,omitempty" jsonschema:"example=Doug <hello@defenseunicorns.com>, Pepr <hello@defenseunicorns.com>"` - // Link to package documentation when online + // Link to package documentation when online. Documentation string `json:"documentation,omitempty"` - // Link to package source code when online + // Link to package source code when online. Source string `json:"source,omitempty"` - // Name of the distributing entity, organization or individual + // Name of the distributing entity, organization or individual. Vendor string `json:"vendor,omitempty"` - // Checksum of a checksums.txt file that contains checksums all the layers within the package + // Checksum of a checksums.txt file that contains checksums all the layers within the package. AggregateChecksum string `json:"aggregateChecksum,omitempty"` } // ZarfBuildData is written during the packager.Create() operation to track details of the created package. type ZarfBuildData struct { - // The machine name that created this package + // The machine name that created this package. Terminal string `json:"terminal"` - // The username who created this package + // The username who created this package. User string `json:"user"` - // The architecture this package was created on + // The architecture this package was created on. Architecture string `json:"architecture"` - // The timestamp when this package was created + // The timestamp when this package was created. Timestamp string `json:"timestamp"` - // The version of Zarf used to build this package + // The version of Zarf used to build this package. Version string `json:"version"` - // Any migrations that have been run on this package + // Any migrations that have been run on this package. Migrations []string `json:"migrations,omitempty"` - // Any registry domains that were overridden on package create when pulling images + // Any registry domains that were overridden on package create when pulling images. RegistryOverrides map[string]string `json:"registryOverrides,omitempty"` - // Whether this package was created with differential components + // Whether this package was created with differential components. Differential bool `json:"differential,omitempty"` - // Version of a previously built package used as the basis for creating this differential package + // Version of a previously built package used as the basis for creating this differential package. DifferentialPackageVersion string `json:"differentialPackageVersion,omitempty"` - // List of components that were not included in this package due to differential packaging + // List of components that were not included in this package due to differential packaging. DifferentialMissing []string `json:"differentialMissing,omitempty"` - // The minimum version of Zarf that does not have breaking package structure changes + // The minimum version of Zarf that does not have breaking package structure changes. LastNonBreakingVersion string `json:"lastNonBreakingVersion,omitempty"` - // The flavor of Zarf used to build this package + // The flavor of Zarf used to build this package. Flavor string `json:"flavor,omitempty"` } diff --git a/src/types/runtime.go b/src/types/runtime.go index 5a4cf728c1..0298d80346 100644 --- a/src/types/runtime.go +++ b/src/types/runtime.go @@ -176,17 +176,6 @@ type ZarfSplitPackageData struct { Count int } -// ConnectString contains information about a connection made with Zarf connect. -type ConnectString struct { - // Descriptive text that explains what the resource you would be connecting to is used for - Description string `json:"description"` - // URL path that gets appended to the k8s port-forward result - URL string `json:"url"` -} - -// ConnectStrings is a map of connect names to connection information. -type ConnectStrings map[string]ConnectString - // DifferentialData contains image and repository information about the package a Differential Package is Based on. type DifferentialData struct { DifferentialImages map[string]bool diff --git a/zarf.schema.json b/zarf.schema.json index af0138282d..f4a0690553 100644 --- a/zarf.schema.json +++ b/zarf.schema.json @@ -6,29 +6,29 @@ "properties": { "version": { "type": "string", - "description": "The version of Big Bang to use" + "description": "The version of Big Bang to use." }, "repo": { "type": "string", - "description": "Override repo to pull Big Bang from instead of Repo One" + "description": "Override repo to pull Big Bang from instead of Repo One." }, "valuesFiles": { "items": { "type": "string" }, "type": "array", - "description": "The list of values files to pass to Big Bang; these will be merged together" + "description": "The list of values files to pass to Big Bang; these will be merged together." }, "skipFlux": { "type": "boolean", - "description": "Whether to skip deploying flux; Defaults to false" + "description": "Whether to skip deploying flux; Defaults to false." }, "fluxPatchFiles": { "items": { "type": "string" }, "type": "array", - "description": "Optional paths to Flux kustomize strategic merge patch files" + "description": "Optional paths to Flux kustomize strategic merge patch files." } }, "additionalProperties": false, @@ -36,7 +36,7 @@ "required": [ "version" ], - "description": "BigBang holds the configuration for the Big Bang extension", + "description": "BigBang holds the configuration for the Big Bang extension.", "patternProperties": { "^x-": {} } @@ -80,41 +80,41 @@ "properties": { "showOutput": { "type": "boolean", - "description": "Show the output of the script during package deployment" + "description": "Show the output of the script during package deployment." }, "timeoutSeconds": { "type": "integer", - "description": "Timeout in seconds for the script" + "description": "Timeout in seconds for the script." }, "retry": { "type": "boolean", - "description": "Retry the script if it fails" + "description": "Retry the script if it fails." }, "prepare": { "items": { "type": "string" }, "type": "array", - "description": "Scripts to run before the component is added during package create" + "description": "Scripts to run before the component is added during package create." }, "before": { "items": { "type": "string" }, "type": "array", - "description": "Scripts to run before the component is deployed" + "description": "Scripts to run before the component is deployed." }, "after": { "items": { "type": "string" }, "type": "array", - "description": "Scripts to run after the component successfully deploys" + "description": "Scripts to run after the component successfully deploys." } }, "additionalProperties": false, "type": "object", - "description": "DeprecatedZarfComponentScripts are scripts that run before or after a component is deployed", + "description": "DeprecatedZarfComponentScripts are scripts that run before or after a component is deployed.", "patternProperties": { "^x-": {} } @@ -254,60 +254,60 @@ "properties": { "terminal": { "type": "string", - "description": "The machine name that created this package" + "description": "The machine name that created this package." }, "user": { "type": "string", - "description": "The username who created this package" + "description": "The username who created this package." }, "architecture": { "type": "string", - "description": "The architecture this package was created on" + "description": "The architecture this package was created on." }, "timestamp": { "type": "string", - "description": "The timestamp when this package was created" + "description": "The timestamp when this package was created." }, "version": { "type": "string", - "description": "The version of Zarf used to build this package" + "description": "The version of Zarf used to build this package." }, "migrations": { "items": { "type": "string" }, "type": "array", - "description": "Any migrations that have been run on this package" + "description": "Any migrations that have been run on this package." }, "registryOverrides": { "additionalProperties": { "type": "string" }, "type": "object", - "description": "Any registry domains that were overridden on package create when pulling images" + "description": "Any registry domains that were overridden on package create when pulling images." }, "differential": { "type": "boolean", - "description": "Whether this package was created with differential components" + "description": "Whether this package was created with differential components." }, "differentialPackageVersion": { "type": "string", - "description": "Version of a previously built package used as the basis for creating this differential package" + "description": "Version of a previously built package used as the basis for creating this differential package." }, "differentialMissing": { "items": { "type": "string" }, "type": "array", - "description": "List of components that were not included in this package due to differential packaging" + "description": "List of components that were not included in this package due to differential packaging." }, "lastNonBreakingVersion": { "type": "string", - "description": "The minimum version of Zarf that does not have breaking package structure changes" + "description": "The minimum version of Zarf that does not have breaking package structure changes." }, "flavor": { "type": "string", - "description": "The flavor of Zarf used to build this package" + "description": "The flavor of Zarf used to build this package." } }, "additionalProperties": false, @@ -328,15 +328,15 @@ "properties": { "name": { "type": "string", - "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" + "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": { "type": "string", - "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')" + "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": { "type": "string", - "description": "The URL of the OCI registry, chart repository, or git repo where the helm chart is stored", + "description": "The URL of the OCI registry, chart repository, or git repo where the helm chart is stored.", "examples": [ "OCI registry: oci://ghcr.io/stefanprodan/charts/podinfo", "helm chart repo: https://stefanprodan.github.io/podinfo", @@ -345,44 +345,44 @@ }, "repoName": { "type": "string", - "description": "The name of a chart within a Helm repository (defaults to the Zarf name of the chart)" + "description": "The name of a chart within a Helm repository (defaults to the Zarf name of the chart)." }, "gitPath": { "type": "string", - "description": "(git repo only) The sub directory to the chart within a git repo", + "description": "(git repo only) The sub directory to the chart within a git repo.", "examples": [ "charts/your-chart" ] }, "localPath": { "type": "string", - "description": "The path to a local chart's folder or .tgz archive" + "description": "The path to a local chart's folder or .tgz archive." }, "namespace": { "type": "string", - "description": "The namespace to deploy the chart to" + "description": "The namespace to deploy the chart to." }, "releaseName": { "type": "string", - "description": "The name of the Helm release to create (defaults to the Zarf name of the chart)" + "description": "The name of the Helm release to create (defaults to the Zarf name of the chart)." }, "noWait": { "type": "boolean", - "description": "Whether to not wait for chart resources to be ready before continuing" + "description": "Whether to not wait for chart resources to be ready before continuing." }, "valuesFiles": { "items": { "type": "string" }, "type": "array", - "description": "List of local values file paths or remote URLs to include in the package; these will be merged together when deployed" + "description": "List of local values file paths or remote URLs to include in the package; these will be merged together when deployed." }, "variables": { "items": { "$ref": "#/$defs/ZarfChartVariable" }, "type": "array", - "description": "[alpha] List of variables to set in the Helm chart" + "description": "[alpha] List of variables to set in the Helm chart." } }, "additionalProperties": false, @@ -400,15 +400,15 @@ "name": { "type": "string", "pattern": "^[A-Z0-9_]+$", - "description": "The name of the variable" + "description": "The name of the variable." }, "description": { "type": "string", - "description": "A brief description of what the variable controls" + "description": "A brief description of what the variable controls." }, "path": { "type": "string", - "description": "The path within the Helm chart values where this variable applies" + "description": "The path within the Helm chart values where this variable applies." } }, "additionalProperties": false, @@ -428,23 +428,23 @@ "name": { "type": "string", "pattern": "^[a-z0-9][a-z0-9\\-]*$", - "description": "The name of the component" + "description": "The name of the component." }, "description": { "type": "string", - "description": "Message to include during package deploy describing the purpose of this component" + "description": "Message to include during package deploy describing the purpose of this component." }, "default": { "type": "boolean", - "description": "Determines the default Y/N state for installing this component on package deploy" + "description": "Determines the default Y/N state for installing this component on package deploy." }, "required": { "type": "boolean", - "description": "Do not prompt user to install this component" + "description": "Do not prompt user to install this component." }, "only": { "$ref": "#/$defs/ZarfComponentOnlyTarget", - "description": "Filter when this component is included in package creation or deployment" + "description": "Filter when this component is included in package creation or deployment." }, "group": { "type": "string", @@ -456,53 +456,53 @@ }, "import": { "$ref": "#/$defs/ZarfComponentImport", - "description": "Import a component from another Zarf package" + "description": "Import a component from another Zarf package." }, "manifests": { "items": { "$ref": "#/$defs/ZarfManifest" }, "type": "array", - "description": "Kubernetes manifests to be included in a generated Helm chart on package deploy" + "description": "Kubernetes manifests to be included in a generated Helm chart on package deploy." }, "charts": { "items": { "$ref": "#/$defs/ZarfChart" }, "type": "array", - "description": "Helm charts to install during package deploy" + "description": "Helm charts to install during package deploy." }, "dataInjections": { "items": { "$ref": "#/$defs/ZarfDataInjection" }, "type": "array", - "description": "Datasets to inject into a container in the target cluster" + "description": "Datasets to inject into a container in the target cluster." }, "files": { "items": { "$ref": "#/$defs/ZarfFile" }, "type": "array", - "description": "Files or folders to place on disk during package deployment" + "description": "Files or folders to place on disk during package deployment." }, "images": { "items": { "type": "string" }, "type": "array", - "description": "List of OCI images to include in the package" + "description": "List of OCI images to include in the package." }, "repos": { "items": { "type": "string" }, "type": "array", - "description": "List of git repos to include in the package" + "description": "List of git repos to include in the package." }, "extensions": { "$ref": "#/$defs/ZarfComponentExtensions", - "description": "Extend component functionality with additional features" + "description": "Extend component functionality with additional features." }, "scripts": { "$ref": "#/$defs/DeprecatedZarfComponentScripts", @@ -510,7 +510,7 @@ }, "actions": { "$ref": "#/$defs/ZarfComponentActions", - "description": "Custom commands to run at various stages of a package lifecycle" + "description": "Custom commands to run at various stages of a package lifecycle." } }, "additionalProperties": false, @@ -527,26 +527,26 @@ "properties": { "mute": { "type": "boolean", - "description": "Hide the output of the command during package deployment (default false)" + "description": "Hide the output of the command during package deployment (default false)." }, "maxTotalSeconds": { "type": "integer", - "description": "Timeout in seconds for the command (default to 0, no timeout for cmd actions and 300, 5 minutes for wait actions)" + "description": "Timeout in seconds for the command (default to 0, no timeout for cmd actions and 300, 5 minutes for wait actions)." }, "maxRetries": { "type": "integer", - "description": "Retry the command if it fails up to given number of times (default 0)" + "description": "Retry the command if it fails up to given number of times (default 0)." }, "dir": { "type": "string", - "description": "The working directory to run the command in (default is CWD)" + "description": "The working directory to run the command in (default is CWD)." }, "env": { "items": { "type": "string" }, "type": "array", - "description": "Additional environment variables to set for the command" + "description": "Additional environment variables to set for the command." }, "cmd": { "type": "string", @@ -554,12 +554,12 @@ }, "shell": { "$ref": "#/$defs/Shell", - "description": "(cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems" + "description": "(cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems." }, "setVariable": { "type": "string", "pattern": "^[A-Z0-9_]+$", - "description": "[Deprecated] (replaced by setVariables) (onDeploy/cmd only) The name of a variable to update with the output of the command. This variable will be available to all remaining actions and components in the package. This will be removed in Zarf v1.0.0" + "description": "[Deprecated] (replaced by setVariables) (onDeploy/cmd only) The name of a variable to update with the output of the command. This variable will be available to all remaining actions and components in the package. This will be removed in Zarf v1.0.0." }, "setVariables": { "items": { @@ -570,7 +570,7 @@ }, "description": { "type": "string", - "description": "Description of the action to be displayed during package execution instead of the command" + "description": "Description of the action to be displayed during package execution instead of the command." }, "wait": { "$ref": "#/$defs/ZarfComponentActionWait", @@ -579,7 +579,7 @@ }, "additionalProperties": false, "type": "object", - "description": "ZarfComponentAction represents a single action to run during a zarf package operation", + "description": "ZarfComponentAction represents a single action to run during a zarf package operation.", "patternProperties": { "^x-": {} } @@ -588,35 +588,35 @@ "properties": { "mute": { "type": "boolean", - "description": "Hide the output of commands during execution (default false)" + "description": "Hide the output of commands during execution (default false)." }, "maxTotalSeconds": { "type": "integer", - "description": "Default timeout in seconds for commands (default to 0, no timeout)" + "description": "Default timeout in seconds for commands (default to 0, no timeout)." }, "maxRetries": { "type": "integer", - "description": "Retry commands given number of times if they fail (default 0)" + "description": "Retry commands given number of times if they fail (default 0)." }, "dir": { "type": "string", - "description": "Working directory for commands (default CWD)" + "description": "Working directory for commands (default CWD)." }, "env": { "items": { "type": "string" }, "type": "array", - "description": "Additional environment variables for commands" + "description": "Additional environment variables for commands." }, "shell": { "$ref": "#/$defs/Shell", - "description": "(cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems" + "description": "(cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems." } }, "additionalProperties": false, "type": "object", - "description": "ZarfComponentActionDefaults sets the default configs for child actions", + "description": "ZarfComponentActionDefaults sets the default configs for child actions.", "patternProperties": { "^x-": {} } @@ -625,40 +625,40 @@ "properties": { "defaults": { "$ref": "#/$defs/ZarfComponentActionDefaults", - "description": "Default configuration for all actions in this set" + "description": "Default configuration for all actions in this set." }, "before": { "items": { "$ref": "#/$defs/ZarfComponentAction" }, "type": "array", - "description": "Actions to run at the start of an operation" + "description": "Actions to run at the start of an operation." }, "after": { "items": { "$ref": "#/$defs/ZarfComponentAction" }, "type": "array", - "description": "Actions to run at the end of an operation" + "description": "Actions to run at the end of an operation." }, "onSuccess": { "items": { "$ref": "#/$defs/ZarfComponentAction" }, "type": "array", - "description": "Actions to run if all operations succeed" + "description": "Actions to run if all operations succeed." }, "onFailure": { "items": { "$ref": "#/$defs/ZarfComponentAction" }, "type": "array", - "description": "Actions to run if all operations fail" + "description": "Actions to run if all operations fail." } }, "additionalProperties": false, "type": "object", - "description": "ZarfComponentActionSet is a set of actions to run during a zarf package operation", + "description": "ZarfComponentActionSet is a set of actions to run during a zarf package operation.", "patternProperties": { "^x-": {} } @@ -685,7 +685,7 @@ "properties": { "kind": { "type": "string", - "description": "The kind of resource to wait for", + "description": "The kind of resource to wait for.", "examples": [ "Pod", "Deployment" @@ -693,7 +693,7 @@ }, "name": { "type": "string", - "description": "The name of the resource or selector to wait for", + "description": "The name of the resource or selector to wait for.", "examples": [ "podinfo", "app=podinfo" @@ -701,11 +701,11 @@ }, "namespace": { "type": "string", - "description": "The namespace of the resource to wait for" + "description": "The namespace of the resource to wait for." }, "condition": { "type": "string", - "description": "The condition or jsonpath state to wait for; defaults to exist, a special condition that will wait for the resource to exist", + "description": "The condition or jsonpath state to wait for; defaults to exist, a special condition that will wait for the resource to exist.", "examples": [ "Ready", "Available" @@ -732,11 +732,11 @@ "http", "https" ], - "description": "The protocol to wait for" + "description": "The protocol to wait for." }, "address": { "type": "string", - "description": "The address to wait for", + "description": "The address to wait for.", "examples": [ "localhost:8080", "1.1.1.1" @@ -744,7 +744,7 @@ }, "code": { "type": "integer", - "description": "The HTTP status code to wait for if using http or https", + "description": "The HTTP status code to wait for if using http or https.", "examples": [ 200, 404 @@ -766,20 +766,20 @@ "properties": { "onCreate": { "$ref": "#/$defs/ZarfComponentActionSet", - "description": "Actions to run during package creation" + "description": "Actions to run during package creation." }, "onDeploy": { "$ref": "#/$defs/ZarfComponentActionSet", - "description": "Actions to run during package deployment" + "description": "Actions to run during package deployment." }, "onRemove": { "$ref": "#/$defs/ZarfComponentActionSet", - "description": "Actions to run during package removal" + "description": "Actions to run during package removal." } }, "additionalProperties": false, "type": "object", - "description": "ZarfComponentActions are ActionSets that map to different zarf package operations", + "description": "ZarfComponentActions are ActionSets that map to different zarf package operations.", "patternProperties": { "^x-": {} } @@ -788,12 +788,12 @@ "properties": { "bigbang": { "$ref": "#/$defs/BigBang", - "description": "Configurations for installing Big Bang and Flux in the cluster" + "description": "Configurations for installing Big Bang and Flux in the cluster." } }, "additionalProperties": false, "type": "object", - "description": "ZarfComponentExtensions is a struct that contains all the official extensions", + "description": "ZarfComponentExtensions is a struct that contains all the official extensions.", "patternProperties": { "^x-": {} } @@ -802,14 +802,14 @@ "properties": { "name": { "type": "string", - "description": "The name of the component to import from the referenced zarf.yaml" + "description": "The name of the component to import from the referenced zarf.yaml." }, "path": { "not": { "pattern": "###ZARF_PKG_TMPL_" }, "type": "string", - "description": "The path to the directory containing the zarf.yaml to import" + "description": "The path to the directory containing the zarf.yaml to import." }, "url": { "not": { @@ -817,7 +817,7 @@ }, "type": "string", "pattern": "^oci://.*$", - "description": "[beta] The URL to a Zarf package to import via OCI" + "description": "[beta] The URL to a Zarf package to import via OCI." } }, "additionalProperties": false, @@ -835,7 +835,7 @@ "amd64", "arm64" ], - "description": "Only create and deploy to clusters of the given architecture" + "description": "Only create and deploy to clusters of the given architecture." }, "distros": { "items": { @@ -846,7 +846,7 @@ ] }, "type": "array", - "description": "A list of kubernetes distros this package works with (Reserved for future use)" + "description": "A list of kubernetes distros this package works with (Reserved for future use)." } }, "additionalProperties": false, @@ -865,15 +865,15 @@ "darwin", "windows" ], - "description": "Only deploy component to specified OS" + "description": "Only deploy component to specified OS." }, "cluster": { "$ref": "#/$defs/ZarfComponentOnlyCluster", - "description": "Only deploy component to specified clusters" + "description": "Only deploy component to specified clusters." }, "flavor": { "type": "string", - "description": "Only include this component when a matching '--flavor' is specified on 'zarf package create'" + "description": "Only include this component when a matching '--flavor' is specified on 'zarf package create'." } }, "additionalProperties": false, @@ -887,22 +887,22 @@ "properties": { "namespace": { "type": "string", - "description": "The namespace to target for data injection" + "description": "The namespace to target for data injection." }, "selector": { "type": "string", - "description": "The K8s selector to target for data injection", + "description": "The K8s selector to target for data injection.", "examples": [ "app=data-injection" ] }, "container": { "type": "string", - "description": "The container name to target for data injection" + "description": "The container name to target for data injection." }, "path": { "type": "string", - "description": "The path within the container to copy the data into" + "description": "The path within the container to copy the data into." } }, "additionalProperties": false, @@ -922,11 +922,11 @@ "properties": { "source": { "type": "string", - "description": "Either a path to a local folder/file or a remote URL of a file to inject into the given target pod + container" + "description": "Either a path to a local folder/file or a remote URL of a file to inject into the given target pod + container." }, "target": { "$ref": "#/$defs/ZarfContainerTarget", - "description": "The target pod + container to inject the data into" + "description": "The target pod + container to inject the data into." }, "compress": { "type": "boolean", @@ -948,30 +948,30 @@ "properties": { "source": { "type": "string", - "description": "Local folder or file path or remote URL to pull into the package" + "description": "Local folder or file path or remote URL to pull into the package." }, "shasum": { "type": "string", - "description": "(files only) Optional SHA256 checksum of the file" + "description": "(files only) Optional SHA256 checksum of the file." }, "target": { "type": "string", - "description": "The absolute or relative path where the file or folder should be copied to during package deploy" + "description": "The absolute or relative path where the file or folder should be copied to during package deploy." }, "executable": { "type": "boolean", - "description": "(files only) Determines if the file should be made executable during package deploy" + "description": "(files only) Determines if the file should be made executable during package deploy." }, "symlinks": { "items": { "type": "string" }, "type": "array", - "description": "List of symlinks to create during package deploy" + "description": "List of symlinks to create during package deploy." }, "extractPath": { "type": "string", - "description": "Local folder or file to be extracted from a 'source' archive" + "description": "Local folder or file to be extracted from a 'source' archive." } }, "additionalProperties": false, @@ -989,33 +989,33 @@ "properties": { "name": { "type": "string", - "description": "A name to give this collection of manifests; this will become the name of the dynamically-created helm chart" + "description": "A name to give this collection of manifests; this will become the name of the dynamically-created helm chart." }, "namespace": { "type": "string", - "description": "The namespace to deploy the manifests to" + "description": "The namespace to deploy the manifests to." }, "files": { "items": { "type": "string" }, "type": "array", - "description": "List of local K8s YAML files or remote URLs to deploy (in order)" + "description": "List of local K8s YAML files or remote URLs to deploy (in order)." }, "kustomizeAllowAnyDirectory": { "type": "boolean", - "description": "Allow traversing directory above the current directory if needed for kustomization" + "description": "Allow traversing directory above the current directory if needed for kustomization." }, "kustomizations": { "items": { "type": "string" }, "type": "array", - "description": "List of local kustomization paths or remote URLs to include in the package" + "description": "List of local kustomization paths or remote URLs to include in the package." }, "noWait": { "type": "boolean", - "description": "Whether to not wait for manifest resources to be ready before continuing" + "description": "Whether to not wait for manifest resources to be ready before continuing." } }, "additionalProperties": false, @@ -1033,31 +1033,31 @@ "name": { "type": "string", "pattern": "^[a-z0-9][a-z0-9\\-]*$", - "description": "Name to identify this Zarf package" + "description": "Name to identify this Zarf package." }, "description": { "type": "string", - "description": "Additional information about this package" + "description": "Additional information about this package." }, "version": { "type": "string", - "description": "Generic string set by a package author to track the package version (Note: ZarfInitConfigs will always be versioned to the CLIVersion they were created with)" + "description": "Generic string set by a package author to track the package version (Note: ZarfInitConfigs will always be versioned to the CLIVersion they were created with)." }, "url": { "type": "string", - "description": "Link to package information when online" + "description": "Link to package information when online." }, "image": { "type": "string", - "description": "An image URL to embed in this package (Reserved for future use in Zarf UI)" + "description": "An image URL to embed in this package (Reserved for future use in Zarf UI)." }, "uncompressed": { "type": "boolean", - "description": "Disable compression of this package" + "description": "Disable compression of this package." }, "architecture": { "type": "string", - "description": "The target cluster architecture for this package", + "description": "The target cluster architecture for this package.", "examples": [ "arm64", "amd64" @@ -1069,26 +1069,26 @@ }, "authors": { "type": "string", - "description": "Comma-separated list of package authors (including contact info)", + "description": "Comma-separated list of package authors (including contact info).", "examples": [ "Doug <hello@defenseunicorns.com>, Pepr <hello@defenseunicorns.com>" ] }, "documentation": { "type": "string", - "description": "Link to package documentation when online" + "description": "Link to package documentation when online." }, "source": { "type": "string", - "description": "Link to package source code when online" + "description": "Link to package source code when online." }, "vendor": { "type": "string", - "description": "Name of the distributing entity, organization or individual" + "description": "Name of the distributing entity, organization or individual." }, "aggregateChecksum": { "type": "string", - "description": "Checksum of a checksums.txt file that contains checksums all the layers within the package" + "description": "Checksum of a checksums.txt file that contains checksums all the layers within the package." } }, "additionalProperties": false, @@ -1109,16 +1109,16 @@ "ZarfInitConfig", "ZarfPackageConfig" ], - "description": "The kind of Zarf package", + "description": "The kind of Zarf package.", "default": "ZarfPackageConfig" }, "metadata": { "$ref": "#/$defs/ZarfMetadata", - "description": "Package metadata" + "description": "Package metadata." }, "build": { "$ref": "#/$defs/ZarfBuildData", - "description": "Zarf-generated package build data" + "description": "Zarf-generated package build data." }, "components": { "items": { @@ -1126,21 +1126,21 @@ }, "type": "array", "minItems": 1, - "description": "List of components to deploy in this package" + "description": "List of components to deploy in this package." }, "constants": { "items": { "$ref": "#/$defs/Constant" }, "type": "array", - "description": "Constant template values applied on deploy for K8s resources" + "description": "Constant template values applied on deploy for K8s resources." }, "variables": { "items": { "$ref": "#/$defs/InteractiveVariable" }, "type": "array", - "description": "Variable template values applied on deploy for K8s resources" + "description": "Variable template values applied on deploy for K8s resources." } }, "additionalProperties": false, From 5e91b841421c0addec4519032ef76c345838144c Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 30 Jul 2024 17:13:30 +0000 Subject: [PATCH 17/34] use more invopop features Signed-off-by: Austin Abro --- src/pkg/cluster/injector.go | 6 ++---- src/pkg/variables/types.go | 30 ++++++++++++++++++++++-------- src/types/component.go | 28 +++++++++++++++++++++++++--- src/types/package.go | 14 ++++++++++++-- src/types/validate.go | 2 +- 5 files changed, 62 insertions(+), 18 deletions(-) diff --git a/src/pkg/cluster/injector.go b/src/pkg/cluster/injector.go index 48552ac5e1..1ee24c2150 100644 --- a/src/pkg/cluster/injector.go +++ b/src/pkg/cluster/injector.go @@ -260,13 +260,11 @@ func (c *Cluster) createPayloadConfigMaps(ctx context.Context, spinner *message. return cmNames, shasum, nil } +var zarfImageRegex = regexp.MustCompile(`(?m)^127\.0\.0\.1:`) + // getImagesAndNodesForInjection checks for images on schedulable nodes within a cluster. func (c *Cluster) getInjectorImageAndNode(ctx context.Context, resReq corev1.ResourceRequirements) (string, string, error) { // Regex for Zarf seed image - zarfImageRegex, err := regexp.Compile(`(?m)^127\.0\.0\.1:`) - if err != nil { - return "", "", err - } listOpts := metav1.ListOptions{ FieldSelector: fmt.Sprintf("status.phase=%s", corev1.PodRunning), } diff --git a/src/pkg/variables/types.go b/src/pkg/variables/types.go index 6b3be2863b..442d35bbb2 100644 --- a/src/pkg/variables/types.go +++ b/src/pkg/variables/types.go @@ -8,6 +8,7 @@ import ( "fmt" "regexp" + "github.com/invopop/jsonschema" "github.com/zarf-dev/zarf/src/config/lang" ) @@ -21,16 +22,14 @@ const ( FileVariableType VariableType = "file" ) -var ( - // IsUppercaseNumberUnderscore is a regex for uppercase, numbers and underscores. - // https://regex101.com/r/tfsEuZ/1 - IsUppercaseNumberUnderscore = regexp.MustCompile(`^[A-Z0-9_]+$`).MatchString -) +// UppercaseNumberUnderscorePattern is a regex for uppercase, numbers and underscores. +// https://regex101.com/r/tfsEuZ/1 +const UppercaseNumberUnderscorePattern = `^[A-Z0-9_]+$` // Variable represents a variable that has a value set programmatically type Variable struct { // The name to be used for the variable - Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"` + Name string `json:"name"` // Whether to mark this variable as sensitive to not print it in the log Sensitive bool `json:"sensitive,omitempty"` // Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_. @@ -38,7 +37,16 @@ type Variable struct { // An optional regex pattern that a variable value must match before a package deployment can continue. Pattern string `json:"pattern,omitempty"` // Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB) - Type VariableType `json:"type,omitempty" jsonschema:"enum=raw,enum=file"` + Type VariableType `json:"type,omitempty"` +} + +// JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` +func (Variable) JSONSchemaExtend(schema *jsonschema.Schema) { + kind, _ := schema.Properties.Get("type") + kind.Enum = []any{RawVariableType, FileVariableType} + + name, _ := schema.Properties.Get("name") + name.Pattern = UppercaseNumberUnderscorePattern } // InteractiveVariable is a variable that can be used to prompt a user for more information @@ -55,7 +63,7 @@ type InteractiveVariable struct { // Constant are constants that can be used to dynamically template K8s resources or run in actions. type Constant struct { // The name to be used for the constant - Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"` + Name string `json:"name"` // The value to set for the constant during deploy Value string `json:"value"` // A description of the constant to explain its purpose on package create or deploy confirmation prompts @@ -66,6 +74,12 @@ type Constant struct { Pattern string `json:"pattern,omitempty"` } +// JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` +func (Constant) JSONSchemaExtend(schema *jsonschema.Schema) { + name, _ := schema.Properties.Get("name") + name.Pattern = UppercaseNumberUnderscorePattern +} + // SetVariable tracks internal variables that have been set during this run of Zarf type SetVariable struct { Variable `json:",inline"` diff --git a/src/types/component.go b/src/types/component.go index b43493ad0a..32193cfc29 100644 --- a/src/types/component.go +++ b/src/types/component.go @@ -92,13 +92,23 @@ 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" jsonschema:"enum=linux,enum=darwin,enum=windows"` + LocalOS string `json:"localOS,omitempty"` // 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. @@ -152,13 +162,19 @@ 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" jsonschema:"pattern=^[A-Z0-9_]+$"` + Name string `json:"name"` // 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. @@ -248,7 +264,7 @@ type ZarfComponentAction struct { // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems. Shell *exec.Shell `json:"shell,omitempty"` // [Deprecated] (replaced by setVariables) (onDeploy/cmd only) The name of a variable to update with the output of the command. This variable will be available to all remaining actions and components in the package. This will be removed in Zarf v1.0.0. - DeprecatedSetVariable string `json:"setVariable,omitempty" jsonschema:"pattern=^[A-Z0-9_]+$"` + DeprecatedSetVariable string `json:"setVariable,omitempty"` // (onDeploy/cmd only) An array of variables to update with the output of the command. These variables will be available to all remaining actions and components in the package. SetVariables []variables.Variable `json:"setVariables,omitempty"` // Description of the action to be displayed during package execution instead of the command. @@ -257,6 +273,12 @@ type ZarfComponentAction struct { Wait *ZarfComponentActionWait `json:"wait,omitempty"` } +// JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` +func (ZarfComponentAction) JSONSchemaExtend(schema *jsonschema.Schema) { + name, _ := schema.Properties.Get("setVariable") + name.Pattern = variables.UppercaseNumberUnderscorePattern +} + // ZarfComponentActionWait specifies a condition to wait for before continuing type ZarfComponentActionWait struct { // Wait for a condition to be met in the cluster before continuing. Only one of cluster or network can be specified. diff --git a/src/types/package.go b/src/types/package.go index bb4b0edc0a..f2d3394e8f 100644 --- a/src/types/package.go +++ b/src/types/package.go @@ -4,7 +4,10 @@ // Package types contains all the types used by Zarf. package types -import "github.com/zarf-dev/zarf/src/pkg/variables" +import ( + "github.com/invopop/jsonschema" + "github.com/zarf-dev/zarf/src/pkg/variables" +) // ZarfPackageKind is an enum of the different kinds of Zarf packages. type ZarfPackageKind string @@ -19,7 +22,7 @@ const ( // ZarfPackage the top-level structure of a Zarf config file. type ZarfPackage struct { // The kind of Zarf package. - Kind ZarfPackageKind `json:"kind" jsonschema:"enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` + Kind ZarfPackageKind `json:"kind"` // Package metadata. Metadata ZarfMetadata `json:"metadata,omitempty"` // Zarf-generated package build data. @@ -32,6 +35,13 @@ 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 +} + // IsInitConfig returns whether a Zarf package is an init config. func (pkg ZarfPackage) IsInitConfig() bool { return pkg.Kind == ZarfInitConfig diff --git a/src/types/validate.go b/src/types/validate.go index e045e69520..7ed7019b5a 100644 --- a/src/types/validate.go +++ b/src/types/validate.go @@ -25,7 +25,7 @@ var ( IsLowercaseNumberHyphenNoStartHyphen = regexp.MustCompile(`^[a-z0-9][a-z0-9\-]*$`).MatchString // Define allowed OS, an empty string means it is allowed on all operating systems // same as enums on ZarfComponentOnlyTarget - supportedOS = []string{"linux", "darwin", "windows", ""} + supportedOS = []string{"linux", "darwin", "windows"} ) // SupportedOS returns the supported operating systems. From 457a23eb3096d55d4e5d94f171d264fc5d51f3dc Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 31 Jul 2024 15:13:12 +0000 Subject: [PATCH 18/34] move v1alpha1 to it's own package Signed-off-by: Austin Abro --- src/{types => api/v1alpha1}/component.go | 19 ++- src/{types => api/v1alpha1}/package.go | 12 +- src/{types => api/v1alpha1}/validate.go | 16 +-- src/{types => api/v1alpha1}/validate_test.go | 4 +- src/cmd/internal.go | 5 +- src/extensions/bigbang/bigbang.go | 30 ++--- src/extensions/bigbang/flux.go | 6 +- src/internal/packager/helm/common.go | 13 +- src/internal/packager/helm/zarf.go | 6 +- src/pkg/cluster/data.go | 4 +- src/pkg/cluster/zarf.go | 9 +- src/pkg/cluster/zarf_test.go | 23 ++-- src/pkg/interactive/components.go | 6 +- src/pkg/layout/component.go | 8 +- src/pkg/layout/package.go | 8 +- src/pkg/lint/lint.go | 11 +- src/pkg/lint/lint_test.go | 21 +-- src/pkg/lint/rules.go | 14 +- src/pkg/lint/rules_test.go | 10 +- src/pkg/lint/schema_test.go | 50 ++++---- src/pkg/packager/actions/actions.go | 12 +- src/pkg/packager/common_test.go | 7 +- src/pkg/packager/composer/list.go | 20 +-- src/pkg/packager/composer/list_test.go | 120 +++++++++--------- src/pkg/packager/composer/override.go | 10 +- src/pkg/packager/composer/pathfixer.go | 6 +- src/pkg/packager/creator/compose.go | 10 +- src/pkg/packager/creator/compose_test.go | 78 ++++++------ src/pkg/packager/creator/creator.go | 8 +- src/pkg/packager/creator/normal.go | 31 ++--- src/pkg/packager/creator/skeleton.go | 21 +-- src/pkg/packager/creator/template.go | 24 ++-- src/pkg/packager/creator/utils.go | 5 +- src/pkg/packager/deploy.go | 11 +- src/pkg/packager/deploy_test.go | 41 +++--- src/pkg/packager/deprecated/common.go | 6 +- .../deprecated/pluralize-set-variable.go | 10 +- .../packager/deprecated/scripts-to-actions.go | 12 +- src/pkg/packager/filters/deploy.go | 12 +- src/pkg/packager/filters/deploy_test.go | 44 +++---- src/pkg/packager/filters/diff.go | 5 +- src/pkg/packager/filters/diff_test.go | 5 +- src/pkg/packager/filters/empty.go | 4 +- src/pkg/packager/filters/empty_test.go | 6 +- src/pkg/packager/filters/os.go | 6 +- src/pkg/packager/filters/os_test.go | 12 +- src/pkg/packager/filters/select.go | 6 +- src/pkg/packager/filters/select_test.go | 24 ++-- src/pkg/packager/filters/strat.go | 6 +- src/pkg/packager/filters/strat_test.go | 10 +- src/pkg/packager/generate.go | 14 +- src/pkg/packager/mirror.go | 3 +- src/pkg/packager/prepare.go | 3 +- src/pkg/packager/publish.go | 8 +- src/pkg/packager/remove.go | 3 +- src/pkg/packager/sources/cluster.go | 13 +- src/pkg/packager/sources/new.go | 5 +- src/pkg/packager/sources/new_test.go | 3 +- src/pkg/packager/sources/oci.go | 7 +- src/pkg/packager/sources/split.go | 5 +- src/pkg/packager/sources/tarball.go | 5 +- src/pkg/packager/sources/url.go | 5 +- src/pkg/packager/sources/utils.go | 10 +- src/pkg/zoci/fetch.go | 6 +- src/pkg/zoci/pull.go | 6 +- src/pkg/zoci/push.go | 6 +- src/pkg/zoci/utils.go | 4 +- src/test/e2e/05_tarball_test.go | 5 +- src/test/e2e/08_create_differential_test.go | 4 +- src/test/e2e/13_zarf_package_generate_test.go | 4 +- src/test/e2e/51_oci_compose_test.go | 6 +- src/types/k8s.go | 3 +- src/types/packager.go | 4 +- src/types/runtime.go | 8 -- 74 files changed, 509 insertions(+), 478 deletions(-) rename src/{types => api/v1alpha1}/component.go (97%) rename src/{types => api/v1alpha1}/package.go (93%) rename src/{types => api/v1alpha1}/validate.go (94%) rename src/{types => api/v1alpha1}/validate_test.go (99%) diff --git a/src/types/component.go b/src/api/v1alpha1/component.go similarity index 97% rename from src/types/component.go rename to src/api/v1alpha1/component.go index 32193cfc29..cb16f9ad80 100644 --- a/src/types/component.go +++ b/src/api/v1alpha1/component.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package types contains all the types used by Zarf. -package types +// Package v1alpha1 contains all the structs for the v1alpha1 ZarfPackageConfig +package v1alpha1 import ( "github.com/invopop/jsonschema" @@ -11,6 +11,21 @@ import ( "github.com/zarf-dev/zarf/src/types/extensions" ) +var ( + // Define allowed OS, an empty string means it is allowed on all operating systems + // same as enums on ZarfComponentOnlyTarget + supportedOS = []string{"linux", "darwin", "windows"} +) + +// SupportedOS returns the supported operating systems. +// +// The supported operating systems are: linux, darwin, windows. +// +// An empty string signifies no OS restrictions. +func SupportedOS() []string { + return supportedOS +} + // ZarfComponent is the primary functional grouping of assets to deploy by Zarf. type ZarfComponent struct { // The name of the component. diff --git a/src/types/package.go b/src/api/v1alpha1/package.go similarity index 93% rename from src/types/package.go rename to src/api/v1alpha1/package.go index f2d3394e8f..2475790fc6 100644 --- a/src/types/package.go +++ b/src/api/v1alpha1/package.go @@ -1,14 +1,22 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package types contains all the types used by Zarf. -package types +// Package v1alpha1 contains all the structs for the v1alpha1 ZarfPackageConfig +package v1alpha1 import ( "github.com/invopop/jsonschema" "github.com/zarf-dev/zarf/src/pkg/variables" ) +// Zarf looks for these strings in zarf.yaml to make dynamic changes +const ( + ZarfPackageTemplatePrefix = "###ZARF_PKG_TMPL_" + ZarfPackageVariablePrefix = "###ZARF_PKG_VAR_" + ZarfPackageArch = "###ZARF_PKG_ARCH###" + ZarfComponentName = "###ZARF_COMPONENT_NAME###" +) + // ZarfPackageKind is an enum of the different kinds of Zarf packages. type ZarfPackageKind string diff --git a/src/types/validate.go b/src/api/v1alpha1/validate.go similarity index 94% rename from src/types/validate.go rename to src/api/v1alpha1/validate.go index 7ed7019b5a..d3cb5620d4 100644 --- a/src/types/validate.go +++ b/src/api/v1alpha1/validate.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package types contains all the types used by Zarf. -package types +// Package v1alpha1 contains all the structs for the v1alpha1 ZarfPackageConfig +package v1alpha1 import ( "errors" @@ -23,20 +23,8 @@ var ( // IsLowercaseNumberHyphenNoStartHyphen is a regex for lowercase, numbers and hyphens that cannot start with a hyphen. // https://regex101.com/r/FLdG9G/2 IsLowercaseNumberHyphenNoStartHyphen = regexp.MustCompile(`^[a-z0-9][a-z0-9\-]*$`).MatchString - // Define allowed OS, an empty string means it is allowed on all operating systems - // same as enums on ZarfComponentOnlyTarget - supportedOS = []string{"linux", "darwin", "windows"} ) -// SupportedOS returns the supported operating systems. -// -// The supported operating systems are: linux, darwin, windows. -// -// An empty string signifies no OS restrictions. -func SupportedOS() []string { - return supportedOS -} - // Validate runs all validation checks on the package. func (pkg ZarfPackage) Validate() error { var err error diff --git a/src/types/validate_test.go b/src/api/v1alpha1/validate_test.go similarity index 99% rename from src/types/validate_test.go rename to src/api/v1alpha1/validate_test.go index b0ebc60e8f..a71819df40 100644 --- a/src/types/validate_test.go +++ b/src/api/v1alpha1/validate_test.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package types contains all the types used by Zarf. -package types +// Package v1alpha1 contains all the structs for the v1alpha1 ZarfPackageConfig +package v1alpha1 import ( "fmt" diff --git a/src/cmd/internal.go b/src/cmd/internal.go index 3d77c01190..18219bb021 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -18,6 +18,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/cobra/doc" "github.com/spf13/pflag" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/cmd/common" "github.com/zarf-dev/zarf/src/config/lang" "github.com/zarf-dev/zarf/src/internal/agent" @@ -181,7 +182,7 @@ var genConfigSchemaCmd = &cobra.Command{ return err } - schema := reflector.Reflect(&types.ZarfPackage{}) + schema := reflector.Reflect(&v1alpha1.ZarfPackage{}) output, err := json.MarshalIndent(schema, "", " ") if err != nil { return fmt.Errorf("unable to generate the Zarf config schema: %w", err) @@ -193,7 +194,7 @@ var genConfigSchemaCmd = &cobra.Command{ type zarfTypes struct { DeployedPackage types.DeployedPackage - ZarfPackage types.ZarfPackage + ZarfPackage v1alpha1.ZarfPackage ZarfState types.ZarfState } diff --git a/src/extensions/bigbang/bigbang.go b/src/extensions/bigbang/bigbang.go index 951ae88ccf..a00c267b7c 100644 --- a/src/extensions/bigbang/bigbang.go +++ b/src/extensions/bigbang/bigbang.go @@ -17,12 +17,12 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" fluxHelmCtrl "github.com/fluxcd/helm-controller/api/v2beta1" fluxSrcCtrl "github.com/fluxcd/source-controller/api/v1beta2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/internal/packager/helm" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/pkg/variables" - "github.com/zarf-dev/zarf/src/types" "github.com/zarf-dev/zarf/src/types/extensions" "helm.sh/helm/v3/pkg/chartutil" corev1 "k8s.io/api/core/v1" @@ -43,9 +43,9 @@ var tenMins = metav1.Duration{ // Run mutates a component that should deploy Big Bang to a set of manifests // that contain the flux deployment of Big Bang -func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c types.ZarfComponent) (types.ZarfComponent, error) { +func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c v1alpha1.ZarfComponent) (v1alpha1.ZarfComponent, error) { cfg := c.Extensions.BigBang - manifests := []types.ZarfManifest{} + manifests := []v1alpha1.ZarfManifest{} validVersionResponse, err := isValidVersion(cfg.Version) @@ -86,7 +86,7 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c type // Configure helm to pull down the Big Bang chart. helmCfg := helm.New( - types.ZarfChart{ + v1alpha1.ZarfChart{ Name: bb, Namespace: bb, URL: bbRepo, @@ -149,11 +149,11 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c type // Add wait actions for each of the helm releases in generally the order they should be deployed. for _, hrNamespacedName := range namespacedHelmReleaseNames { hr := hrDependencies[hrNamespacedName] - action := types.ZarfComponentAction{ + action := v1alpha1.ZarfComponentAction{ Description: fmt.Sprintf("Big Bang Helm Release `%s` to be ready", hrNamespacedName), MaxTotalSeconds: &maxTotalSeconds, - Wait: &types.ZarfComponentActionWait{ - Cluster: &types.ZarfComponentActionWaitCluster{ + Wait: &v1alpha1.ZarfComponentActionWait{ + Cluster: &v1alpha1.ZarfComponentActionWaitCluster{ Kind: "HelmRelease", Name: hr.Metadata.Name, Namespace: hr.Metadata.Namespace, @@ -168,7 +168,7 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c type // https://repo1.dso.mil/big-bang/bigbang/-/blob/1.54.0/chart/templates/metrics-server/helmrelease.yaml if hr.Metadata.Name == "metrics-server" { action.Description = "K8s metric server to exist or be deployed by Big Bang" - action.Wait.Cluster = &types.ZarfComponentActionWaitCluster{ + action.Wait.Cluster = &v1alpha1.ZarfComponentActionWaitCluster{ Kind: "APIService", // https://github.com/kubernetes-sigs/metrics-server#compatibility-matrix Name: "v1beta1.metrics.k8s.io", @@ -195,13 +195,13 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c type // Add onFailure actions with additional troubleshooting information. for _, cmd := range failureGeneral { - c.Actions.OnDeploy.OnFailure = append(c.Actions.OnDeploy.OnFailure, types.ZarfComponentAction{ + c.Actions.OnDeploy.OnFailure = append(c.Actions.OnDeploy.OnFailure, v1alpha1.ZarfComponentAction{ Cmd: fmt.Sprintf("./zarf tools kubectl %s", cmd), }) } for _, cmd := range failureDebug { - c.Actions.OnDeploy.OnFailure = append(c.Actions.OnDeploy.OnFailure, types.ZarfComponentAction{ + c.Actions.OnDeploy.OnFailure = append(c.Actions.OnDeploy.OnFailure, v1alpha1.ZarfComponentAction{ Mute: &t, Description: "Storing debug information to the log for troubleshooting.", Cmd: fmt.Sprintf("./zarf tools kubectl %s", cmd), @@ -209,7 +209,7 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c type } // Add a pre-remove action to suspend the Big Bang HelmReleases to prevent reconciliation during removal. - c.Actions.OnRemove.Before = append(c.Actions.OnRemove.Before, types.ZarfComponentAction{ + c.Actions.OnRemove.Before = append(c.Actions.OnRemove.Before, v1alpha1.ZarfComponentAction{ Description: "Suspend Big Bang HelmReleases to prevent reconciliation during removal.", Cmd: `./zarf tools kubectl patch helmrelease -n bigbang bigbang --type=merge -p '{"spec":{"suspend":true}}'`, }) @@ -250,7 +250,7 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c type } // Skeletonize mutates a component so that the valuesFiles can be contained inside a skeleton package -func Skeletonize(tmpPaths *layout.ComponentPaths, c types.ZarfComponent) (types.ZarfComponent, error) { +func Skeletonize(tmpPaths *layout.ComponentPaths, c v1alpha1.ZarfComponent) (v1alpha1.ZarfComponent, error) { for valuesIdx, valuesFile := range c.Extensions.BigBang.ValuesFiles { // Get the base file name for this file. baseName := filepath.Base(valuesFile) @@ -297,7 +297,7 @@ func Skeletonize(tmpPaths *layout.ComponentPaths, c types.ZarfComponent) (types. // Compose mutates a component so that its local paths are relative to the provided path // // additionally, it will merge any overrides -func Compose(c *types.ZarfComponent, override types.ZarfComponent, relativeTo string) { +func Compose(c *v1alpha1.ZarfComponent, override v1alpha1.ZarfComponent, relativeTo string) { // perform any overrides if override.Extensions.BigBang != nil { for valuesIdx, valuesFile := range override.Extensions.BigBang.ValuesFiles { @@ -453,9 +453,9 @@ func findBBResources(t string) (gitRepos map[string]string, helmReleaseDeps map[ } // addBigBangManifests creates the manifests component for deploying Big Bang. -func addBigBangManifests(YOLO bool, manifestDir string, cfg *extensions.BigBang) (types.ZarfManifest, error) { +func addBigBangManifests(YOLO bool, manifestDir string, cfg *extensions.BigBang) (v1alpha1.ZarfManifest, error) { // Create a manifest component that we add to the zarf package for bigbang. - manifest := types.ZarfManifest{ + manifest := v1alpha1.ZarfManifest{ Name: bb, Namespace: bb, } diff --git a/src/extensions/bigbang/flux.go b/src/extensions/bigbang/flux.go index 91680970e9..0b37aed2e2 100644 --- a/src/extensions/bigbang/flux.go +++ b/src/extensions/bigbang/flux.go @@ -12,9 +12,9 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" fluxHelmCtrl "github.com/fluxcd/helm-controller/api/v2beta1" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/internal/packager/kustomize" "github.com/zarf-dev/zarf/src/pkg/utils" - "github.com/zarf-dev/zarf/src/types" "github.com/zarf-dev/zarf/src/types/extensions" "helm.sh/helm/v3/pkg/chartutil" v1 "k8s.io/api/apps/v1" @@ -43,7 +43,7 @@ func (h HelmReleaseDependency) Dependencies() []string { } // getFlux Creates a component to deploy Flux. -func getFlux(baseDir string, cfg *extensions.BigBang) (manifest types.ZarfManifest, images []string, err error) { +func getFlux(baseDir string, cfg *extensions.BigBang) (manifest v1alpha1.ZarfManifest, images []string, err error) { localPath := path.Join(baseDir, "bb-ext-flux.yaml") kustomizePath := path.Join(baseDir, "kustomization.yaml") @@ -72,7 +72,7 @@ func getFlux(baseDir string, cfg *extensions.BigBang) (manifest types.ZarfManife } // Add the flux.yaml file to the component manifests. - manifest = types.ZarfManifest{ + manifest = v1alpha1.ZarfManifest{ Name: "flux-system", Namespace: "flux-system", Files: []string{localPath}, diff --git a/src/internal/packager/helm/common.go b/src/internal/packager/helm/common.go index e4dd729a19..8d20e84483 100644 --- a/src/internal/packager/helm/common.go +++ b/src/internal/packager/helm/common.go @@ -14,6 +14,7 @@ import ( "strconv" "time" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/cluster" "github.com/zarf-dev/zarf/src/pkg/message" @@ -26,7 +27,7 @@ import ( // Helm is a config object for working with helm charts. type Helm struct { - chart types.ZarfChart + chart v1alpha1.ZarfChart chartPath string valuesPath string @@ -50,7 +51,7 @@ type Helm struct { type Modifier func(*Helm) // New returns a new Helm config struct. -func New(chart types.ZarfChart, chartPath string, valuesPath string, mods ...Modifier) *Helm { +func New(chart v1alpha1.ZarfChart, chartPath string, valuesPath string, mods ...Modifier) *Helm { h := &Helm{ chart: chart, chartPath: chartPath, @@ -78,7 +79,7 @@ func NewClusterOnly(cfg *types.PackagerConfig, variableConfig *variables.Variabl } // NewFromZarfManifest generates a helm chart and config from a given Zarf manifest. -func NewFromZarfManifest(manifest types.ZarfManifest, manifestPath, packageName, componentName string, mods ...Modifier) (h *Helm, err error) { +func NewFromZarfManifest(manifest v1alpha1.ZarfManifest, manifestPath, packageName, componentName string, mods ...Modifier) (h *Helm, err error) { spinner := message.NewProgressSpinner("Starting helm chart generation %s", manifest.Name) defer spinner.Stop() @@ -115,7 +116,7 @@ func NewFromZarfManifest(manifest types.ZarfManifest, manifestPath, packageName, // Generate the struct to pass to InstallOrUpgradeChart(). h = &Helm{ - chart: types.ZarfChart{ + chart: v1alpha1.ZarfChart{ Name: tmpChart.Metadata.Name, // Preserve the zarf prefix for chart names to match v0.22.x and earlier behavior. ReleaseName: fmt.Sprintf("zarf-%s", sha1ReleaseName), @@ -164,11 +165,11 @@ func WithVariableConfig(variableConfig *variables.VariableConfig) Modifier { } // StandardName generates a predictable full path for a helm chart for Zarf. -func StandardName(destination string, chart types.ZarfChart) string { +func StandardName(destination string, chart v1alpha1.ZarfChart) string { return filepath.Join(destination, chart.Name+"-"+chart.Version) } // StandardValuesName generates a predictable full path for the values file for a helm chart for zarf -func StandardValuesName(destination string, chart types.ZarfChart, idx int) string { +func StandardValuesName(destination string, chart v1alpha1.ZarfChart, idx int) string { return fmt.Sprintf("%s-%d", StandardName(destination, chart), idx) } diff --git a/src/internal/packager/helm/zarf.go b/src/internal/packager/helm/zarf.go index 8706fe2711..9f72dce5a4 100644 --- a/src/internal/packager/helm/zarf.go +++ b/src/internal/packager/helm/zarf.go @@ -17,13 +17,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/internal/packager/template" "github.com/zarf-dev/zarf/src/pkg/cluster" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/transform" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/pkg/variables" - "github.com/zarf-dev/zarf/src/types" ) // UpdateZarfRegistryValues updates the Zarf registry deployment with the new state values @@ -41,7 +41,7 @@ func (h *Helm) UpdateZarfRegistryValues(ctx context.Context) error { "htpasswd": fmt.Sprintf("%s\n%s", pushUser, pullUser), }, } - h.chart = types.ZarfChart{ + h.chart = v1alpha1.ZarfChart{ Namespace: "zarf", ReleaseName: "zarf-docker-registry", } @@ -99,7 +99,7 @@ func (h *Helm) UpdateZarfAgentValues(ctx context.Context) error { for _, release := range releases { // Update the Zarf Agent release with the new values if release.Chart.Name() == "raw-init-zarf-agent-zarf-agent" { - h.chart = types.ZarfChart{ + h.chart = v1alpha1.ZarfChart{ Namespace: "zarf", ReleaseName: release.Name, } diff --git a/src/pkg/cluster/data.go b/src/pkg/cluster/data.go index 8d9c2070cc..8f1687123a 100644 --- a/src/pkg/cluster/data.go +++ b/src/pkg/cluster/data.go @@ -21,17 +21,17 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/pkg/utils/exec" - "github.com/zarf-dev/zarf/src/types" ) // HandleDataInjection waits for the target pod(s) to come up and inject the data into them // todo: this currently requires kubectl but we should have enough k8s work to make this native now. -func (c *Cluster) HandleDataInjection(ctx context.Context, data types.ZarfDataInjection, componentPath *layout.ComponentPaths, dataIdx int) error { +func (c *Cluster) HandleDataInjection(ctx context.Context, data v1alpha1.ZarfDataInjection, componentPath *layout.ComponentPaths, dataIdx int) error { injectionCompletionMarker := filepath.Join(componentPath.DataInjections, config.GetDataInjectionMarker()) if err := os.WriteFile(injectionCompletionMarker, []byte("🦄"), helpers.ReadWriteUser); err != nil { return fmt.Errorf("unable to create the data injection completion marker: %w", err) diff --git a/src/pkg/cluster/zarf.go b/src/pkg/cluster/zarf.go index 71d6f73c9e..cf14ab2f83 100644 --- a/src/pkg/cluster/zarf.go +++ b/src/pkg/cluster/zarf.go @@ -17,6 +17,7 @@ import ( kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/types" @@ -104,7 +105,7 @@ func (c *Cluster) StripZarfLabelsAndSecretsFromNamespaces(ctx context.Context) { } // PackageSecretNeedsWait checks if a package component has a running webhook that needs to be waited on. -func (c *Cluster) PackageSecretNeedsWait(deployedPackage *types.DeployedPackage, component types.ZarfComponent, skipWebhooks bool) (needsWait bool, waitSeconds int, hookName string) { +func (c *Cluster) PackageSecretNeedsWait(deployedPackage *types.DeployedPackage, component v1alpha1.ZarfComponent, skipWebhooks bool) (needsWait bool, waitSeconds int, hookName string) { // Skip checking webhook status when '--skip-webhooks' flag is provided and for YOLO packages if skipWebhooks || deployedPackage == nil || deployedPackage.Data.Metadata.YOLO { return false, 0, "" @@ -128,7 +129,7 @@ func (c *Cluster) PackageSecretNeedsWait(deployedPackage *types.DeployedPackage, } // RecordPackageDeploymentAndWait records the deployment of a package to the cluster and waits for any webhooks to complete. -func (c *Cluster) RecordPackageDeploymentAndWait(ctx context.Context, pkg types.ZarfPackage, components []types.DeployedComponent, connectStrings types.ConnectStrings, generation int, component types.ZarfComponent, skipWebhooks bool) (deployedPackage *types.DeployedPackage, err error) { +func (c *Cluster) RecordPackageDeploymentAndWait(ctx context.Context, pkg v1alpha1.ZarfPackage, components []types.DeployedComponent, connectStrings types.ConnectStrings, generation int, component v1alpha1.ZarfComponent, skipWebhooks bool) (deployedPackage *types.DeployedPackage, err error) { deployedPackage, err = c.RecordPackageDeployment(ctx, pkg, components, connectStrings, generation) if err != nil { return nil, err @@ -176,7 +177,7 @@ func (c *Cluster) RecordPackageDeploymentAndWait(ctx context.Context, pkg types. } // RecordPackageDeployment saves metadata about a package that has been deployed to the cluster. -func (c *Cluster) RecordPackageDeployment(ctx context.Context, pkg types.ZarfPackage, components []types.DeployedComponent, connectStrings types.ConnectStrings, generation int) (deployedPackage *types.DeployedPackage, err error) { +func (c *Cluster) RecordPackageDeployment(ctx context.Context, pkg v1alpha1.ZarfPackage, components []types.DeployedComponent, connectStrings types.ConnectStrings, generation int) (deployedPackage *types.DeployedPackage, err error) { packageName := pkg.Metadata.Name // Attempt to load information about webhooks for the package @@ -277,7 +278,7 @@ func (c *Cluster) DisableRegHPAScaleDown(ctx context.Context) error { } // GetInstalledChartsForComponent returns any installed Helm Charts for the provided package component. -func (c *Cluster) GetInstalledChartsForComponent(ctx context.Context, packageName string, component types.ZarfComponent) (installedCharts []types.InstalledChart, err error) { +func (c *Cluster) GetInstalledChartsForComponent(ctx context.Context, packageName string, component v1alpha1.ZarfComponent) (installedCharts []types.InstalledChart, err error) { deployedPackage, err := c.GetDeployedPackage(ctx, packageName) if err != nil { return installedCharts, err diff --git a/src/pkg/cluster/zarf_test.go b/src/pkg/cluster/zarf_test.go index f7e9b481ec..fe8b91d188 100644 --- a/src/pkg/cluster/zarf_test.go +++ b/src/pkg/cluster/zarf_test.go @@ -16,6 +16,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/types" ) @@ -27,7 +28,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { type testCase struct { name string deployedPackage *types.DeployedPackage - component types.ZarfComponent + component v1alpha1.ZarfComponent skipWebhooks bool needsWait bool waitSeconds int @@ -43,7 +44,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { testCases := []testCase{ { name: "NoWebhooks", - component: types.ZarfComponent{Name: componentName}, + component: v1alpha1.ZarfComponent{Name: componentName}, deployedPackage: &types.DeployedPackage{ Name: packageName, ComponentWebhooks: map[string]map[string]types.Webhook{}, @@ -54,7 +55,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, { name: "WebhookRunning", - component: types.ZarfComponent{Name: componentName}, + component: v1alpha1.ZarfComponent{Name: componentName}, deployedPackage: &types.DeployedPackage{ Name: packageName, ComponentWebhooks: map[string]map[string]types.Webhook{ @@ -73,7 +74,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { // Ensure we only wait on running webhooks for the provided component { name: "WebhookRunningOnDifferentComponent", - component: types.ZarfComponent{Name: componentName}, + component: v1alpha1.ZarfComponent{Name: componentName}, deployedPackage: &types.DeployedPackage{ Name: packageName, ComponentWebhooks: map[string]map[string]types.Webhook{ @@ -91,7 +92,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, { name: "WebhookSucceeded", - component: types.ZarfComponent{Name: componentName}, + component: v1alpha1.ZarfComponent{Name: componentName}, deployedPackage: &types.DeployedPackage{ Name: packageName, ComponentWebhooks: map[string]map[string]types.Webhook{ @@ -108,7 +109,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, { name: "WebhookFailed", - component: types.ZarfComponent{Name: componentName}, + component: v1alpha1.ZarfComponent{Name: componentName}, deployedPackage: &types.DeployedPackage{ Name: packageName, ComponentWebhooks: map[string]map[string]types.Webhook{ @@ -125,7 +126,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, { name: "WebhookRemoving", - component: types.ZarfComponent{Name: componentName}, + component: v1alpha1.ZarfComponent{Name: componentName}, deployedPackage: &types.DeployedPackage{ Name: packageName, ComponentWebhooks: map[string]map[string]types.Webhook{ @@ -142,11 +143,11 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, { name: "SkipWaitForYOLO", - component: types.ZarfComponent{Name: componentName}, + component: v1alpha1.ZarfComponent{Name: componentName}, deployedPackage: &types.DeployedPackage{ Name: packageName, - Data: types.ZarfPackage{ - Metadata: types.ZarfMetadata{ + Data: v1alpha1.ZarfPackage{ + Metadata: v1alpha1.ZarfMetadata{ YOLO: true, }, }, @@ -165,7 +166,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, { name: "SkipWebhooksFlagUsed", - component: types.ZarfComponent{Name: componentName}, + component: v1alpha1.ZarfComponent{Name: componentName}, skipWebhooks: true, deployedPackage: &types.DeployedPackage{ Name: packageName, diff --git a/src/pkg/interactive/components.go b/src/pkg/interactive/components.go index f48db25043..719228cb5c 100644 --- a/src/pkg/interactive/components.go +++ b/src/pkg/interactive/components.go @@ -9,13 +9,13 @@ import ( "github.com/AlecAivazis/survey/v2" "github.com/pterm/pterm" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/utils" - "github.com/zarf-dev/zarf/src/types" ) // SelectOptionalComponent prompts to confirm optional components -func SelectOptionalComponent(component types.ZarfComponent) (confirm bool, err error) { +func SelectOptionalComponent(component v1alpha1.ZarfComponent) (confirm bool, err error) { message.HorizontalRule() displayComponent := component @@ -34,7 +34,7 @@ func SelectOptionalComponent(component types.ZarfComponent) (confirm bool, err e } // SelectChoiceGroup prompts to select component groups -func SelectChoiceGroup(componentGroup []types.ZarfComponent) (types.ZarfComponent, error) { +func SelectChoiceGroup(componentGroup []v1alpha1.ZarfComponent) (v1alpha1.ZarfComponent, error) { message.HorizontalRule() var chosen int diff --git a/src/pkg/layout/component.go b/src/pkg/layout/component.go index ec5e82507b..fee2d90082 100644 --- a/src/pkg/layout/component.go +++ b/src/pkg/layout/component.go @@ -12,8 +12,8 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/mholt/archiver/v3" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/message" - "github.com/zarf-dev/zarf/src/types" ) // ComponentPaths contains paths for a component. @@ -39,7 +39,7 @@ type Components struct { var ErrNotLoaded = fmt.Errorf("not loaded") // Archive archives a component. -func (c *Components) Archive(component types.ZarfComponent, cleanupTemp bool) (err error) { +func (c *Components) Archive(component v1alpha1.ZarfComponent, cleanupTemp bool) (err error) { name := component.Name if _, ok := c.Dirs[name]; !ok { return &fs.PathError{ @@ -75,7 +75,7 @@ func (c *Components) Archive(component types.ZarfComponent, cleanupTemp bool) (e } // Unarchive unarchives a component. -func (c *Components) Unarchive(component types.ZarfComponent) (err error) { +func (c *Components) Unarchive(component v1alpha1.ZarfComponent) (err error) { name := component.Name tb, ok := c.Tarballs[name] if !ok { @@ -138,7 +138,7 @@ func (c *Components) Unarchive(component types.ZarfComponent) (err error) { } // Create creates a new component directory structure. -func (c *Components) Create(component types.ZarfComponent) (cp *ComponentPaths, err error) { +func (c *Components) Create(component v1alpha1.ZarfComponent) (cp *ComponentPaths, err error) { name := component.Name _, ok := c.Tarballs[name] diff --git a/src/pkg/layout/package.go b/src/pkg/layout/package.go index aef5e849d6..a38ec599a1 100644 --- a/src/pkg/layout/package.go +++ b/src/pkg/layout/package.go @@ -16,11 +16,11 @@ import ( "github.com/google/go-containerregistry/pkg/crane" "github.com/mholt/archiver/v3" ocispec "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/interactive" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/deprecated" "github.com/zarf-dev/zarf/src/pkg/utils" - "github.com/zarf-dev/zarf/src/types" ) // PackagePaths is the default package layout. @@ -52,9 +52,9 @@ func New(baseDir string) *PackagePaths { // ReadZarfYAML reads a zarf.yaml file into memory, // checks if it's using the legacy layout, and migrates deprecated component configs. -func (pp *PackagePaths) ReadZarfYAML() (pkg types.ZarfPackage, warnings []string, err error) { +func (pp *PackagePaths) ReadZarfYAML() (pkg v1alpha1.ZarfPackage, warnings []string, err error) { if err := utils.ReadYaml(pp.ZarfYAML, &pkg); err != nil { - return types.ZarfPackage{}, nil, fmt.Errorf("unable to read zarf.yaml: %w", err) + return v1alpha1.ZarfPackage{}, nil, fmt.Errorf("unable to read zarf.yaml: %w", err) } if pp.IsLegacyLayout() { @@ -75,7 +75,7 @@ func (pp *PackagePaths) ReadZarfYAML() (pkg types.ZarfPackage, warnings []string // MigrateLegacy migrates a legacy package layout to the new layout. func (pp *PackagePaths) MigrateLegacy() (err error) { - var pkg types.ZarfPackage + var pkg v1alpha1.ZarfPackage base := pp.Base // legacy layout does not contain a checksums file, nor a signature diff --git a/src/pkg/lint/lint.go b/src/pkg/lint/lint.go index fda3da01f9..9c0132f2e8 100644 --- a/src/pkg/lint/lint.go +++ b/src/pkg/lint/lint.go @@ -10,6 +10,7 @@ import ( "fmt" "os" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/config/lang" "github.com/zarf-dev/zarf/src/pkg/layout" @@ -25,7 +26,7 @@ func Validate(ctx context.Context, createOpts types.ZarfCreateOptions) error { if err := os.Chdir(createOpts.BaseDir); err != nil { return fmt.Errorf("unable to access directory %q: %w", createOpts.BaseDir, err) } - var pkg types.ZarfPackage + var pkg v1alpha1.ZarfPackage if err := utils.ReadYaml(layout.ZarfYAML, &pkg); err != nil { return err } @@ -52,7 +53,7 @@ func Validate(ctx context.Context, createOpts types.ZarfCreateOptions) error { return nil } -func lintComponents(ctx context.Context, pkg types.ZarfPackage, createOpts types.ZarfCreateOptions) ([]PackageFinding, error) { +func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts types.ZarfCreateOptions) ([]PackageFinding, error) { var findings []PackageFinding for i, component := range pkg.Components { @@ -86,7 +87,7 @@ func lintComponents(ctx context.Context, pkg types.ZarfPackage, createOpts types return findings, nil } -func fillComponentTemplate(c *types.ZarfComponent, createOpts types.ZarfCreateOptions) ([]PackageFinding, error) { +func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreateOptions) ([]PackageFinding, error) { var findings []PackageFinding templateMap := map[string]string{} @@ -120,12 +121,12 @@ func fillComponentTemplate(c *types.ZarfComponent, createOpts types.ZarfCreateOp return nil } - if err := setVarsAndWarn(types.ZarfPackageTemplatePrefix, false); err != nil { + if err := setVarsAndWarn(v1alpha1.ZarfPackageTemplatePrefix, false); err != nil { return nil, err } // [DEPRECATION] Set the Package Variable syntax as well for backward compatibility - if err := setVarsAndWarn(types.ZarfPackageVariablePrefix, true); err != nil { + if err := setVarsAndWarn(v1alpha1.ZarfPackageVariablePrefix, true); err != nil { return nil, err } diff --git a/src/pkg/lint/lint_test.go b/src/pkg/lint/lint_test.go index d5c5a03495..d6ad24ad82 100644 --- a/src/pkg/lint/lint_test.go +++ b/src/pkg/lint/lint_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config/lang" "github.com/zarf-dev/zarf/src/types" ) @@ -17,13 +18,13 @@ import ( func TestLintComponents(t *testing.T) { t.Run("Test composable components with bad path", func(t *testing.T) { t.Parallel() - zarfPackage := types.ZarfPackage{ - Components: []types.ZarfComponent{ + zarfPackage := v1alpha1.ZarfPackage{ + Components: []v1alpha1.ZarfComponent{ { - Import: types.ZarfComponentImport{Path: "bad-path"}, + Import: v1alpha1.ZarfComponentImport{Path: "bad-path"}, }, }, - Metadata: types.ZarfMetadata{Name: "test-zarf-package"}, + Metadata: v1alpha1.ZarfMetadata{Name: "test-zarf-package"}, } createOpts := types.ZarfCreateOptions{Flavor: "", BaseDir: "."} @@ -39,11 +40,11 @@ func TestFillComponentTemplate(t *testing.T) { }, } - component := types.ZarfComponent{ + component := v1alpha1.ZarfComponent{ Images: []string{ - fmt.Sprintf("%s%s###", types.ZarfPackageTemplatePrefix, "KEY1"), - fmt.Sprintf("%s%s###", types.ZarfPackageVariablePrefix, "KEY2"), - fmt.Sprintf("%s%s###", types.ZarfPackageTemplatePrefix, "KEY3"), + fmt.Sprintf("%s%s###", v1alpha1.ZarfPackageTemplatePrefix, "KEY1"), + fmt.Sprintf("%s%s###", v1alpha1.ZarfPackageVariablePrefix, "KEY2"), + fmt.Sprintf("%s%s###", v1alpha1.ZarfPackageTemplatePrefix, "KEY3"), }, } @@ -59,11 +60,11 @@ func TestFillComponentTemplate(t *testing.T) { Description: fmt.Sprintf(lang.PkgValidateTemplateDeprecation, "KEY2", "KEY2", "KEY2"), }, } - expectedComponent := types.ZarfComponent{ + expectedComponent := v1alpha1.ZarfComponent{ Images: []string{ "value1", "value2", - fmt.Sprintf("%s%s###", types.ZarfPackageTemplatePrefix, "KEY3"), + fmt.Sprintf("%s%s###", v1alpha1.ZarfPackageTemplatePrefix, "KEY3"), }, } require.ElementsMatch(t, expectedFindings, findings) diff --git a/src/pkg/lint/rules.go b/src/pkg/lint/rules.go index 17c22256a4..0be01cf687 100644 --- a/src/pkg/lint/rules.go +++ b/src/pkg/lint/rules.go @@ -9,15 +9,15 @@ import ( "strings" "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/transform" - "github.com/zarf-dev/zarf/src/types" ) func isPinnedImage(image string) (bool, error) { transformedImage, err := transform.ParseImageRef(image) if err != nil { - if strings.Contains(image, types.ZarfPackageTemplatePrefix) || - strings.Contains(image, types.ZarfPackageVariablePrefix) { + if strings.Contains(image, v1alpha1.ZarfPackageTemplatePrefix) || + strings.Contains(image, v1alpha1.ZarfPackageVariablePrefix) { return true, nil } return false, err @@ -41,7 +41,7 @@ func isPinnedRepo(repo string) bool { } // CheckComponentValues runs lint rules validating values on component keys, should be run after templating -func CheckComponentValues(c types.ZarfComponent, i int) []PackageFinding { +func CheckComponentValues(c v1alpha1.ZarfComponent, i int) []PackageFinding { var findings []PackageFinding findings = append(findings, checkForUnpinnedRepos(c, i)...) findings = append(findings, checkForUnpinnedImages(c, i)...) @@ -49,7 +49,7 @@ func CheckComponentValues(c types.ZarfComponent, i int) []PackageFinding { return findings } -func checkForUnpinnedRepos(c types.ZarfComponent, i int) []PackageFinding { +func checkForUnpinnedRepos(c v1alpha1.ZarfComponent, i int) []PackageFinding { var findings []PackageFinding for j, repo := range c.Repos { repoYqPath := fmt.Sprintf(".components.[%d].repos.[%d]", i, j) @@ -65,7 +65,7 @@ func checkForUnpinnedRepos(c types.ZarfComponent, i int) []PackageFinding { return findings } -func checkForUnpinnedImages(c types.ZarfComponent, i int) []PackageFinding { +func checkForUnpinnedImages(c v1alpha1.ZarfComponent, i int) []PackageFinding { var findings []PackageFinding for j, image := range c.Images { imageYqPath := fmt.Sprintf(".components.[%d].images.[%d]", i, j) @@ -91,7 +91,7 @@ func checkForUnpinnedImages(c types.ZarfComponent, i int) []PackageFinding { return findings } -func checkForUnpinnedFiles(c types.ZarfComponent, i int) []PackageFinding { +func checkForUnpinnedFiles(c v1alpha1.ZarfComponent, i int) []PackageFinding { var findings []PackageFinding for j, file := range c.Files { fileYqPath := fmt.Sprintf(".components.[%d].files.[%d]", i, j) diff --git a/src/pkg/lint/rules_test.go b/src/pkg/lint/rules_test.go index bf080ac506..803dae9096 100644 --- a/src/pkg/lint/rules_test.go +++ b/src/pkg/lint/rules_test.go @@ -9,13 +9,13 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) func TestUnpinnedRepo(t *testing.T) { t.Parallel() unpinnedRepo := "https://github.com/zarf-dev/zarf-public-test.git" - component := types.ZarfComponent{Repos: []string{ + component := v1alpha1.ZarfComponent{Repos: []string{ unpinnedRepo, "https://dev.azure.com/zarf-dev/zarf-public-test/_git/zarf-public-test@v0.0.1", }} @@ -37,7 +37,7 @@ func TestUnpinnedImageWarning(t *testing.T) { badImage := "badimage:badimage@@sha256:3fbc632167424a6d997e74f5" cosignSignature := "ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.sig" cosignAttestation := "ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.att" - component := types.ZarfComponent{Images: []string{ + component := v1alpha1.ZarfComponent{Images: []string{ unpinnedImage, "busybox:latest@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79", badImage, @@ -66,7 +66,7 @@ func TestUnpinnnedFileWarning(t *testing.T) { t.Parallel() fileURL := "http://example.com/file.zip" localFile := "local.txt" - zarfFiles := []types.ZarfFile{ + zarfFiles := []v1alpha1.ZarfFile{ { Source: fileURL, }, @@ -78,7 +78,7 @@ func TestUnpinnnedFileWarning(t *testing.T) { Shasum: "fake-shasum", }, } - component := types.ZarfComponent{Files: zarfFiles} + component := v1alpha1.ZarfComponent{Files: zarfFiles} findings := checkForUnpinnedFiles(component, 0) expected := []PackageFinding{ { diff --git a/src/pkg/lint/schema_test.go b/src/pkg/lint/schema_test.go index bb6adde541..385832bebf 100644 --- a/src/pkg/lint/schema_test.go +++ b/src/pkg/lint/schema_test.go @@ -11,8 +11,8 @@ import ( goyaml "github.com/goccy/go-yaml" "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/variables" - "github.com/zarf-dev/zarf/src/types" ) func TestZarfSchema(t *testing.T) { @@ -22,17 +22,17 @@ func TestZarfSchema(t *testing.T) { tests := []struct { name string - pkg types.ZarfPackage + pkg v1alpha1.ZarfPackage expectedSchemaStrings []string }{ { name: "valid package", - pkg: types.ZarfPackage{ - Kind: types.ZarfInitConfig, - Metadata: types.ZarfMetadata{ + pkg: v1alpha1.ZarfPackage{ + Kind: v1alpha1.ZarfInitConfig, + Metadata: v1alpha1.ZarfMetadata{ Name: "valid-name", }, - Components: []types.ZarfComponent{ + Components: []v1alpha1.ZarfComponent{ { Name: "valid-comp", }, @@ -42,11 +42,11 @@ func TestZarfSchema(t *testing.T) { }, { name: "no comp or kind", - pkg: types.ZarfPackage{ - Metadata: types.ZarfMetadata{ + pkg: v1alpha1.ZarfPackage{ + Metadata: v1alpha1.ZarfMetadata{ Name: "no-comp-or-kind", }, - Components: []types.ZarfComponent{}, + Components: []v1alpha1.ZarfComponent{}, }, expectedSchemaStrings: []string{ "kind: kind must be one of the following: \"ZarfInitConfig\", \"ZarfPackageConfig\"", @@ -55,35 +55,35 @@ func TestZarfSchema(t *testing.T) { }, { name: "invalid package", - pkg: types.ZarfPackage{ - Kind: types.ZarfInitConfig, - Metadata: types.ZarfMetadata{ + pkg: v1alpha1.ZarfPackage{ + Kind: v1alpha1.ZarfInitConfig, + Metadata: v1alpha1.ZarfMetadata{ Name: "-invalid-name", }, - Components: []types.ZarfComponent{ + Components: []v1alpha1.ZarfComponent{ { Name: "invalid-name", - Only: types.ZarfComponentOnlyTarget{ + Only: v1alpha1.ZarfComponentOnlyTarget{ LocalOS: "unsupportedOS", }, - Import: types.ZarfComponentImport{ - Path: fmt.Sprintf("start%send", types.ZarfPackageTemplatePrefix), - URL: fmt.Sprintf("oci://start%send", types.ZarfPackageTemplatePrefix), + Import: v1alpha1.ZarfComponentImport{ + Path: fmt.Sprintf("start%send", v1alpha1.ZarfPackageTemplatePrefix), + URL: fmt.Sprintf("oci://start%send", v1alpha1.ZarfPackageTemplatePrefix), }, }, { Name: "actions", - Actions: types.ZarfComponentActions{ - OnCreate: types.ZarfComponentActionSet{ - Before: []types.ZarfComponentAction{ + Actions: v1alpha1.ZarfComponentActions{ + OnCreate: v1alpha1.ZarfComponentActionSet{ + Before: []v1alpha1.ZarfComponentAction{ { Cmd: "echo 'invalid setVariable'", SetVariables: []variables.Variable{{Name: "not_uppercase"}}, }, }, }, - OnRemove: types.ZarfComponentActionSet{ - OnSuccess: []types.ZarfComponentAction{ + OnRemove: v1alpha1.ZarfComponentActionSet{ + OnSuccess: []v1alpha1.ZarfComponentAction{ { Cmd: "echo 'invalid setVariable'", SetVariables: []variables.Variable{{Name: "not_uppercase"}}, @@ -170,9 +170,9 @@ components: t.Run("test schema findings is created as expected", func(t *testing.T) { t.Parallel() - findings, err := getSchemaFindings(zarfSchema, types.ZarfPackage{ - Kind: types.ZarfInitConfig, - Metadata: types.ZarfMetadata{ + findings, err := getSchemaFindings(zarfSchema, v1alpha1.ZarfPackage{ + Kind: v1alpha1.ZarfInitConfig, + Metadata: v1alpha1.ZarfMetadata{ Name: "invalid", }, }) diff --git a/src/pkg/packager/actions/actions.go b/src/pkg/packager/actions/actions.go index ee66b84c39..afd882c2b0 100644 --- a/src/pkg/packager/actions/actions.go +++ b/src/pkg/packager/actions/actions.go @@ -13,16 +13,16 @@ import ( "time" "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/internal/packager/template" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/pkg/utils/exec" "github.com/zarf-dev/zarf/src/pkg/variables" - "github.com/zarf-dev/zarf/src/types" ) // Run runs all provided actions. -func Run(defaultCfg types.ZarfComponentActionDefaults, actions []types.ZarfComponentAction, variableConfig *variables.VariableConfig) error { +func Run(defaultCfg v1alpha1.ZarfComponentActionDefaults, actions []v1alpha1.ZarfComponentAction, variableConfig *variables.VariableConfig) error { if variableConfig == nil { variableConfig = template.GetZarfVariableConfig() } @@ -36,7 +36,7 @@ func Run(defaultCfg types.ZarfComponentActionDefaults, actions []types.ZarfCompo } // Run commands that a component has provided. -func runAction(defaultCfg types.ZarfComponentActionDefaults, action types.ZarfComponentAction, variableConfig *variables.VariableConfig) error { +func runAction(defaultCfg v1alpha1.ZarfComponentActionDefaults, action v1alpha1.ZarfComponentAction, variableConfig *variables.VariableConfig) error { var ( ctx context.Context cancel context.CancelFunc @@ -169,7 +169,7 @@ retryCmd: } // convertWaitToCmd will return the wait command if it exists, otherwise it will return the original command. -func convertWaitToCmd(wait types.ZarfComponentActionWait, timeout *int) (string, error) { +func convertWaitToCmd(wait v1alpha1.ZarfComponentActionWait, timeout *int) (string, error) { // Build the timeout string. timeoutString := fmt.Sprintf("--timeout %ds", *timeout) @@ -236,7 +236,7 @@ func actionCmdMutation(cmd string, shellPref exec.Shell) (string, error) { } // Merge the ActionSet defaults with the action config. -func actionGetCfg(cfg types.ZarfComponentActionDefaults, a types.ZarfComponentAction, vars map[string]*variables.TextTemplate) types.ZarfComponentActionDefaults { +func actionGetCfg(cfg v1alpha1.ZarfComponentActionDefaults, a v1alpha1.ZarfComponentAction, vars map[string]*variables.TextTemplate) v1alpha1.ZarfComponentActionDefaults { if a.Mute != nil { cfg.Mute = *a.Mute } @@ -275,7 +275,7 @@ func actionGetCfg(cfg types.ZarfComponentActionDefaults, a types.ZarfComponentAc return cfg } -func actionRun(ctx context.Context, cfg types.ZarfComponentActionDefaults, cmd string, shellPref exec.Shell, spinner *message.Spinner) (string, error) { +func actionRun(ctx context.Context, cfg v1alpha1.ZarfComponentActionDefaults, cmd string, shellPref exec.Shell, spinner *message.Spinner) (string, error) { shell, shellArgs := exec.GetOSShell(shellPref) message.Debugf("Running command in %s: %s", shell, cmd) diff --git a/src/pkg/packager/common_test.go b/src/pkg/packager/common_test.go index ac47544515..d2f4a7aa7a 100644 --- a/src/pkg/packager/common_test.go +++ b/src/pkg/packager/common_test.go @@ -13,6 +13,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config/lang" "github.com/zarf-dev/zarf/src/pkg/cluster" "github.com/zarf-dev/zarf/src/types" @@ -83,9 +84,9 @@ func TestValidatePackageArchitecture(t *testing.T) { Clientset: cs, }, cfg: &types.PackagerConfig{ - Pkg: types.ZarfPackage{ - Metadata: types.ZarfMetadata{Architecture: tt.pkgArch}, - Components: []types.ZarfComponent{ + Pkg: v1alpha1.ZarfPackage{ + Metadata: v1alpha1.ZarfMetadata{Architecture: tt.pkgArch}, + Components: []v1alpha1.ZarfComponent{ { Images: tt.images, }, diff --git a/src/pkg/packager/composer/list.go b/src/pkg/packager/composer/list.go index 0edb04d448..8d5531b85e 100644 --- a/src/pkg/packager/composer/list.go +++ b/src/pkg/packager/composer/list.go @@ -11,18 +11,18 @@ import ( "strings" "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/extensions/bigbang" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/packager/deprecated" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/pkg/variables" "github.com/zarf-dev/zarf/src/pkg/zoci" - "github.com/zarf-dev/zarf/src/types" ) // Node is a node in the import chain type Node struct { - types.ZarfComponent + v1alpha1.ZarfComponent index int @@ -95,7 +95,7 @@ func (ic *ImportChain) Tail() *Node { return ic.tail } -func (ic *ImportChain) append(c types.ZarfComponent, index int, originalPackageName string, +func (ic *ImportChain) append(c v1alpha1.ZarfComponent, index int, originalPackageName string, relativeToHead string, vars []variables.InteractiveVariable, consts []variables.Constant) { node := &Node{ ZarfComponent: c, @@ -120,7 +120,7 @@ func (ic *ImportChain) append(c types.ZarfComponent, index int, originalPackageN // NewImportChain creates a new import chain from a component // Returning the chain on error so we can have additional information to use during lint -func NewImportChain(ctx context.Context, head types.ZarfComponent, index int, originalPackageName, arch, flavor string) (*ImportChain, error) { +func NewImportChain(ctx context.Context, head v1alpha1.ZarfComponent, index int, originalPackageName, arch, flavor string) (*ImportChain, error) { ic := &ImportChain{} if arch == "" { return ic, fmt.Errorf("cannot build import chain: architecture must be provided") @@ -155,7 +155,7 @@ func NewImportChain(ctx context.Context, head types.ZarfComponent, index int, or return ic, fmt.Errorf("detected malformed import chain, cannot import local components from remote components") } - var pkg types.ZarfPackage + var pkg v1alpha1.ZarfPackage var relativeToHead string var importURL string @@ -193,7 +193,7 @@ func NewImportChain(ctx context.Context, head types.ZarfComponent, index int, or // 'found' and 'index' are parallel slices. Each element in found[x] corresponds to pkg[index[x]] // found[0] and pkg[index[0]] would be the same component for example - found := []types.ZarfComponent{} + found := []v1alpha1.ZarfComponent{} index := []int{} for i, component := range pkg.Components { if component.Name == name && CompatibleComponent(component, arch, flavor) { @@ -257,7 +257,7 @@ func (ic *ImportChain) String() string { } // Migrate performs migrations on the import chain -func (ic *ImportChain) Migrate(build types.ZarfBuildData) (warnings []string) { +func (ic *ImportChain) Migrate(build v1alpha1.ZarfBuildData) (warnings []string) { node := ic.head for node != nil { migrated, w := deprecated.MigrateComponent(build, node.ZarfComponent) @@ -274,7 +274,7 @@ func (ic *ImportChain) Migrate(build types.ZarfBuildData) (warnings []string) { // Compose merges the import chain into a single component // fixing paths, overriding metadata, etc -func (ic *ImportChain) Compose(ctx context.Context) (composed *types.ZarfComponent, err error) { +func (ic *ImportChain) Compose(ctx context.Context) (composed *v1alpha1.ZarfComponent, err error) { composed = &ic.tail.ZarfComponent if ic.tail.prev == nil { @@ -287,7 +287,7 @@ func (ic *ImportChain) Compose(ctx context.Context) (composed *types.ZarfCompone } // start with an empty component to compose into - composed = &types.ZarfComponent{} + composed = &v1alpha1.ZarfComponent{} // start overriding with the tail node node := ic.tail @@ -347,7 +347,7 @@ func (ic *ImportChain) MergeConstants(existing []variables.Constant) (merged []v } // CompatibleComponent determines if this component is compatible with the given create options -func CompatibleComponent(c types.ZarfComponent, arch, flavor string) bool { +func CompatibleComponent(c v1alpha1.ZarfComponent, arch, flavor string) bool { satisfiesArch := c.Only.Cluster.Architecture == "" || c.Only.Cluster.Architecture == arch satisfiesFlavor := c.Only.Flavor == "" || c.Only.Flavor == flavor return satisfiesArch && satisfiesFlavor diff --git a/src/pkg/packager/composer/list_test.go b/src/pkg/packager/composer/list_test.go index e720fdf57c..97a9790741 100644 --- a/src/pkg/packager/composer/list_test.go +++ b/src/pkg/packager/composer/list_test.go @@ -12,8 +12,8 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/variables" - "github.com/zarf-dev/zarf/src/types" "github.com/zarf-dev/zarf/src/types/extensions" ) @@ -22,20 +22,20 @@ func TestNewImportChain(t *testing.T) { tests := []struct { name string - head types.ZarfComponent + head v1alpha1.ZarfComponent arch string flavor string expectedErr string }{ { name: "No Architecture", - head: types.ZarfComponent{}, + head: v1alpha1.ZarfComponent{}, expectedErr: "architecture must be provided", }, { name: "Circular Import", - head: types.ZarfComponent{ - Import: types.ZarfComponentImport{ + head: v1alpha1.ZarfComponent{ + Import: v1alpha1.ZarfComponentImport{ Path: ".", }, }, @@ -69,36 +69,36 @@ func TestCompose(t *testing.T) { tests := []struct { name string ic *ImportChain - expectedComposed types.ZarfComponent + expectedComposed v1alpha1.ZarfComponent }{ { name: "Single Component", - ic: createChainFromSlice(t, []types.ZarfComponent{ + ic: createChainFromSlice(t, []v1alpha1.ZarfComponent{ { Name: "no-import", }, }), - expectedComposed: types.ZarfComponent{ + expectedComposed: v1alpha1.ZarfComponent{ Name: "no-import", }, }, { name: "Multiple Components", - ic: createChainFromSlice(t, []types.ZarfComponent{ + ic: createChainFromSlice(t, []v1alpha1.ZarfComponent{ createDummyComponent(t, "hello", firstDirectory, "hello"), createDummyComponent(t, "world", secondDirectory, "world"), createDummyComponent(t, "today", "", "hello"), }), - expectedComposed: types.ZarfComponent{ + expectedComposed: v1alpha1.ZarfComponent{ Name: "import-hello", // Files should always be appended with corrected directories - Files: []types.ZarfFile{ + Files: []v1alpha1.ZarfFile{ {Source: fmt.Sprintf("%s%stoday.txt", finalDirectory, string(os.PathSeparator))}, {Source: fmt.Sprintf("%s%sworld.txt", firstDirectory, string(os.PathSeparator))}, {Source: "hello.txt"}, }, // Charts should be merged if names match and appended if not with corrected directories - Charts: []types.ZarfChart{ + Charts: []v1alpha1.ZarfChart{ { Name: "hello", LocalPath: fmt.Sprintf("%s%schart", finalDirectory, string(os.PathSeparator)), @@ -116,7 +116,7 @@ func TestCompose(t *testing.T) { }, }, // Manifests should be merged if names match and appended if not with corrected directories - Manifests: []types.ZarfManifest{ + Manifests: []v1alpha1.ZarfManifest{ { Name: "hello", Files: []string{ @@ -132,85 +132,85 @@ func TestCompose(t *testing.T) { }, }, // DataInjections should always be appended with corrected directories - DataInjections: []types.ZarfDataInjection{ + DataInjections: []v1alpha1.ZarfDataInjection{ {Source: fmt.Sprintf("%s%stoday", finalDirectory, string(os.PathSeparator))}, {Source: fmt.Sprintf("%s%sworld", firstDirectory, string(os.PathSeparator))}, {Source: "hello"}, }, - Actions: types.ZarfComponentActions{ + Actions: v1alpha1.ZarfComponentActions{ // OnCreate actions should be appended with corrected directories that properly handle default directories - OnCreate: types.ZarfComponentActionSet{ - Defaults: types.ZarfComponentActionDefaults{ + OnCreate: v1alpha1.ZarfComponentActionSet{ + Defaults: v1alpha1.ZarfComponentActionDefaults{ Dir: "hello-dc", }, - Before: []types.ZarfComponentAction{ + Before: []v1alpha1.ZarfComponentAction{ {Cmd: "today-bc", Dir: &finalDirectoryActionDefault}, {Cmd: "world-bc", Dir: &secondDirectoryActionDefault}, {Cmd: "hello-bc", Dir: &firstDirectoryActionDefault}, }, - After: []types.ZarfComponentAction{ + After: []v1alpha1.ZarfComponentAction{ {Cmd: "today-ac", Dir: &finalDirectoryActionDefault}, {Cmd: "world-ac", Dir: &secondDirectoryActionDefault}, {Cmd: "hello-ac", Dir: &firstDirectoryActionDefault}, }, - OnSuccess: []types.ZarfComponentAction{ + OnSuccess: []v1alpha1.ZarfComponentAction{ {Cmd: "today-sc", Dir: &finalDirectoryActionDefault}, {Cmd: "world-sc", Dir: &secondDirectoryActionDefault}, {Cmd: "hello-sc", Dir: &firstDirectoryActionDefault}, }, - OnFailure: []types.ZarfComponentAction{ + OnFailure: []v1alpha1.ZarfComponentAction{ {Cmd: "today-fc", Dir: &finalDirectoryActionDefault}, {Cmd: "world-fc", Dir: &secondDirectoryActionDefault}, {Cmd: "hello-fc", Dir: &firstDirectoryActionDefault}, }, }, // OnDeploy actions should be appended without corrected directories - OnDeploy: types.ZarfComponentActionSet{ - Defaults: types.ZarfComponentActionDefaults{ + OnDeploy: v1alpha1.ZarfComponentActionSet{ + Defaults: v1alpha1.ZarfComponentActionDefaults{ Dir: "hello-dd", }, - Before: []types.ZarfComponentAction{ + Before: []v1alpha1.ZarfComponentAction{ {Cmd: "today-bd"}, {Cmd: "world-bd"}, {Cmd: "hello-bd"}, }, - After: []types.ZarfComponentAction{ + After: []v1alpha1.ZarfComponentAction{ {Cmd: "today-ad"}, {Cmd: "world-ad"}, {Cmd: "hello-ad"}, }, - OnSuccess: []types.ZarfComponentAction{ + OnSuccess: []v1alpha1.ZarfComponentAction{ {Cmd: "today-sd"}, {Cmd: "world-sd"}, {Cmd: "hello-sd"}, }, - OnFailure: []types.ZarfComponentAction{ + OnFailure: []v1alpha1.ZarfComponentAction{ {Cmd: "today-fd"}, {Cmd: "world-fd"}, {Cmd: "hello-fd"}, }, }, // OnRemove actions should be appended without corrected directories - OnRemove: types.ZarfComponentActionSet{ - Defaults: types.ZarfComponentActionDefaults{ + OnRemove: v1alpha1.ZarfComponentActionSet{ + Defaults: v1alpha1.ZarfComponentActionDefaults{ Dir: "hello-dr", }, - Before: []types.ZarfComponentAction{ + Before: []v1alpha1.ZarfComponentAction{ {Cmd: "today-br"}, {Cmd: "world-br"}, {Cmd: "hello-br"}, }, - After: []types.ZarfComponentAction{ + After: []v1alpha1.ZarfComponentAction{ {Cmd: "today-ar"}, {Cmd: "world-ar"}, {Cmd: "hello-ar"}, }, - OnSuccess: []types.ZarfComponentAction{ + OnSuccess: []v1alpha1.ZarfComponentAction{ {Cmd: "today-sr"}, {Cmd: "world-sr"}, {Cmd: "hello-sr"}, }, - OnFailure: []types.ZarfComponentAction{ + OnFailure: []v1alpha1.ZarfComponentAction{ {Cmd: "today-fr"}, {Cmd: "world-fr"}, {Cmd: "hello-fr"}, @@ -424,7 +424,7 @@ func TestMerging(t *testing.T) { } } -func createChainFromSlice(t *testing.T, components []types.ZarfComponent) (ic *ImportChain) { +func createChainFromSlice(t *testing.T, components []v1alpha1.ZarfComponent) (ic *ImportChain) { t.Helper() ic = &ImportChain{} @@ -441,20 +441,20 @@ func createChainFromSlice(t *testing.T, components []types.ZarfComponent) (ic *I return ic } -func createDummyComponent(t *testing.T, name, importDir, subName string) types.ZarfComponent { +func createDummyComponent(t *testing.T, name, importDir, subName string) v1alpha1.ZarfComponent { t.Helper() - return types.ZarfComponent{ + return v1alpha1.ZarfComponent{ Name: fmt.Sprintf("import-%s", name), - Import: types.ZarfComponentImport{ + Import: v1alpha1.ZarfComponentImport{ Path: importDir, }, - Files: []types.ZarfFile{ + Files: []v1alpha1.ZarfFile{ { Source: fmt.Sprintf("%s.txt", name), }, }, - Charts: []types.ZarfChart{ + Charts: []v1alpha1.ZarfChart{ { Name: subName, LocalPath: "chart", @@ -463,7 +463,7 @@ func createDummyComponent(t *testing.T, name, importDir, subName string) types.Z }, }, }, - Manifests: []types.ZarfManifest{ + Manifests: []v1alpha1.ZarfManifest{ { Name: subName, Files: []string{ @@ -471,60 +471,60 @@ func createDummyComponent(t *testing.T, name, importDir, subName string) types.Z }, }, }, - DataInjections: []types.ZarfDataInjection{ + DataInjections: []v1alpha1.ZarfDataInjection{ { Source: name, }, }, - Actions: types.ZarfComponentActions{ - OnCreate: types.ZarfComponentActionSet{ - Defaults: types.ZarfComponentActionDefaults{ + Actions: v1alpha1.ZarfComponentActions{ + OnCreate: v1alpha1.ZarfComponentActionSet{ + Defaults: v1alpha1.ZarfComponentActionDefaults{ Dir: name + "-dc", }, - Before: []types.ZarfComponentAction{ + Before: []v1alpha1.ZarfComponentAction{ {Cmd: name + "-bc"}, }, - After: []types.ZarfComponentAction{ + After: []v1alpha1.ZarfComponentAction{ {Cmd: name + "-ac"}, }, - OnSuccess: []types.ZarfComponentAction{ + OnSuccess: []v1alpha1.ZarfComponentAction{ {Cmd: name + "-sc"}, }, - OnFailure: []types.ZarfComponentAction{ + OnFailure: []v1alpha1.ZarfComponentAction{ {Cmd: name + "-fc"}, }, }, - OnDeploy: types.ZarfComponentActionSet{ - Defaults: types.ZarfComponentActionDefaults{ + OnDeploy: v1alpha1.ZarfComponentActionSet{ + Defaults: v1alpha1.ZarfComponentActionDefaults{ Dir: name + "-dd", }, - Before: []types.ZarfComponentAction{ + Before: []v1alpha1.ZarfComponentAction{ {Cmd: name + "-bd"}, }, - After: []types.ZarfComponentAction{ + After: []v1alpha1.ZarfComponentAction{ {Cmd: name + "-ad"}, }, - OnSuccess: []types.ZarfComponentAction{ + OnSuccess: []v1alpha1.ZarfComponentAction{ {Cmd: name + "-sd"}, }, - OnFailure: []types.ZarfComponentAction{ + OnFailure: []v1alpha1.ZarfComponentAction{ {Cmd: name + "-fd"}, }, }, - OnRemove: types.ZarfComponentActionSet{ - Defaults: types.ZarfComponentActionDefaults{ + OnRemove: v1alpha1.ZarfComponentActionSet{ + Defaults: v1alpha1.ZarfComponentActionDefaults{ Dir: name + "-dr", }, - Before: []types.ZarfComponentAction{ + Before: []v1alpha1.ZarfComponentAction{ {Cmd: name + "-br"}, }, - After: []types.ZarfComponentAction{ + After: []v1alpha1.ZarfComponentAction{ {Cmd: name + "-ar"}, }, - OnSuccess: []types.ZarfComponentAction{ + OnSuccess: []v1alpha1.ZarfComponentAction{ {Cmd: name + "-sr"}, }, - OnFailure: []types.ZarfComponentAction{ + OnFailure: []v1alpha1.ZarfComponentAction{ {Cmd: name + "-fr"}, }, }, diff --git a/src/pkg/packager/composer/override.go b/src/pkg/packager/composer/override.go index feb4b4b6f3..d5f96559cb 100644 --- a/src/pkg/packager/composer/override.go +++ b/src/pkg/packager/composer/override.go @@ -7,10 +7,10 @@ package composer import ( "fmt" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) -func overrideMetadata(c *types.ZarfComponent, override types.ZarfComponent) error { +func overrideMetadata(c *v1alpha1.ZarfComponent, override v1alpha1.ZarfComponent) error { c.Name = override.Name c.Default = override.Default c.Required = override.Required @@ -31,7 +31,7 @@ func overrideMetadata(c *types.ZarfComponent, override types.ZarfComponent) erro return nil } -func overrideDeprecated(c *types.ZarfComponent, override types.ZarfComponent) { +func overrideDeprecated(c *v1alpha1.ZarfComponent, override v1alpha1.ZarfComponent) { // Override cosign key path if it was provided. if override.DeprecatedCosignKeyPath != "" { c.DeprecatedCosignKeyPath = override.DeprecatedCosignKeyPath @@ -54,7 +54,7 @@ func overrideDeprecated(c *types.ZarfComponent, override types.ZarfComponent) { } } -func overrideActions(c *types.ZarfComponent, override types.ZarfComponent) { +func overrideActions(c *v1alpha1.ZarfComponent, override v1alpha1.ZarfComponent) { // Merge create actions. c.Actions.OnCreate.Defaults = override.Actions.OnCreate.Defaults c.Actions.OnCreate.Before = append(c.Actions.OnCreate.Before, override.Actions.OnCreate.Before...) @@ -77,7 +77,7 @@ func overrideActions(c *types.ZarfComponent, override types.ZarfComponent) { c.Actions.OnRemove.OnSuccess = append(c.Actions.OnRemove.OnSuccess, override.Actions.OnRemove.OnSuccess...) } -func overrideResources(c *types.ZarfComponent, override types.ZarfComponent) { +func overrideResources(c *v1alpha1.ZarfComponent, override v1alpha1.ZarfComponent) { c.DataInjections = append(c.DataInjections, override.DataInjections...) c.Files = append(c.Files, override.Files...) c.Images = append(c.Images, override.Images...) diff --git a/src/pkg/packager/composer/pathfixer.go b/src/pkg/packager/composer/pathfixer.go index f13537dfd9..b2372c7389 100644 --- a/src/pkg/packager/composer/pathfixer.go +++ b/src/pkg/packager/composer/pathfixer.go @@ -8,7 +8,7 @@ import ( "path/filepath" "github.com/defenseunicorns/pkg/helpers/v2" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) func makePathRelativeTo(path, relativeTo string) string { @@ -19,7 +19,7 @@ func makePathRelativeTo(path, relativeTo string) string { return filepath.Join(relativeTo, path) } -func fixPaths(child *types.ZarfComponent, relativeToHead string) { +func fixPaths(child *v1alpha1.ZarfComponent, relativeToHead string) { for fileIdx, file := range child.Files { composed := makePathRelativeTo(file.Source, relativeToHead) child.Files[fileIdx].Source = composed @@ -71,7 +71,7 @@ func fixPaths(child *types.ZarfComponent, relativeToHead string) { } // fixActionPaths takes a slice of actions and mutates the Dir to be relative to the head node -func fixActionPaths(actions []types.ZarfComponentAction, defaultDir, relativeToHead string) []types.ZarfComponentAction { +func fixActionPaths(actions []v1alpha1.ZarfComponentAction, defaultDir, relativeToHead string) []v1alpha1.ZarfComponentAction { for actionIdx, action := range actions { var composed string if action.Dir != nil { diff --git a/src/pkg/packager/creator/compose.go b/src/pkg/packager/creator/compose.go index bbd1325b31..fa63b218d6 100644 --- a/src/pkg/packager/creator/compose.go +++ b/src/pkg/packager/creator/compose.go @@ -7,13 +7,13 @@ package creator import ( "context" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/packager/composer" - "github.com/zarf-dev/zarf/src/types" ) // ComposeComponents composes components and their dependencies into a single Zarf package using an import chain. -func ComposeComponents(ctx context.Context, pkg types.ZarfPackage, flavor string) (types.ZarfPackage, []string, error) { - components := []types.ZarfComponent{} +func ComposeComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, flavor string) (v1alpha1.ZarfPackage, []string, error) { + components := []v1alpha1.ZarfComponent{} warnings := []string{} pkgVars := pkg.Variables @@ -34,7 +34,7 @@ func ComposeComponents(ctx context.Context, pkg types.ZarfPackage, flavor string // build the import chain chain, err := composer.NewImportChain(ctx, component, i, pkg.Metadata.Name, arch, flavor) if err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } // migrate any deprecated component configurations now @@ -44,7 +44,7 @@ func ComposeComponents(ctx context.Context, pkg types.ZarfPackage, flavor string // get the composed component composed, err := chain.Compose(ctx) if err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } components = append(components, *composed) diff --git a/src/pkg/packager/creator/compose_test.go b/src/pkg/packager/creator/compose_test.go index a4dd2fdf9e..711e9baf7b 100644 --- a/src/pkg/packager/creator/compose_test.go +++ b/src/pkg/packager/creator/compose_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) func TestComposeComponents(t *testing.T) { @@ -17,36 +17,36 @@ func TestComposeComponents(t *testing.T) { tests := []struct { name string - pkg types.ZarfPackage + pkg v1alpha1.ZarfPackage flavor string - expectedPkg types.ZarfPackage + expectedPkg v1alpha1.ZarfPackage expectedErr string }{ { name: "filter by architecture match", - pkg: types.ZarfPackage{ - Metadata: types.ZarfMetadata{Architecture: "amd64"}, - Components: []types.ZarfComponent{ + pkg: v1alpha1.ZarfPackage{ + Metadata: v1alpha1.ZarfMetadata{Architecture: "amd64"}, + Components: []v1alpha1.ZarfComponent{ { Name: "component1", - Only: types.ZarfComponentOnlyTarget{ - Cluster: types.ZarfComponentOnlyCluster{ + Only: v1alpha1.ZarfComponentOnlyTarget{ + Cluster: v1alpha1.ZarfComponentOnlyCluster{ Architecture: "amd64", }, }, }, { Name: "component2", - Only: types.ZarfComponentOnlyTarget{ - Cluster: types.ZarfComponentOnlyCluster{ + Only: v1alpha1.ZarfComponentOnlyTarget{ + Cluster: v1alpha1.ZarfComponentOnlyCluster{ Architecture: "amd64", }, }, }, }, }, - expectedPkg: types.ZarfPackage{ - Components: []types.ZarfComponent{ + expectedPkg: v1alpha1.ZarfPackage{ + Components: []v1alpha1.ZarfComponent{ {Name: "component1"}, {Name: "component2"}, }, @@ -55,29 +55,29 @@ func TestComposeComponents(t *testing.T) { }, { name: "filter by architecture mismatch", - pkg: types.ZarfPackage{ - Metadata: types.ZarfMetadata{Architecture: "amd64"}, - Components: []types.ZarfComponent{ + pkg: v1alpha1.ZarfPackage{ + Metadata: v1alpha1.ZarfMetadata{Architecture: "amd64"}, + Components: []v1alpha1.ZarfComponent{ { Name: "component1", - Only: types.ZarfComponentOnlyTarget{ - Cluster: types.ZarfComponentOnlyCluster{ + Only: v1alpha1.ZarfComponentOnlyTarget{ + Cluster: v1alpha1.ZarfComponentOnlyCluster{ Architecture: "amd64", }, }, }, { Name: "component2", - Only: types.ZarfComponentOnlyTarget{ - Cluster: types.ZarfComponentOnlyCluster{ + Only: v1alpha1.ZarfComponentOnlyTarget{ + Cluster: v1alpha1.ZarfComponentOnlyCluster{ Architecture: "arm64", }, }, }, }, }, - expectedPkg: types.ZarfPackage{ - Components: []types.ZarfComponent{ + expectedPkg: v1alpha1.ZarfPackage{ + Components: []v1alpha1.ZarfComponent{ {Name: "component1"}, }, }, @@ -85,26 +85,26 @@ func TestComposeComponents(t *testing.T) { }, { name: "filter by flavor match", - pkg: types.ZarfPackage{ - Metadata: types.ZarfMetadata{Architecture: "amd64"}, - Components: []types.ZarfComponent{ + pkg: v1alpha1.ZarfPackage{ + Metadata: v1alpha1.ZarfMetadata{Architecture: "amd64"}, + Components: []v1alpha1.ZarfComponent{ { Name: "component1", - Only: types.ZarfComponentOnlyTarget{ + Only: v1alpha1.ZarfComponentOnlyTarget{ Flavor: "default", }, }, { Name: "component2", - Only: types.ZarfComponentOnlyTarget{ + Only: v1alpha1.ZarfComponentOnlyTarget{ Flavor: "default", }, }, }, }, flavor: "default", - expectedPkg: types.ZarfPackage{ - Components: []types.ZarfComponent{ + expectedPkg: v1alpha1.ZarfPackage{ + Components: []v1alpha1.ZarfComponent{ {Name: "component1"}, {Name: "component2"}, }, @@ -113,26 +113,26 @@ func TestComposeComponents(t *testing.T) { }, { name: "filter by flavor mismatch", - pkg: types.ZarfPackage{ - Metadata: types.ZarfMetadata{Architecture: "amd64"}, - Components: []types.ZarfComponent{ + pkg: v1alpha1.ZarfPackage{ + Metadata: v1alpha1.ZarfMetadata{Architecture: "amd64"}, + Components: []v1alpha1.ZarfComponent{ { Name: "component1", - Only: types.ZarfComponentOnlyTarget{ + Only: v1alpha1.ZarfComponentOnlyTarget{ Flavor: "default", }, }, { Name: "component2", - Only: types.ZarfComponentOnlyTarget{ + Only: v1alpha1.ZarfComponentOnlyTarget{ Flavor: "special", }, }, }, }, flavor: "default", - expectedPkg: types.ZarfPackage{ - Components: []types.ZarfComponent{ + expectedPkg: v1alpha1.ZarfPackage{ + Components: []v1alpha1.ZarfComponent{ {Name: "component1"}, }, }, @@ -140,18 +140,18 @@ func TestComposeComponents(t *testing.T) { }, { name: "no architecture set error", - pkg: types.ZarfPackage{ - Components: []types.ZarfComponent{ + pkg: v1alpha1.ZarfPackage{ + Components: []v1alpha1.ZarfComponent{ { Name: "component1", - Only: types.ZarfComponentOnlyTarget{ + Only: v1alpha1.ZarfComponentOnlyTarget{ Flavor: "default", }, }, }, }, flavor: "default", - expectedPkg: types.ZarfPackage{}, + expectedPkg: v1alpha1.ZarfPackage{}, expectedErr: "cannot build import chain: architecture must be provided", }, } diff --git a/src/pkg/packager/creator/creator.go b/src/pkg/packager/creator/creator.go index 34e511458f..d136ee7d86 100644 --- a/src/pkg/packager/creator/creator.go +++ b/src/pkg/packager/creator/creator.go @@ -7,13 +7,13 @@ package creator import ( "context" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/layout" - "github.com/zarf-dev/zarf/src/types" ) // Creator is an interface for creating Zarf packages. type Creator interface { - LoadPackageDefinition(ctx context.Context, src *layout.PackagePaths) (pkg types.ZarfPackage, warnings []string, err error) - Assemble(ctx context.Context, dst *layout.PackagePaths, components []types.ZarfComponent, arch string) error - Output(ctx context.Context, dst *layout.PackagePaths, pkg *types.ZarfPackage) error + LoadPackageDefinition(ctx context.Context, src *layout.PackagePaths) (pkg v1alpha1.ZarfPackage, warnings []string, err error) + Assemble(ctx context.Context, dst *layout.PackagePaths, components []v1alpha1.ZarfComponent, arch string) error + Output(ctx context.Context, dst *layout.PackagePaths, pkg *v1alpha1.ZarfPackage) error } diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index 99b0f572b4..41e96e018b 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -18,6 +18,7 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/defenseunicorns/pkg/oci" "github.com/mholt/archiver/v3" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/config/lang" "github.com/zarf-dev/zarf/src/extensions/bigbang" @@ -61,10 +62,10 @@ func NewPackageCreator(createOpts types.ZarfCreateOptions, cwd string) *PackageC } // LoadPackageDefinition loads and configures a zarf.yaml file during package create. -func (pc *PackageCreator) LoadPackageDefinition(ctx context.Context, src *layout.PackagePaths) (pkg types.ZarfPackage, warnings []string, err error) { +func (pc *PackageCreator) LoadPackageDefinition(ctx context.Context, src *layout.PackagePaths) (pkg v1alpha1.ZarfPackage, warnings []string, err error) { pkg, warnings, err = src.ReadZarfYAML() if err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } pkg.Metadata.Architecture = config.GetArch(pkg.Metadata.Architecture) @@ -72,14 +73,14 @@ func (pc *PackageCreator) LoadPackageDefinition(ctx context.Context, src *layout // Compose components into a single zarf.yaml file pkg, composeWarnings, err := ComposeComponents(ctx, pkg, pc.createOpts.Flavor) if err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } warnings = append(warnings, composeWarnings...) // After components are composed, template the active package. pkg, templateWarnings, err := FillActiveTemplate(pkg, pc.createOpts.SetVariables) if err != nil { - return types.ZarfPackage{}, nil, fmt.Errorf("unable to fill values in template: %w", err) + return v1alpha1.ZarfPackage{}, nil, fmt.Errorf("unable to fill values in template: %w", err) } warnings = append(warnings, templateWarnings...) @@ -87,7 +88,7 @@ func (pc *PackageCreator) LoadPackageDefinition(ctx context.Context, src *layout // After templates are filled process any create extensions pkg.Components, err = pc.processExtensions(ctx, pkg.Components, src, pkg.Metadata.YOLO) if err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } // If we are creating a differential package, remove duplicate images and repos. @@ -96,37 +97,37 @@ func (pc *PackageCreator) LoadPackageDefinition(ctx context.Context, src *layout diffData, err := loadDifferentialData(ctx, pc.createOpts.DifferentialPackagePath) if err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } pkg.Build.DifferentialPackageVersion = diffData.DifferentialPackageVersion versionsMatch := diffData.DifferentialPackageVersion == pkg.Metadata.Version if versionsMatch { - return types.ZarfPackage{}, nil, errors.New(lang.PkgCreateErrDifferentialSameVersion) + return v1alpha1.ZarfPackage{}, nil, errors.New(lang.PkgCreateErrDifferentialSameVersion) } noVersionSet := diffData.DifferentialPackageVersion == "" || pkg.Metadata.Version == "" if noVersionSet { - return types.ZarfPackage{}, nil, errors.New(lang.PkgCreateErrDifferentialNoVersion) + return v1alpha1.ZarfPackage{}, nil, errors.New(lang.PkgCreateErrDifferentialNoVersion) } filter := filters.ByDifferentialData(diffData) pkg.Components, err = filter.Apply(pkg) if err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } } if err := Validate(pkg, pc.createOpts.BaseDir); err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } return pkg, warnings, nil } // Assemble assembles all of the package assets into Zarf's tmp directory layout. -func (pc *PackageCreator) Assemble(ctx context.Context, dst *layout.PackagePaths, components []types.ZarfComponent, arch string) error { +func (pc *PackageCreator) Assemble(ctx context.Context, dst *layout.PackagePaths, components []v1alpha1.ZarfComponent, arch string) error { var imageList []transform.Image skipSBOMFlagUsed := pc.createOpts.SkipSBOM @@ -235,7 +236,7 @@ func (pc *PackageCreator) Assemble(ctx context.Context, dst *layout.PackagePaths // // - writes the Zarf package as a tarball to a local directory, // or an OCI registry based on the --output flag -func (pc *PackageCreator) Output(ctx context.Context, dst *layout.PackagePaths, pkg *types.ZarfPackage) (err error) { +func (pc *PackageCreator) Output(ctx context.Context, dst *layout.PackagePaths, pkg *v1alpha1.ZarfPackage) (err error) { // Process the component directories into compressed tarballs // NOTE: This is purposefully being done after the SBOM cataloging for _, component := range pkg.Components { @@ -329,7 +330,7 @@ func (pc *PackageCreator) Output(ctx context.Context, dst *layout.PackagePaths, return nil } -func (pc *PackageCreator) processExtensions(ctx context.Context, components []types.ZarfComponent, layout *layout.PackagePaths, isYOLO bool) (processedComponents []types.ZarfComponent, err error) { +func (pc *PackageCreator) processExtensions(ctx context.Context, components []v1alpha1.ZarfComponent, layout *layout.PackagePaths, isYOLO bool) (processedComponents []v1alpha1.ZarfComponent, err error) { // Create component paths and process extensions for each component. for _, c := range components { componentPaths, err := layout.Components.Create(c) @@ -350,7 +351,7 @@ func (pc *PackageCreator) processExtensions(ctx context.Context, components []ty return processedComponents, nil } -func (pc *PackageCreator) addComponent(ctx context.Context, component types.ZarfComponent, dst *layout.PackagePaths) error { +func (pc *PackageCreator) addComponent(ctx context.Context, component v1alpha1.ZarfComponent, dst *layout.PackagePaths) error { message.HeaderInfof("📦 %s COMPONENT", strings.ToUpper(component.Name)) componentPaths, err := dst.Components.Create(component) @@ -528,7 +529,7 @@ func (pc *PackageCreator) addComponent(ctx context.Context, component types.Zarf return nil } -func (pc *PackageCreator) getFilesToSBOM(component types.ZarfComponent, dst *layout.PackagePaths) (*layout.ComponentSBOM, error) { +func (pc *PackageCreator) getFilesToSBOM(component v1alpha1.ZarfComponent, dst *layout.PackagePaths) (*layout.ComponentSBOM, error) { componentPaths, err := dst.Components.Create(component) if err != nil { return nil, err diff --git a/src/pkg/packager/creator/skeleton.go b/src/pkg/packager/creator/skeleton.go index c7b2d3d706..218830b75f 100644 --- a/src/pkg/packager/creator/skeleton.go +++ b/src/pkg/packager/creator/skeleton.go @@ -14,6 +14,7 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/mholt/archiver/v3" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/config/lang" "github.com/zarf-dev/zarf/src/extensions/bigbang" @@ -43,10 +44,10 @@ func NewSkeletonCreator(createOpts types.ZarfCreateOptions, publishOpts types.Za } // LoadPackageDefinition loads and configure a zarf.yaml file when creating and publishing a skeleton package. -func (sc *SkeletonCreator) LoadPackageDefinition(ctx context.Context, src *layout.PackagePaths) (pkg types.ZarfPackage, warnings []string, err error) { +func (sc *SkeletonCreator) LoadPackageDefinition(ctx context.Context, src *layout.PackagePaths) (pkg v1alpha1.ZarfPackage, warnings []string, err error) { pkg, warnings, err = src.ReadZarfYAML() if err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } pkg.Metadata.Architecture = config.GetArch() @@ -54,7 +55,7 @@ func (sc *SkeletonCreator) LoadPackageDefinition(ctx context.Context, src *layou // Compose components into a single zarf.yaml file pkg, composeWarnings, err := ComposeComponents(ctx, pkg, sc.createOpts.Flavor) if err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } pkg.Metadata.Architecture = zoci.SkeletonArch @@ -63,7 +64,7 @@ func (sc *SkeletonCreator) LoadPackageDefinition(ctx context.Context, src *layou pkg.Components, err = sc.processExtensions(pkg.Components, src) if err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } for _, warning := range warnings { @@ -71,7 +72,7 @@ func (sc *SkeletonCreator) LoadPackageDefinition(ctx context.Context, src *layou } if err := Validate(pkg, sc.createOpts.BaseDir); err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } return pkg, warnings, nil @@ -80,7 +81,7 @@ func (sc *SkeletonCreator) LoadPackageDefinition(ctx context.Context, src *layou // Assemble updates all components of the loaded Zarf package with necessary modifications for package assembly. // // It processes each component to ensure correct structure and resource locations. -func (sc *SkeletonCreator) Assemble(_ context.Context, dst *layout.PackagePaths, components []types.ZarfComponent, _ string) error { +func (sc *SkeletonCreator) Assemble(_ context.Context, dst *layout.PackagePaths, components []v1alpha1.ZarfComponent, _ string) error { for _, component := range components { c, err := sc.addComponent(component, dst) if err != nil { @@ -101,7 +102,7 @@ func (sc *SkeletonCreator) Assemble(_ context.Context, dst *layout.PackagePaths, // - writes the loaded zarf.yaml to disk // // - signs the package -func (sc *SkeletonCreator) Output(_ context.Context, dst *layout.PackagePaths, pkg *types.ZarfPackage) (err error) { +func (sc *SkeletonCreator) Output(_ context.Context, dst *layout.PackagePaths, pkg *v1alpha1.ZarfPackage) (err error) { for _, component := range pkg.Components { if err := dst.Components.Archive(component, false); err != nil { return err @@ -125,7 +126,7 @@ func (sc *SkeletonCreator) Output(_ context.Context, dst *layout.PackagePaths, p return dst.SignPackage(sc.publishOpts.SigningKeyPath, sc.publishOpts.SigningKeyPassword, !config.CommonOptions.Confirm) } -func (sc *SkeletonCreator) processExtensions(components []types.ZarfComponent, layout *layout.PackagePaths) (processedComponents []types.ZarfComponent, err error) { +func (sc *SkeletonCreator) processExtensions(components []v1alpha1.ZarfComponent, layout *layout.PackagePaths) (processedComponents []v1alpha1.ZarfComponent, err error) { // Create component paths and process extensions for each component. for _, c := range components { componentPaths, err := layout.Components.Create(c) @@ -146,7 +147,7 @@ func (sc *SkeletonCreator) processExtensions(components []types.ZarfComponent, l return processedComponents, nil } -func (sc *SkeletonCreator) addComponent(component types.ZarfComponent, dst *layout.PackagePaths) (updatedComponent *types.ZarfComponent, err error) { +func (sc *SkeletonCreator) addComponent(component v1alpha1.ZarfComponent, dst *layout.PackagePaths) (updatedComponent *v1alpha1.ZarfComponent, err error) { message.HeaderInfof("📦 %s COMPONENT", strings.ToUpper(component.Name)) updatedComponent = &component @@ -168,7 +169,7 @@ func (sc *SkeletonCreator) addComponent(component types.ZarfComponent, dst *layo // TODO: (@WSTARR) Shim the skeleton component's create action dirs to be empty. This prevents actions from failing by cd'ing into directories that will be flattened. updatedComponent.Actions.OnCreate.Defaults.Dir = "" - resetActions := func(actions []types.ZarfComponentAction) []types.ZarfComponentAction { + resetActions := func(actions []v1alpha1.ZarfComponentAction) []v1alpha1.ZarfComponentAction { for idx := range actions { actions[idx].Dir = nil } diff --git a/src/pkg/packager/creator/template.go b/src/pkg/packager/creator/template.go index 5a06651c53..65d0d56c99 100644 --- a/src/pkg/packager/creator/template.go +++ b/src/pkg/packager/creator/template.go @@ -7,16 +7,16 @@ package creator import ( "fmt" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/config/lang" "github.com/zarf-dev/zarf/src/pkg/interactive" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/pkg/variables" - "github.com/zarf-dev/zarf/src/types" ) // FillActiveTemplate merges user-specified variables into the configuration templates of a zarf.yaml. -func FillActiveTemplate(pkg types.ZarfPackage, setVariables map[string]string) (types.ZarfPackage, []string, error) { +func FillActiveTemplate(pkg v1alpha1.ZarfPackage, setVariables map[string]string) (v1alpha1.ZarfPackage, []string, error) { templateMap := map[string]string{} warnings := []string{} @@ -54,22 +54,22 @@ func FillActiveTemplate(pkg types.ZarfPackage, setVariables map[string]string) ( // update the component templates on the package if err := ReloadComponentTemplatesInPackage(&pkg); err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } - if err := promptAndSetTemplate(types.ZarfPackageTemplatePrefix, false); err != nil { - return types.ZarfPackage{}, nil, err + if err := promptAndSetTemplate(v1alpha1.ZarfPackageTemplatePrefix, false); err != nil { + return v1alpha1.ZarfPackage{}, nil, err } // [DEPRECATION] Set the Package Variable syntax as well for backward compatibility - if err := promptAndSetTemplate(types.ZarfPackageVariablePrefix, true); err != nil { - return types.ZarfPackage{}, nil, err + if err := promptAndSetTemplate(v1alpha1.ZarfPackageVariablePrefix, true); err != nil { + return v1alpha1.ZarfPackage{}, nil, err } // Add special variable for the current package architecture - templateMap[types.ZarfPackageArch] = pkg.Metadata.Architecture + templateMap[v1alpha1.ZarfPackageArch] = pkg.Metadata.Architecture if err := utils.ReloadYamlTemplate(&pkg, templateMap); err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } return pkg, warnings, nil @@ -77,9 +77,9 @@ func FillActiveTemplate(pkg types.ZarfPackage, setVariables map[string]string) ( // ReloadComponentTemplate appends ###ZARF_COMPONENT_NAME### for the component, assigns value, and reloads // Any instance of ###ZARF_COMPONENT_NAME### within a component will be replaced with that components name -func ReloadComponentTemplate(component *types.ZarfComponent) error { +func ReloadComponentTemplate(component *v1alpha1.ZarfComponent) error { mappings := map[string]string{} - mappings[types.ZarfComponentName] = component.Name + mappings[v1alpha1.ZarfComponentName] = component.Name err := utils.ReloadYamlTemplate(component, mappings) if err != nil { return err @@ -88,7 +88,7 @@ func ReloadComponentTemplate(component *types.ZarfComponent) error { } // ReloadComponentTemplatesInPackage appends ###ZARF_COMPONENT_NAME### for each component, assigns value, and reloads -func ReloadComponentTemplatesInPackage(zarfPackage *types.ZarfPackage) error { +func ReloadComponentTemplatesInPackage(zarfPackage *v1alpha1.ZarfPackage) error { // iterate through components to and find all ###ZARF_COMPONENT_NAME, assign to component Name and value for i := range zarfPackage.Components { if err := ReloadComponentTemplate(&zarfPackage.Components[i]); err != nil { diff --git a/src/pkg/packager/creator/utils.go b/src/pkg/packager/creator/utils.go index 4d72edb59f..fdf1da49f6 100644 --- a/src/pkg/packager/creator/utils.go +++ b/src/pkg/packager/creator/utils.go @@ -10,6 +10,7 @@ import ( "runtime" "time" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/packager/deprecated" @@ -18,7 +19,7 @@ import ( // Validate errors if a package violates the schema or any runtime validations // This must be run while in the parent directory of the zarf.yaml being validated -func Validate(pkg types.ZarfPackage, baseDir string) error { +func Validate(pkg v1alpha1.ZarfPackage, baseDir string) error { if err := pkg.Validate(); err != nil { return fmt.Errorf("package validation failed: %w", err) } @@ -37,7 +38,7 @@ func Validate(pkg types.ZarfPackage, baseDir string) error { } // recordPackageMetadata records various package metadata during package create. -func recordPackageMetadata(pkg *types.ZarfPackage, createOpts types.ZarfCreateOptions) error { +func recordPackageMetadata(pkg *v1alpha1.ZarfPackage, createOpts types.ZarfCreateOptions) error { now := time.Now() // Just use $USER env variable to avoid CGO issue. // https://groups.google.com/g/golang-dev/c/ZFDDX3ZiJ84. diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 2f7304580b..c3c9bcdf48 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -24,6 +24,7 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/internal/packager/git" "github.com/zarf-dev/zarf/src/internal/packager/helm" @@ -230,7 +231,7 @@ func (p *Packager) deployComponents(ctx context.Context) (deployedComponents []t return deployedComponents, nil } -func (p *Packager) deployInitComponent(ctx context.Context, component types.ZarfComponent) (charts []types.InstalledChart, err error) { +func (p *Packager) deployInitComponent(ctx context.Context, component v1alpha1.ZarfComponent) (charts []types.InstalledChart, err error) { hasExternalRegistry := p.cfg.InitOpts.RegistryInfo.Address != "" isSeedRegistry := component.Name == "zarf-seed-registry" isRegistry := component.Name == "zarf-registry" @@ -284,7 +285,7 @@ func (p *Packager) deployInitComponent(ctx context.Context, component types.Zarf } // Deploy a Zarf Component. -func (p *Packager) deployComponent(ctx context.Context, component types.ZarfComponent, noImgChecksum bool, noImgPush bool) (charts []types.InstalledChart, err error) { +func (p *Packager) deployComponent(ctx context.Context, component v1alpha1.ZarfComponent, noImgChecksum bool, noImgPush bool) (charts []types.InstalledChart, err error) { // Toggles for general deploy operations componentPath := p.layout.Components.Dirs[component.Name] @@ -370,7 +371,7 @@ func (p *Packager) deployComponent(ctx context.Context, component types.ZarfComp } // Move files onto the host of the machine performing the deployment. -func (p *Packager) processComponentFiles(component types.ZarfComponent, pkgLocation string) error { +func (p *Packager) processComponentFiles(component v1alpha1.ZarfComponent, pkgLocation string) error { spinner := message.NewProgressSpinner("Copying %d files", len(component.Files)) defer spinner.Stop() @@ -590,7 +591,7 @@ func (p *Packager) pushReposToRepository(ctx context.Context, reposPath string, // generateValuesOverrides creates a map containing overrides for chart values based on the chart and component // Specifically it merges DeployOpts.ValuesOverridesMap over Zarf `variables` for a given component/chart combination -func (p *Packager) generateValuesOverrides(chart types.ZarfChart, componentName string) (map[string]any, error) { +func (p *Packager) generateValuesOverrides(chart v1alpha1.ZarfChart, componentName string) (map[string]any, error) { valuesOverrides := make(map[string]any) chartOverrides := make(map[string]any) @@ -616,7 +617,7 @@ func (p *Packager) generateValuesOverrides(chart types.ZarfChart, componentName } // Install all Helm charts and raw k8s manifests into the k8s cluster. -func (p *Packager) installChartAndManifests(ctx context.Context, componentPaths *layout.ComponentPaths, component types.ZarfComponent) (installedCharts []types.InstalledChart, err error) { +func (p *Packager) installChartAndManifests(ctx context.Context, componentPaths *layout.ComponentPaths, component v1alpha1.ZarfComponent) (installedCharts []types.InstalledChart, err error) { for _, chart := range component.Charts { // Do not wait for the chart to be ready if data injections are present. if len(component.DataInjections) > 0 { diff --git a/src/pkg/packager/deploy_test.go b/src/pkg/packager/deploy_test.go index 6e82cbcb10..d0802a4ac5 100644 --- a/src/pkg/packager/deploy_test.go +++ b/src/pkg/packager/deploy_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/packager/sources" "github.com/zarf-dev/zarf/src/pkg/variables" "github.com/zarf-dev/zarf/src/types" @@ -17,7 +18,7 @@ func TestGenerateValuesOverrides(t *testing.T) { tests := []struct { name string - chart types.ZarfChart + chart v1alpha1.ZarfChart setVariables map[string]string deployOpts types.ZarfDeployOptions componentName string @@ -25,7 +26,7 @@ func TestGenerateValuesOverrides(t *testing.T) { }{ { name: "Empty inputs", - chart: types.ZarfChart{}, + chart: v1alpha1.ZarfChart{}, setVariables: map[string]string{}, deployOpts: types.ZarfDeployOptions{}, componentName: "", @@ -33,9 +34,9 @@ func TestGenerateValuesOverrides(t *testing.T) { }, { name: "Single variable", - chart: types.ZarfChart{ + chart: v1alpha1.ZarfChart{ Name: "test-chart", - Variables: []types.ZarfChartVariable{{Name: "TEST_VAR", Path: "testVar"}}, + Variables: []v1alpha1.ZarfChartVariable{{Name: "TEST_VAR", Path: "testVar"}}, }, setVariables: map[string]string{"TEST_VAR": "testValue"}, deployOpts: types.ZarfDeployOptions{}, @@ -44,9 +45,9 @@ func TestGenerateValuesOverrides(t *testing.T) { }, { name: "Non-matching setVariable", - chart: types.ZarfChart{ + chart: v1alpha1.ZarfChart{ Name: "test-chart", - Variables: []types.ZarfChartVariable{{Name: "EXPECTED_VAR", Path: "path.to.expectedVar"}}, + Variables: []v1alpha1.ZarfChartVariable{{Name: "EXPECTED_VAR", Path: "path.to.expectedVar"}}, }, setVariables: map[string]string{"UNEXPECTED_VAR": "unexpectedValue"}, deployOpts: types.ZarfDeployOptions{}, @@ -55,9 +56,9 @@ func TestGenerateValuesOverrides(t *testing.T) { }, { name: "Nested 3 level setVariables", - chart: types.ZarfChart{ + chart: v1alpha1.ZarfChart{ Name: "nested-chart", - Variables: []types.ZarfChartVariable{ + Variables: []v1alpha1.ZarfChartVariable{ {Name: "LEVEL1_LEVEL2_LEVEL3_VAR", Path: "level1.level2.level3Var"}, }, }, @@ -74,9 +75,9 @@ func TestGenerateValuesOverrides(t *testing.T) { }, { name: "Multiple variables with nested and non-nested paths, distinct values", - chart: types.ZarfChart{ + chart: v1alpha1.ZarfChart{ Name: "mixed-chart", - Variables: []types.ZarfChartVariable{ + Variables: []v1alpha1.ZarfChartVariable{ {Name: "NESTED_VAR_LEVEL2", Path: "nestedVar.level2"}, {Name: "SIMPLE_VAR", Path: "simpleVar"}, }, @@ -96,9 +97,9 @@ func TestGenerateValuesOverrides(t *testing.T) { }, { name: "Values override test", - chart: types.ZarfChart{ + chart: v1alpha1.ZarfChart{ Name: "test-chart", - Variables: []types.ZarfChartVariable{ + Variables: []v1alpha1.ZarfChartVariable{ {Name: "OVERRIDE_VAR", Path: "path"}, }, }, @@ -119,9 +120,9 @@ func TestGenerateValuesOverrides(t *testing.T) { }, { name: "Missing variable in setVariables but present in ValuesOverridesMap", - chart: types.ZarfChart{ + chart: v1alpha1.ZarfChart{ Name: "test-chart", - Variables: []types.ZarfChartVariable{ + Variables: []v1alpha1.ZarfChartVariable{ {Name: "MISSING_VAR", Path: "missingVarPath"}, }, }, @@ -142,9 +143,9 @@ func TestGenerateValuesOverrides(t *testing.T) { }, { name: "Non-existent component or chart", - chart: types.ZarfChart{ + chart: v1alpha1.ZarfChart{ Name: "actual-chart", - Variables: []types.ZarfChartVariable{{Name: "SOME_VAR", Path: "someVar"}}, + Variables: []v1alpha1.ZarfChartVariable{{Name: "SOME_VAR", Path: "someVar"}}, }, setVariables: map[string]string{"SOME_VAR": "value"}, deployOpts: types.ZarfDeployOptions{ @@ -161,7 +162,7 @@ func TestGenerateValuesOverrides(t *testing.T) { }, { name: "Variable in setVariables but not in chartVariables", - chart: types.ZarfChart{Name: "orphan-chart"}, + chart: v1alpha1.ZarfChart{Name: "orphan-chart"}, setVariables: map[string]string{"ORPHAN_VAR": "orphanValue"}, deployOpts: types.ZarfDeployOptions{}, componentName: "orphan-component", @@ -169,9 +170,9 @@ func TestGenerateValuesOverrides(t *testing.T) { }, { name: "Empty ValuesOverridesMap with non-empty setVariableMap and chartVariables", - chart: types.ZarfChart{ + chart: v1alpha1.ZarfChart{ Name: "chart-with-vars", - Variables: []types.ZarfChartVariable{ + Variables: []v1alpha1.ZarfChartVariable{ {Name: "VAR1", Path: "path.to.var1"}, {Name: "VAR2", Path: "path.to.var2"}, {Name: "VAR3", Path: "path.to3.var3"}, @@ -198,7 +199,7 @@ func TestGenerateValuesOverrides(t *testing.T) { }, { name: "Empty chartVariables and non-empty setVariableMap", - chart: types.ZarfChart{Name: "chart-with-vars"}, + chart: v1alpha1.ZarfChart{Name: "chart-with-vars"}, setVariables: map[string]string{ "VAR1": "value1", "VAR2": "value2", diff --git a/src/pkg/packager/deprecated/common.go b/src/pkg/packager/deprecated/common.go index e0dd708c27..578f8c4ff2 100644 --- a/src/pkg/packager/deprecated/common.go +++ b/src/pkg/packager/deprecated/common.go @@ -14,8 +14,8 @@ import ( "github.com/Masterminds/semver/v3" "github.com/pterm/pterm" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/message" - "github.com/zarf-dev/zarf/src/types" ) // BreakingChange represents a breaking change that happened on a specified Zarf version. @@ -44,12 +44,12 @@ const ( // MigrateComponent runs all migrations on a component. // Build should be empty on package create, but include just in case someone copied a zarf.yaml from a zarf package. -func MigrateComponent(build types.ZarfBuildData, component types.ZarfComponent) (migratedComponent types.ZarfComponent, warnings []string) { +func MigrateComponent(build v1alpha1.ZarfBuildData, component v1alpha1.ZarfComponent) (migratedComponent v1alpha1.ZarfComponent, warnings []string) { migratedComponent = component // If the component has already been migrated, clear the deprecated scripts. if slices.Contains(build.Migrations, ScriptsToActionsMigrated) { - migratedComponent.DeprecatedScripts = types.DeprecatedZarfComponentScripts{} + migratedComponent.DeprecatedScripts = v1alpha1.DeprecatedZarfComponentScripts{} } else { // Otherwise, run the migration. var warning string diff --git a/src/pkg/packager/deprecated/pluralize-set-variable.go b/src/pkg/packager/deprecated/pluralize-set-variable.go index 44ea9c7f9c..04981f2790 100644 --- a/src/pkg/packager/deprecated/pluralize-set-variable.go +++ b/src/pkg/packager/deprecated/pluralize-set-variable.go @@ -7,14 +7,14 @@ package deprecated import ( "fmt" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/variables" - "github.com/zarf-dev/zarf/src/types" ) -func migrateSetVariableToSetVariables(c types.ZarfComponent) (types.ZarfComponent, string) { +func migrateSetVariableToSetVariables(c v1alpha1.ZarfComponent) (v1alpha1.ZarfComponent, string) { hasSetVariable := false - migrate := func(actions []types.ZarfComponentAction) []types.ZarfComponentAction { + migrate := func(actions []v1alpha1.ZarfComponentAction) []v1alpha1.ZarfComponentAction { for i := range actions { if actions[i].DeprecatedSetVariable != "" && len(actions[i].SetVariables) < 1 { hasSetVariable = true @@ -56,8 +56,8 @@ func migrateSetVariableToSetVariables(c types.ZarfComponent) (types.ZarfComponen return c, "" } -func clearSetVariables(c types.ZarfComponent) types.ZarfComponent { - clear := func(actions []types.ZarfComponentAction) []types.ZarfComponentAction { +func clearSetVariables(c v1alpha1.ZarfComponent) v1alpha1.ZarfComponent { + clear := func(actions []v1alpha1.ZarfComponentAction) []v1alpha1.ZarfComponentAction { for i := range actions { actions[i].DeprecatedSetVariable = "" } diff --git a/src/pkg/packager/deprecated/scripts-to-actions.go b/src/pkg/packager/deprecated/scripts-to-actions.go index f296e49ec3..02f92d0262 100644 --- a/src/pkg/packager/deprecated/scripts-to-actions.go +++ b/src/pkg/packager/deprecated/scripts-to-actions.go @@ -8,7 +8,7 @@ import ( "fmt" "math" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) // migrateScriptsToActions coverts the deprecated scripts to the new actions @@ -18,11 +18,11 @@ import ( // - Actions.*.OnSuccess // - Actions.*.OnFailure // - Actions.*.*.Env -func migrateScriptsToActions(c types.ZarfComponent) (types.ZarfComponent, string) { +func migrateScriptsToActions(c v1alpha1.ZarfComponent) (v1alpha1.ZarfComponent, string) { var hasScripts bool // Convert a script configs to action defaults. - defaults := types.ZarfComponentActionDefaults{ + defaults := v1alpha1.ZarfComponentActionDefaults{ // ShowOutput (default false) -> Mute (default false) Mute: !c.DeprecatedScripts.ShowOutput, // TimeoutSeconds -> MaxSeconds @@ -39,7 +39,7 @@ func migrateScriptsToActions(c types.ZarfComponent) (types.ZarfComponent, string hasScripts = true c.Actions.OnCreate.Defaults = defaults for _, s := range c.DeprecatedScripts.Prepare { - c.Actions.OnCreate.Before = append(c.Actions.OnCreate.Before, types.ZarfComponentAction{Cmd: s}) + c.Actions.OnCreate.Before = append(c.Actions.OnCreate.Before, v1alpha1.ZarfComponentAction{Cmd: s}) } } @@ -48,7 +48,7 @@ func migrateScriptsToActions(c types.ZarfComponent) (types.ZarfComponent, string hasScripts = true c.Actions.OnDeploy.Defaults = defaults for _, s := range c.DeprecatedScripts.Before { - c.Actions.OnDeploy.Before = append(c.Actions.OnDeploy.Before, types.ZarfComponentAction{Cmd: s}) + c.Actions.OnDeploy.Before = append(c.Actions.OnDeploy.Before, v1alpha1.ZarfComponentAction{Cmd: s}) } } @@ -57,7 +57,7 @@ func migrateScriptsToActions(c types.ZarfComponent) (types.ZarfComponent, string hasScripts = true c.Actions.OnDeploy.Defaults = defaults for _, s := range c.DeprecatedScripts.After { - c.Actions.OnDeploy.After = append(c.Actions.OnDeploy.After, types.ZarfComponentAction{Cmd: s}) + c.Actions.OnDeploy.After = append(c.Actions.OnDeploy.After, v1alpha1.ZarfComponentAction{Cmd: s}) } } diff --git a/src/pkg/packager/filters/deploy.go b/src/pkg/packager/filters/deploy.go index 40555fb9a2..4b562d1c92 100644 --- a/src/pkg/packager/filters/deploy.go +++ b/src/pkg/packager/filters/deploy.go @@ -11,8 +11,8 @@ import ( "github.com/agnivade/levenshtein" "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/interactive" - "github.com/zarf-dev/zarf/src/types" ) // ForDeploy creates a new deployment filter. @@ -40,9 +40,9 @@ var ( ) // Apply applies the filter. -func (f *deploymentFilter) Apply(pkg types.ZarfPackage) ([]types.ZarfComponent, error) { - var selectedComponents []types.ZarfComponent - groupedComponents := map[string][]types.ZarfComponent{} +func (f *deploymentFilter) Apply(pkg v1alpha1.ZarfPackage) ([]v1alpha1.ZarfComponent, error) { + var selectedComponents []v1alpha1.ZarfComponent + groupedComponents := map[string][]v1alpha1.ZarfComponent{} orderedComponentGroups := []string{} // Group the components by Name and Group while maintaining order @@ -66,8 +66,8 @@ func (f *deploymentFilter) Apply(pkg types.ZarfPackage) ([]types.ZarfComponent, // NOTE: This does not use forIncludedComponents as it takes group, default and required status into account. for _, groupKey := range orderedComponentGroups { - var groupDefault *types.ZarfComponent - var groupSelected *types.ZarfComponent + var groupDefault *v1alpha1.ZarfComponent + var groupSelected *v1alpha1.ZarfComponent for _, component := range groupedComponents[groupKey] { // Ensure we have a local version of the component to point to (otherwise the pointer might change on us) diff --git a/src/pkg/packager/filters/deploy_test.go b/src/pkg/packager/filters/deploy_test.go index 7c69007223..f9899de228 100644 --- a/src/pkg/packager/filters/deploy_test.go +++ b/src/pkg/packager/filters/deploy_test.go @@ -11,11 +11,11 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/stretchr/testify/require" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) -func componentFromQuery(t *testing.T, q string) types.ZarfComponent { - c := types.ZarfComponent{ +func componentFromQuery(t *testing.T, q string) v1alpha1.ZarfComponent { + c := v1alpha1.ZarfComponent{ Name: q, } @@ -48,8 +48,8 @@ func componentFromQuery(t *testing.T, q string) types.ZarfComponent { return c } -func componentMatrix(_ *testing.T) []types.ZarfComponent { - var components []types.ZarfComponent +func componentMatrix(_ *testing.T) []v1alpha1.ZarfComponent { + var components []v1alpha1.ZarfComponent defaultValues := []bool{true, false} requiredValues := []interface{}{nil, true, false} @@ -92,7 +92,7 @@ func componentMatrix(_ *testing.T) []types.ZarfComponent { } } - c := types.ZarfComponent{ + c := v1alpha1.ZarfComponent{ Name: name.String(), Default: defaultValue, DeprecatedGroup: groupValue, @@ -114,20 +114,20 @@ func TestDeployFilter_Apply(t *testing.T) { possibilities := componentMatrix(t) tests := map[string]struct { - pkg types.ZarfPackage + pkg v1alpha1.ZarfPackage optionalComponents string - want []types.ZarfComponent + want []v1alpha1.ZarfComponent expectedErr error }{ "Test when version is less than v0.33.0 w/ no optional components selected": { - pkg: types.ZarfPackage{ - Build: types.ZarfBuildData{ + pkg: v1alpha1.ZarfPackage{ + Build: v1alpha1.ZarfBuildData{ Version: "v0.32.0", }, Components: possibilities, }, optionalComponents: "", - want: []types.ZarfComponent{ + want: []v1alpha1.ZarfComponent{ componentFromQuery(t, "required= && default=true"), componentFromQuery(t, "required=true && default=true"), componentFromQuery(t, "required=false && default=true"), @@ -137,14 +137,14 @@ func TestDeployFilter_Apply(t *testing.T) { }, }, "Test when version is less than v0.33.0 w/ some optional components selected": { - pkg: types.ZarfPackage{ - Build: types.ZarfBuildData{ + pkg: v1alpha1.ZarfPackage{ + Build: v1alpha1.ZarfBuildData{ Version: "v0.32.0", }, Components: possibilities, }, optionalComponents: strings.Join([]string{"required=false", "required= && group=bar && idx=5 && default=false", "-required=true"}, ","), - want: []types.ZarfComponent{ + want: []v1alpha1.ZarfComponent{ componentFromQuery(t, "required= && default=true"), componentFromQuery(t, "required=true && default=true"), componentFromQuery(t, "required=false && default=true"), @@ -157,11 +157,11 @@ func TestDeployFilter_Apply(t *testing.T) { }, }, "Test failing when group has no default and no selection was made": { - pkg: types.ZarfPackage{ - Build: types.ZarfBuildData{ + pkg: v1alpha1.ZarfPackage{ + Build: v1alpha1.ZarfBuildData{ Version: "v0.32.0", }, - Components: []types.ZarfComponent{ + Components: []v1alpha1.ZarfComponent{ componentFromQuery(t, "group=foo && default=false"), componentFromQuery(t, "group=foo && default=false"), }, @@ -170,11 +170,11 @@ func TestDeployFilter_Apply(t *testing.T) { expectedErr: ErrNoDefaultOrSelection, }, "Test failing when multiple are selected from the same group": { - pkg: types.ZarfPackage{ - Build: types.ZarfBuildData{ + pkg: v1alpha1.ZarfPackage{ + Build: v1alpha1.ZarfBuildData{ Version: "v0.32.0", }, - Components: []types.ZarfComponent{ + Components: []v1alpha1.ZarfComponent{ componentFromQuery(t, "group=foo && default=true"), componentFromQuery(t, "group=foo && default=false"), }, @@ -183,8 +183,8 @@ func TestDeployFilter_Apply(t *testing.T) { expectedErr: ErrMultipleSameGroup, }, "Test failing when no components are found that match the query": { - pkg: types.ZarfPackage{ - Build: types.ZarfBuildData{ + pkg: v1alpha1.ZarfPackage{ + Build: v1alpha1.ZarfBuildData{ Version: "v0.32.0", }, Components: possibilities, diff --git a/src/pkg/packager/filters/diff.go b/src/pkg/packager/filters/diff.go index bbba9ab789..42bdc94f41 100644 --- a/src/pkg/packager/filters/diff.go +++ b/src/pkg/packager/filters/diff.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/go-git/go-git/v5/plumbing" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/internal/packager/git" "github.com/zarf-dev/zarf/src/pkg/transform" "github.com/zarf-dev/zarf/src/types" @@ -23,8 +24,8 @@ type differentialDataFilter struct { diffData *types.DifferentialData } -func (f *differentialDataFilter) Apply(pkg types.ZarfPackage) ([]types.ZarfComponent, error) { - diffComponents := []types.ZarfComponent{} +func (f *differentialDataFilter) Apply(pkg v1alpha1.ZarfPackage) ([]v1alpha1.ZarfComponent, error) { + diffComponents := []v1alpha1.ZarfComponent{} for _, component := range pkg.Components { filteredImages := []string{} for _, img := range component.Images { diff --git a/src/pkg/packager/filters/diff_test.go b/src/pkg/packager/filters/diff_test.go index 0b279b8f08..ce89629159 100644 --- a/src/pkg/packager/filters/diff_test.go +++ b/src/pkg/packager/filters/diff_test.go @@ -7,12 +7,13 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/types" ) func TestCopyFilter(t *testing.T) { - pkg := types.ZarfPackage{ - Components: []types.ZarfComponent{ + pkg := v1alpha1.ZarfPackage{ + Components: []v1alpha1.ZarfComponent{ { Images: []string{ "example.com/include-image-tag:latest", diff --git a/src/pkg/packager/filters/empty.go b/src/pkg/packager/filters/empty.go index af4eb09663..4729adc509 100644 --- a/src/pkg/packager/filters/empty.go +++ b/src/pkg/packager/filters/empty.go @@ -4,7 +4,7 @@ // Package filters contains core implementations of the ComponentFilterStrategy interface. package filters -import "github.com/zarf-dev/zarf/src/types" +import "github.com/zarf-dev/zarf/src/api/v1alpha1" // Empty returns a filter that does nothing. func Empty() ComponentFilterStrategy { @@ -15,6 +15,6 @@ func Empty() ComponentFilterStrategy { type emptyFilter struct{} // Apply returns the components unchanged. -func (f *emptyFilter) Apply(pkg types.ZarfPackage) ([]types.ZarfComponent, error) { +func (f *emptyFilter) Apply(pkg v1alpha1.ZarfPackage) ([]v1alpha1.ZarfComponent, error) { return pkg.Components, nil } diff --git a/src/pkg/packager/filters/empty_test.go b/src/pkg/packager/filters/empty_test.go index 8d55fd70ad..2b74597723 100644 --- a/src/pkg/packager/filters/empty_test.go +++ b/src/pkg/packager/filters/empty_test.go @@ -8,11 +8,11 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) func TestEmptyFilter_Apply(t *testing.T) { - components := []types.ZarfComponent{ + components := []v1alpha1.ZarfComponent{ { Name: "component1", }, @@ -20,7 +20,7 @@ func TestEmptyFilter_Apply(t *testing.T) { Name: "component2", }, } - pkg := types.ZarfPackage{ + pkg := v1alpha1.ZarfPackage{ Components: components, } filter := Empty() diff --git a/src/pkg/packager/filters/os.go b/src/pkg/packager/filters/os.go index 845c0cb400..2bc7dffa2e 100644 --- a/src/pkg/packager/filters/os.go +++ b/src/pkg/packager/filters/os.go @@ -7,7 +7,7 @@ package filters import ( "errors" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) // ByLocalOS creates a new filter that filters components based on local (runtime) OS. @@ -24,12 +24,12 @@ type localOSFilter struct { var ErrLocalOSRequired = errors.New("localOS is required") // Apply applies the filter. -func (f *localOSFilter) Apply(pkg types.ZarfPackage) ([]types.ZarfComponent, error) { +func (f *localOSFilter) Apply(pkg v1alpha1.ZarfPackage) ([]v1alpha1.ZarfComponent, error) { if f.localOS == "" { return nil, ErrLocalOSRequired } - filtered := []types.ZarfComponent{} + filtered := []v1alpha1.ZarfComponent{} for _, component := range pkg.Components { if component.Only.LocalOS == "" || component.Only.LocalOS == f.localOS { filtered = append(filtered, component) diff --git a/src/pkg/packager/filters/os_test.go b/src/pkg/packager/filters/os_test.go index 98c5678c96..fb81d1355a 100644 --- a/src/pkg/packager/filters/os_test.go +++ b/src/pkg/packager/filters/os_test.go @@ -8,20 +8,20 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) func TestLocalOSFilter(t *testing.T) { - pkg := types.ZarfPackage{} - for _, os := range types.SupportedOS() { - pkg.Components = append(pkg.Components, types.ZarfComponent{ - Only: types.ZarfComponentOnlyTarget{ + pkg := v1alpha1.ZarfPackage{} + for _, os := range v1alpha1.SupportedOS() { + pkg.Components = append(pkg.Components, v1alpha1.ZarfComponent{ + Only: v1alpha1.ZarfComponentOnlyTarget{ LocalOS: os, }, }) } - for _, os := range types.SupportedOS() { + for _, os := range v1alpha1.SupportedOS() { filter := ByLocalOS(os) result, err := filter.Apply(pkg) if os == "" { diff --git a/src/pkg/packager/filters/select.go b/src/pkg/packager/filters/select.go index 35694f580f..fafc8c64fa 100644 --- a/src/pkg/packager/filters/select.go +++ b/src/pkg/packager/filters/select.go @@ -6,7 +6,7 @@ package filters import ( "github.com/defenseunicorns/pkg/helpers/v2" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) // BySelectState creates a new simple included filter. @@ -24,9 +24,9 @@ type selectStateFilter struct { } // Apply applies the filter. -func (f *selectStateFilter) Apply(pkg types.ZarfPackage) ([]types.ZarfComponent, error) { +func (f *selectStateFilter) Apply(pkg v1alpha1.ZarfPackage) ([]v1alpha1.ZarfComponent, error) { isPartial := len(f.requestedComponents) > 0 && f.requestedComponents[0] != "" - result := []types.ZarfComponent{} + result := []v1alpha1.ZarfComponent{} for _, component := range pkg.Components { selectState := included if isPartial { diff --git a/src/pkg/packager/filters/select_test.go b/src/pkg/packager/filters/select_test.go index b4d4ac9289..a384ce56e8 100644 --- a/src/pkg/packager/filters/select_test.go +++ b/src/pkg/packager/filters/select_test.go @@ -8,26 +8,26 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) func Test_selectStateFilter_Apply(t *testing.T) { tests := []struct { name string requestedComponents string - components []types.ZarfComponent - expectedResult []types.ZarfComponent + components []v1alpha1.ZarfComponent + expectedResult []v1alpha1.ZarfComponent expectedError error }{ { name: "Test when requestedComponents is empty", requestedComponents: "", - components: []types.ZarfComponent{ + components: []v1alpha1.ZarfComponent{ {Name: "component1"}, {Name: "component2"}, {Name: "component3"}, }, - expectedResult: []types.ZarfComponent{ + expectedResult: []v1alpha1.ZarfComponent{ {Name: "component1"}, {Name: "component2"}, {Name: "component3"}, @@ -37,12 +37,12 @@ func Test_selectStateFilter_Apply(t *testing.T) { { name: "Test when requestedComponents contains a valid component name", requestedComponents: "component2", - components: []types.ZarfComponent{ + components: []v1alpha1.ZarfComponent{ {Name: "component1"}, {Name: "component2"}, {Name: "component3"}, }, - expectedResult: []types.ZarfComponent{ + expectedResult: []v1alpha1.ZarfComponent{ {Name: "component2"}, }, expectedError: nil, @@ -50,12 +50,12 @@ func Test_selectStateFilter_Apply(t *testing.T) { { name: "Test when requestedComponents contains an excluded component name", requestedComponents: "comp*, -component2", - components: []types.ZarfComponent{ + components: []v1alpha1.ZarfComponent{ {Name: "component1"}, {Name: "component2"}, {Name: "component3"}, }, - expectedResult: []types.ZarfComponent{ + expectedResult: []v1alpha1.ZarfComponent{ {Name: "component1"}, {Name: "component3"}, }, @@ -64,12 +64,12 @@ func Test_selectStateFilter_Apply(t *testing.T) { { name: "Test when requestedComponents contains a glob pattern", requestedComponents: "comp*", - components: []types.ZarfComponent{ + components: []v1alpha1.ZarfComponent{ {Name: "component1"}, {Name: "component2"}, {Name: "other"}, }, - expectedResult: []types.ZarfComponent{ + expectedResult: []v1alpha1.ZarfComponent{ {Name: "component1"}, {Name: "component2"}, }, @@ -81,7 +81,7 @@ func Test_selectStateFilter_Apply(t *testing.T) { t.Run(tc.name, func(t *testing.T) { filter := BySelectState(tc.requestedComponents) - result, err := filter.Apply(types.ZarfPackage{ + result, err := filter.Apply(v1alpha1.ZarfPackage{ Components: tc.components, }) diff --git a/src/pkg/packager/filters/strat.go b/src/pkg/packager/filters/strat.go index 1411ae3c5f..b63f39bd42 100644 --- a/src/pkg/packager/filters/strat.go +++ b/src/pkg/packager/filters/strat.go @@ -7,12 +7,12 @@ package filters import ( "fmt" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) // ComponentFilterStrategy is a strategy interface for filtering components. type ComponentFilterStrategy interface { - Apply(types.ZarfPackage) ([]types.ZarfComponent, error) + Apply(v1alpha1.ZarfPackage) ([]v1alpha1.ZarfComponent, error) } // comboFilter is a filter that applies a sequence of filters. @@ -21,7 +21,7 @@ type comboFilter struct { } // Apply applies the filter. -func (f *comboFilter) Apply(pkg types.ZarfPackage) ([]types.ZarfComponent, error) { +func (f *comboFilter) Apply(pkg v1alpha1.ZarfPackage) ([]v1alpha1.ZarfComponent, error) { result := pkg for _, filter := range f.filters { diff --git a/src/pkg/packager/filters/strat_test.go b/src/pkg/packager/filters/strat_test.go index 12f7dad86e..69c39beff9 100644 --- a/src/pkg/packager/filters/strat_test.go +++ b/src/pkg/packager/filters/strat_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" ) func TestCombine(t *testing.T) { @@ -18,8 +18,8 @@ func TestCombine(t *testing.T) { combo := Combine(f1, f2, f3) - pkg := types.ZarfPackage{ - Components: []types.ZarfComponent{ + pkg := v1alpha1.ZarfPackage{ + Components: []v1alpha1.ZarfComponent{ { Name: "foo", }, @@ -35,7 +35,7 @@ func TestCombine(t *testing.T) { }, } - expected := []types.ZarfComponent{ + expected := []v1alpha1.ZarfComponent{ { Name: "bar", }, @@ -50,7 +50,7 @@ func TestCombine(t *testing.T) { // Test error propagation combo = Combine(f1, f2, ForDeploy("group with no default", false)) - pkg.Components = append(pkg.Components, types.ZarfComponent{ + pkg.Components = append(pkg.Components, v1alpha1.ZarfComponent{ Name: "group with no default", DeprecatedGroup: "g1", }) diff --git a/src/pkg/packager/generate.go b/src/pkg/packager/generate.go index d1fc593033..cc3393dbb5 100644 --- a/src/pkg/packager/generate.go +++ b/src/pkg/packager/generate.go @@ -13,10 +13,10 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" goyaml "github.com/goccy/go-yaml" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/message" - "github.com/zarf-dev/zarf/src/types" ) // Generate generates a Zarf package definition. @@ -36,10 +36,10 @@ func (p *Packager) Generate(ctx context.Context) (err error) { } } - generatedComponent := types.ZarfComponent{ + generatedComponent := v1alpha1.ZarfComponent{ Name: p.cfg.GenerateOpts.Name, Required: helpers.BoolPtr(true), - Charts: []types.ZarfChart{ + Charts: []v1alpha1.ZarfChart{ { Name: p.cfg.GenerateOpts.Name, Version: p.cfg.GenerateOpts.Version, @@ -50,14 +50,14 @@ func (p *Packager) Generate(ctx context.Context) (err error) { }, } - p.cfg.Pkg = types.ZarfPackage{ - Kind: types.ZarfPackageConfig, - Metadata: types.ZarfMetadata{ + p.cfg.Pkg = v1alpha1.ZarfPackage{ + Kind: v1alpha1.ZarfPackageConfig, + Metadata: v1alpha1.ZarfMetadata{ Name: p.cfg.GenerateOpts.Name, Version: p.cfg.GenerateOpts.Version, Description: "auto-generated using `zarf dev generate`", }, - Components: []types.ZarfComponent{ + Components: []v1alpha1.ZarfComponent{ generatedComponent, }, } diff --git a/src/pkg/packager/mirror.go b/src/pkg/packager/mirror.go index 9cafe38f58..9e61604144 100644 --- a/src/pkg/packager/mirror.go +++ b/src/pkg/packager/mirror.go @@ -10,6 +10,7 @@ import ( "runtime" "strings" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/filters" @@ -54,7 +55,7 @@ func (p *Packager) Mirror(ctx context.Context) error { } // mirrorComponent mirrors a Zarf Component. -func (p *Packager) mirrorComponent(ctx context.Context, component types.ZarfComponent) error { +func (p *Packager) mirrorComponent(ctx context.Context, component v1alpha1.ZarfComponent) error { componentPaths := p.layout.Components.Dirs[component.Name] // All components now require a name diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index a52cc9c0f4..d007e862bd 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -17,6 +17,7 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/google/go-containerregistry/pkg/crane" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config/lang" "github.com/zarf-dev/zarf/src/internal/packager/helm" "github.com/zarf-dev/zarf/src/internal/packager/images" @@ -136,7 +137,7 @@ func (p *Packager) findImages(ctx context.Context) (imgMap map[string][]string, repoHelmChartPath = strings.TrimPrefix(repoHelmChartPath, "/") // If a repo helm chart path is specified, - component.Charts = append(component.Charts, types.ZarfChart{ + component.Charts = append(component.Charts, v1alpha1.ZarfChart{ Name: repo, URL: matches[0], Version: matches[1], diff --git a/src/pkg/packager/publish.go b/src/pkg/packager/publish.go index 4cefc1d872..94fdee63c2 100644 --- a/src/pkg/packager/publish.go +++ b/src/pkg/packager/publish.go @@ -13,6 +13,7 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/defenseunicorns/pkg/oci" ocispec "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/message" @@ -21,7 +22,6 @@ import ( "github.com/zarf-dev/zarf/src/pkg/packager/sources" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/pkg/zoci" - "github.com/zarf-dev/zarf/src/types" ) // Publish publishes the package to a registry @@ -107,11 +107,11 @@ func (p *Packager) Publish(ctx context.Context) (err error) { } if p.cfg.CreateOpts.IsSkeleton { message.Title("How to import components from this skeleton:", "") - ex := []types.ZarfComponent{} + ex := []v1alpha1.ZarfComponent{} for _, c := range p.cfg.Pkg.Components { - ex = append(ex, types.ZarfComponent{ + ex = append(ex, v1alpha1.ZarfComponent{ Name: fmt.Sprintf("import-%s", c.Name), - Import: types.ZarfComponentImport{ + Import: v1alpha1.ZarfComponentImport{ Name: c.Name, URL: helpers.OCIURLPrefix + remote.Repo().Reference.String(), }, diff --git a/src/pkg/packager/remove.go b/src/pkg/packager/remove.go index dbfbf7d690..0476129d0a 100644 --- a/src/pkg/packager/remove.go +++ b/src/pkg/packager/remove.go @@ -18,6 +18,7 @@ import ( kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/internal/packager/helm" "github.com/zarf-dev/zarf/src/pkg/cluster" @@ -163,7 +164,7 @@ func (p *Packager) updatePackageSecret(ctx context.Context, deployedPackage type func (p *Packager) removeComponent(ctx context.Context, deployedPackage *types.DeployedPackage, deployedComponent types.DeployedComponent, spinner *message.Spinner) (*types.DeployedPackage, error) { components := deployedPackage.Data.Components - c := helpers.Find(components, func(t types.ZarfComponent) bool { + c := helpers.Find(components, func(t v1alpha1.ZarfComponent) bool { return t.Name == deployedComponent.Name }) diff --git a/src/pkg/packager/sources/cluster.go b/src/pkg/packager/sources/cluster.go index bd671120e8..ea45b254dd 100644 --- a/src/pkg/packager/sources/cluster.go +++ b/src/pkg/packager/sources/cluster.go @@ -9,6 +9,7 @@ import ( "fmt" "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/cluster" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/packager/filters" @@ -23,7 +24,7 @@ var ( // NewClusterSource creates a new cluster source. func NewClusterSource(pkgOpts *types.ZarfPackageOptions) (PackageSource, error) { - if !types.IsLowercaseNumberHyphenNoStartHyphen(pkgOpts.PackageSource) { + if !v1alpha1.IsLowercaseNumberHyphenNoStartHyphen(pkgOpts.PackageSource) { return nil, fmt.Errorf("invalid package name %q", pkgOpts.PackageSource) } @@ -46,8 +47,8 @@ type ClusterSource struct { // LoadPackage loads a package from a cluster. // // This is not implemented. -func (s *ClusterSource) LoadPackage(_ context.Context, _ *layout.PackagePaths, _ filters.ComponentFilterStrategy, _ bool) (types.ZarfPackage, []string, error) { - return types.ZarfPackage{}, nil, fmt.Errorf("not implemented") +func (s *ClusterSource) LoadPackage(_ context.Context, _ *layout.PackagePaths, _ filters.ComponentFilterStrategy, _ bool) (v1alpha1.ZarfPackage, []string, error) { + return v1alpha1.ZarfPackage{}, nil, fmt.Errorf("not implemented") } // Collect collects a package from a cluster. @@ -58,14 +59,14 @@ func (s *ClusterSource) Collect(_ context.Context, _ string) (string, error) { } // LoadPackageMetadata loads package metadata from a cluster. -func (s *ClusterSource) LoadPackageMetadata(ctx context.Context, dst *layout.PackagePaths, _ bool, _ bool) (types.ZarfPackage, []string, error) { +func (s *ClusterSource) LoadPackageMetadata(ctx context.Context, dst *layout.PackagePaths, _ bool, _ bool) (v1alpha1.ZarfPackage, []string, error) { dpkg, err := s.GetDeployedPackage(ctx, s.PackageSource) if err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } if err := utils.WriteYaml(dst.ZarfYAML, dpkg.Data, helpers.ReadUser); err != nil { - return types.ZarfPackage{}, nil, err + return v1alpha1.ZarfPackage{}, nil, err } return dpkg.Data, nil, nil diff --git a/src/pkg/packager/sources/new.go b/src/pkg/packager/sources/new.go index 4d43cc229c..65d0af6762 100644 --- a/src/pkg/packager/sources/new.go +++ b/src/pkg/packager/sources/new.go @@ -12,6 +12,7 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/defenseunicorns/pkg/oci" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/packager/filters" @@ -30,10 +31,10 @@ import ( // `sources.ValidatePackageSignature` and `sources.ValidatePackageIntegrity` can be leveraged for this purpose. type PackageSource interface { // LoadPackage loads a package from a source. - LoadPackage(ctx context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg types.ZarfPackage, warnings []string, err error) + LoadPackage(ctx context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg v1alpha1.ZarfPackage, warnings []string, err error) // LoadPackageMetadata loads a package's metadata from a source. - LoadPackageMetadata(ctx context.Context, dst *layout.PackagePaths, wantSBOM bool, skipValidation bool) (pkg types.ZarfPackage, warnings []string, err error) + LoadPackageMetadata(ctx context.Context, dst *layout.PackagePaths, wantSBOM bool, skipValidation bool) (pkg v1alpha1.ZarfPackage, warnings []string, err error) // Collect relocates a package from its source to a tarball in a given destination directory. Collect(ctx context.Context, destinationDirectory string) (tarball string, err error) diff --git a/src/pkg/packager/sources/new_test.go b/src/pkg/packager/sources/new_test.go index a1a495b3ca..9ae3147168 100644 --- a/src/pkg/packager/sources/new_test.go +++ b/src/pkg/packager/sources/new_test.go @@ -17,6 +17,7 @@ import ( "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/packager/filters" "github.com/zarf-dev/zarf/src/types" @@ -117,7 +118,7 @@ func TestPackageSource(t *testing.T) { b, err := os.ReadFile("./testdata/expected-pkg.json") require.NoError(t, err) - expectedPkg := types.ZarfPackage{} + expectedPkg := v1alpha1.ZarfPackage{} err = json.Unmarshal(b, &expectedPkg) require.NoError(t, err) diff --git a/src/pkg/packager/sources/oci.go b/src/pkg/packager/sources/oci.go index f22547d520..7961f1360f 100644 --- a/src/pkg/packager/sources/oci.go +++ b/src/pkg/packager/sources/oci.go @@ -13,6 +13,7 @@ import ( "strings" "github.com/mholt/archiver/v3" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/message" @@ -34,7 +35,7 @@ type OCISource struct { } // LoadPackage loads a package from an OCI registry. -func (s *OCISource) LoadPackage(ctx context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg types.ZarfPackage, warnings []string, err error) { +func (s *OCISource) LoadPackage(ctx context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg v1alpha1.ZarfPackage, warnings []string, err error) { pkg, err = s.FetchZarfYAML(ctx) if err != nil { return pkg, nil, err @@ -108,7 +109,7 @@ func (s *OCISource) LoadPackage(ctx context.Context, dst *layout.PackagePaths, f } // LoadPackageMetadata loads a package's metadata from an OCI registry. -func (s *OCISource) LoadPackageMetadata(ctx context.Context, dst *layout.PackagePaths, wantSBOM bool, skipValidation bool) (pkg types.ZarfPackage, warnings []string, err error) { +func (s *OCISource) LoadPackageMetadata(ctx context.Context, dst *layout.PackagePaths, wantSBOM bool, skipValidation bool) (pkg v1alpha1.ZarfPackage, warnings []string, err error) { toPull := zoci.PackageAlwaysPull if wantSBOM { toPull = append(toPull, layout.SBOMTar) @@ -174,7 +175,7 @@ func (s *OCISource) Collect(ctx context.Context, dir string) (string, error) { loaded := layout.New(tmp) loaded.SetFromLayers(fetched) - var pkg types.ZarfPackage + var pkg v1alpha1.ZarfPackage if err := utils.ReadYaml(loaded.ZarfYAML, &pkg); err != nil { return "", err diff --git a/src/pkg/packager/sources/split.go b/src/pkg/packager/sources/split.go index 8176b68882..f4f97a25a6 100644 --- a/src/pkg/packager/sources/split.go +++ b/src/pkg/packager/sources/split.go @@ -15,6 +15,7 @@ import ( "strings" "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/filters" @@ -110,7 +111,7 @@ func (s *SplitTarballSource) Collect(_ context.Context, dir string) (string, err } // LoadPackage loads a package from a split tarball. -func (s *SplitTarballSource) LoadPackage(ctx context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg types.ZarfPackage, warnings []string, err error) { +func (s *SplitTarballSource) LoadPackage(ctx context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg v1alpha1.ZarfPackage, warnings []string, err error) { tb, err := s.Collect(ctx, filepath.Dir(s.PackageSource)) if err != nil { return pkg, nil, err @@ -128,7 +129,7 @@ func (s *SplitTarballSource) LoadPackage(ctx context.Context, dst *layout.Packag } // LoadPackageMetadata loads a package's metadata from a split tarball. -func (s *SplitTarballSource) LoadPackageMetadata(ctx context.Context, dst *layout.PackagePaths, wantSBOM bool, skipValidation bool) (pkg types.ZarfPackage, warnings []string, err error) { +func (s *SplitTarballSource) LoadPackageMetadata(ctx context.Context, dst *layout.PackagePaths, wantSBOM bool, skipValidation bool) (pkg v1alpha1.ZarfPackage, warnings []string, err error) { tb, err := s.Collect(ctx, filepath.Dir(s.PackageSource)) if err != nil { return pkg, nil, err diff --git a/src/pkg/packager/sources/tarball.go b/src/pkg/packager/sources/tarball.go index 9cbbf1b071..4de1c58006 100644 --- a/src/pkg/packager/sources/tarball.go +++ b/src/pkg/packager/sources/tarball.go @@ -15,6 +15,7 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/mholt/archiver/v3" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/filters" @@ -33,7 +34,7 @@ type TarballSource struct { } // LoadPackage loads a package from a tarball. -func (s *TarballSource) LoadPackage(_ context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg types.ZarfPackage, warnings []string, err error) { +func (s *TarballSource) LoadPackage(_ context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg v1alpha1.ZarfPackage, warnings []string, err error) { spinner := message.NewProgressSpinner("Loading package from %q", s.PackageSource) defer spinner.Stop() @@ -138,7 +139,7 @@ func (s *TarballSource) LoadPackage(_ context.Context, dst *layout.PackagePaths, } // LoadPackageMetadata loads a package's metadata from a tarball. -func (s *TarballSource) LoadPackageMetadata(_ context.Context, dst *layout.PackagePaths, wantSBOM bool, skipValidation bool) (pkg types.ZarfPackage, warnings []string, err error) { +func (s *TarballSource) LoadPackageMetadata(_ context.Context, dst *layout.PackagePaths, wantSBOM bool, skipValidation bool) (pkg v1alpha1.ZarfPackage, warnings []string, err error) { if s.Shasum != "" { if err := helpers.SHAsMatch(s.PackageSource, s.Shasum); err != nil { return pkg, nil, err diff --git a/src/pkg/packager/sources/url.go b/src/pkg/packager/sources/url.go index d3d79af237..dd4aa05ff5 100644 --- a/src/pkg/packager/sources/url.go +++ b/src/pkg/packager/sources/url.go @@ -12,6 +12,7 @@ import ( "strings" "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/packager/filters" @@ -51,7 +52,7 @@ func (s *URLSource) Collect(ctx context.Context, dir string) (string, error) { } // LoadPackage loads a package from an http, https or sget URL. -func (s *URLSource) LoadPackage(ctx context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg types.ZarfPackage, warnings []string, err error) { +func (s *URLSource) LoadPackage(ctx context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg v1alpha1.ZarfPackage, warnings []string, err error) { tmp, err := utils.MakeTempDir(config.CommonOptions.TempDirectory) if err != nil { return pkg, nil, err @@ -75,7 +76,7 @@ func (s *URLSource) LoadPackage(ctx context.Context, dst *layout.PackagePaths, f } // LoadPackageMetadata loads a package's metadata from an http, https or sget URL. -func (s *URLSource) LoadPackageMetadata(ctx context.Context, dst *layout.PackagePaths, wantSBOM bool, skipValidation bool) (pkg types.ZarfPackage, warnings []string, err error) { +func (s *URLSource) LoadPackageMetadata(ctx context.Context, dst *layout.PackagePaths, wantSBOM bool, skipValidation bool) (pkg v1alpha1.ZarfPackage, warnings []string, err error) { tmp, err := utils.MakeTempDir(config.CommonOptions.TempDirectory) if err != nil { return pkg, nil, err diff --git a/src/pkg/packager/sources/utils.go b/src/pkg/packager/sources/utils.go index bb2e3227d9..0e3f455c55 100644 --- a/src/pkg/packager/sources/utils.go +++ b/src/pkg/packager/sources/utils.go @@ -14,10 +14,10 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" goyaml "github.com/goccy/go-yaml" "github.com/mholt/archiver/v3" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/zoci" - "github.com/zarf-dev/zarf/src/types" ) // GetValidPackageExtensions returns the valid package extensions. @@ -79,7 +79,7 @@ func identifyUnknownTarball(path string) (string, error) { // RenameFromMetadata renames a tarball based on its metadata. func RenameFromMetadata(path string) (string, error) { - var pkg types.ZarfPackage + var pkg v1alpha1.ZarfPackage ext := filepath.Ext(path) if ext == "" { @@ -123,7 +123,7 @@ func RenameFromMetadata(path string) (string, error) { } // NameFromMetadata generates a name from a package's metadata. -func NameFromMetadata(pkg *types.ZarfPackage, isSkeleton bool) string { +func NameFromMetadata(pkg *v1alpha1.ZarfPackage, isSkeleton bool) string { var name string arch := config.GetArch(pkg.Metadata.Architecture, pkg.Build.Architecture) @@ -133,9 +133,9 @@ func NameFromMetadata(pkg *types.ZarfPackage, isSkeleton bool) string { } switch pkg.Kind { - case types.ZarfInitConfig: + case v1alpha1.ZarfInitConfig: name = fmt.Sprintf("zarf-init-%s", arch) - case types.ZarfPackageConfig: + case v1alpha1.ZarfPackageConfig: name = fmt.Sprintf("zarf-package-%s-%s", pkg.Metadata.Name, arch) default: name = fmt.Sprintf("zarf-%s-%s", strings.ToLower(string(pkg.Kind)), arch) diff --git a/src/pkg/zoci/fetch.go b/src/pkg/zoci/fetch.go index 3a2d04bb9f..923e3d7c24 100644 --- a/src/pkg/zoci/fetch.go +++ b/src/pkg/zoci/fetch.go @@ -9,17 +9,17 @@ import ( "github.com/defenseunicorns/pkg/oci" ocispec "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/layout" - "github.com/zarf-dev/zarf/src/types" ) // FetchZarfYAML fetches the zarf.yaml file from the remote repository. -func (r *Remote) FetchZarfYAML(ctx context.Context) (pkg types.ZarfPackage, err error) { +func (r *Remote) FetchZarfYAML(ctx context.Context) (pkg v1alpha1.ZarfPackage, err error) { manifest, err := r.FetchRoot(ctx) if err != nil { return pkg, err } - return oci.FetchYAMLFile[types.ZarfPackage](ctx, r.FetchLayer, manifest, layout.ZarfYAML) + return oci.FetchYAMLFile[v1alpha1.ZarfPackage](ctx, r.FetchLayer, manifest, layout.ZarfYAML) } // FetchImagesIndex fetches the images/index.json file from the remote repository. diff --git a/src/pkg/zoci/pull.go b/src/pkg/zoci/pull.go index c74e66588d..9fd76e9ccc 100644 --- a/src/pkg/zoci/pull.go +++ b/src/pkg/zoci/pull.go @@ -12,10 +12,10 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/defenseunicorns/pkg/oci" ocispec "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/transform" "github.com/zarf-dev/zarf/src/pkg/utils" - "github.com/zarf-dev/zarf/src/types" "oras.land/oras-go/v2/content/file" ) @@ -76,7 +76,7 @@ func (r *Remote) PullPackage(ctx context.Context, destinationDir string, concurr // LayersFromRequestedComponents returns the descriptors for the given components from the root manifest. // // It also retrieves the descriptors for all image layers that are required by the components. -func (r *Remote) LayersFromRequestedComponents(ctx context.Context, requestedComponents []types.ZarfComponent) (layers []ocispec.Descriptor, err error) { +func (r *Remote) LayersFromRequestedComponents(ctx context.Context, requestedComponents []v1alpha1.ZarfComponent) (layers []ocispec.Descriptor, err error) { root, err := r.FetchRoot(ctx) if err != nil { return nil, err @@ -89,7 +89,7 @@ func (r *Remote) LayersFromRequestedComponents(ctx context.Context, requestedCom tarballFormat := "%s.tar" images := map[string]bool{} for _, rc := range requestedComponents { - component := helpers.Find(pkg.Components, func(component types.ZarfComponent) bool { + component := helpers.Find(pkg.Components, func(component v1alpha1.ZarfComponent) bool { return component.Name == rc.Name }) if component.Name == "" { diff --git a/src/pkg/zoci/push.go b/src/pkg/zoci/push.go index 63a80b425f..e080e80f99 100644 --- a/src/pkg/zoci/push.go +++ b/src/pkg/zoci/push.go @@ -11,15 +11,15 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/defenseunicorns/pkg/oci" ocispec "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/message" - "github.com/zarf-dev/zarf/src/types" "oras.land/oras-go/v2" "oras.land/oras-go/v2/content/file" ) // PublishPackage publishes the zarf package to the remote repository. -func (r *Remote) PublishPackage(ctx context.Context, pkg *types.ZarfPackage, paths *layout.PackagePaths, concurrency int) error { +func (r *Remote) PublishPackage(ctx context.Context, pkg *v1alpha1.ZarfPackage, paths *layout.PackagePaths, concurrency int) error { src, err := file.New(paths.Base) if err != nil { return err @@ -88,7 +88,7 @@ func (r *Remote) PublishPackage(ctx context.Context, pkg *types.ZarfPackage, pat return nil } -func annotationsFromMetadata(metadata *types.ZarfMetadata) map[string]string { +func annotationsFromMetadata(metadata *v1alpha1.ZarfMetadata) map[string]string { annotations := map[string]string{ ocispec.AnnotationTitle: metadata.Name, ocispec.AnnotationDescription: metadata.Description, diff --git a/src/pkg/zoci/utils.go b/src/pkg/zoci/utils.go index e9ac1f57e3..5679754449 100644 --- a/src/pkg/zoci/utils.go +++ b/src/pkg/zoci/utils.go @@ -10,12 +10,12 @@ import ( "strings" "github.com/defenseunicorns/pkg/helpers/v2" - "github.com/zarf-dev/zarf/src/types" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "oras.land/oras-go/v2/registry" ) // ReferenceFromMetadata returns a reference for the given metadata. -func ReferenceFromMetadata(registryLocation string, metadata *types.ZarfMetadata, build *types.ZarfBuildData) (string, error) { +func ReferenceFromMetadata(registryLocation string, metadata *v1alpha1.ZarfMetadata, build *v1alpha1.ZarfBuildData) (string, error) { ver := metadata.Version if len(ver) == 0 { return "", errors.New("version is required for publishing") diff --git a/src/test/e2e/05_tarball_test.go b/src/test/e2e/05_tarball_test.go index cac1a07582..a9af583002 100644 --- a/src/test/e2e/05_tarball_test.go +++ b/src/test/e2e/05_tarball_test.go @@ -13,6 +13,7 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/types" @@ -93,7 +94,7 @@ func TestReproducibleTarballs(t *testing.T) { stdOut, stdErr, err = e2e.Zarf(t, "tools", "archiver", "decompress", tb, unpack1) require.NoError(t, err, stdOut, stdErr) - var pkg1 types.ZarfPackage + var pkg1 v1alpha1.ZarfPackage err = utils.ReadYaml(filepath.Join(unpack1, layout.ZarfYAML), &pkg1) require.NoError(t, err) @@ -105,7 +106,7 @@ func TestReproducibleTarballs(t *testing.T) { stdOut, stdErr, err = e2e.Zarf(t, "tools", "archiver", "decompress", tb, unpack2) require.NoError(t, err, stdOut, stdErr) - var pkg2 types.ZarfPackage + var pkg2 v1alpha1.ZarfPackage err = utils.ReadYaml(filepath.Join(unpack2, layout.ZarfYAML), &pkg2) require.NoError(t, err) diff --git a/src/test/e2e/08_create_differential_test.go b/src/test/e2e/08_create_differential_test.go index 97aaf40de2..59e298c22d 100644 --- a/src/test/e2e/08_create_differential_test.go +++ b/src/test/e2e/08_create_differential_test.go @@ -11,10 +11,10 @@ import ( "github.com/mholt/archiver/v3" "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config/lang" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/utils" - "github.com/zarf-dev/zarf/src/types" ) // TestCreateDifferential creates several differential packages and ensures the reference package images and repos are not included in the new package. @@ -47,7 +47,7 @@ func TestCreateDifferential(t *testing.T) { require.NoError(t, err, "unable to extract zarf.yaml from the differential git package") // Load the extracted zarf.yaml specification - var differentialZarfConfig types.ZarfPackage + var differentialZarfConfig v1alpha1.ZarfPackage err = utils.ReadYaml(filepath.Join(tmpdir, layout.ZarfYAML), &differentialZarfConfig) require.NoError(t, err, "unable to read zarf.yaml from the differential git package") diff --git a/src/test/e2e/13_zarf_package_generate_test.go b/src/test/e2e/13_zarf_package_generate_test.go index 9d73747210..e1249ff8dc 100644 --- a/src/test/e2e/13_zarf_package_generate_test.go +++ b/src/test/e2e/13_zarf_package_generate_test.go @@ -9,9 +9,9 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/utils" - "github.com/zarf-dev/zarf/src/types" ) func TestZarfDevGenerate(t *testing.T) { @@ -27,7 +27,7 @@ func TestZarfDevGenerate(t *testing.T) { stdOut, stdErr, err := e2e.Zarf(t, "dev", "generate", "podinfo", "--url", url, "--version", version, "--gitPath", gitPath, "--output-directory", tmpDir) require.NoError(t, err, stdOut, stdErr) - zarfPackage := types.ZarfPackage{} + zarfPackage := v1alpha1.ZarfPackage{} packageLocation := filepath.Join(tmpDir, layout.ZarfYAML) err = utils.ReadYaml(packageLocation, &zarfPackage) require.NoError(t, err) diff --git a/src/test/e2e/51_oci_compose_test.go b/src/test/e2e/51_oci_compose_test.go index 034fc0e15a..fda9d5eeab 100644 --- a/src/test/e2e/51_oci_compose_test.go +++ b/src/test/e2e/51_oci_compose_test.go @@ -15,10 +15,10 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/transform" "github.com/zarf-dev/zarf/src/pkg/utils" - "github.com/zarf-dev/zarf/src/types" corev1 "k8s.io/api/core/v1" "oras.land/oras-go/v2/registry" ) @@ -135,7 +135,7 @@ func (suite *SkeletonSuite) Test_2_FilePaths() { } for _, pkgTar := range pkgTars { - var pkg types.ZarfPackage + var pkg v1alpha1.ZarfPackage unpacked := strings.TrimSuffix(pkgTar, ".tar.zst") defer os.RemoveAll(unpacked) @@ -184,7 +184,7 @@ func (suite *SkeletonSuite) DirOrFileExists(path string) { suite.Falsef(invalid, "path specified does not exist: %s", path) } -func (suite *SkeletonSuite) verifyComponentPaths(unpackedPath string, components []types.ZarfComponent, isSkeleton bool) { +func (suite *SkeletonSuite) verifyComponentPaths(unpackedPath string, components []v1alpha1.ZarfComponent, isSkeleton bool) { if isSkeleton { suite.NoDirExists(filepath.Join(unpackedPath, "images")) suite.NoDirExists(filepath.Join(unpackedPath, "sboms")) diff --git a/src/types/k8s.go b/src/types/k8s.go index 6804de17ee..33a288983d 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -9,6 +9,7 @@ import ( "time" "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config/lang" ) @@ -81,7 +82,7 @@ type ZarfState struct { // This object is saved as the data of a k8s secret within the 'Zarf' namespace (not as part of the ZarfState secret). type DeployedPackage struct { Name string `json:"name"` - Data ZarfPackage `json:"data"` + Data v1alpha1.ZarfPackage `json:"data"` CLIVersion string `json:"cliVersion"` Generation int `json:"generation"` DeployedComponents []DeployedComponent `json:"deployedComponents"` diff --git a/src/types/packager.go b/src/types/packager.go index 0089b2ae07..fb3f68bfd5 100644 --- a/src/types/packager.go +++ b/src/types/packager.go @@ -4,6 +4,8 @@ // Package types contains all the types used by Zarf. package types +import "github.com/zarf-dev/zarf/src/api/v1alpha1" + // PackagerConfig is the main struct that the packager uses to hold high-level options. type PackagerConfig struct { // CreateOpts tracks the user-defined options used to create the package @@ -37,5 +39,5 @@ type PackagerConfig struct { GenerateOpts ZarfGenerateOptions // The package data - Pkg ZarfPackage + Pkg v1alpha1.ZarfPackage } diff --git a/src/types/runtime.go b/src/types/runtime.go index 0298d80346..0faed8c9e6 100644 --- a/src/types/runtime.go +++ b/src/types/runtime.go @@ -8,14 +8,6 @@ import ( "time" ) -// Zarf looks for these strings in zarf.yaml to make dynamic changes -const ( - ZarfPackageTemplatePrefix = "###ZARF_PKG_TMPL_" - ZarfPackageVariablePrefix = "###ZARF_PKG_VAR_" - ZarfPackageArch = "###ZARF_PKG_ARCH###" - ZarfComponentName = "###ZARF_COMPONENT_NAME###" -) - // ZarfCommonOptions tracks the user-defined preferences used across commands. type ZarfCommonOptions struct { // Verify that Zarf should perform an action From cd3f49707513d2d3de0593256fd2e8f6c1c21494 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 31 Jul 2024 16:11:06 +0000 Subject: [PATCH 19/34] adding go mod to api package Signed-off-by: Austin Abro --- go.mod | 5 ++++- go.sum | 4 ++-- src/api/go.mod | 28 ++++++++++++++++++++++++++++ src/api/go.sum | 37 +++++++++++++++++++++++++++++++++++++ src/api/v1alpha1/package.go | 7 +++++++ 5 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 src/api/go.mod create mode 100644 src/api/go.sum diff --git a/go.mod b/go.mod index db29e4a620..58990c6b21 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/zarf-dev/zarf go 1.22.4 +replace github.com/zarf-dev/zarf/src/api => ./src/api + // TODO (@AABRO): Pending merge into github.com/gojsonschema/gojsonschema (https://github.com/gojsonschema/gojsonschema/pull/5) replace github.com/xeipuuv/gojsonschema => github.com/defenseunicorns/gojsonschema v0.0.0-20231116163348-e00f069122d6 @@ -45,12 +47,13 @@ require ( github.com/spf13/viper v1.18.2 github.com/stretchr/testify v1.9.0 github.com/xeipuuv/gojsonschema v1.2.0 + github.com/zarf-dev/zarf/src/api v0.0.0-00010101000000-000000000000 golang.org/x/crypto v0.24.0 golang.org/x/sync v0.7.0 golang.org/x/term v0.22.0 helm.sh/helm/v3 v3.14.2 k8s.io/api v0.30.0 - k8s.io/apimachinery v0.30.0 + k8s.io/apimachinery v0.30.3 k8s.io/client-go v0.30.0 k8s.io/component-base v0.30.0 k8s.io/klog/v2 v2.120.1 diff --git a/go.sum b/go.sum index 23759f5ede..0ae563ee50 100644 --- a/go.sum +++ b/go.sum @@ -2462,8 +2462,8 @@ k8s.io/api v0.30.0 h1:siWhRq7cNjy2iHssOB9SCGNCl2spiF1dO3dABqZ8niA= k8s.io/api v0.30.0/go.mod h1:OPlaYhoHs8EQ1ql0R/TsUgaRPhpKNxIMrKQfWUp8QSE= k8s.io/apiextensions-apiserver v0.30.0 h1:jcZFKMqnICJfRxTgnC4E+Hpcq8UEhT8B2lhBcQ+6uAs= k8s.io/apiextensions-apiserver v0.30.0/go.mod h1:N9ogQFGcrbWqAY9p2mUAL5mGxsLqwgtUce127VtRX5Y= -k8s.io/apimachinery v0.30.0 h1:qxVPsyDM5XS96NIh9Oj6LavoVFYff/Pon9cZeDIkHHA= -k8s.io/apimachinery v0.30.0/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= +k8s.io/apimachinery v0.30.3 h1:q1laaWCmrszyQuSQCfNB8cFgCuDAoPszKY4ucAjDwHc= +k8s.io/apimachinery v0.30.3/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= k8s.io/apiserver v0.30.0 h1:QCec+U72tMQ+9tR6A0sMBB5Vh6ImCEkoKkTDRABWq6M= k8s.io/apiserver v0.30.0/go.mod h1:smOIBq8t0MbKZi7O7SyIpjPsiKJ8qa+llcFCluKyqiY= k8s.io/cli-runtime v0.29.1 h1:By3WVOlEWYfyxhGko0f/IuAOLQcbBSMzwSaDren2JUs= diff --git a/src/api/go.mod b/src/api/go.mod new file mode 100644 index 0000000000..1351380609 --- /dev/null +++ b/src/api/go.mod @@ -0,0 +1,28 @@ +module github.com/zarf-dev/zarf/src/api + +go 1.22.4 + +replace github.com/zarf-dev/zarf => ../.. + +require ( + github.com/defenseunicorns/pkg/helpers/v2 v2.0.1 + github.com/invopop/jsonschema v0.12.0 + github.com/stretchr/testify v1.9.0 + github.com/zarf-dev/zarf v0.37.0 + k8s.io/apimachinery v0.30.3 +) + +require ( + github.com/bahlo/generic-list-go v0.2.0 // indirect + github.com/buger/jsonparser v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/mailru/easyjson v0.7.7 // indirect + github.com/otiai10/copy v1.14.0 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.22.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + k8s.io/utils v0.0.0-20231127182322-b307cd553661 // indirect + oras.land/oras-go/v2 v2.5.0 // indirect +) diff --git a/src/api/go.sum b/src/api/go.sum new file mode 100644 index 0000000000..3cd2d742fb --- /dev/null +++ b/src/api/go.sum @@ -0,0 +1,37 @@ +github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= +github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= +github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= +github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/defenseunicorns/pkg/helpers/v2 v2.0.1 h1:j08rz9vhyD9Bs+yKiyQMY2tSSejXRMxTqEObZ5M1Wbk= +github.com/defenseunicorns/pkg/helpers/v2 v2.0.1/go.mod h1:u1PAqOICZyiGIVA2v28g55bQH1GiAt0Bc4U9/rnWQvQ= +github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI= +github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= +github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks= +github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc= +github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +k8s.io/apimachinery v0.30.3 h1:q1laaWCmrszyQuSQCfNB8cFgCuDAoPszKY4ucAjDwHc= +k8s.io/apimachinery v0.30.3/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= +k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6RxQGZDnzuLcrUTI= +k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +oras.land/oras-go/v2 v2.5.0 h1:o8Me9kLY74Vp5uw07QXPiitjsw7qNXi8Twd+19Zf02c= +oras.land/oras-go/v2 v2.5.0/go.mod h1:z4eisnLP530vwIOUOJeBIj0aGI0L1C3d53atvCBqZHg= diff --git a/src/api/v1alpha1/package.go b/src/api/v1alpha1/package.go index 2475790fc6..e489a99fc3 100644 --- a/src/api/v1alpha1/package.go +++ b/src/api/v1alpha1/package.go @@ -27,8 +27,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"` // The kind of Zarf package. Kind ZarfPackageKind `json:"kind"` // Package metadata. @@ -48,6 +52,9 @@ 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. From d16a7d77dfeab946ace3a949817963c4bd484b4d Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 31 Jul 2024 16:23:26 +0000 Subject: [PATCH 20/34] move bigbang over Signed-off-by: Austin Abro --- src/api/v1alpha1/component.go | 2 +- src/{types => api/v1alpha1}/extensions/bigbang.go | 0 src/{types => api/v1alpha1}/extensions/common.go | 0 src/cmd/internal.go | 4 ++-- src/extensions/bigbang/bigbang.go | 2 +- src/extensions/bigbang/flux.go | 2 +- src/extensions/bigbang/manifests.go | 2 +- src/pkg/packager/composer/list_test.go | 2 +- zarf.schema.json | 10 +++++++++- 9 files changed, 16 insertions(+), 8 deletions(-) rename src/{types => api/v1alpha1}/extensions/bigbang.go (100%) rename src/{types => api/v1alpha1}/extensions/common.go (100%) diff --git a/src/api/v1alpha1/component.go b/src/api/v1alpha1/component.go index cb16f9ad80..cc8431be37 100644 --- a/src/api/v1alpha1/component.go +++ b/src/api/v1alpha1/component.go @@ -6,9 +6,9 @@ package v1alpha1 import ( "github.com/invopop/jsonschema" + "github.com/zarf-dev/zarf/src/api/v1alpha1/extensions" "github.com/zarf-dev/zarf/src/pkg/utils/exec" "github.com/zarf-dev/zarf/src/pkg/variables" - "github.com/zarf-dev/zarf/src/types/extensions" ) var ( diff --git a/src/types/extensions/bigbang.go b/src/api/v1alpha1/extensions/bigbang.go similarity index 100% rename from src/types/extensions/bigbang.go rename to src/api/v1alpha1/extensions/bigbang.go diff --git a/src/types/extensions/common.go b/src/api/v1alpha1/extensions/common.go similarity index 100% rename from src/types/extensions/common.go rename to src/api/v1alpha1/extensions/common.go diff --git a/src/cmd/internal.go b/src/cmd/internal.go index 19fc74e0b9..fabda97ee7 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -161,8 +161,8 @@ tableOfContents: false func addGoComments(reflector *jsonschema.Reflector) error { addCommentErr := errors.New("this command must be called from the root of the Zarf repo") - typePackagePath := filepath.Join("src", "types") - if err := reflector.AddGoComments("github.com/zarf-dev/zarf", typePackagePath); err != nil { + // typePackagePath := filepath.Join("src", "types") + if err := reflector.AddGoComments("github.com/zarf-dev/zarf", "./src/api/v1alpha1"); err != nil { return fmt.Errorf("%w: %w", addCommentErr, err) } varPackagePath := filepath.Join("src", "pkg", "variables") diff --git a/src/extensions/bigbang/bigbang.go b/src/extensions/bigbang/bigbang.go index a00c267b7c..b940b8221d 100644 --- a/src/extensions/bigbang/bigbang.go +++ b/src/extensions/bigbang/bigbang.go @@ -18,12 +18,12 @@ import ( fluxHelmCtrl "github.com/fluxcd/helm-controller/api/v2beta1" fluxSrcCtrl "github.com/fluxcd/source-controller/api/v1beta2" "github.com/zarf-dev/zarf/src/api/v1alpha1" + "github.com/zarf-dev/zarf/src/api/v1alpha1/extensions" "github.com/zarf-dev/zarf/src/internal/packager/helm" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/pkg/variables" - "github.com/zarf-dev/zarf/src/types/extensions" "helm.sh/helm/v3/pkg/chartutil" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/src/extensions/bigbang/flux.go b/src/extensions/bigbang/flux.go index 0b37aed2e2..2acdee4f99 100644 --- a/src/extensions/bigbang/flux.go +++ b/src/extensions/bigbang/flux.go @@ -13,9 +13,9 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" fluxHelmCtrl "github.com/fluxcd/helm-controller/api/v2beta1" "github.com/zarf-dev/zarf/src/api/v1alpha1" + "github.com/zarf-dev/zarf/src/api/v1alpha1/extensions" "github.com/zarf-dev/zarf/src/internal/packager/kustomize" "github.com/zarf-dev/zarf/src/pkg/utils" - "github.com/zarf-dev/zarf/src/types/extensions" "helm.sh/helm/v3/pkg/chartutil" v1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" diff --git a/src/extensions/bigbang/manifests.go b/src/extensions/bigbang/manifests.go index 686458c6cc..c10d81390a 100644 --- a/src/extensions/bigbang/manifests.go +++ b/src/extensions/bigbang/manifests.go @@ -13,7 +13,7 @@ import ( "github.com/Masterminds/semver/v3" fluxHelmCtrl "github.com/fluxcd/helm-controller/api/v2beta1" fluxSrcCtrl "github.com/fluxcd/source-controller/api/v1" - "github.com/zarf-dev/zarf/src/types/extensions" + "github.com/zarf-dev/zarf/src/api/v1alpha1/extensions" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/src/pkg/packager/composer/list_test.go b/src/pkg/packager/composer/list_test.go index 97a9790741..56e266738b 100644 --- a/src/pkg/packager/composer/list_test.go +++ b/src/pkg/packager/composer/list_test.go @@ -13,8 +13,8 @@ import ( "github.com/stretchr/testify/require" "github.com/zarf-dev/zarf/src/api/v1alpha1" + "github.com/zarf-dev/zarf/src/api/v1alpha1/extensions" "github.com/zarf-dev/zarf/src/pkg/variables" - "github.com/zarf-dev/zarf/src/types/extensions" ) func TestNewImportChain(t *testing.T) { diff --git a/zarf.schema.json b/zarf.schema.json index f4a0690553..79784a4f41 100644 --- a/zarf.schema.json +++ b/zarf.schema.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/zarf-dev/zarf/src/types/zarf-package", + "$id": "https://github.com/zarf-dev/zarf/src/api/v1alpha1/zarf-package", "$defs": { "BigBang": { "properties": { @@ -1103,6 +1103,13 @@ } }, "properties": { + "apiVersion": { + "type": "string", + "enum": [ + "zarf.dev/v1alpha1" + ], + "description": "The API version of the Zarf package." + }, "kind": { "type": "string", "enum": [ @@ -1146,6 +1153,7 @@ "additionalProperties": false, "type": "object", "required": [ + "apiVersion", "kind", "components" ], From 2716d41feb0ccc732865dd834199d5a289208f2f Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 31 Jul 2024 16:26:03 +0000 Subject: [PATCH 21/34] avoid introducing dependencies Signed-off-by: Austin Abro --- go.mod | 2 +- go.sum | 4 ++-- src/api/go.mod | 2 +- src/api/go.sum | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 58990c6b21..884d57d9cc 100644 --- a/go.mod +++ b/go.mod @@ -53,7 +53,7 @@ require ( golang.org/x/term v0.22.0 helm.sh/helm/v3 v3.14.2 k8s.io/api v0.30.0 - k8s.io/apimachinery v0.30.3 + k8s.io/apimachinery v0.30.0 k8s.io/client-go v0.30.0 k8s.io/component-base v0.30.0 k8s.io/klog/v2 v2.120.1 diff --git a/go.sum b/go.sum index 0ae563ee50..23759f5ede 100644 --- a/go.sum +++ b/go.sum @@ -2462,8 +2462,8 @@ k8s.io/api v0.30.0 h1:siWhRq7cNjy2iHssOB9SCGNCl2spiF1dO3dABqZ8niA= k8s.io/api v0.30.0/go.mod h1:OPlaYhoHs8EQ1ql0R/TsUgaRPhpKNxIMrKQfWUp8QSE= k8s.io/apiextensions-apiserver v0.30.0 h1:jcZFKMqnICJfRxTgnC4E+Hpcq8UEhT8B2lhBcQ+6uAs= k8s.io/apiextensions-apiserver v0.30.0/go.mod h1:N9ogQFGcrbWqAY9p2mUAL5mGxsLqwgtUce127VtRX5Y= -k8s.io/apimachinery v0.30.3 h1:q1laaWCmrszyQuSQCfNB8cFgCuDAoPszKY4ucAjDwHc= -k8s.io/apimachinery v0.30.3/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= +k8s.io/apimachinery v0.30.0 h1:qxVPsyDM5XS96NIh9Oj6LavoVFYff/Pon9cZeDIkHHA= +k8s.io/apimachinery v0.30.0/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= k8s.io/apiserver v0.30.0 h1:QCec+U72tMQ+9tR6A0sMBB5Vh6ImCEkoKkTDRABWq6M= k8s.io/apiserver v0.30.0/go.mod h1:smOIBq8t0MbKZi7O7SyIpjPsiKJ8qa+llcFCluKyqiY= k8s.io/cli-runtime v0.29.1 h1:By3WVOlEWYfyxhGko0f/IuAOLQcbBSMzwSaDren2JUs= diff --git a/src/api/go.mod b/src/api/go.mod index 1351380609..b7783a9211 100644 --- a/src/api/go.mod +++ b/src/api/go.mod @@ -9,7 +9,7 @@ require ( github.com/invopop/jsonschema v0.12.0 github.com/stretchr/testify v1.9.0 github.com/zarf-dev/zarf v0.37.0 - k8s.io/apimachinery v0.30.3 + k8s.io/apimachinery v0.30.0 ) require ( diff --git a/src/api/go.sum b/src/api/go.sum index 3cd2d742fb..60ab6795e3 100644 --- a/src/api/go.sum +++ b/src/api/go.sum @@ -29,8 +29,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/apimachinery v0.30.3 h1:q1laaWCmrszyQuSQCfNB8cFgCuDAoPszKY4ucAjDwHc= -k8s.io/apimachinery v0.30.3/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= +k8s.io/apimachinery v0.30.0 h1:qxVPsyDM5XS96NIh9Oj6LavoVFYff/Pon9cZeDIkHHA= +k8s.io/apimachinery v0.30.0/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6RxQGZDnzuLcrUTI= k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= oras.land/oras-go/v2 v2.5.0 h1:o8Me9kLY74Vp5uw07QXPiitjsw7qNXi8Twd+19Zf02c= From 648bbf0c48df3f0d5cc5c332089a3339ee69672f Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 31 Jul 2024 16:28:52 +0000 Subject: [PATCH 22/34] header title Signed-off-by: Austin Abro --- src/api/v1alpha1/component.go | 2 +- src/api/v1alpha1/package.go | 2 +- src/api/v1alpha1/validate.go | 2 +- src/api/v1alpha1/validate_test.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/v1alpha1/component.go b/src/api/v1alpha1/component.go index cc8431be37..3c00a325f6 100644 --- a/src/api/v1alpha1/component.go +++ b/src/api/v1alpha1/component.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package v1alpha1 contains all the structs for the v1alpha1 ZarfPackageConfig +// Package v1alpha1 holds the definition of the v1alpha1 Zarf Package package v1alpha1 import ( diff --git a/src/api/v1alpha1/package.go b/src/api/v1alpha1/package.go index e489a99fc3..2758a6b288 100644 --- a/src/api/v1alpha1/package.go +++ b/src/api/v1alpha1/package.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package v1alpha1 contains all the structs for the v1alpha1 ZarfPackageConfig +// Package v1alpha1 holds the definition of the v1alpha1 Zarf Package package v1alpha1 import ( diff --git a/src/api/v1alpha1/validate.go b/src/api/v1alpha1/validate.go index fba0a576ff..86da6283f7 100644 --- a/src/api/v1alpha1/validate.go +++ b/src/api/v1alpha1/validate.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package v1alpha1 contains all the structs for the v1alpha1 ZarfPackageConfig +// Package v1alpha1 holds the definition of the v1alpha1 Zarf Package package v1alpha1 import ( diff --git a/src/api/v1alpha1/validate_test.go b/src/api/v1alpha1/validate_test.go index d84eb18fd4..de3f675c2e 100644 --- a/src/api/v1alpha1/validate_test.go +++ b/src/api/v1alpha1/validate_test.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package v1alpha1 contains all the structs for the v1alpha1 ZarfPackageConfig +// Package v1alpha1 holds the definition of the v1alpha1 Zarf Package package v1alpha1 import ( From df9c182601026ad9a2cbef5aa9a57a81c36826d4 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 31 Jul 2024 16:32:43 +0000 Subject: [PATCH 23/34] package Signed-off-by: Austin Abro --- src/api/v1alpha1/package.go | 2 +- zarf.schema.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/api/v1alpha1/package.go b/src/api/v1alpha1/package.go index 2758a6b288..c7ae1af3ad 100644 --- a/src/api/v1alpha1/package.go +++ b/src/api/v1alpha1/package.go @@ -32,7 +32,7 @@ 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"` + ApiVersion string `json:"apiVersion,omitempty"` // The kind of Zarf package. Kind ZarfPackageKind `json:"kind"` // Package metadata. diff --git a/zarf.schema.json b/zarf.schema.json index 79784a4f41..6249898643 100644 --- a/zarf.schema.json +++ b/zarf.schema.json @@ -1153,7 +1153,6 @@ "additionalProperties": false, "type": "object", "required": [ - "apiVersion", "kind", "components" ], From c955d6f7506e2ebccda60217525fe07244c3cef5 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 1 Aug 2024 18:03:58 +0000 Subject: [PATCH 24/34] move validate to lint Signed-off-by: Austin Abro --- src/api/go.mod | 7 +- src/api/go.sum | 4 - src/api/v1alpha1/component.go | 28 +--- src/{api/v1alpha1 => pkg/lint}/validate.go | 86 +++++----- .../v1alpha1 => pkg/lint}/validate_test.go | 153 +++++++++--------- src/pkg/packager/composer/list.go | 8 +- src/pkg/packager/creator/utils.go | 2 +- src/pkg/packager/generate.go | 3 +- src/pkg/packager/sources/cluster.go | 3 +- src/pkg/variables/types.go | 26 +-- 10 files changed, 135 insertions(+), 185 deletions(-) rename src/{api/v1alpha1 => pkg/lint}/validate.go (79%) rename src/{api/v1alpha1 => pkg/lint}/validate_test.go (73%) diff --git a/src/api/go.mod b/src/api/go.mod index b7783a9211..7f18f88c76 100644 --- a/src/api/go.mod +++ b/src/api/go.mod @@ -5,24 +5,19 @@ go 1.22.4 replace github.com/zarf-dev/zarf => ../.. require ( - github.com/defenseunicorns/pkg/helpers/v2 v2.0.1 github.com/invopop/jsonschema v0.12.0 - github.com/stretchr/testify v1.9.0 github.com/zarf-dev/zarf v0.37.0 - k8s.io/apimachinery v0.30.0 ) require ( github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/buger/jsonparser v1.1.1 // indirect - github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/defenseunicorns/pkg/helpers/v2 v2.0.1 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/otiai10/copy v1.14.0 // indirect - github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.22.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/utils v0.0.0-20231127182322-b307cd553661 // indirect oras.land/oras-go/v2 v2.5.0 // indirect ) diff --git a/src/api/go.sum b/src/api/go.sum index 60ab6795e3..dd52f17424 100644 --- a/src/api/go.sum +++ b/src/api/go.sum @@ -29,9 +29,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/apimachinery v0.30.0 h1:qxVPsyDM5XS96NIh9Oj6LavoVFYff/Pon9cZeDIkHHA= -k8s.io/apimachinery v0.30.0/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= -k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6RxQGZDnzuLcrUTI= -k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= oras.land/oras-go/v2 v2.5.0 h1:o8Me9kLY74Vp5uw07QXPiitjsw7qNXi8Twd+19Zf02c= oras.land/oras-go/v2 v2.5.0/go.mod h1:z4eisnLP530vwIOUOJeBIj0aGI0L1C3d53atvCBqZHg= diff --git a/src/api/v1alpha1/component.go b/src/api/v1alpha1/component.go index 3c00a325f6..c9928e95c1 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. @@ -279,7 +263,7 @@ type ZarfComponentAction struct { // (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems. Shell *exec.Shell `json:"shell,omitempty"` // [Deprecated] (replaced by setVariables) (onDeploy/cmd only) The name of a variable to update with the output of the command. This variable will be available to all remaining actions and components in the package. This will be removed in Zarf v1.0.0. - DeprecatedSetVariable string `json:"setVariable,omitempty"` + DeprecatedSetVariable string `json:"setVariable,omitempty" jsonschema:"pattern=^[A-Z0-9_]+$"` // (onDeploy/cmd only) An array of variables to update with the output of the command. These variables will be available to all remaining actions and components in the package. SetVariables []variables.Variable `json:"setVariables,omitempty"` // Description of the action to be displayed during package execution instead of the command. @@ -288,12 +272,6 @@ type ZarfComponentAction struct { Wait *ZarfComponentActionWait `json:"wait,omitempty"` } -// JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` -func (ZarfComponentAction) JSONSchemaExtend(schema *jsonschema.Schema) { - name, _ := schema.Properties.Get("setVariable") - name.Pattern = variables.UppercaseNumberUnderscorePattern -} - // ZarfComponentActionWait specifies a condition to wait for before continuing type ZarfComponentActionWait struct { // Wait for a condition to be met in the cluster before continuing. Only one of cluster or network can be specified. diff --git a/src/api/v1alpha1/validate.go b/src/pkg/lint/validate.go similarity index 79% rename from src/api/v1alpha1/validate.go rename to src/pkg/lint/validate.go index 86da6283f7..c37658139e 100644 --- a/src/api/v1alpha1/validate.go +++ b/src/pkg/lint/validate.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package v1alpha1 holds the definition of the v1alpha1 Zarf Package -package v1alpha1 +// Package lint contains functions for verifying zarf yaml files are valid +package lint import ( "errors" @@ -12,6 +12,7 @@ import ( "strings" "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config/lang" "k8s.io/apimachinery/pkg/util/validation" ) @@ -27,52 +28,56 @@ var ( // IsLowercaseNumberHyphenNoStartHyphen is a regex for lowercase, numbers and hyphens that cannot start with a hyphen. // https://regex101.com/r/FLdG9G/2 IsLowercaseNumberHyphenNoStartHyphen = regexp.MustCompile(`^[a-z0-9][a-z0-9\-]*$`).MatchString + // Define allowed OS, an empty string means it is allowed on all operating systems + // same as enums on ZarfComponentOnlyTarget + supportedOS = []string{"linux", "darwin", "windows", ""} ) -// Validate runs all validation checks on the package. -func (pkg ZarfPackage) Validate() error { +// SupportedOS returns the supported operating systems. +// +// The supported operating systems are: linux, darwin, windows. +// +// An empty string signifies no OS restrictions. +func SupportedOS() []string { + return supportedOS +} + +// ValidatePackage runs all validation checks on the package. +func ValidatePackage(pkg v1alpha1.ZarfPackage) error { var err error - if pkg.Kind == ZarfInitConfig && pkg.Metadata.YOLO { + if pkg.Kind == v1alpha1.ZarfInitConfig && pkg.Metadata.YOLO { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrInitNoYOLO)) } - for _, constant := range pkg.Constants { if varErr := constant.Validate(); varErr != nil { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrConstant, varErr)) } } - uniqueComponentNames := make(map[string]bool) groupDefault := make(map[string]string) groupedComponents := make(map[string][]string) - if pkg.Metadata.YOLO { for _, component := range pkg.Components { if len(component.Images) > 0 { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrYOLONoOCI)) } - if len(component.Repos) > 0 { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrYOLONoGit)) } - if component.Only.Cluster.Architecture != "" { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrYOLONoArch)) } - if len(component.Only.Cluster.Distros) > 0 { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrYOLONoDistro)) } } } - for _, component := range pkg.Components { // ensure component name is unique if _, ok := uniqueComponentNames[component.Name]; ok { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrComponentNameNotUnique, component.Name)) } uniqueComponentNames[component.Name] = true - if component.IsRequired() { if component.Default { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrComponentReqDefault, component.Name)) @@ -81,7 +86,6 @@ func (pkg ZarfPackage) Validate() error { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrComponentReqGrouped, component.Name)) } } - uniqueChartNames := make(map[string]bool) for _, chart := range component.Charts { // ensure chart name is unique @@ -89,12 +93,10 @@ func (pkg ZarfPackage) Validate() error { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrChartNameNotUnique, chart.Name)) } uniqueChartNames[chart.Name] = true - - if chartErr := chart.Validate(); chartErr != nil { + if chartErr := ValidateChart(chart); chartErr != nil { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrChart, chartErr)) } } - uniqueManifestNames := make(map[string]bool) for _, manifest := range component.Manifests { // ensure manifest name is unique @@ -102,16 +104,13 @@ func (pkg ZarfPackage) Validate() error { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrManifestNameNotUnique, manifest.Name)) } uniqueManifestNames[manifest.Name] = true - - if manifestErr := manifest.Validate(); manifestErr != nil { + if manifestErr := ValidateManifest(manifest); manifestErr != nil { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrManifest, manifestErr)) } } - - if actionsErr := component.Actions.validate(); actionsErr != nil { + if actionsErr := ValidateActions(component.Actions); actionsErr != nil { err = errors.Join(err, fmt.Errorf("%q: %w", component.Name, actionsErr)) } - // ensure groups don't have multiple defaults or only one component if component.DeprecatedGroup != "" { if component.Default { @@ -123,38 +122,37 @@ func (pkg ZarfPackage) Validate() error { groupedComponents[component.DeprecatedGroup] = append(groupedComponents[component.DeprecatedGroup], component.Name) } } - for groupKey, componentNames := range groupedComponents { if len(componentNames) == 1 { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrGroupOneComponent, groupKey, componentNames[0])) } } - return err } -func (a ZarfComponentActions) validate() error { +// ValidateActions validates the actions of a component. +func ValidateActions(a v1alpha1.ZarfComponentActions) error { var err error - err = errors.Join(err, a.OnCreate.Validate()) + err = errors.Join(err, ValidateActionSet(a.OnCreate)) - if a.OnCreate.HasSetVariables() { + if HasSetVariables(a.OnCreate) { err = errors.Join(err, fmt.Errorf("cannot contain setVariables outside of onDeploy in actions")) } - err = errors.Join(err, a.OnDeploy.Validate()) + err = errors.Join(err, ValidateActionSet(a.OnDeploy)) - if a.OnRemove.HasSetVariables() { + if HasSetVariables(a.OnRemove) { err = errors.Join(err, fmt.Errorf("cannot contain setVariables outside of onDeploy in actions")) } - err = errors.Join(err, a.OnRemove.Validate()) + err = errors.Join(err, ValidateActionSet(a.OnRemove)) return err } -// Validate validates the component trying to be imported. -func (c ZarfComponent) Validate() error { +// ValidateComponent validates the component trying to be imported. +func ValidateComponent(c v1alpha1.ZarfComponent) error { var err error path := c.Import.Path url := c.Import.URL @@ -189,8 +187,8 @@ func (c ZarfComponent) Validate() error { } // HasSetVariables returns true if any of the actions contain setVariables. -func (as ZarfComponentActionSet) HasSetVariables() bool { - check := func(actions []ZarfComponentAction) bool { +func HasSetVariables(as v1alpha1.ZarfComponentActionSet) bool { + check := func(actions []v1alpha1.ZarfComponentAction) bool { for _, action := range actions { if len(action.SetVariables) > 0 { return true @@ -202,12 +200,12 @@ func (as ZarfComponentActionSet) HasSetVariables() bool { return check(as.Before) || check(as.After) || check(as.OnSuccess) || check(as.OnFailure) } -// Validate runs all validation checks on component action sets. -func (as ZarfComponentActionSet) Validate() error { +// ValidateActionSet runs all validation checks on component action sets. +func ValidateActionSet(as v1alpha1.ZarfComponentActionSet) error { var err error - validate := func(actions []ZarfComponentAction) { + validate := func(actions []v1alpha1.ZarfComponentAction) { for _, action := range actions { - if actionErr := action.Validate(); actionErr != nil { + if actionErr := ValidateAction(action); actionErr != nil { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrAction, actionErr)) } } @@ -220,8 +218,8 @@ func (as ZarfComponentActionSet) Validate() error { return err } -// Validate runs all validation checks on an action. -func (action ZarfComponentAction) Validate() error { +// ValidateAction runs all validation checks on an action. +func ValidateAction(action v1alpha1.ZarfComponentAction) error { var err error if action.Wait != nil { @@ -267,8 +265,8 @@ func validateReleaseName(chartName, releaseName string) (err error) { return } -// Validate runs all validation checks on a chart. -func (chart ZarfChart) Validate() error { +// ValidateChart runs all validation checks on a chart. +func ValidateChart(chart v1alpha1.ZarfChart) error { var err error if len(chart.Name) > ZarfMaxChartNameLength { @@ -299,8 +297,8 @@ func (chart ZarfChart) Validate() error { return err } -// Validate runs all validation checks on a manifest. -func (manifest ZarfManifest) Validate() error { +// ValidateManifest runs all validation checks on a manifest. +func ValidateManifest(manifest v1alpha1.ZarfManifest) error { var err error if len(manifest.Name) > ZarfMaxChartNameLength { diff --git a/src/api/v1alpha1/validate_test.go b/src/pkg/lint/validate_test.go similarity index 73% rename from src/api/v1alpha1/validate_test.go rename to src/pkg/lint/validate_test.go index de3f675c2e..c3b4f8b519 100644 --- a/src/api/v1alpha1/validate_test.go +++ b/src/pkg/lint/validate_test.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package v1alpha1 holds the definition of the v1alpha1 Zarf Package -package v1alpha1 +// Package lint contains functions for verifying zarf yaml files are valid +package lint import ( "fmt" @@ -12,6 +12,7 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config/lang" "github.com/zarf-dev/zarf/src/pkg/variables" ) @@ -20,17 +21,17 @@ func TestZarfPackageValidate(t *testing.T) { t.Parallel() tests := []struct { name string - pkg ZarfPackage + pkg v1alpha1.ZarfPackage expectedErrs []string }{ { name: "valid package", - pkg: ZarfPackage{ - Kind: ZarfPackageConfig, - Metadata: ZarfMetadata{ + pkg: v1alpha1.ZarfPackage{ + Kind: v1alpha1.ZarfPackageConfig, + Metadata: v1alpha1.ZarfMetadata{ Name: "valid-package", }, - Components: []ZarfComponent{ + Components: []v1alpha1.ZarfComponent{ { Name: "component1", }, @@ -40,21 +41,21 @@ func TestZarfPackageValidate(t *testing.T) { }, { name: "invalid package", - pkg: ZarfPackage{ - Kind: ZarfPackageConfig, - Metadata: ZarfMetadata{ + pkg: v1alpha1.ZarfPackage{ + Kind: v1alpha1.ZarfPackageConfig, + Metadata: v1alpha1.ZarfMetadata{ Name: "invalid-package", }, - Components: []ZarfComponent{ + Components: []v1alpha1.ZarfComponent{ { Name: "invalid", Required: helpers.BoolPtr(true), Default: true, - Charts: []ZarfChart{ + Charts: []v1alpha1.ZarfChart{ {Name: "chart1", Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0"}, {Name: "chart1", Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0"}, }, - Manifests: []ZarfManifest{ + Manifests: []v1alpha1.ZarfManifest{ {Name: "manifest1", Files: []string{"file1"}}, {Name: "manifest1", Files: []string{"file2"}}, }, @@ -102,19 +103,19 @@ func TestZarfPackageValidate(t *testing.T) { }, { name: "invalid yolo", - pkg: ZarfPackage{ - Kind: ZarfInitConfig, - Metadata: ZarfMetadata{ + pkg: v1alpha1.ZarfPackage{ + Kind: v1alpha1.ZarfInitConfig, + Metadata: v1alpha1.ZarfMetadata{ Name: "invalid-yolo", YOLO: true, }, - Components: []ZarfComponent{ + Components: []v1alpha1.ZarfComponent{ { Name: "yolo", Images: []string{"an-image"}, Repos: []string{"a-repo"}, - Only: ZarfComponentOnlyTarget{ - Cluster: ZarfComponentOnlyCluster{ + Only: v1alpha1.ZarfComponentOnlyTarget{ + Cluster: v1alpha1.ZarfComponentOnlyCluster{ Architecture: "not-empty", Distros: []string{"not-empty"}, }, @@ -136,7 +137,7 @@ func TestZarfPackageValidate(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - err := tt.pkg.Validate() + err := ValidatePackage(tt.pkg) if tt.expectedErrs == nil { require.NoError(t, err) return @@ -151,23 +152,23 @@ func TestValidateManifest(t *testing.T) { t.Parallel() longName := strings.Repeat("a", ZarfMaxChartNameLength+1) tests := []struct { - manifest ZarfManifest + manifest v1alpha1.ZarfManifest expectedErrs []string name string }{ { name: "valid", - manifest: ZarfManifest{Name: "valid", Files: []string{"a-file"}}, + manifest: v1alpha1.ZarfManifest{Name: "valid", Files: []string{"a-file"}}, expectedErrs: nil, }, { name: "long name", - manifest: ZarfManifest{Name: longName, Files: []string{"a-file"}}, + manifest: v1alpha1.ZarfManifest{Name: longName, Files: []string{"a-file"}}, expectedErrs: []string{fmt.Sprintf(lang.PkgValidateErrManifestNameLength, longName, ZarfMaxChartNameLength)}, }, { name: "no files or kustomize", - manifest: ZarfManifest{Name: "nothing-there"}, + manifest: v1alpha1.ZarfManifest{Name: "nothing-there"}, expectedErrs: []string{fmt.Sprintf(lang.PkgValidateErrManifestFileOrKustomize, "nothing-there")}, }, } @@ -175,7 +176,7 @@ func TestValidateManifest(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - err := tt.manifest.Validate() + err := ValidateManifest(tt.manifest) if tt.expectedErrs == nil { require.NoError(t, err) return @@ -255,25 +256,25 @@ func TestValidateChart(t *testing.T) { longName := strings.Repeat("a", ZarfMaxChartNameLength+1) tests := []struct { name string - chart ZarfChart + chart v1alpha1.ZarfChart expectedErrs []string partialMatch bool }{ { name: "valid", - chart: ZarfChart{Name: "chart1", Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0", ReleaseName: "this-is-valid"}, + chart: v1alpha1.ZarfChart{Name: "chart1", Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0", ReleaseName: "this-is-valid"}, expectedErrs: nil, }, { name: "long name", - chart: ZarfChart{Name: longName, Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0"}, + chart: v1alpha1.ZarfChart{Name: longName, Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0"}, expectedErrs: []string{ fmt.Sprintf(lang.PkgValidateErrChartName, longName, ZarfMaxChartNameLength), }, }, { name: "no url, local path, version, or namespace", - chart: ZarfChart{Name: "invalid"}, + chart: v1alpha1.ZarfChart{Name: "invalid"}, expectedErrs: []string{ fmt.Sprintf(lang.PkgValidateErrChartNamespaceMissing, "invalid"), fmt.Sprintf(lang.PkgValidateErrChartURLOrPath, "invalid"), @@ -282,25 +283,25 @@ func TestValidateChart(t *testing.T) { }, { name: "both url and local path", - chart: ZarfChart{Name: "invalid", Namespace: "whatever", URL: "http://whatever", LocalPath: "wherever", Version: "v1.0.0"}, + chart: v1alpha1.ZarfChart{Name: "invalid", Namespace: "whatever", URL: "http://whatever", LocalPath: "wherever", Version: "v1.0.0"}, expectedErrs: []string{ fmt.Sprintf(lang.PkgValidateErrChartURLOrPath, "invalid"), }, }, { name: "invalid releaseName", - chart: ZarfChart{ReleaseName: "namedwithperiods-0.47.0", Name: "releaseName", Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0"}, + chart: v1alpha1.ZarfChart{ReleaseName: "namedwithperiods-0.47.0", Name: "releaseName", Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0"}, expectedErrs: []string{"invalid release name 'namedwithperiods-0.47.0'"}, partialMatch: true, }, { name: "missing releaseName fallsback to name", - chart: ZarfChart{Name: "chart3", Namespace: "namespace", URL: "http://whatever", Version: "v1.0.0"}, + chart: v1alpha1.ZarfChart{Name: "chart3", Namespace: "namespace", URL: "http://whatever", Version: "v1.0.0"}, expectedErrs: nil, }, { name: "missing name and releaseName", - chart: ZarfChart{Namespace: "namespace", URL: "http://whatever", Version: "v1.0.0"}, + chart: v1alpha1.ZarfChart{Namespace: "namespace", URL: "http://whatever", Version: "v1.0.0"}, expectedErrs: []string{errChartReleaseNameEmpty}, }, } @@ -308,7 +309,7 @@ func TestValidateChart(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - err := tt.chart.Validate() + err := ValidateChart(tt.chart) if tt.expectedErrs == nil { require.NoError(t, err) return @@ -331,21 +332,21 @@ func TestValidateComponentActions(t *testing.T) { t.Parallel() tests := []struct { name string - actions ZarfComponentActions + actions v1alpha1.ZarfComponentActions expectedErrs []string }{ { name: "valid actions", - actions: ZarfComponentActions{ - OnCreate: ZarfComponentActionSet{ - Before: []ZarfComponentAction{ + actions: v1alpha1.ZarfComponentActions{ + OnCreate: v1alpha1.ZarfComponentActionSet{ + Before: []v1alpha1.ZarfComponentAction{ { Cmd: "echo 'onCreate before valid'", }, }, }, - OnDeploy: ZarfComponentActionSet{ - Before: []ZarfComponentAction{ + OnDeploy: v1alpha1.ZarfComponentActionSet{ + Before: []v1alpha1.ZarfComponentAction{ { Cmd: "echo 'onDeploy before valid'", }, @@ -356,9 +357,9 @@ func TestValidateComponentActions(t *testing.T) { }, { name: "setVariables in onCreate", - actions: ZarfComponentActions{ - OnCreate: ZarfComponentActionSet{ - Before: []ZarfComponentAction{ + actions: v1alpha1.ZarfComponentActions{ + OnCreate: v1alpha1.ZarfComponentActionSet{ + Before: []v1alpha1.ZarfComponentAction{ { Cmd: "echo 'invalid setVariable'", SetVariables: []variables.Variable{{Name: "VAR"}}, @@ -370,34 +371,34 @@ func TestValidateComponentActions(t *testing.T) { }, { name: "invalid onCreate action", - actions: ZarfComponentActions{ - OnCreate: ZarfComponentActionSet{ - Before: []ZarfComponentAction{ + actions: v1alpha1.ZarfComponentActions{ + OnCreate: v1alpha1.ZarfComponentActionSet{ + Before: []v1alpha1.ZarfComponentAction{ { Cmd: "create", - Wait: &ZarfComponentActionWait{Cluster: &ZarfComponentActionWaitCluster{}}, + Wait: &v1alpha1.ZarfComponentActionWait{Cluster: &v1alpha1.ZarfComponentActionWaitCluster{}}, }, }, }, - OnDeploy: ZarfComponentActionSet{ - After: []ZarfComponentAction{ + OnDeploy: v1alpha1.ZarfComponentActionSet{ + After: []v1alpha1.ZarfComponentAction{ { Cmd: "deploy", - Wait: &ZarfComponentActionWait{Cluster: &ZarfComponentActionWaitCluster{}}, + Wait: &v1alpha1.ZarfComponentActionWait{Cluster: &v1alpha1.ZarfComponentActionWaitCluster{}}, }, }, }, - OnRemove: ZarfComponentActionSet{ - OnSuccess: []ZarfComponentAction{ + OnRemove: v1alpha1.ZarfComponentActionSet{ + OnSuccess: []v1alpha1.ZarfComponentAction{ { Cmd: "remove", - Wait: &ZarfComponentActionWait{Cluster: &ZarfComponentActionWaitCluster{}}, + Wait: &v1alpha1.ZarfComponentActionWait{Cluster: &v1alpha1.ZarfComponentActionWaitCluster{}}, }, }, - OnFailure: []ZarfComponentAction{ + OnFailure: []v1alpha1.ZarfComponentAction{ { Cmd: "remove2", - Wait: &ZarfComponentActionWait{Cluster: &ZarfComponentActionWaitCluster{}}, + Wait: &v1alpha1.ZarfComponentActionWait{Cluster: &v1alpha1.ZarfComponentActionWaitCluster{}}, }, }, }, @@ -415,7 +416,7 @@ func TestValidateComponentActions(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - err := tt.actions.validate() + err := ValidateActions(tt.actions) if tt.expectedErrs == nil { require.NoError(t, err) return @@ -430,18 +431,18 @@ func TestValidateComponentAction(t *testing.T) { t.Parallel() tests := []struct { name string - action ZarfComponentAction + action v1alpha1.ZarfComponentAction expectedErrs []string }{ { name: "valid action no conditions", - action: ZarfComponentAction{}, + action: v1alpha1.ZarfComponentAction{}, }, { name: "cmd and wait both set, nothing in wait", - action: ZarfComponentAction{ + action: v1alpha1.ZarfComponentAction{ Cmd: "ls", - Wait: &ZarfComponentActionWait{}, + Wait: &v1alpha1.ZarfComponentActionWait{}, }, expectedErrs: []string{ fmt.Sprintf(lang.PkgValidateErrActionCmdWait, "ls"), @@ -450,8 +451,8 @@ func TestValidateComponentAction(t *testing.T) { }, { name: "cluster and network both set", - action: ZarfComponentAction{ - Wait: &ZarfComponentActionWait{Cluster: &ZarfComponentActionWaitCluster{}, Network: &ZarfComponentActionWaitNetwork{}}, + action: v1alpha1.ZarfComponentAction{ + Wait: &v1alpha1.ZarfComponentActionWait{Cluster: &v1alpha1.ZarfComponentActionWaitCluster{}, Network: &v1alpha1.ZarfComponentActionWaitNetwork{}}, }, expectedErrs: []string{fmt.Sprintf(lang.PkgValidateErrActionClusterNetwork)}, }, @@ -461,7 +462,7 @@ func TestValidateComponentAction(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - err := tt.action.Validate() + err := ValidateAction(tt.action) if tt.expectedErrs == nil { require.NoError(t, err) return @@ -477,15 +478,15 @@ func TestValidateZarfComponent(t *testing.T) { absPath, err := filepath.Abs("abs") require.NoError(t, err) tests := []struct { - component ZarfComponent + component v1alpha1.ZarfComponent expectedErrs []string name string }{ { name: "valid path", - component: ZarfComponent{ + component: v1alpha1.ZarfComponent{ Name: "component1", - Import: ZarfComponentImport{ + Import: v1alpha1.ZarfComponentImport{ Path: "relative/path", }, }, @@ -493,9 +494,9 @@ func TestValidateZarfComponent(t *testing.T) { }, { name: "valid URL", - component: ZarfComponent{ + component: v1alpha1.ZarfComponent{ Name: "component2", - Import: ZarfComponentImport{ + Import: v1alpha1.ZarfComponentImport{ URL: "oci://example.com/package:v0.0.1", }, }, @@ -503,7 +504,7 @@ func TestValidateZarfComponent(t *testing.T) { }, { name: "neither path nor URL provided", - component: ZarfComponent{ + component: v1alpha1.ZarfComponent{ Name: "neither", }, expectedErrs: []string{ @@ -512,9 +513,9 @@ func TestValidateZarfComponent(t *testing.T) { }, { name: "both path and URL provided", - component: ZarfComponent{ + component: v1alpha1.ZarfComponent{ Name: "both", - Import: ZarfComponentImport{ + Import: v1alpha1.ZarfComponentImport{ Path: "relative/path", URL: "https://example.com", }, @@ -525,9 +526,9 @@ func TestValidateZarfComponent(t *testing.T) { }, { name: "absolute path provided", - component: ZarfComponent{ + component: v1alpha1.ZarfComponent{ Name: "abs-path", - Import: ZarfComponentImport{ + Import: v1alpha1.ZarfComponentImport{ Path: absPath, }, }, @@ -537,9 +538,9 @@ func TestValidateZarfComponent(t *testing.T) { }, { name: "invalid URL provided", - component: ZarfComponent{ + component: v1alpha1.ZarfComponent{ Name: "bad-url", - Import: ZarfComponentImport{ + Import: v1alpha1.ZarfComponentImport{ URL: "https://example.com", }, }, @@ -553,7 +554,7 @@ func TestValidateZarfComponent(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - err := tt.component.Validate() + err := ValidateComponent(tt.component) if tt.expectedErrs == nil { require.NoError(t, err) return diff --git a/src/pkg/packager/composer/list.go b/src/pkg/packager/composer/list.go index 8d5531b85e..5cd7f83403 100644 --- a/src/pkg/packager/composer/list.go +++ b/src/pkg/packager/composer/list.go @@ -141,10 +141,10 @@ func NewImportChain(ctx context.Context, head v1alpha1.ZarfComponent, index int, return ic, nil } - // TODO: stuff like this should also happen in linting - if err := node.ZarfComponent.Validate(); err != nil { - return ic, err - } + // TODO figure out how to deal with cyclic import before merge + // if err := Validate(); err != nil { + // return ic, err + // } // ensure that remote components are not importing other remote components if node.prev != nil && node.prev.Import.URL != "" && isRemote { diff --git a/src/pkg/packager/creator/utils.go b/src/pkg/packager/creator/utils.go index fdf1da49f6..b138ce7af2 100644 --- a/src/pkg/packager/creator/utils.go +++ b/src/pkg/packager/creator/utils.go @@ -20,7 +20,7 @@ import ( // Validate errors if a package violates the schema or any runtime validations // This must be run while in the parent directory of the zarf.yaml being validated func Validate(pkg v1alpha1.ZarfPackage, baseDir string) error { - if err := pkg.Validate(); err != nil { + if err := lint.ValidatePackage(pkg); err != nil { return fmt.Errorf("package validation failed: %w", err) } diff --git a/src/pkg/packager/generate.go b/src/pkg/packager/generate.go index cc3393dbb5..068808b171 100644 --- a/src/pkg/packager/generate.go +++ b/src/pkg/packager/generate.go @@ -16,6 +16,7 @@ import ( "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/message" ) @@ -73,7 +74,7 @@ func (p *Packager) Generate(ctx context.Context) (err error) { p.cfg.Pkg.Components[i].Images = images[name] } - if err := p.cfg.Pkg.Validate(); err != nil { + if err := lint.ValidatePackage(p.cfg.Pkg); err != nil { return err } diff --git a/src/pkg/packager/sources/cluster.go b/src/pkg/packager/sources/cluster.go index ea45b254dd..5c4da94271 100644 --- a/src/pkg/packager/sources/cluster.go +++ b/src/pkg/packager/sources/cluster.go @@ -12,6 +12,7 @@ import ( "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/cluster" "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/packager/filters" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/types" @@ -24,7 +25,7 @@ var ( // NewClusterSource creates a new cluster source. func NewClusterSource(pkgOpts *types.ZarfPackageOptions) (PackageSource, error) { - if !v1alpha1.IsLowercaseNumberHyphenNoStartHyphen(pkgOpts.PackageSource) { + if !lint.IsLowercaseNumberHyphenNoStartHyphen(pkgOpts.PackageSource) { return nil, fmt.Errorf("invalid package name %q", pkgOpts.PackageSource) } diff --git a/src/pkg/variables/types.go b/src/pkg/variables/types.go index 442d35bbb2..222709e951 100644 --- a/src/pkg/variables/types.go +++ b/src/pkg/variables/types.go @@ -8,7 +8,6 @@ import ( "fmt" "regexp" - "github.com/invopop/jsonschema" "github.com/zarf-dev/zarf/src/config/lang" ) @@ -22,14 +21,10 @@ const ( FileVariableType VariableType = "file" ) -// UppercaseNumberUnderscorePattern is a regex for uppercase, numbers and underscores. -// https://regex101.com/r/tfsEuZ/1 -const UppercaseNumberUnderscorePattern = `^[A-Z0-9_]+$` - // Variable represents a variable that has a value set programmatically type Variable struct { // The name to be used for the variable - Name string `json:"name"` + Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"` // Whether to mark this variable as sensitive to not print it in the log Sensitive bool `json:"sensitive,omitempty"` // Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_. @@ -37,16 +32,7 @@ type Variable struct { // An optional regex pattern that a variable value must match before a package deployment can continue. Pattern string `json:"pattern,omitempty"` // Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB) - Type VariableType `json:"type,omitempty"` -} - -// JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` -func (Variable) JSONSchemaExtend(schema *jsonschema.Schema) { - kind, _ := schema.Properties.Get("type") - kind.Enum = []any{RawVariableType, FileVariableType} - - name, _ := schema.Properties.Get("name") - name.Pattern = UppercaseNumberUnderscorePattern + Type VariableType `json:"type,omitempty" jsonschema:"enum=raw,enum=file"` } // InteractiveVariable is a variable that can be used to prompt a user for more information @@ -63,7 +49,7 @@ type InteractiveVariable struct { // Constant are constants that can be used to dynamically template K8s resources or run in actions. type Constant struct { // The name to be used for the constant - Name string `json:"name"` + Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"` // The value to set for the constant during deploy Value string `json:"value"` // A description of the constant to explain its purpose on package create or deploy confirmation prompts @@ -74,12 +60,6 @@ type Constant struct { Pattern string `json:"pattern,omitempty"` } -// JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` -func (Constant) JSONSchemaExtend(schema *jsonschema.Schema) { - name, _ := schema.Properties.Get("name") - name.Pattern = UppercaseNumberUnderscorePattern -} - // SetVariable tracks internal variables that have been set during this run of Zarf type SetVariable struct { Variable `json:",inline"` From 9b4fbe9a6063ce928f3c4f6296bb18b42dc08761 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 5 Aug 2024 17:11:42 +0000 Subject: [PATCH 25/34] moving validate to lint and separating out packages Signed-off-by: Austin Abro --- main.go | 4 ++-- src/pkg/lint/lint.go | 27 ++++++++++++------------ src/pkg/lint/lint_test.go | 7 +++--- src/pkg/packager/composer/list.go | 8 +++---- src/pkg/packager/creator/creator_test.go | 4 ++-- src/pkg/packager/creator/utils.go | 10 ++++----- src/pkg/packager/generate.go | 4 ++-- src/pkg/packager/sources/cluster.go | 4 ++-- src/pkg/{lint => rules}/findings.go | 4 ++-- src/pkg/{lint => rules}/findings_test.go | 4 ++-- src/pkg/{lint => rules}/rules.go | 4 ++-- src/pkg/{lint => rules}/rules_test.go | 4 ++-- src/pkg/{lint => rules}/schema.go | 4 ++-- src/pkg/{lint => rules}/schema_test.go | 4 ++-- src/pkg/{lint => rules}/validate.go | 4 ++-- src/pkg/{lint => rules}/validate_test.go | 4 ++-- 16 files changed, 51 insertions(+), 49 deletions(-) rename src/pkg/{lint => rules}/findings.go (97%) rename src/pkg/{lint => rules}/findings_test.go (96%) rename src/pkg/{lint => rules}/rules.go (97%) rename src/pkg/{lint => rules}/rules_test.go (97%) rename src/pkg/{lint => rules}/schema.go (95%) rename src/pkg/{lint => rules}/schema_test.go (98%) rename src/pkg/{lint => rules}/validate.go (99%) rename src/pkg/{lint => rules}/validate_test.go (99%) diff --git a/main.go b/main.go index f424789b54..df0b3a78e7 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( "github.com/zarf-dev/zarf/src/cmd" "github.com/zarf-dev/zarf/src/config" - "github.com/zarf-dev/zarf/src/pkg/lint" + "github.com/zarf-dev/zarf/src/pkg/rules" ) //go:embed cosign.pub @@ -41,6 +41,6 @@ func main() { }() config.CosignPublicKey = cosignPublicKey - lint.ZarfSchema = zarfSchema + rules.ZarfSchema = zarfSchema cmd.Execute(ctx) } diff --git a/src/pkg/lint/lint.go b/src/pkg/lint/lint.go index 9c0132f2e8..9b5f6667c9 100644 --- a/src/pkg/lint/lint.go +++ b/src/pkg/lint/lint.go @@ -16,13 +16,14 @@ import ( "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/composer" + "github.com/zarf-dev/zarf/src/pkg/rules" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/types" ) // Validate lints the given Zarf package func Validate(ctx context.Context, createOpts types.ZarfCreateOptions) error { - var findings []PackageFinding + var findings []rules.PackageFinding if err := os.Chdir(createOpts.BaseDir); err != nil { return fmt.Errorf("unable to access directory %q: %w", createOpts.BaseDir, err) } @@ -36,7 +37,7 @@ func Validate(ctx context.Context, createOpts types.ZarfCreateOptions) error { return err } findings = append(findings, compFindings...) - schemaFindings, err := ValidatePackageSchema() + schemaFindings, err := rules.ValidatePackageSchema() if err != nil { return err } @@ -46,15 +47,15 @@ func Validate(ctx context.Context, createOpts types.ZarfCreateOptions) error { message.Successf("0 findings for %q", pkg.Metadata.Name) return nil } - PrintFindings(findings, SevWarn, createOpts.BaseDir, pkg.Metadata.Name) - if HasSevOrHigher(findings, SevErr) { + rules.PrintFindings(findings, rules.SevWarn, createOpts.BaseDir, pkg.Metadata.Name) + if rules.HasSevOrHigher(findings, rules.SevErr) { return errors.New("errors during lint") } return nil } -func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts types.ZarfCreateOptions) ([]PackageFinding, error) { - var findings []PackageFinding +func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts types.ZarfCreateOptions) ([]rules.PackageFinding, error) { + var findings []rules.PackageFinding for i, component := range pkg.Components { arch := config.GetArch(pkg.Metadata.Architecture) @@ -75,7 +76,7 @@ func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts ty if err != nil { return nil, err } - compFindings = append(compFindings, CheckComponentValues(component, node.Index())...) + compFindings = append(compFindings, rules.CheckComponentValues(component, node.Index())...) for i := range compFindings { compFindings[i].PackagePathOverride = node.ImportLocation() compFindings[i].PackageNameOverride = node.OriginalPackageName() @@ -87,8 +88,8 @@ func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts ty return findings, nil } -func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreateOptions) ([]PackageFinding, error) { - var findings []PackageFinding +func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreateOptions) ([]rules.PackageFinding, error) { + var findings []rules.PackageFinding templateMap := map[string]string{} setVarsAndWarn := func(templatePrefix string, deprecated bool) error { @@ -100,9 +101,9 @@ func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreat var unSetTemplates bool for key := range yamlTemplates { if deprecated { - findings = append(findings, PackageFinding{ + findings = append(findings, rules.PackageFinding{ Description: fmt.Sprintf(lang.PkgValidateTemplateDeprecation, key, key, key), - Severity: SevWarn, + Severity: rules.SevWarn, }) } if _, present := createOpts.SetVariables[key]; !present { @@ -110,9 +111,9 @@ func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreat } } if unSetTemplates { - findings = append(findings, PackageFinding{ + findings = append(findings, rules.PackageFinding{ Description: lang.UnsetVarLintWarning, - Severity: SevWarn, + Severity: rules.SevWarn, }) } for key, value := range createOpts.SetVariables { diff --git a/src/pkg/lint/lint_test.go b/src/pkg/lint/lint_test.go index d6ad24ad82..3176ab2da6 100644 --- a/src/pkg/lint/lint_test.go +++ b/src/pkg/lint/lint_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config/lang" + "github.com/zarf-dev/zarf/src/pkg/rules" "github.com/zarf-dev/zarf/src/types" ) @@ -50,13 +51,13 @@ func TestFillComponentTemplate(t *testing.T) { findings, err := fillComponentTemplate(&component, createOpts) require.NoError(t, err) - expectedFindings := []PackageFinding{ + expectedFindings := []rules.PackageFinding{ { - Severity: SevWarn, + Severity: rules.SevWarn, Description: "There are templates that are not set and won't be evaluated during lint", }, { - Severity: SevWarn, + Severity: rules.SevWarn, Description: fmt.Sprintf(lang.PkgValidateTemplateDeprecation, "KEY2", "KEY2", "KEY2"), }, } diff --git a/src/pkg/packager/composer/list.go b/src/pkg/packager/composer/list.go index 5cd7f83403..45a4cdd94c 100644 --- a/src/pkg/packager/composer/list.go +++ b/src/pkg/packager/composer/list.go @@ -15,6 +15,7 @@ import ( "github.com/zarf-dev/zarf/src/extensions/bigbang" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/packager/deprecated" + "github.com/zarf-dev/zarf/src/pkg/rules" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/pkg/variables" "github.com/zarf-dev/zarf/src/pkg/zoci" @@ -141,10 +142,9 @@ func NewImportChain(ctx context.Context, head v1alpha1.ZarfComponent, index int, return ic, nil } - // TODO figure out how to deal with cyclic import before merge - // if err := Validate(); err != nil { - // return ic, err - // } + if err := rules.ValidateComponent(node.ZarfComponent); err != nil { + return ic, err + } // ensure that remote components are not importing other remote components if node.prev != nil && node.prev.Import.URL != "" && isRemote { diff --git a/src/pkg/packager/creator/creator_test.go b/src/pkg/packager/creator/creator_test.go index 9312fe0a2c..52847ad33f 100644 --- a/src/pkg/packager/creator/creator_test.go +++ b/src/pkg/packager/creator/creator_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/zarf-dev/zarf/src/pkg/layout" - "github.com/zarf-dev/zarf/src/pkg/lint" + "github.com/zarf-dev/zarf/src/pkg/rules" "github.com/zarf-dev/zarf/src/types" ) @@ -66,7 +66,7 @@ func TestLoadPackageDefinition(t *testing.T) { } b, err := os.ReadFile("../../../../zarf.schema.json") require.NoError(t, err) - lint.ZarfSchema = &mockSchemaLoader{b: b} + rules.ZarfSchema = &mockSchemaLoader{b: b} for _, tt := range tests { tt := tt diff --git a/src/pkg/packager/creator/utils.go b/src/pkg/packager/creator/utils.go index b138ce7af2..e43a1ca973 100644 --- a/src/pkg/packager/creator/utils.go +++ b/src/pkg/packager/creator/utils.go @@ -12,25 +12,25 @@ import ( "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" - "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/packager/deprecated" + "github.com/zarf-dev/zarf/src/pkg/rules" "github.com/zarf-dev/zarf/src/types" ) // Validate errors if a package violates the schema or any runtime validations // This must be run while in the parent directory of the zarf.yaml being validated func Validate(pkg v1alpha1.ZarfPackage, baseDir string) error { - if err := lint.ValidatePackage(pkg); err != nil { + if err := rules.ValidatePackage(pkg); err != nil { return fmt.Errorf("package validation failed: %w", err) } - findings, err := lint.ValidatePackageSchema() + findings, err := rules.ValidatePackageSchema() if err != nil { return fmt.Errorf("unable to check schema: %w", err) } - if lint.HasSevOrHigher(findings, lint.SevErr) { - lint.PrintFindings(findings, lint.SevErr, baseDir, pkg.Metadata.Name) + if rules.HasSevOrHigher(findings, rules.SevErr) { + rules.PrintFindings(findings, rules.SevErr, baseDir, pkg.Metadata.Name) return fmt.Errorf("found errors in schema") } diff --git a/src/pkg/packager/generate.go b/src/pkg/packager/generate.go index 068808b171..3df9ea1933 100644 --- a/src/pkg/packager/generate.go +++ b/src/pkg/packager/generate.go @@ -16,8 +16,8 @@ import ( "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" - "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/message" + "github.com/zarf-dev/zarf/src/pkg/rules" ) // Generate generates a Zarf package definition. @@ -74,7 +74,7 @@ func (p *Packager) Generate(ctx context.Context) (err error) { p.cfg.Pkg.Components[i].Images = images[name] } - if err := lint.ValidatePackage(p.cfg.Pkg); err != nil { + if err := rules.ValidatePackage(p.cfg.Pkg); err != nil { return err } diff --git a/src/pkg/packager/sources/cluster.go b/src/pkg/packager/sources/cluster.go index 5c4da94271..169f8a28f9 100644 --- a/src/pkg/packager/sources/cluster.go +++ b/src/pkg/packager/sources/cluster.go @@ -12,8 +12,8 @@ import ( "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/cluster" "github.com/zarf-dev/zarf/src/pkg/layout" - "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/packager/filters" + "github.com/zarf-dev/zarf/src/pkg/rules" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/types" ) @@ -25,7 +25,7 @@ var ( // NewClusterSource creates a new cluster source. func NewClusterSource(pkgOpts *types.ZarfPackageOptions) (PackageSource, error) { - if !lint.IsLowercaseNumberHyphenNoStartHyphen(pkgOpts.PackageSource) { + if !rules.IsLowercaseNumberHyphenNoStartHyphen(pkgOpts.PackageSource) { return nil, fmt.Errorf("invalid package name %q", pkgOpts.PackageSource) } diff --git a/src/pkg/lint/findings.go b/src/pkg/rules/findings.go similarity index 97% rename from src/pkg/lint/findings.go rename to src/pkg/rules/findings.go index a8ad9b5eac..c751a39069 100644 --- a/src/pkg/lint/findings.go +++ b/src/pkg/rules/findings.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package lint contains functions for verifying zarf yaml files are valid -package lint +// Package rules checks Zarf packages and reports any findings or errors +package rules import ( "fmt" diff --git a/src/pkg/lint/findings_test.go b/src/pkg/rules/findings_test.go similarity index 96% rename from src/pkg/lint/findings_test.go rename to src/pkg/rules/findings_test.go index f3c09673c8..b4cb527b4e 100644 --- a/src/pkg/lint/findings_test.go +++ b/src/pkg/rules/findings_test.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package lint contains functions for verifying zarf yaml files are valid -package lint +// Package rules checks Zarf packages and reports any findings or errors +package rules import ( "testing" diff --git a/src/pkg/lint/rules.go b/src/pkg/rules/rules.go similarity index 97% rename from src/pkg/lint/rules.go rename to src/pkg/rules/rules.go index 0be01cf687..5926e00b9d 100644 --- a/src/pkg/lint/rules.go +++ b/src/pkg/rules/rules.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package lint contains functions for verifying zarf yaml files are valid -package lint +// Package rules checks Zarf packages and reports any findings or errors +package rules import ( "fmt" diff --git a/src/pkg/lint/rules_test.go b/src/pkg/rules/rules_test.go similarity index 97% rename from src/pkg/lint/rules_test.go rename to src/pkg/rules/rules_test.go index 803dae9096..928469be38 100644 --- a/src/pkg/lint/rules_test.go +++ b/src/pkg/rules/rules_test.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package lint contains functions for verifying zarf yaml files are valid -package lint +// Package rules checks Zarf packages and reports any findings or errors +package rules import ( "errors" diff --git a/src/pkg/lint/schema.go b/src/pkg/rules/schema.go similarity index 95% rename from src/pkg/lint/schema.go rename to src/pkg/rules/schema.go index ae3e991863..9ab1d2e0b1 100644 --- a/src/pkg/lint/schema.go +++ b/src/pkg/rules/schema.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package lint contains functions for verifying zarf yaml files are valid -package lint +// Package rules checks Zarf packages and reports any findings or errors +package rules import ( "fmt" diff --git a/src/pkg/lint/schema_test.go b/src/pkg/rules/schema_test.go similarity index 98% rename from src/pkg/lint/schema_test.go rename to src/pkg/rules/schema_test.go index 385832bebf..a1ef87314d 100644 --- a/src/pkg/lint/schema_test.go +++ b/src/pkg/rules/schema_test.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package lint contains functions for verifying zarf yaml files are valid -package lint +// Package rules checks Zarf packages and reports any findings or errors +package rules import ( "fmt" diff --git a/src/pkg/lint/validate.go b/src/pkg/rules/validate.go similarity index 99% rename from src/pkg/lint/validate.go rename to src/pkg/rules/validate.go index c37658139e..8c4864f00f 100644 --- a/src/pkg/lint/validate.go +++ b/src/pkg/rules/validate.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package lint contains functions for verifying zarf yaml files are valid -package lint +// Package rules checks Zarf packages and reports any findings or errors +package rules import ( "errors" diff --git a/src/pkg/lint/validate_test.go b/src/pkg/rules/validate_test.go similarity index 99% rename from src/pkg/lint/validate_test.go rename to src/pkg/rules/validate_test.go index c3b4f8b519..e50bfca9b5 100644 --- a/src/pkg/lint/validate_test.go +++ b/src/pkg/rules/validate_test.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package lint contains functions for verifying zarf yaml files are valid -package lint +// Package rules checks Zarf packages and reports any findings or errors +package rules import ( "fmt" From b1ce576d92fd8dd1b748992bcb1ed1bad4dfaac6 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 7 Aug 2024 14:33:12 +0000 Subject: [PATCH 26/34] move validate to lint Signed-off-by: Austin Abro --- src/api/v1alpha1/component.go | 15 -------------- src/api/v1alpha1/package.go | 31 +++++++++-------------------- src/pkg/cluster/injector.go | 6 ++++-- src/pkg/packager/filters/os_test.go | 5 +++-- 4 files changed, 16 insertions(+), 41 deletions(-) diff --git a/src/api/v1alpha1/component.go b/src/api/v1alpha1/component.go index c9928e95c1..bd798c82f6 100644 --- a/src/api/v1alpha1/component.go +++ b/src/api/v1alpha1/component.go @@ -11,21 +11,6 @@ import ( "github.com/zarf-dev/zarf/src/pkg/variables" ) -var ( - // Define allowed OS, an empty string means it is allowed on all operating systems - // same as enums on ZarfComponentOnlyTarget - supportedOS = []string{"linux", "darwin", "windows"} -) - -// SupportedOS returns the supported operating systems. -// -// The supported operating systems are: linux, darwin, windows. -// -// An empty string signifies no OS restrictions. -func SupportedOS() []string { - return supportedOS -} - // ZarfComponent is the primary functional grouping of assets to deploy by Zarf. type ZarfComponent struct { // The name of the component. diff --git a/src/api/v1alpha1/package.go b/src/api/v1alpha1/package.go index f82ccdeb4c..d2ce1c6c43 100644 --- a/src/api/v1alpha1/package.go +++ b/src/api/v1alpha1/package.go @@ -5,10 +5,17 @@ package v1alpha1 import ( - "github.com/invopop/jsonschema" "github.com/zarf-dev/zarf/src/pkg/variables" ) +// Zarf looks for these strings in zarf.yaml to make dynamic changes +const ( + ZarfPackageTemplatePrefix = "###ZARF_PKG_TMPL_" + ZarfPackageVariablePrefix = "###ZARF_PKG_VAR_" + ZarfPackageArch = "###ZARF_PKG_ARCH###" + ZarfComponentName = "###ZARF_COMPONENT_NAME###" +) + // ZarfPackageKind is an enum of the different kinds of Zarf packages. type ZarfPackageKind string @@ -20,22 +27,12 @@ const ( ApiVersion string = "zarf.dev/v1alpha1" ) -// Zarf looks for these strings in zarf.yaml to make dynamic changes -const ( - ZarfPackageTemplatePrefix = "###ZARF_PKG_TMPL_" - ZarfPackageVariablePrefix = "###ZARF_PKG_VAR_" - ZarfPackageArch = "###ZARF_PKG_ARCH###" - ZarfComponentName = "###ZARF_COMPONENT_NAME###" -) - -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," jsonschema:"enum=zarf.dev/v1alpha1"` // The kind of Zarf package. - Kind ZarfPackageKind `json:"kind"` + Kind ZarfPackageKind `json:"kind" jsonschema:"enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` // Package metadata. Metadata ZarfMetadata `json:"metadata,omitempty"` // Zarf-generated package build data. @@ -48,16 +45,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 diff --git a/src/pkg/cluster/injector.go b/src/pkg/cluster/injector.go index 1ee24c2150..48552ac5e1 100644 --- a/src/pkg/cluster/injector.go +++ b/src/pkg/cluster/injector.go @@ -260,11 +260,13 @@ func (c *Cluster) createPayloadConfigMaps(ctx context.Context, spinner *message. return cmNames, shasum, nil } -var zarfImageRegex = regexp.MustCompile(`(?m)^127\.0\.0\.1:`) - // getImagesAndNodesForInjection checks for images on schedulable nodes within a cluster. func (c *Cluster) getInjectorImageAndNode(ctx context.Context, resReq corev1.ResourceRequirements) (string, string, error) { // Regex for Zarf seed image + zarfImageRegex, err := regexp.Compile(`(?m)^127\.0\.0\.1:`) + if err != nil { + return "", "", err + } listOpts := metav1.ListOptions{ FieldSelector: fmt.Sprintf("status.phase=%s", corev1.PodRunning), } diff --git a/src/pkg/packager/filters/os_test.go b/src/pkg/packager/filters/os_test.go index fb81d1355a..c546fca2b2 100644 --- a/src/pkg/packager/filters/os_test.go +++ b/src/pkg/packager/filters/os_test.go @@ -9,11 +9,12 @@ import ( "github.com/stretchr/testify/require" "github.com/zarf-dev/zarf/src/api/v1alpha1" + "github.com/zarf-dev/zarf/src/pkg/rules" ) func TestLocalOSFilter(t *testing.T) { pkg := v1alpha1.ZarfPackage{} - for _, os := range v1alpha1.SupportedOS() { + for _, os := range rules.SupportedOS() { pkg.Components = append(pkg.Components, v1alpha1.ZarfComponent{ Only: v1alpha1.ZarfComponentOnlyTarget{ LocalOS: os, @@ -21,7 +22,7 @@ func TestLocalOSFilter(t *testing.T) { }) } - for _, os := range v1alpha1.SupportedOS() { + for _, os := range rules.SupportedOS() { filter := ByLocalOS(os) result, err := filter.Apply(pkg) if os == "" { From 1d307e28c084a7726ac31d684b4a6e943374d465 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 8 Aug 2024 15:32:53 +0000 Subject: [PATCH 27/34] move lint back Signed-off-by: Austin Abro --- main.go | 4 ++-- src/pkg/{rules => lint}/findings.go | 4 ++-- src/pkg/{rules => lint}/findings_test.go | 4 ++-- src/pkg/lint/lint.go | 27 ++++++++++++------------ src/pkg/lint/lint_test.go | 7 +++--- src/pkg/{rules => lint}/rules.go | 4 ++-- src/pkg/{rules => lint}/rules_test.go | 4 ++-- src/pkg/{rules => lint}/schema.go | 4 ++-- src/pkg/{rules => lint}/schema_test.go | 4 ++-- src/pkg/{rules => lint}/validate.go | 4 ++-- src/pkg/{rules => lint}/validate_test.go | 4 ++-- src/pkg/packager/composer/list.go | 5 ----- src/pkg/packager/creator/creator_test.go | 4 ++-- src/pkg/packager/creator/utils.go | 10 ++++----- src/pkg/packager/filters/os_test.go | 6 +++--- src/pkg/packager/generate.go | 4 ++-- src/pkg/packager/prepare_test.go | 4 ++-- src/pkg/packager/sources/cluster.go | 4 ++-- 18 files changed, 50 insertions(+), 57 deletions(-) rename src/pkg/{rules => lint}/findings.go (97%) rename src/pkg/{rules => lint}/findings_test.go (96%) rename src/pkg/{rules => lint}/rules.go (97%) rename src/pkg/{rules => lint}/rules_test.go (97%) rename src/pkg/{rules => lint}/schema.go (95%) rename src/pkg/{rules => lint}/schema_test.go (98%) rename src/pkg/{rules => lint}/validate.go (99%) rename src/pkg/{rules => lint}/validate_test.go (99%) diff --git a/main.go b/main.go index df0b3a78e7..f424789b54 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( "github.com/zarf-dev/zarf/src/cmd" "github.com/zarf-dev/zarf/src/config" - "github.com/zarf-dev/zarf/src/pkg/rules" + "github.com/zarf-dev/zarf/src/pkg/lint" ) //go:embed cosign.pub @@ -41,6 +41,6 @@ func main() { }() config.CosignPublicKey = cosignPublicKey - rules.ZarfSchema = zarfSchema + lint.ZarfSchema = zarfSchema cmd.Execute(ctx) } diff --git a/src/pkg/rules/findings.go b/src/pkg/lint/findings.go similarity index 97% rename from src/pkg/rules/findings.go rename to src/pkg/lint/findings.go index c751a39069..a8ad9b5eac 100644 --- a/src/pkg/rules/findings.go +++ b/src/pkg/lint/findings.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package rules checks Zarf packages and reports any findings or errors -package rules +// Package lint contains functions for verifying zarf yaml files are valid +package lint import ( "fmt" diff --git a/src/pkg/rules/findings_test.go b/src/pkg/lint/findings_test.go similarity index 96% rename from src/pkg/rules/findings_test.go rename to src/pkg/lint/findings_test.go index b4cb527b4e..f3c09673c8 100644 --- a/src/pkg/rules/findings_test.go +++ b/src/pkg/lint/findings_test.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package rules checks Zarf packages and reports any findings or errors -package rules +// Package lint contains functions for verifying zarf yaml files are valid +package lint import ( "testing" diff --git a/src/pkg/lint/lint.go b/src/pkg/lint/lint.go index 9b5f6667c9..9c0132f2e8 100644 --- a/src/pkg/lint/lint.go +++ b/src/pkg/lint/lint.go @@ -16,14 +16,13 @@ import ( "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/composer" - "github.com/zarf-dev/zarf/src/pkg/rules" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/types" ) // Validate lints the given Zarf package func Validate(ctx context.Context, createOpts types.ZarfCreateOptions) error { - var findings []rules.PackageFinding + var findings []PackageFinding if err := os.Chdir(createOpts.BaseDir); err != nil { return fmt.Errorf("unable to access directory %q: %w", createOpts.BaseDir, err) } @@ -37,7 +36,7 @@ func Validate(ctx context.Context, createOpts types.ZarfCreateOptions) error { return err } findings = append(findings, compFindings...) - schemaFindings, err := rules.ValidatePackageSchema() + schemaFindings, err := ValidatePackageSchema() if err != nil { return err } @@ -47,15 +46,15 @@ func Validate(ctx context.Context, createOpts types.ZarfCreateOptions) error { message.Successf("0 findings for %q", pkg.Metadata.Name) return nil } - rules.PrintFindings(findings, rules.SevWarn, createOpts.BaseDir, pkg.Metadata.Name) - if rules.HasSevOrHigher(findings, rules.SevErr) { + PrintFindings(findings, SevWarn, createOpts.BaseDir, pkg.Metadata.Name) + if HasSevOrHigher(findings, SevErr) { return errors.New("errors during lint") } return nil } -func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts types.ZarfCreateOptions) ([]rules.PackageFinding, error) { - var findings []rules.PackageFinding +func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts types.ZarfCreateOptions) ([]PackageFinding, error) { + var findings []PackageFinding for i, component := range pkg.Components { arch := config.GetArch(pkg.Metadata.Architecture) @@ -76,7 +75,7 @@ func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts ty if err != nil { return nil, err } - compFindings = append(compFindings, rules.CheckComponentValues(component, node.Index())...) + compFindings = append(compFindings, CheckComponentValues(component, node.Index())...) for i := range compFindings { compFindings[i].PackagePathOverride = node.ImportLocation() compFindings[i].PackageNameOverride = node.OriginalPackageName() @@ -88,8 +87,8 @@ func lintComponents(ctx context.Context, pkg v1alpha1.ZarfPackage, createOpts ty return findings, nil } -func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreateOptions) ([]rules.PackageFinding, error) { - var findings []rules.PackageFinding +func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreateOptions) ([]PackageFinding, error) { + var findings []PackageFinding templateMap := map[string]string{} setVarsAndWarn := func(templatePrefix string, deprecated bool) error { @@ -101,9 +100,9 @@ func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreat var unSetTemplates bool for key := range yamlTemplates { if deprecated { - findings = append(findings, rules.PackageFinding{ + findings = append(findings, PackageFinding{ Description: fmt.Sprintf(lang.PkgValidateTemplateDeprecation, key, key, key), - Severity: rules.SevWarn, + Severity: SevWarn, }) } if _, present := createOpts.SetVariables[key]; !present { @@ -111,9 +110,9 @@ func fillComponentTemplate(c *v1alpha1.ZarfComponent, createOpts types.ZarfCreat } } if unSetTemplates { - findings = append(findings, rules.PackageFinding{ + findings = append(findings, PackageFinding{ Description: lang.UnsetVarLintWarning, - Severity: rules.SevWarn, + Severity: SevWarn, }) } for key, value := range createOpts.SetVariables { diff --git a/src/pkg/lint/lint_test.go b/src/pkg/lint/lint_test.go index 3176ab2da6..d6ad24ad82 100644 --- a/src/pkg/lint/lint_test.go +++ b/src/pkg/lint/lint_test.go @@ -12,7 +12,6 @@ import ( "github.com/stretchr/testify/require" "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config/lang" - "github.com/zarf-dev/zarf/src/pkg/rules" "github.com/zarf-dev/zarf/src/types" ) @@ -51,13 +50,13 @@ func TestFillComponentTemplate(t *testing.T) { findings, err := fillComponentTemplate(&component, createOpts) require.NoError(t, err) - expectedFindings := []rules.PackageFinding{ + expectedFindings := []PackageFinding{ { - Severity: rules.SevWarn, + Severity: SevWarn, Description: "There are templates that are not set and won't be evaluated during lint", }, { - Severity: rules.SevWarn, + Severity: SevWarn, Description: fmt.Sprintf(lang.PkgValidateTemplateDeprecation, "KEY2", "KEY2", "KEY2"), }, } diff --git a/src/pkg/rules/rules.go b/src/pkg/lint/rules.go similarity index 97% rename from src/pkg/rules/rules.go rename to src/pkg/lint/rules.go index 5926e00b9d..0be01cf687 100644 --- a/src/pkg/rules/rules.go +++ b/src/pkg/lint/rules.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package rules checks Zarf packages and reports any findings or errors -package rules +// Package lint contains functions for verifying zarf yaml files are valid +package lint import ( "fmt" diff --git a/src/pkg/rules/rules_test.go b/src/pkg/lint/rules_test.go similarity index 97% rename from src/pkg/rules/rules_test.go rename to src/pkg/lint/rules_test.go index 928469be38..803dae9096 100644 --- a/src/pkg/rules/rules_test.go +++ b/src/pkg/lint/rules_test.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package rules checks Zarf packages and reports any findings or errors -package rules +// Package lint contains functions for verifying zarf yaml files are valid +package lint import ( "errors" diff --git a/src/pkg/rules/schema.go b/src/pkg/lint/schema.go similarity index 95% rename from src/pkg/rules/schema.go rename to src/pkg/lint/schema.go index 9ab1d2e0b1..ae3e991863 100644 --- a/src/pkg/rules/schema.go +++ b/src/pkg/lint/schema.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package rules checks Zarf packages and reports any findings or errors -package rules +// Package lint contains functions for verifying zarf yaml files are valid +package lint import ( "fmt" diff --git a/src/pkg/rules/schema_test.go b/src/pkg/lint/schema_test.go similarity index 98% rename from src/pkg/rules/schema_test.go rename to src/pkg/lint/schema_test.go index 0a3a58100f..9e59dddcd4 100644 --- a/src/pkg/rules/schema_test.go +++ b/src/pkg/lint/schema_test.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package rules checks Zarf packages and reports any findings or errors -package rules +// Package lint contains functions for verifying zarf yaml files are valid +package lint import ( "fmt" diff --git a/src/pkg/rules/validate.go b/src/pkg/lint/validate.go similarity index 99% rename from src/pkg/rules/validate.go rename to src/pkg/lint/validate.go index 8c4864f00f..c37658139e 100644 --- a/src/pkg/rules/validate.go +++ b/src/pkg/lint/validate.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package rules checks Zarf packages and reports any findings or errors -package rules +// Package lint contains functions for verifying zarf yaml files are valid +package lint import ( "errors" diff --git a/src/pkg/rules/validate_test.go b/src/pkg/lint/validate_test.go similarity index 99% rename from src/pkg/rules/validate_test.go rename to src/pkg/lint/validate_test.go index e50bfca9b5..c3b4f8b519 100644 --- a/src/pkg/rules/validate_test.go +++ b/src/pkg/lint/validate_test.go @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -// Package rules checks Zarf packages and reports any findings or errors -package rules +// Package lint contains functions for verifying zarf yaml files are valid +package lint import ( "fmt" diff --git a/src/pkg/packager/composer/list.go b/src/pkg/packager/composer/list.go index 45a4cdd94c..6f33003097 100644 --- a/src/pkg/packager/composer/list.go +++ b/src/pkg/packager/composer/list.go @@ -15,7 +15,6 @@ import ( "github.com/zarf-dev/zarf/src/extensions/bigbang" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/packager/deprecated" - "github.com/zarf-dev/zarf/src/pkg/rules" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/pkg/variables" "github.com/zarf-dev/zarf/src/pkg/zoci" @@ -142,10 +141,6 @@ func NewImportChain(ctx context.Context, head v1alpha1.ZarfComponent, index int, return ic, nil } - if err := rules.ValidateComponent(node.ZarfComponent); err != nil { - return ic, err - } - // ensure that remote components are not importing other remote components if node.prev != nil && node.prev.Import.URL != "" && isRemote { return ic, fmt.Errorf("detected malformed import chain, cannot import remote components from remote components") diff --git a/src/pkg/packager/creator/creator_test.go b/src/pkg/packager/creator/creator_test.go index 67a92ae005..95803cc0f4 100644 --- a/src/pkg/packager/creator/creator_test.go +++ b/src/pkg/packager/creator/creator_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/zarf-dev/zarf/src/pkg/layout" - "github.com/zarf-dev/zarf/src/pkg/rules" + "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/test/testutil" "github.com/zarf-dev/zarf/src/types" ) @@ -51,7 +51,7 @@ func TestLoadPackageDefinition(t *testing.T) { creator: NewSkeletonCreator(types.ZarfCreateOptions{}, types.ZarfPublishOptions{}), }, } - rules.ZarfSchema = testutil.LoadSchema(t, "../../../../zarf.schema.json") + lint.ZarfSchema = testutil.LoadSchema(t, "../../../../zarf.schema.json") for _, tt := range tests { tt := tt diff --git a/src/pkg/packager/creator/utils.go b/src/pkg/packager/creator/utils.go index e43a1ca973..b138ce7af2 100644 --- a/src/pkg/packager/creator/utils.go +++ b/src/pkg/packager/creator/utils.go @@ -12,25 +12,25 @@ import ( "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" + "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/packager/deprecated" - "github.com/zarf-dev/zarf/src/pkg/rules" "github.com/zarf-dev/zarf/src/types" ) // Validate errors if a package violates the schema or any runtime validations // This must be run while in the parent directory of the zarf.yaml being validated func Validate(pkg v1alpha1.ZarfPackage, baseDir string) error { - if err := rules.ValidatePackage(pkg); err != nil { + if err := lint.ValidatePackage(pkg); err != nil { return fmt.Errorf("package validation failed: %w", err) } - findings, err := rules.ValidatePackageSchema() + findings, err := lint.ValidatePackageSchema() if err != nil { return fmt.Errorf("unable to check schema: %w", err) } - if rules.HasSevOrHigher(findings, rules.SevErr) { - rules.PrintFindings(findings, rules.SevErr, baseDir, pkg.Metadata.Name) + if lint.HasSevOrHigher(findings, lint.SevErr) { + lint.PrintFindings(findings, lint.SevErr, baseDir, pkg.Metadata.Name) return fmt.Errorf("found errors in schema") } diff --git a/src/pkg/packager/filters/os_test.go b/src/pkg/packager/filters/os_test.go index c546fca2b2..c2e022a752 100644 --- a/src/pkg/packager/filters/os_test.go +++ b/src/pkg/packager/filters/os_test.go @@ -9,12 +9,12 @@ import ( "github.com/stretchr/testify/require" "github.com/zarf-dev/zarf/src/api/v1alpha1" - "github.com/zarf-dev/zarf/src/pkg/rules" + "github.com/zarf-dev/zarf/src/pkg/lint" ) func TestLocalOSFilter(t *testing.T) { pkg := v1alpha1.ZarfPackage{} - for _, os := range rules.SupportedOS() { + for _, os := range lint.SupportedOS() { pkg.Components = append(pkg.Components, v1alpha1.ZarfComponent{ Only: v1alpha1.ZarfComponentOnlyTarget{ LocalOS: os, @@ -22,7 +22,7 @@ func TestLocalOSFilter(t *testing.T) { }) } - for _, os := range rules.SupportedOS() { + for _, os := range lint.SupportedOS() { filter := ByLocalOS(os) result, err := filter.Apply(pkg) if os == "" { diff --git a/src/pkg/packager/generate.go b/src/pkg/packager/generate.go index 3df9ea1933..068808b171 100644 --- a/src/pkg/packager/generate.go +++ b/src/pkg/packager/generate.go @@ -16,8 +16,8 @@ import ( "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/message" - "github.com/zarf-dev/zarf/src/pkg/rules" ) // Generate generates a Zarf package definition. @@ -74,7 +74,7 @@ func (p *Packager) Generate(ctx context.Context) (err error) { p.cfg.Pkg.Components[i].Images = images[name] } - if err := rules.ValidatePackage(p.cfg.Pkg); err != nil { + if err := lint.ValidatePackage(p.cfg.Pkg); err != nil { return err } diff --git a/src/pkg/packager/prepare_test.go b/src/pkg/packager/prepare_test.go index 3d4bb85092..8c43e194ac 100644 --- a/src/pkg/packager/prepare_test.go +++ b/src/pkg/packager/prepare_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/zarf-dev/zarf/src/pkg/rules" + "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/test/testutil" "github.com/zarf-dev/zarf/src/types" ) @@ -18,7 +18,7 @@ func TestFindImages(t *testing.T) { ctx := testutil.TestContext(t) - rules.ZarfSchema = testutil.LoadSchema(t, "../../../zarf.schema.json") + lint.ZarfSchema = testutil.LoadSchema(t, "../../../zarf.schema.json") cfg := &types.PackagerConfig{ CreateOpts: types.ZarfCreateOptions{ diff --git a/src/pkg/packager/sources/cluster.go b/src/pkg/packager/sources/cluster.go index 169f8a28f9..5c4da94271 100644 --- a/src/pkg/packager/sources/cluster.go +++ b/src/pkg/packager/sources/cluster.go @@ -12,8 +12,8 @@ import ( "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/cluster" "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/packager/filters" - "github.com/zarf-dev/zarf/src/pkg/rules" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/types" ) @@ -25,7 +25,7 @@ var ( // NewClusterSource creates a new cluster source. func NewClusterSource(pkgOpts *types.ZarfPackageOptions) (PackageSource, error) { - if !rules.IsLowercaseNumberHyphenNoStartHyphen(pkgOpts.PackageSource) { + if !lint.IsLowercaseNumberHyphenNoStartHyphen(pkgOpts.PackageSource) { return nil, fmt.Errorf("invalid package name %q", pkgOpts.PackageSource) } From 16dead060e30eaf227c4e2acd7bb003855671654 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 8 Aug 2024 16:08:13 +0000 Subject: [PATCH 28/34] call validate component Signed-off-by: Austin Abro --- src/pkg/lint/validate.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pkg/lint/validate.go b/src/pkg/lint/validate.go index c37658139e..3f2f92c3b8 100644 --- a/src/pkg/lint/validate.go +++ b/src/pkg/lint/validate.go @@ -73,6 +73,9 @@ func ValidatePackage(pkg v1alpha1.ZarfPackage) error { } } for _, component := range pkg.Components { + if compErr := ValidateComponent(component); compErr != nil { + err = errors.Join(err, compErr) + } // ensure component name is unique if _, ok := uniqueComponentNames[component.Name]; ok { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrComponentNameNotUnique, component.Name)) From 9d62adfa21883e946f35cd7aaef2ae9a6de4cff3 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 8 Aug 2024 16:17:58 +0000 Subject: [PATCH 29/34] unexport validate functions Signed-off-by: Austin Abro --- src/pkg/lint/validate.go | 48 +++++++++++++++++------------------ src/pkg/lint/validate_test.go | 10 ++++---- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/pkg/lint/validate.go b/src/pkg/lint/validate.go index 3f2f92c3b8..776c63781f 100644 --- a/src/pkg/lint/validate.go +++ b/src/pkg/lint/validate.go @@ -73,7 +73,7 @@ func ValidatePackage(pkg v1alpha1.ZarfPackage) error { } } for _, component := range pkg.Components { - if compErr := ValidateComponent(component); compErr != nil { + if compErr := validateComponent(component); compErr != nil { err = errors.Join(err, compErr) } // ensure component name is unique @@ -96,7 +96,7 @@ func ValidatePackage(pkg v1alpha1.ZarfPackage) error { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrChartNameNotUnique, chart.Name)) } uniqueChartNames[chart.Name] = true - if chartErr := ValidateChart(chart); chartErr != nil { + if chartErr := validateChart(chart); chartErr != nil { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrChart, chartErr)) } } @@ -107,11 +107,11 @@ func ValidatePackage(pkg v1alpha1.ZarfPackage) error { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrManifestNameNotUnique, manifest.Name)) } uniqueManifestNames[manifest.Name] = true - if manifestErr := ValidateManifest(manifest); manifestErr != nil { + if manifestErr := validateManifest(manifest); manifestErr != nil { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrManifest, manifestErr)) } } - if actionsErr := ValidateActions(component.Actions); actionsErr != nil { + if actionsErr := validateActions(component.Actions); actionsErr != nil { err = errors.Join(err, fmt.Errorf("%q: %w", component.Name, actionsErr)) } // ensure groups don't have multiple defaults or only one component @@ -133,29 +133,29 @@ func ValidatePackage(pkg v1alpha1.ZarfPackage) error { return err } -// ValidateActions validates the actions of a component. -func ValidateActions(a v1alpha1.ZarfComponentActions) error { +// validateActions validates the actions of a component. +func validateActions(a v1alpha1.ZarfComponentActions) error { var err error - err = errors.Join(err, ValidateActionSet(a.OnCreate)) + err = errors.Join(err, validateActionSet(a.OnCreate)) - if HasSetVariables(a.OnCreate) { + if hasSetVariables(a.OnCreate) { err = errors.Join(err, fmt.Errorf("cannot contain setVariables outside of onDeploy in actions")) } - err = errors.Join(err, ValidateActionSet(a.OnDeploy)) + err = errors.Join(err, validateActionSet(a.OnDeploy)) - if HasSetVariables(a.OnRemove) { + if hasSetVariables(a.OnRemove) { err = errors.Join(err, fmt.Errorf("cannot contain setVariables outside of onDeploy in actions")) } - err = errors.Join(err, ValidateActionSet(a.OnRemove)) + err = errors.Join(err, validateActionSet(a.OnRemove)) return err } -// ValidateComponent validates the component trying to be imported. -func ValidateComponent(c v1alpha1.ZarfComponent) error { +// validateComponent validates the component trying to be imported. +func validateComponent(c v1alpha1.ZarfComponent) error { var err error path := c.Import.Path url := c.Import.URL @@ -189,8 +189,8 @@ func ValidateComponent(c v1alpha1.ZarfComponent) error { return err } -// HasSetVariables returns true if any of the actions contain setVariables. -func HasSetVariables(as v1alpha1.ZarfComponentActionSet) bool { +// hasSetVariables returns true if any of the actions contain setVariables. +func hasSetVariables(as v1alpha1.ZarfComponentActionSet) bool { check := func(actions []v1alpha1.ZarfComponentAction) bool { for _, action := range actions { if len(action.SetVariables) > 0 { @@ -203,12 +203,12 @@ func HasSetVariables(as v1alpha1.ZarfComponentActionSet) bool { return check(as.Before) || check(as.After) || check(as.OnSuccess) || check(as.OnFailure) } -// ValidateActionSet runs all validation checks on component action sets. -func ValidateActionSet(as v1alpha1.ZarfComponentActionSet) error { +// validateActionSet runs all validation checks on component action sets. +func validateActionSet(as v1alpha1.ZarfComponentActionSet) error { var err error validate := func(actions []v1alpha1.ZarfComponentAction) { for _, action := range actions { - if actionErr := ValidateAction(action); actionErr != nil { + if actionErr := validateAction(action); actionErr != nil { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrAction, actionErr)) } } @@ -221,8 +221,8 @@ func ValidateActionSet(as v1alpha1.ZarfComponentActionSet) error { return err } -// ValidateAction runs all validation checks on an action. -func ValidateAction(action v1alpha1.ZarfComponentAction) error { +// validateAction runs all validation checks on an action. +func validateAction(action v1alpha1.ZarfComponentAction) error { var err error if action.Wait != nil { @@ -268,8 +268,8 @@ func validateReleaseName(chartName, releaseName string) (err error) { return } -// ValidateChart runs all validation checks on a chart. -func ValidateChart(chart v1alpha1.ZarfChart) error { +// validateChart runs all validation checks on a chart. +func validateChart(chart v1alpha1.ZarfChart) error { var err error if len(chart.Name) > ZarfMaxChartNameLength { @@ -300,8 +300,8 @@ func ValidateChart(chart v1alpha1.ZarfChart) error { return err } -// ValidateManifest runs all validation checks on a manifest. -func ValidateManifest(manifest v1alpha1.ZarfManifest) error { +// validateManifest runs all validation checks on a manifest. +func validateManifest(manifest v1alpha1.ZarfManifest) error { var err error if len(manifest.Name) > ZarfMaxChartNameLength { diff --git a/src/pkg/lint/validate_test.go b/src/pkg/lint/validate_test.go index c3b4f8b519..bef3872015 100644 --- a/src/pkg/lint/validate_test.go +++ b/src/pkg/lint/validate_test.go @@ -176,7 +176,7 @@ func TestValidateManifest(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - err := ValidateManifest(tt.manifest) + err := validateManifest(tt.manifest) if tt.expectedErrs == nil { require.NoError(t, err) return @@ -309,7 +309,7 @@ func TestValidateChart(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - err := ValidateChart(tt.chart) + err := validateChart(tt.chart) if tt.expectedErrs == nil { require.NoError(t, err) return @@ -416,7 +416,7 @@ func TestValidateComponentActions(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - err := ValidateActions(tt.actions) + err := validateActions(tt.actions) if tt.expectedErrs == nil { require.NoError(t, err) return @@ -462,7 +462,7 @@ func TestValidateComponentAction(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - err := ValidateAction(tt.action) + err := validateAction(tt.action) if tt.expectedErrs == nil { require.NoError(t, err) return @@ -554,7 +554,7 @@ func TestValidateZarfComponent(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - err := ValidateComponent(tt.component) + err := validateComponent(tt.component) if tt.expectedErrs == nil { require.NoError(t, err) return From 9c4d24b5f372d8735f14022bd1d7a05c98ac7bcf Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 12 Aug 2024 14:47:52 +0000 Subject: [PATCH 30/34] re-delete file Signed-off-by: Austin Abro --- src/pkg/variables/types.go | 74 -------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 src/pkg/variables/types.go diff --git a/src/pkg/variables/types.go b/src/pkg/variables/types.go deleted file mode 100644 index 8f20e5ad99..0000000000 --- a/src/pkg/variables/types.go +++ /dev/null @@ -1,74 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package variables contains functions for interacting with variables -package variables - -import ( - "fmt" - "regexp" -) - -// VariableType represents a type of a Zarf package variable -type VariableType string - -const ( - // RawVariableType is the default type for a Zarf package variable - RawVariableType VariableType = "raw" - // FileVariableType is a type for a Zarf package variable that loads its contents from a file - FileVariableType VariableType = "file" -) - -// Variable represents a variable that has a value set programmatically -type Variable struct { - // The name to be used for the variable - Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"` - // Whether to mark this variable as sensitive to not print it in the log - Sensitive bool `json:"sensitive,omitempty"` - // Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_. - AutoIndent bool `json:"autoIndent,omitempty"` - // An optional regex pattern that a variable value must match before a package deployment can continue. - Pattern string `json:"pattern,omitempty"` - // Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB) - Type VariableType `json:"type,omitempty" jsonschema:"enum=raw,enum=file"` -} - -// InteractiveVariable is a variable that can be used to prompt a user for more information -type InteractiveVariable struct { - Variable `json:",inline"` - // A description of the variable to be used when prompting the user a value - Description string `json:"description,omitempty"` - // The default value to use for the variable - Default string `json:"default,omitempty"` - // Whether to prompt the user for input for this variable - Prompt bool `json:"prompt,omitempty"` -} - -// Constant are constants that can be used to dynamically template K8s resources or run in actions. -type Constant struct { - // The name to be used for the constant - Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"` - // The value to set for the constant during deploy - Value string `json:"value"` - // A description of the constant to explain its purpose on package create or deploy confirmation prompts - Description string `json:"description,omitempty"` - // Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_. - AutoIndent bool `json:"autoIndent,omitempty"` - // An optional regex pattern that a constant value must match before a package can be created. - Pattern string `json:"pattern,omitempty"` -} - -// SetVariable tracks internal variables that have been set during this run of Zarf -type SetVariable struct { - Variable `json:",inline"` - // The value the variable is currently set with - Value string `json:"value"` -} - -// Validate runs all validation checks on a package constant. -func (c Constant) Validate() error { - if !regexp.MustCompile(c.Pattern).MatchString(c.Value) { - return fmt.Errorf("provided value for constant %s does not match pattern %s", c.Name, c.Pattern) - } - return nil -} From 759414e496d7004c5dd268d3a1d87fff4b68e178 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 12 Aug 2024 14:54:09 +0000 Subject: [PATCH 31/34] static check Signed-off-by: Austin Abro --- src/pkg/lint/validate_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pkg/lint/validate_test.go b/src/pkg/lint/validate_test.go index d95655cb75..f199b6836f 100644 --- a/src/pkg/lint/validate_test.go +++ b/src/pkg/lint/validate_test.go @@ -452,8 +452,7 @@ func TestValidateComponentAction(t *testing.T) { action: v1alpha1.ZarfComponentAction{ Wait: &v1alpha1.ZarfComponentActionWait{Cluster: &v1alpha1.ZarfComponentActionWaitCluster{}, Network: &v1alpha1.ZarfComponentActionWaitNetwork{}}, }, - //nolint:staticcheck //ignore - expectedErrs: []string{fmt.Sprintf(PkgValidateErrActionClusterNetwork)}, + expectedErrs: []string{PkgValidateErrActionClusterNetwork}, }, } From a881426f8254e3cec457ea551f9639568f47dd45 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 12 Aug 2024 14:59:24 +0000 Subject: [PATCH 32/34] remove unnecessary lint checks Signed-off-by: Austin Abro --- src/pkg/lint/validate.go | 77 ++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 51 deletions(-) diff --git a/src/pkg/lint/validate.go b/src/pkg/lint/validate.go index c768867e15..70489e498d 100644 --- a/src/pkg/lint/validate.go +++ b/src/pkg/lint/validate.go @@ -40,59 +40,34 @@ const ( errChartReleaseNameEmpty = "release name empty, unable to fallback to chart name" ) +// Package errors found during validation. const ( - //nolint:revive //ignore - PkgValidateErrInitNoYOLO = "sorry, you can't YOLO an init package" - //nolint:revive //ignore - PkgValidateErrConstant = "invalid package constant: %w" - //nolint:revive //ignore - PkgValidateErrYOLONoOCI = "OCI images not allowed in YOLO" - //nolint:revive //ignore - PkgValidateErrYOLONoGit = "git repos not allowed in YOLO" - //nolint:revive //ignore - PkgValidateErrYOLONoArch = "cluster architecture not allowed in YOLO" - //nolint:revive //ignore - PkgValidateErrYOLONoDistro = "cluster distros not allowed in YOLO" - //nolint:revive //ignore - PkgValidateErrComponentNameNotUnique = "component name %q is not unique" - //nolint:revive //ignore - PkgValidateErrComponentReqDefault = "component %q cannot be both required and default" - //nolint:revive //ignore - PkgValidateErrComponentReqGrouped = "component %q cannot be both required and grouped" - //nolint:revive //ignore - PkgValidateErrChartNameNotUnique = "chart name %q is not unique" - //nolint:revive //ignore - PkgValidateErrChart = "invalid chart definition: %w" - //nolint:revive //ignore - PkgValidateErrManifestNameNotUnique = "manifest name %q is not unique" - //nolint:revive //ignore - PkgValidateErrManifest = "invalid manifest definition: %w" - //nolint:revive //ignore - PkgValidateErrGroupMultipleDefaults = "group %q has multiple defaults (%q, %q)" - //nolint:revive //ignore - PkgValidateErrGroupOneComponent = "group %q only has one component (%q)" - //nolint:revive //ignore - PkgValidateErrAction = "invalid action: %w" - //nolint:revive //ignore - PkgValidateErrActionCmdWait = "action %q cannot be both a command and wait action" - //nolint:revive //ignore - PkgValidateErrActionClusterNetwork = "a single wait action must contain only one of cluster or network" - //nolint:revive //ignore - PkgValidateErrChartName = "chart %q exceed the maximum length of %d characters" - //nolint:revive //ignore - PkgValidateErrChartNamespaceMissing = "chart %q must include a namespace" - //nolint:revive //ignore - PkgValidateErrChartURLOrPath = "chart %q must have either a url or localPath" - //nolint:revive //ignore - PkgValidateErrChartVersion = "chart %q must include a chart version" - //nolint:revive //ignore - PkgValidateErrImportDefinition = "invalid imported definition for %s: %s" - //nolint:revive //ignore + PkgValidateErrInitNoYOLO = "sorry, you can't YOLO an init package" + PkgValidateErrConstant = "invalid package constant: %w" + PkgValidateErrYOLONoOCI = "OCI images not allowed in YOLO" + PkgValidateErrYOLONoGit = "git repos not allowed in YOLO" + PkgValidateErrYOLONoArch = "cluster architecture not allowed in YOLO" + PkgValidateErrYOLONoDistro = "cluster distros not allowed in YOLO" + 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" + PkgValidateErrChartNameNotUnique = "chart name %q is not unique" + PkgValidateErrChart = "invalid chart definition: %w" + PkgValidateErrManifestNameNotUnique = "manifest name %q is not unique" + PkgValidateErrManifest = "invalid manifest definition: %w" + PkgValidateErrGroupMultipleDefaults = "group %q has multiple defaults (%q, %q)" + PkgValidateErrGroupOneComponent = "group %q only has one component (%q)" + PkgValidateErrAction = "invalid action: %w" + PkgValidateErrActionCmdWait = "action %q cannot be both a command and wait action" + PkgValidateErrActionClusterNetwork = "a single wait action must contain only one of cluster or network" + PkgValidateErrChartName = "chart %q exceed the maximum length of %d characters" + PkgValidateErrChartNamespaceMissing = "chart %q must include a namespace" + PkgValidateErrChartURLOrPath = "chart %q must have either a url or localPath" + PkgValidateErrChartVersion = "chart %q must include a chart version" + PkgValidateErrImportDefinition = "invalid imported definition for %s: %s" PkgValidateErrManifestFileOrKustomize = "manifest %q must have at least one file or kustomization" - //nolint:revive //ignore - PkgValidateErrManifestNameLength = "manifest %q exceed the maximum length of %d characters" - //nolint:revive //ignore - PkgValidateErrVariable = "invalid package variable: %w" + PkgValidateErrManifestNameLength = "manifest %q exceed the maximum length of %d characters" + PkgValidateErrVariable = "invalid package variable: %w" ) // ValidatePackage runs all validation checks on the package. From 265df7c38f743ae2a7f3b612d7169c542432d240 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 12 Aug 2024 15:22:31 +0000 Subject: [PATCH 33/34] move validate compose code to compose Signed-off-by: Austin Abro --- src/pkg/lint/validate.go | 41 ------------ src/pkg/lint/validate_test.go | 93 -------------------------- src/pkg/packager/composer/list.go | 38 +++++++++++ src/pkg/packager/composer/list_test.go | 93 ++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 134 deletions(-) diff --git a/src/pkg/lint/validate.go b/src/pkg/lint/validate.go index 70489e498d..0cba4efe15 100644 --- a/src/pkg/lint/validate.go +++ b/src/pkg/lint/validate.go @@ -7,11 +7,9 @@ package lint import ( "errors" "fmt" - "path/filepath" "regexp" "strings" - "github.com/defenseunicorns/pkg/helpers/v2" "github.com/zarf-dev/zarf/src/api/v1alpha1" "k8s.io/apimachinery/pkg/util/validation" ) @@ -64,7 +62,6 @@ const ( PkgValidateErrChartNamespaceMissing = "chart %q must include a namespace" PkgValidateErrChartURLOrPath = "chart %q must have either a url or localPath" PkgValidateErrChartVersion = "chart %q must include a chart version" - PkgValidateErrImportDefinition = "invalid imported definition for %s: %s" PkgValidateErrManifestFileOrKustomize = "manifest %q must have at least one file or kustomization" PkgValidateErrManifestNameLength = "manifest %q exceed the maximum length of %d characters" PkgValidateErrVariable = "invalid package variable: %w" @@ -101,9 +98,6 @@ func ValidatePackage(pkg v1alpha1.ZarfPackage) error { } } for _, component := range pkg.Components { - if compErr := validateComponent(component); compErr != nil { - err = errors.Join(err, compErr) - } // ensure component name is unique if _, ok := uniqueComponentNames[component.Name]; ok { err = errors.Join(err, fmt.Errorf(PkgValidateErrComponentNameNotUnique, component.Name)) @@ -182,41 +176,6 @@ func validateActions(a v1alpha1.ZarfComponentActions) error { return err } -// validateComponent validates the component trying to be imported. -func validateComponent(c v1alpha1.ZarfComponent) error { - var err error - path := c.Import.Path - url := c.Import.URL - - // ensure path or url is provided - if path == "" && url == "" { - err = errors.Join(err, fmt.Errorf(PkgValidateErrImportDefinition, c.Name, "neither a path nor a URL was provided")) - } - - // ensure path and url are not both provided - if path != "" && url != "" { - err = errors.Join(err, fmt.Errorf(PkgValidateErrImportDefinition, c.Name, "both a path and a URL were provided")) - } - - // validation for path - if url == "" && path != "" { - // ensure path is not an absolute path - if filepath.IsAbs(path) { - err = errors.Join(err, fmt.Errorf(PkgValidateErrImportDefinition, c.Name, "path cannot be an absolute path")) - } - } - - // validation for url - if url != "" && path == "" { - ok := helpers.IsOCIURL(url) - if !ok { - err = errors.Join(err, fmt.Errorf(PkgValidateErrImportDefinition, c.Name, "URL is not a valid OCI URL")) - } - } - - return err -} - // hasSetVariables returns true if any of the actions contain setVariables. func hasSetVariables(as v1alpha1.ZarfComponentActionSet) bool { check := func(actions []v1alpha1.ZarfComponentAction) bool { diff --git a/src/pkg/lint/validate_test.go b/src/pkg/lint/validate_test.go index f199b6836f..4e0abeda96 100644 --- a/src/pkg/lint/validate_test.go +++ b/src/pkg/lint/validate_test.go @@ -6,7 +6,6 @@ package lint import ( "fmt" - "path/filepath" "strings" "testing" @@ -470,95 +469,3 @@ func TestValidateComponentAction(t *testing.T) { }) } } - -func TestValidateZarfComponent(t *testing.T) { - t.Parallel() - absPath, err := filepath.Abs("abs") - require.NoError(t, err) - tests := []struct { - component v1alpha1.ZarfComponent - expectedErrs []string - name string - }{ - { - name: "valid path", - component: v1alpha1.ZarfComponent{ - Name: "component1", - Import: v1alpha1.ZarfComponentImport{ - Path: "relative/path", - }, - }, - expectedErrs: nil, - }, - { - name: "valid URL", - component: v1alpha1.ZarfComponent{ - Name: "component2", - Import: v1alpha1.ZarfComponentImport{ - URL: "oci://example.com/package:v0.0.1", - }, - }, - expectedErrs: nil, - }, - { - name: "neither path nor URL provided", - component: v1alpha1.ZarfComponent{ - Name: "neither", - }, - expectedErrs: []string{ - fmt.Sprintf(PkgValidateErrImportDefinition, "neither", "neither a path nor a URL was provided"), - }, - }, - { - name: "both path and URL provided", - component: v1alpha1.ZarfComponent{ - Name: "both", - Import: v1alpha1.ZarfComponentImport{ - Path: "relative/path", - URL: "https://example.com", - }, - }, - expectedErrs: []string{ - fmt.Sprintf(PkgValidateErrImportDefinition, "both", "both a path and a URL were provided"), - }, - }, - { - name: "absolute path provided", - component: v1alpha1.ZarfComponent{ - Name: "abs-path", - Import: v1alpha1.ZarfComponentImport{ - Path: absPath, - }, - }, - expectedErrs: []string{ - fmt.Sprintf(PkgValidateErrImportDefinition, "abs-path", "path cannot be an absolute path"), - }, - }, - { - name: "invalid URL provided", - component: v1alpha1.ZarfComponent{ - Name: "bad-url", - Import: v1alpha1.ZarfComponentImport{ - URL: "https://example.com", - }, - }, - expectedErrs: []string{ - fmt.Sprintf(PkgValidateErrImportDefinition, "bad-url", "URL is not a valid OCI URL"), - }, - }, - } - - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - err := validateComponent(tt.component) - if tt.expectedErrs == nil { - require.NoError(t, err) - return - } - errs := strings.Split(err.Error(), "\n") - require.ElementsMatch(t, tt.expectedErrs, errs) - }) - } -} diff --git a/src/pkg/packager/composer/list.go b/src/pkg/packager/composer/list.go index 07b70fade2..f032bd92ba 100644 --- a/src/pkg/packager/composer/list.go +++ b/src/pkg/packager/composer/list.go @@ -6,6 +6,7 @@ package composer import ( "context" + "errors" "fmt" "path/filepath" "strings" @@ -117,6 +118,43 @@ func (ic *ImportChain) append(c v1alpha1.ZarfComponent, index int, originalPacka } } +const pkgValidateErrImportDefinition = "invalid imported definition for %s: %s" + +// validateComponentCompose validates that a component doesn't break compose rules +func validateComponentCompose(c v1alpha1.ZarfComponent) error { + var err error + path := c.Import.Path + url := c.Import.URL + + // ensure path or url is provided + if path == "" && url == "" { + err = errors.Join(err, fmt.Errorf(pkgValidateErrImportDefinition, c.Name, "neither a path nor a URL was provided")) + } + + // ensure path and url are not both provided + if path != "" && url != "" { + err = errors.Join(err, fmt.Errorf(pkgValidateErrImportDefinition, c.Name, "both a path and a URL were provided")) + } + + // validation for path + if url == "" && path != "" { + // ensure path is not an absolute path + if filepath.IsAbs(path) { + err = errors.Join(err, fmt.Errorf(pkgValidateErrImportDefinition, c.Name, "path cannot be an absolute path")) + } + } + + // validation for url + if url != "" && path == "" { + ok := helpers.IsOCIURL(url) + if !ok { + err = errors.Join(err, fmt.Errorf(pkgValidateErrImportDefinition, c.Name, "URL is not a valid OCI URL")) + } + } + + return err +} + // NewImportChain creates a new import chain from a component // Returning the chain on error so we can have additional information to use during lint func NewImportChain(ctx context.Context, head v1alpha1.ZarfComponent, index int, originalPackageName, arch, flavor string) (*ImportChain, error) { diff --git a/src/pkg/packager/composer/list_test.go b/src/pkg/packager/composer/list_test.go index beff63b524..33ef79819a 100644 --- a/src/pkg/packager/composer/list_test.go +++ b/src/pkg/packager/composer/list_test.go @@ -9,6 +9,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "testing" "github.com/stretchr/testify/require" @@ -540,3 +541,95 @@ func createDummyComponent(t *testing.T, name, importDir, subName string) v1alpha }, } } + +func TestValidateZarfComponent(t *testing.T) { + t.Parallel() + absPath, err := filepath.Abs("abs") + require.NoError(t, err) + tests := []struct { + component v1alpha1.ZarfComponent + expectedErrs []string + name string + }{ + { + name: "valid path", + component: v1alpha1.ZarfComponent{ + Name: "component1", + Import: v1alpha1.ZarfComponentImport{ + Path: "relative/path", + }, + }, + expectedErrs: nil, + }, + { + name: "valid URL", + component: v1alpha1.ZarfComponent{ + Name: "component2", + Import: v1alpha1.ZarfComponentImport{ + URL: "oci://example.com/package:v0.0.1", + }, + }, + expectedErrs: nil, + }, + { + name: "neither path nor URL provided", + component: v1alpha1.ZarfComponent{ + Name: "neither", + }, + expectedErrs: []string{ + fmt.Sprintf(pkgValidateErrImportDefinition, "neither", "neither a path nor a URL was provided"), + }, + }, + { + name: "both path and URL provided", + component: v1alpha1.ZarfComponent{ + Name: "both", + Import: v1alpha1.ZarfComponentImport{ + Path: "relative/path", + URL: "https://example.com", + }, + }, + expectedErrs: []string{ + fmt.Sprintf(pkgValidateErrImportDefinition, "both", "both a path and a URL were provided"), + }, + }, + { + name: "absolute path provided", + component: v1alpha1.ZarfComponent{ + Name: "abs-path", + Import: v1alpha1.ZarfComponentImport{ + Path: absPath, + }, + }, + expectedErrs: []string{ + fmt.Sprintf(pkgValidateErrImportDefinition, "abs-path", "path cannot be an absolute path"), + }, + }, + { + name: "invalid URL provided", + component: v1alpha1.ZarfComponent{ + Name: "bad-url", + Import: v1alpha1.ZarfComponentImport{ + URL: "https://example.com", + }, + }, + expectedErrs: []string{ + fmt.Sprintf(pkgValidateErrImportDefinition, "bad-url", "URL is not a valid OCI URL"), + }, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + err := validateComponentCompose(tt.component) + if tt.expectedErrs == nil { + require.NoError(t, err) + return + } + errs := strings.Split(err.Error(), "\n") + require.ElementsMatch(t, tt.expectedErrs, errs) + }) + } +} From e831b01ff25ffe8c5dfdfe9cf349fdb0e812676a Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 12 Aug 2024 15:28:24 +0000 Subject: [PATCH 34/34] move compose check to compose Signed-off-by: Austin Abro --- src/pkg/packager/composer/list.go | 14 ++++++++------ src/pkg/packager/composer/list_test.go | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/pkg/packager/composer/list.go b/src/pkg/packager/composer/list.go index f032bd92ba..291fdb71db 100644 --- a/src/pkg/packager/composer/list.go +++ b/src/pkg/packager/composer/list.go @@ -118,8 +118,6 @@ func (ic *ImportChain) append(c v1alpha1.ZarfComponent, index int, originalPacka } } -const pkgValidateErrImportDefinition = "invalid imported definition for %s: %s" - // validateComponentCompose validates that a component doesn't break compose rules func validateComponentCompose(c v1alpha1.ZarfComponent) error { var err error @@ -128,19 +126,19 @@ func validateComponentCompose(c v1alpha1.ZarfComponent) error { // ensure path or url is provided if path == "" && url == "" { - err = errors.Join(err, fmt.Errorf(pkgValidateErrImportDefinition, c.Name, "neither a path nor a URL was provided")) + err = errors.Join(err, errors.New("neither a path nor a URL was provided")) } // ensure path and url are not both provided if path != "" && url != "" { - err = errors.Join(err, fmt.Errorf(pkgValidateErrImportDefinition, c.Name, "both a path and a URL were provided")) + err = errors.Join(err, errors.New("both a path and a URL were provided")) } // validation for path if url == "" && path != "" { // ensure path is not an absolute path if filepath.IsAbs(path) { - err = errors.Join(err, fmt.Errorf(pkgValidateErrImportDefinition, c.Name, "path cannot be an absolute path")) + err = errors.Join(err, errors.New("path cannot be an absolute path")) } } @@ -148,7 +146,7 @@ func validateComponentCompose(c v1alpha1.ZarfComponent) error { if url != "" && path == "" { ok := helpers.IsOCIURL(url) if !ok { - err = errors.Join(err, fmt.Errorf(pkgValidateErrImportDefinition, c.Name, "URL is not a valid OCI URL")) + err = errors.Join(err, errors.New("URL is not a valid OCI URL")) } } @@ -178,6 +176,10 @@ func NewImportChain(ctx context.Context, head v1alpha1.ZarfComponent, index int, return ic, nil } + if err := validateComponentCompose(node.ZarfComponent); err != nil { + return nil, fmt.Errorf("invalid imported definition for %s: %w", node.Name, err) + } + // ensure that remote components are not importing other remote components if node.prev != nil && node.prev.Import.URL != "" && isRemote { return ic, fmt.Errorf("detected malformed import chain, cannot import remote components from remote components") diff --git a/src/pkg/packager/composer/list_test.go b/src/pkg/packager/composer/list_test.go index 33ef79819a..1703348b3d 100644 --- a/src/pkg/packager/composer/list_test.go +++ b/src/pkg/packager/composer/list_test.go @@ -577,7 +577,7 @@ func TestValidateZarfComponent(t *testing.T) { Name: "neither", }, expectedErrs: []string{ - fmt.Sprintf(pkgValidateErrImportDefinition, "neither", "neither a path nor a URL was provided"), + "neither a path nor a URL was provided", }, }, { @@ -590,7 +590,7 @@ func TestValidateZarfComponent(t *testing.T) { }, }, expectedErrs: []string{ - fmt.Sprintf(pkgValidateErrImportDefinition, "both", "both a path and a URL were provided"), + "both a path and a URL were provided", }, }, { @@ -602,7 +602,7 @@ func TestValidateZarfComponent(t *testing.T) { }, }, expectedErrs: []string{ - fmt.Sprintf(pkgValidateErrImportDefinition, "abs-path", "path cannot be an absolute path"), + "path cannot be an absolute path", }, }, { @@ -614,7 +614,7 @@ func TestValidateZarfComponent(t *testing.T) { }, }, expectedErrs: []string{ - fmt.Sprintf(pkgValidateErrImportDefinition, "bad-url", "URL is not a valid OCI URL"), + "URL is not a valid OCI URL", }, }, }