Skip to content

Commit

Permalink
move validate to lint
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Aug 7, 2024
1 parent 3a9f928 commit b1ce576
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 41 deletions.
15 changes: 0 additions & 15 deletions src/api/v1alpha1/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 9 additions & 22 deletions src/api/v1alpha1/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/pkg/cluster/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
5 changes: 3 additions & 2 deletions src/pkg/packager/filters/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ 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,
},
})
}

for _, os := range v1alpha1.SupportedOS() {
for _, os := range rules.SupportedOS() {
filter := ByLocalOS(os)
result, err := filter.Apply(pkg)
if os == "" {
Expand Down

0 comments on commit b1ce576

Please sign in to comment.