From b1ce576d92fd8dd1b748992bcb1ed1bad4dfaac6 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 7 Aug 2024 14:33:12 +0000 Subject: [PATCH] move validate to lint Signed-off-by: Austin Abro --- src/api/v1alpha1/component.go | 15 -------------- src/api/v1alpha1/package.go | 31 +++++++++-------------------- src/pkg/cluster/injector.go | 6 ++++-- src/pkg/packager/filters/os_test.go | 5 +++-- 4 files changed, 16 insertions(+), 41 deletions(-) diff --git a/src/api/v1alpha1/component.go b/src/api/v1alpha1/component.go index c9928e95c1..bd798c82f6 100644 --- a/src/api/v1alpha1/component.go +++ b/src/api/v1alpha1/component.go @@ -11,21 +11,6 @@ import ( "github.com/zarf-dev/zarf/src/pkg/variables" ) -var ( - // Define allowed OS, an empty string means it is allowed on all operating systems - // same as enums on ZarfComponentOnlyTarget - supportedOS = []string{"linux", "darwin", "windows"} -) - -// SupportedOS returns the supported operating systems. -// -// The supported operating systems are: linux, darwin, windows. -// -// An empty string signifies no OS restrictions. -func SupportedOS() []string { - return supportedOS -} - // ZarfComponent is the primary functional grouping of assets to deploy by Zarf. type ZarfComponent struct { // The name of the component. diff --git a/src/api/v1alpha1/package.go b/src/api/v1alpha1/package.go index f82ccdeb4c..d2ce1c6c43 100644 --- a/src/api/v1alpha1/package.go +++ b/src/api/v1alpha1/package.go @@ -5,10 +5,17 @@ package v1alpha1 import ( - "github.com/invopop/jsonschema" "github.com/zarf-dev/zarf/src/pkg/variables" ) +// Zarf looks for these strings in zarf.yaml to make dynamic changes +const ( + ZarfPackageTemplatePrefix = "###ZARF_PKG_TMPL_" + ZarfPackageVariablePrefix = "###ZARF_PKG_VAR_" + ZarfPackageArch = "###ZARF_PKG_ARCH###" + ZarfComponentName = "###ZARF_COMPONENT_NAME###" +) + // ZarfPackageKind is an enum of the different kinds of Zarf packages. type ZarfPackageKind string @@ -20,22 +27,12 @@ const ( ApiVersion string = "zarf.dev/v1alpha1" ) -// Zarf looks for these strings in zarf.yaml to make dynamic changes -const ( - ZarfPackageTemplatePrefix = "###ZARF_PKG_TMPL_" - ZarfPackageVariablePrefix = "###ZARF_PKG_VAR_" - ZarfPackageArch = "###ZARF_PKG_ARCH###" - ZarfComponentName = "###ZARF_COMPONENT_NAME###" -) - -const apiVersion = "zarf.dev/v1alpha1" - // ZarfPackage the top-level structure of a Zarf config file. type ZarfPackage struct { // The API version of the Zarf package. ApiVersion string `json:"apiVersion,omitempty," jsonschema:"enum=zarf.dev/v1alpha1"` // The kind of Zarf package. - Kind ZarfPackageKind `json:"kind"` + Kind ZarfPackageKind `json:"kind" jsonschema:"enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"` // Package metadata. Metadata ZarfMetadata `json:"metadata,omitempty"` // Zarf-generated package build data. @@ -48,16 +45,6 @@ type ZarfPackage struct { Variables []variables.InteractiveVariable `json:"variables,omitempty"` } -// JSONSchemaExtend extends the generated json schema during `zarf internal gen-config-schema` -func (ZarfPackage) JSONSchemaExtend(schema *jsonschema.Schema) { - kind, _ := schema.Properties.Get("kind") - kind.Enum = []interface{}{ZarfInitConfig, ZarfPackageConfig} - kind.Default = ZarfPackageConfig - - apiVersionSchema, _ := schema.Properties.Get("apiVersion") - apiVersionSchema.Enum = []interface{}{apiVersion} -} - // IsInitConfig returns whether a Zarf package is an init config. func (pkg ZarfPackage) IsInitConfig() bool { return pkg.Kind == ZarfInitConfig diff --git a/src/pkg/cluster/injector.go b/src/pkg/cluster/injector.go index 1ee24c2150..48552ac5e1 100644 --- a/src/pkg/cluster/injector.go +++ b/src/pkg/cluster/injector.go @@ -260,11 +260,13 @@ func (c *Cluster) createPayloadConfigMaps(ctx context.Context, spinner *message. return cmNames, shasum, nil } -var zarfImageRegex = regexp.MustCompile(`(?m)^127\.0\.0\.1:`) - // getImagesAndNodesForInjection checks for images on schedulable nodes within a cluster. func (c *Cluster) getInjectorImageAndNode(ctx context.Context, resReq corev1.ResourceRequirements) (string, string, error) { // Regex for Zarf seed image + zarfImageRegex, err := regexp.Compile(`(?m)^127\.0\.0\.1:`) + if err != nil { + return "", "", err + } listOpts := metav1.ListOptions{ FieldSelector: fmt.Sprintf("status.phase=%s", corev1.PodRunning), } diff --git a/src/pkg/packager/filters/os_test.go b/src/pkg/packager/filters/os_test.go index fb81d1355a..c546fca2b2 100644 --- a/src/pkg/packager/filters/os_test.go +++ b/src/pkg/packager/filters/os_test.go @@ -9,11 +9,12 @@ import ( "github.com/stretchr/testify/require" "github.com/zarf-dev/zarf/src/api/v1alpha1" + "github.com/zarf-dev/zarf/src/pkg/rules" ) func TestLocalOSFilter(t *testing.T) { pkg := v1alpha1.ZarfPackage{} - for _, os := range v1alpha1.SupportedOS() { + for _, os := range rules.SupportedOS() { pkg.Components = append(pkg.Components, v1alpha1.ZarfComponent{ Only: v1alpha1.ZarfComponentOnlyTarget{ LocalOS: os, @@ -21,7 +22,7 @@ func TestLocalOSFilter(t *testing.T) { }) } - for _, os := range v1alpha1.SupportedOS() { + for _, os := range rules.SupportedOS() { filter := ByLocalOS(os) result, err := filter.Apply(pkg) if os == "" {