rules

package
v0.1.76 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PackageYAMLRuleName                           = "package-yaml"
	PackageConfigFilename                         = "package.yaml"
	MinimalDeckhouseVersionForPackageRequirements = "1.77.0"
)
View Source
const (
	RequirementsRuleName = "requirements"
	// MinimalDeckhouseVersionForStage defines the minimum required Deckhouse version for stage usage
	MinimalDeckhouseVersionForStage = "1.68.0"
	// MinimalDeckhouseVersionForGoHooks defines the minimum required Deckhouse version for Go hooks usage
	MinimalDeckhouseVersionForGoHooks = "1.68.0"
	// MinimalDeckhouseVersionForReadinessProbes defines the minimum required Deckhouse version for readiness probes usage
	MinimalDeckhouseVersionForReadinessProbes = "1.71.0"
	// MinimalDeckhouseVersionForOptionalModules defines the minimum required Deckhouse version for optional modules usage
	MinimalDeckhouseVersionForOptionalModules = "1.73.0"

	// MinimalModuleSDKVersionRequiresDeckhouse171 defines the minimum module-sdk version that requires Deckhouse >= 1.71
	MinimalModuleSDKVersionRequiresDeckhouse171 = "0.3.0"
	// MinimalDeckhouseVersionForModuleSDK03 defines the minimum Deckhouse version required for Module-SDK >= 0.3
	MinimalDeckhouseVersionForModuleSDK03 = "1.71.0"

	// MinimalDeckhouseVersionForWeightDeprecation defines the version where weight became irrelevant for non-critical modules
	MinimalDeckhouseVersionForWeightDeprecation = "1.72.0"
	// MinimalDeckhouseVersionForBootstrappedDeprecation defines the version where bootstrapped was deprecated
	MinimalDeckhouseVersionForBootstrappedDeprecation = "1.72.0"

	// Common patterns used in Go files
	AppRunPattern = `\w+\.Run\(`
)
View Source
const (
	// Default directory permissions for test files
	DefaultDirPerm = 0755
	// Default file permissions for test files
	DefaultFilePerm = 0600
)
View Source
const (
	ValidModuleContent = `name: test-module
namespace: test`

	StageModuleContent = `name: test-module
namespace: test
stage: "General Availability"`

	StageWithRequirementsContent = `name: test-module
namespace: test
stage: "General Availability"
requirements:
  deckhouse: ">= 1.68.0"`

	GoModWithModuleSDK = `module test
require github.com/deckhouse/module-sdk v0.1.0`

	GoModWithModuleSDK03 = `module test
require github.com/deckhouse/module-sdk v0.3.0`

	MainGoWithAppRun = `package main
func main() { app.Run() }`

	MainGoWithReadiness = `package main
func main() { app.WithReadiness() }`

	MainGoEmpty = `package main
func main() { }`
)

Common test data constants

View Source
const (
	ConversionsRuleName = "conversions"
)
View Source
const (
	DefinitionFileRuleName = "definition-file"
)
View Source
const (
	HelmignoreRuleName = "helmignore"
)
View Source
const (
	LegacyReleaseFileRuleName = "legacy-release-file"
)
View Source
const (
	LicenseRuleName = "license"
)
View Source
const (
	ModuleConfigFilename = "module.yaml"
)
View Source
const ModulePackageConsistencyRuleName = "module-package-consistency"
View Source
const (
	OSSRuleName = "oss"
)

Variables

View Source
var ErrUnsupportedFileType = fmt.Errorf("unsupported file type")
View Source
var ValidBundles = []string{
	"Minimal",
	"Managed",
	"Default",
}

Valid bundle values

View Source
var ValidEditions = []string{
	"ce",
	"fe",
	"ee",
	"se",
	"se-plus",
	"be",
	"_default",
}

Valid edition values

Functions

func RunRequirementsCheck added in v0.1.30

func RunRequirementsCheck(modulePath string) *errors.LintRuleErrorsList

RunRequirementsCheck runs the requirements check and returns the error list

Types

type CommentStyle added in v0.1.41

type CommentStyle struct {
	LinePrefix string // Prefix for single-line comments (e.g., "//", "#")
	BlockStart string // Start of block comment (e.g., "/*", "<!--")
	BlockEnd   string // End of block comment (e.g., "*/", "-->")
	BlockLine  string // Optional prefix for lines within block (e.g., " * ")
}

CommentStyle defines how comments are formatted in different file types

type ComponentRequirement added in v0.1.30

type ComponentRequirement struct {
	ComponentType ComponentType
	MinVersion    string
	Description   string
}

ComponentRequirement defines a requirement for a specific component

type ComponentType added in v0.1.30

type ComponentType string

ComponentType represents the type of component for requirements validation

const (
	ComponentDeckhouse ComponentType = "deckhouse"
	ComponentK8s       ComponentType = "kubernetes"
	ComponentModule    ComponentType = "module"
)

type ConversionsRule

type ConversionsRule struct {
	pkg.RuleMeta
	pkg.BoolRule
}

func NewConversionsRule

func NewConversionsRule(disable bool) *ConversionsRule

func (*ConversionsRule) CheckConversions

func (r *ConversionsRule) CheckConversions(modulePath string, errorList *errors.LintRuleErrorsList)

type DeckhouseModule

type DeckhouseModule struct {
	Name          string               `json:"name"`
	Critical      bool                 `json:"critical,omitempty"`
	Namespace     string               `json:"namespace"`
	Weight        uint32               `json:"weight,omitempty"`
	Tags          []string             `json:"tags"`
	Subsystems    []string             `json:"subsystems,omitempty"`
	Stage         string               `json:"stage"`
	Description   string               `json:"description,omitempty"`
	Descriptions  ModuleDescriptions   `json:"descriptions,omitempty"`
	Requirements  *ModuleRequirements  `json:"requirements,omitempty"`
	Accessibility *ModuleAccessibility `json:"accessibility,omitempty"`
	Update        *ModuleUpdate        `json:"update,omitempty"`
}

type DefinitionFileRule

type DefinitionFileRule struct {
	pkg.RuleMeta
	pkg.BoolRule
}

func NewDefinitionFileRule

func NewDefinitionFileRule(disable bool) *DefinitionFileRule

func (*DefinitionFileRule) CheckDefinitionFile

func (r *DefinitionFileRule) CheckDefinitionFile(modulePath string, errorList *errors.LintRuleErrorsList)

type FileTypeConfig added in v0.1.41

type FileTypeConfig struct {
	Extensions    []string       // File extensions (e.g., ".go", ".py")
	CommentStyles []CommentStyle // Supported comment styles
}

FileTypeConfig defines comment styles for specific file types

type HelmignoreRule added in v0.1.28

type HelmignoreRule struct {
	pkg.RuleMeta
	pkg.BoolRule
}

func NewHelmignoreRule added in v0.1.28

func NewHelmignoreRule(disable bool) *HelmignoreRule

func (*HelmignoreRule) CheckHelmignore added in v0.1.28

func (r *HelmignoreRule) CheckHelmignore(modulePath string, errorList *errors.LintRuleErrorsList)

type LegacyReleaseFileRule added in v0.1.42

type LegacyReleaseFileRule struct {
	pkg.RuleMeta
}

func NewLegacyReleaseFileRule added in v0.1.42

func NewLegacyReleaseFileRule() *LegacyReleaseFileRule

func (*LegacyReleaseFileRule) CheckLegacyReleaseFile added in v0.1.42

func (r *LegacyReleaseFileRule) CheckLegacyReleaseFile(modulePath string, errorList *errors.LintRuleErrorsList)

type License added in v0.1.41

type License struct {
	Type        string // "CE" or "EE"
	Name        string // Human-readable name
	Template    string // License template with {{YEAR}} placeholder
	YearPattern string // Regex pattern for year validation
}

License represents a license type with its template

type LicenseInfo added in v0.1.41

type LicenseInfo struct {
	Type string // "CE", "EE", or empty
	Year string // Extracted year
}

LicenseInfo contains information about parsed license

type LicenseParser added in v0.1.41

type LicenseParser struct {
	// contains filtered or unexported fields
}

LicenseParser handles license parsing and validation

func NewLicenseParser added in v0.1.41

func NewLicenseParser() *LicenseParser

NewLicenseParser creates a new license parser with default configuration

func (*LicenseParser) ParseFile added in v0.1.41

func (p *LicenseParser) ParseFile(filename string) (*LicenseInfo, error)

ParseFile parses a file and extracts license information

type LicenseRule added in v0.1.3

type LicenseRule struct {
	pkg.RuleMeta
	pkg.PathRule
}

func NewLicenseRule added in v0.1.3

func NewLicenseRule(excludeFilesRules []pkg.StringRuleExclude,
	excludeDirectoryRules []pkg.PrefixRuleExclude) *LicenseRule

func (*LicenseRule) CheckFiles added in v0.1.3

func (r *LicenseRule) CheckFiles(mod *module.Module, errorList *pkgerrors.LintRuleErrorsList)

type ModuleAccessibility added in v0.1.33

type ModuleAccessibility struct {
	Editions map[string]ModuleEdition `json:"editions"`
}

type ModuleDescriptions added in v0.1.4

type ModuleDescriptions struct {
	English string `json:"en,omitempty"`
	Russian string `json:"ru,omitempty"`
}

type ModuleEdition added in v0.1.33

type ModuleEdition struct {
	Available        bool     `json:"available"`
	EnabledInBundles []string `json:"enabledInBundles"`
}

type ModulePackage added in v0.1.76

type ModulePackage struct {
	APIVersion   string               `json:"apiVersion,omitempty"`
	Name         string               `json:"name,omitempty"`
	Requirements *PackageRequirements `json:"requirements,omitempty"`
	Subscribe    *PackageSubscribe    `json:"subscribe,omitempty"`
}

ModulePackage describes package.yaml fields used by module lint rules.

type ModulePackageConsistencyRule added in v0.1.76

type ModulePackageConsistencyRule struct {
	pkg.RuleMeta
}

ModulePackageConsistencyRule checks that module.yaml and package.yaml do not diverge when both files exist in the module directory.

func NewModulePackageConsistencyRule added in v0.1.76

func NewModulePackageConsistencyRule() *ModulePackageConsistencyRule

NewModulePackageConsistencyRule creates a rule for cross-validating module.yaml against package.yaml.

func (*ModulePackageConsistencyRule) CheckModulePackageConsistency added in v0.1.76

func (r *ModulePackageConsistencyRule) CheckModulePackageConsistency(modulePath string, errorList *errors.LintRuleErrorsList)

CheckModulePackageConsistency compares overlapping fields between module.yaml and package.yaml. Skips modules that have only one of the two files — without both there is nothing to cross-validate.

type ModulePlatformRequirements

type ModulePlatformRequirements struct {
	Deckhouse    string `json:"deckhouse,omitempty"`
	Kubernetes   string `json:"kubernetes,omitempty"`
	Bootstrapped bool   `json:"bootstrapped,omitempty"`
}

type ModuleRequirements

type ModuleRequirements struct {
	ModulePlatformRequirements `json:",inline"`
	ParentModules              map[string]string `json:"modules,omitempty"`
}

type ModuleUpdate added in v0.1.36

type ModuleUpdate struct {
	Versions []ModuleUpdateVersion `json:"versions,omitempty"`
}

type ModuleUpdateVersion added in v0.1.36

type ModuleUpdateVersion struct {
	From string `json:"from"`
	To   string `json:"to"`
}

type OSSRule

type OSSRule struct {
	pkg.RuleMeta
	pkg.BoolRule
}

func NewOSSRule

func NewOSSRule(disable bool) *OSSRule

NewOSSRule creates an OSS attribution rule instance.

func (*OSSRule) OssModuleRule

func (r *OSSRule) OssModuleRule(moduleRoot string, errorList *errors.LintRuleErrorsList)

OssModuleRule validates oss.yaml only for modules that contain image build sources.

type PackageAnyOfRequirement added in v0.1.76

type PackageAnyOfRequirement struct {
	Description string                     `json:"description,omitempty"`
	Modules     []PackageModuleRequirement `json:"modules,omitempty"`
}

PackageAnyOfRequirement describes an anyOf module dependency group.

type PackageModuleRequirement added in v0.1.76

type PackageModuleRequirement struct {
	Name       string `json:"name,omitempty"`
	Constraint string `json:"constraint,omitempty"`
}

PackageModuleRequirement describes a package.yaml module dependency.

type PackageModulesRequirements added in v0.1.76

type PackageModulesRequirements struct {
	Mandatory   []PackageModuleRequirement `json:"mandatory,omitempty"`
	Conditional []PackageModuleRequirement `json:"conditional,omitempty"`
	AnyOf       []PackageAnyOfRequirement  `json:"anyOf,omitempty"`
}

PackageModulesRequirements describes package.yaml module dependency groups.

type PackageRequirements added in v0.1.76

type PackageRequirements struct {
	Kubernetes PackageVersionRequirement  `json:"kubernetes,omitempty"`
	Deckhouse  PackageVersionRequirement  `json:"deckhouse,omitempty"`
	Modules    PackageModulesRequirements `json:"modules,omitempty"`
}

PackageRequirements describes package.yaml requirements.

type PackageSubscribe added in v0.1.76

type PackageSubscribe struct {
	APIs   []string                `json:"apis,omitempty"`
	Values []PackageSubscribeValue `json:"values,omitempty"`
}

PackageSubscribe describes package.yaml subscribe settings.

type PackageSubscribeValue added in v0.1.76

type PackageSubscribeValue struct {
	Module string `json:"module,omitempty"`
	Value  string `json:"value,omitempty"`
}

PackageSubscribeValue describes a subscribed module value.

type PackageVersionRequirement added in v0.1.76

type PackageVersionRequirement struct {
	Constraint string `json:"constraint,omitempty"`
}

PackageVersionRequirement describes a version constraint requirement.

type PackageYAMLRule added in v0.1.76

type PackageYAMLRule struct {
	pkg.RuleMeta
}

PackageYAMLRule validates the module package.yaml file.

func NewPackageYAMLRule added in v0.1.76

func NewPackageYAMLRule() *PackageYAMLRule

NewPackageYAMLRule creates a rule for validating package.yaml.

func (*PackageYAMLRule) CheckPackageYAML added in v0.1.76

func (r *PackageYAMLRule) CheckPackageYAML(modulePath string, errorList *errors.LintRuleErrorsList)

CheckPackageYAML validates package.yaml in the module root.

type RequirementCheck added in v0.1.30

type RequirementCheck struct {
	Name         string
	Requirements []ComponentRequirement
	Description  string
	Detector     func(modulePath string, module *DeckhouseModule) bool
}

RequirementCheck defines a single requirement check configuration. Detector returns true if the check should be applied to the module. When Requirements is non-empty, validateRequirement verifies version constraints. When Requirements is empty, the Description is emitted as the error.

type RequirementsRegistry added in v0.1.30

type RequirementsRegistry struct {
	// contains filtered or unexported fields
}

RequirementsRegistry holds all requirement checks

func NewRequirementsRegistry added in v0.1.30

func NewRequirementsRegistry() *RequirementsRegistry

NewRequirementsRegistry creates a new registry with default checks

func (*RequirementsRegistry) RegisterCheck added in v0.1.30

func (r *RequirementsRegistry) RegisterCheck(check RequirementCheck)

RegisterCheck adds a new requirement check to the registry

func (*RequirementsRegistry) RunAllChecks added in v0.1.30

func (r *RequirementsRegistry) RunAllChecks(modulePath string, module *DeckhouseModule, errorList *errors.LintRuleErrorsList)

RunAllChecks executes all registered requirement checks.

type RequirementsRule added in v0.1.30

type RequirementsRule struct {
	pkg.RuleMeta
}

func NewRequirementsRule added in v0.1.30

func NewRequirementsRule() *RequirementsRule

func (*RequirementsRule) CheckRequirements added in v0.1.30

func (r *RequirementsRule) CheckRequirements(modulePath string, errorList *errors.LintRuleErrorsList)

type TestCase added in v0.1.30

type TestCase struct {
	Name           string
	Setup          TestSetup
	ExpectedErrors []string
	Description    string
}

TestCase represents a single test case

type TestHelper added in v0.1.30

type TestHelper struct {
	// contains filtered or unexported fields
}

TestHelper provides common testing utilities

func NewTestHelper added in v0.1.30

func NewTestHelper(t *testing.T) *TestHelper

NewTestHelper creates a new test helper

func (*TestHelper) AssertErrors added in v0.1.30

func (h *TestHelper) AssertErrors(errorList *errors.LintRuleErrorsList, expectedErrors []string)

AssertErrors asserts that the error list contains the expected errors

func (*TestHelper) CreateTempModule added in v0.1.30

func (h *TestHelper) CreateTempModule(name string) string

CreateTempModule creates a temporary module directory for testing

func (*TestHelper) RunTestCase added in v0.1.30

func (h *TestHelper) RunTestCase(tc *TestCase)

RunTestCase runs a single test case with the given setup

func (*TestHelper) SetupGoHooks added in v0.1.30

func (h *TestHelper) SetupGoHooks(modulePath, goModContent, mainGoContent string)

SetupGoHooks creates hooks directory with go.mod and main.go files

func (*TestHelper) SetupModule added in v0.1.30

func (h *TestHelper) SetupModule(modulePath, content string)

SetupModule creates module.yaml with given content

type TestSetup added in v0.1.30

type TestSetup struct {
	ModuleContent string
	SetupFiles    func(string) error
}

TestSetup represents the setup configuration for a test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL