diff --git a/go.mod b/go.mod index a5196222e6..4e4ef20ac3 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 @@ -49,6 +51,7 @@ 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.25.0 golang.org/x/sync v0.7.0 golang.org/x/term v0.22.0 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/types/component.go b/src/api/v1alpha1/component.go similarity index 99% rename from src/types/component.go rename to src/api/v1alpha1/component.go index b43493ad0a..bd798c82f6 100644 --- a/src/types/component.go +++ b/src/api/v1alpha1/component.go @@ -1,14 +1,14 @@ // 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 holds the definition of the v1alpha1 Zarf Package +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" ) // ZarfComponent is the primary functional grouping of assets to deploy by Zarf. 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/types/package.go b/src/api/v1alpha1/package.go similarity index 94% rename from src/types/package.go rename to src/api/v1alpha1/package.go index fa3f8e5819..2262bf3e82 100644 --- a/src/types/package.go +++ b/src/api/v1alpha1/package.go @@ -1,10 +1,12 @@ // 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 holds the definition of the v1alpha1 Zarf Package +package v1alpha1 -import "github.com/zarf-dev/zarf/src/pkg/variables" +import ( + "github.com/zarf-dev/zarf/src/pkg/variables" +) // ZarfPackageKind is an enum of the different kinds of Zarf packages. type ZarfPackageKind string @@ -14,10 +16,13 @@ const ( ZarfInitConfig ZarfPackageKind = "ZarfInitConfig" // ZarfPackageConfig is the default kind of Zarf package, primarily used during `zarf package`. ZarfPackageConfig ZarfPackageKind = "ZarfPackageConfig" + ApiVersion string = "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" jsonschema:"enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` // Package metadata. diff --git a/src/types/package_test.go b/src/api/v1alpha1/package_test.go similarity index 95% rename from src/types/package_test.go rename to src/api/v1alpha1/package_test.go index 7dca85bd1f..b23df834d8 100644 --- a/src/types/package_test.go +++ b/src/api/v1alpha1/package_test.go @@ -1,7 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2021-Present The Zarf Authors -package types +// Package v1alpha1 holds the definition of the v1alpha1 Zarf Package +package v1alpha1 import ( "testing" diff --git a/src/types/validate.go b/src/api/v1alpha1/validate.go similarity index 95% rename from src/types/validate.go rename to src/api/v1alpha1/validate.go index 05289a1781..391e0f000d 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 holds the definition of the v1alpha1 Zarf Package +package v1alpha1 import ( "errors" @@ -16,11 +16,12 @@ import ( "k8s.io/apimachinery/pkg/util/validation" ) +// Zarf looks for these strings in zarf.yaml to make dynamic changes const ( - // ZarfMaxChartNameLength limits helm chart name size to account for K8s/helm limits and zarf prefix - ZarfMaxChartNameLength = 40 - errChartReleaseNameEmpty = "release name empty, unable to fallback to chart name" - errChartReleaseNameInvalid = "invalid release name %s: a DNS-1035 label must consist of lower case alphanumeric characters or -, start with an alphabetic character, and end with an alphanumeric character" + ZarfPackageTemplatePrefix = "###ZARF_PKG_TMPL_" + ZarfPackageVariablePrefix = "###ZARF_PKG_VAR_" + ZarfPackageArch = "###ZARF_PKG_ARCH###" + ZarfComponentName = "###ZARF_COMPONENT_NAME###" ) var ( @@ -41,6 +42,12 @@ func SupportedOS() []string { return supportedOS } +const ( + // ZarfMaxChartNameLength limits helm chart name size to account for K8s/helm limits and zarf prefix + ZarfMaxChartNameLength = 40 + errChartReleaseNameEmpty = "release name empty, unable to fallback to chart name" +) + // 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 28895a8df8..de3f675c2e 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 holds the definition of the v1alpha1 Zarf Package +package v1alpha1 import ( "fmt" diff --git a/src/cmd/internal.go b/src/cmd/internal.go index ab14a9d5d6..d989d6ce0a 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" @@ -160,7 +161,7 @@ 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") + typePackagePath := filepath.Join("src", "api", "v1alpha1") if err := reflector.AddGoComments("github.com/zarf-dev/zarf", typePackagePath); err != nil { return fmt.Errorf("%w: %w", addCommentErr, err) } @@ -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 31b71015cf..6b59d2a829 100644 --- a/src/extensions/bigbang/bigbang.go +++ b/src/extensions/bigbang/bigbang.go @@ -17,13 +17,13 @@ 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/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" - "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" @@ -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..2acdee4f99 100644 --- a/src/extensions/bigbang/flux.go +++ b/src/extensions/bigbang/flux.go @@ -12,10 +12,10 @@ 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" - "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" @@ -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/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/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 fa89547dfd..6172e3fa78 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" @@ -107,7 +108,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, "" @@ -131,7 +132,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 @@ -179,7 +180,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 @@ -280,7 +281,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..9e59dddcd4 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,18 @@ 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{ + ApiVersion: v1alpha1.ApiVersion, + Kind: v1alpha1.ZarfInitConfig, + Metadata: v1alpha1.ZarfMetadata{ Name: "valid-name", }, - Components: []types.ZarfComponent{ + Components: []v1alpha1.ZarfComponent{ { Name: "valid-comp", }, @@ -42,11 +43,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 +56,36 @@ func TestZarfSchema(t *testing.T) { }, { name: "invalid package", - pkg: types.ZarfPackage{ - Kind: types.ZarfInitConfig, - Metadata: types.ZarfMetadata{ + pkg: v1alpha1.ZarfPackage{ + ApiVersion: "bad-api-version/wrong", + 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"}}, @@ -113,6 +115,7 @@ func TestZarfSchema(t *testing.T) { "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)", + "apiVersion: apiVersion must be one of the following: \"zarf.dev/v1alpha1\"", }, }, } @@ -170,9 +173,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 3d979ffcac..4fdf71fdd5 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(ctx context.Context, defaultCfg types.ZarfComponentActionDefaults, actions []types.ZarfComponentAction, variableConfig *variables.VariableConfig) error { +func Run(ctx context.Context, defaultCfg v1alpha1.ZarfComponentActionDefaults, actions []v1alpha1.ZarfComponentAction, variableConfig *variables.VariableConfig) error { if variableConfig == nil { variableConfig = template.GetZarfVariableConfig() } @@ -36,7 +36,7 @@ func Run(ctx context.Context, defaultCfg types.ZarfComponentActionDefaults, acti } // Run commands that a component has provided. -func runAction(ctx context.Context, defaultCfg types.ZarfComponentActionDefaults, action types.ZarfComponentAction, variableConfig *variables.VariableConfig) error { +func runAction(ctx context.Context, defaultCfg v1alpha1.ZarfComponentActionDefaults, action v1alpha1.ZarfComponentAction, variableConfig *variables.VariableConfig) error { var ( cmdEscaped string out string @@ -168,7 +168,7 @@ retryCmd: } // convertWaitToCmd will return the wait command if it exists, otherwise it will return the original command. -func convertWaitToCmd(_ context.Context, wait types.ZarfComponentActionWait, timeout *int) (string, error) { +func convertWaitToCmd(_ context.Context, wait v1alpha1.ZarfComponentActionWait, timeout *int) (string, error) { // Build the timeout string. timeoutString := fmt.Sprintf("--timeout %ds", *timeout) @@ -235,7 +235,7 @@ func actionCmdMutation(_ context.Context, cmd string, shellPref exec.Shell) (str } // Merge the ActionSet defaults with the action config. -func actionGetCfg(_ context.Context, cfg types.ZarfComponentActionDefaults, a types.ZarfComponentAction, vars map[string]*variables.TextTemplate) types.ZarfComponentActionDefaults { +func actionGetCfg(_ context.Context, cfg v1alpha1.ZarfComponentActionDefaults, a v1alpha1.ZarfComponentAction, vars map[string]*variables.TextTemplate) v1alpha1.ZarfComponentActionDefaults { if a.Mute != nil { cfg.Mute = *a.Mute } @@ -274,7 +274,7 @@ func actionGetCfg(_ context.Context, cfg types.ZarfComponentActionDefaults, a ty 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..56e266738b 100644 --- a/src/pkg/packager/composer/list_test.go +++ b/src/pkg/packager/composer/list_test.go @@ -12,9 +12,9 @@ import ( "testing" "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" - "github.com/zarf-dev/zarf/src/types/extensions" ) func TestNewImportChain(t *testing.T) { @@ -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 ea9f6d24c9..79c58250c0 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 02519e7848..df6cec2ae2 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/git" "github.com/zarf-dev/zarf/src/internal/gitea" @@ -232,7 +233,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" @@ -286,7 +287,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] @@ -372,7 +373,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() @@ -614,7 +615,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) @@ -640,7 +641,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 7b65f6f576..2ae56e7a45 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/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 59583cee28..4edcdd5b05 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 78276d33af..8bf6d6d1a6 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 822dbd330e..db1b2ed01a 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(ctx context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg types.ZarfPackage, warnings []string, err error) { +func (s *TarballSource) LoadPackage(ctx 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(ctx context.Context, dst *layout.PackagePath } // LoadPackageMetadata loads a package's metadata from a tarball. -func (s *TarballSource) LoadPackageMetadata(ctx context.Context, dst *layout.PackagePaths, wantSBOM bool, skipValidation bool) (pkg types.ZarfPackage, warnings []string, err error) { +func (s *TarballSource) LoadPackageMetadata(ctx 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 6277a0f7d7..84ad8d7994 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 diff --git a/zarf.schema.json b/zarf.schema.json index f4a0690553..6249898643 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": [