artifact

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package artifact provides the logic to store artifacts to the local filesystem. It manages their lifecycle based on the CR instances.

Index

Constants

View Source
const (
	// ReasonArtifactRemoveFailed indicates the artifact failed to be removed.
	ReasonArtifactRemoveFailed = "ArtifactRemoveFailed"
	// ReasonPluginArtifactsRemoved indicates all plugin artifacts (OCI files and config) were removed successfully.
	ReasonPluginArtifactsRemoved = "PluginArtifactsRemoved"
	// ReasonReferenceResolved indicates the reference was resolved successfully.
	ReasonReferenceResolved = "ReferenceResolved"
	// ReasonReferenceResolutionFailed indicates the reference failed to resolve.
	ReasonReferenceResolutionFailed = "ReferenceResolutionFailed"
	// ReasonOCIArtifactStored indicates the OCI artifact was stored successfully.
	ReasonOCIArtifactStored = "OCIArtifactStored"
	// ReasonOCIArtifactUpdated indicates the OCI artifact was updated successfully.
	ReasonOCIArtifactUpdated = "OCIArtifactUpdated"
	// ReasonOCIArtifactRemoved indicates the OCI artifact was removed from the filesystem.
	ReasonOCIArtifactRemoved = "OCIArtifactRemoved"
	// ReasonOCIArtifactPriorityChanged indicates the OCI artifact priority changed and the file was renamed.
	ReasonOCIArtifactPriorityChanged = "OCIArtifactPriorityChanged"
	// ReasonOCIArtifactStoreFailed indicates the OCI artifact failed to store.
	ReasonOCIArtifactStoreFailed = "OCIArtifactStoreFailed"
	// ReasonInlineArtifactStored indicates an inline artifact was stored successfully.
	ReasonInlineArtifactStored = "InlineArtifactStored"
	// ReasonInlineArtifactUpdated indicates an inline artifact was updated successfully.
	ReasonInlineArtifactUpdated = "InlineArtifactUpdated"
	// ReasonInlineArtifactRemoved indicates an inline artifact was removed from the filesystem.
	ReasonInlineArtifactRemoved = "InlineArtifactRemoved"
	// ReasonInlineArtifactPriorityChanged indicates an inline artifact priority changed and the file was renamed.
	ReasonInlineArtifactPriorityChanged = "InlineArtifactPriorityChanged"
	// ReasonInlineRulesStoreFailed indicates inline rules failed to store.
	ReasonInlineRulesStoreFailed = "InlineRulesStoreFailed"
	// ReasonConfigMapArtifactStored indicates a ConfigMap artifact was stored successfully.
	ReasonConfigMapArtifactStored = "ConfigMapArtifactStored"
	// ReasonConfigMapArtifactUpdated indicates a ConfigMap artifact was updated successfully.
	ReasonConfigMapArtifactUpdated = "ConfigMapArtifactUpdated"
	// ReasonConfigMapArtifactRemoved indicates a ConfigMap artifact was removed from the filesystem.
	ReasonConfigMapArtifactRemoved = "ConfigMapArtifactRemoved"
	// ReasonConfigMapArtifactPriorityChanged indicates a ConfigMap artifact priority changed and the file was renamed.
	ReasonConfigMapArtifactPriorityChanged = "ConfigMapArtifactPriorityChanged"
	// ReasonConfigMapRulesStoreFailed indicates rules from a ConfigMap failed to store.
	ReasonConfigMapRulesStoreFailed = "ConfigMapRulesStoreFailed"
	// ReasonInlineConfigStoreFailed indicates inline configuration failed to store.
	ReasonInlineConfigStoreFailed = "InlineConfigStoreFailed"
	// ReasonConfigMapConfigStoreFailed indicates configuration from a ConfigMap failed to store.
	ReasonConfigMapConfigStoreFailed = "ConfigMapConfigStoreFailed"
	// ReasonInlinePluginConfigStoreFailed indicates the plugin configuration failed to store.
	ReasonInlinePluginConfigStoreFailed = "InlinePluginConfigStoreFailed"
	// ReasonReconciled indicates the artifact was reconciled successfully.
	ReasonReconciled = "Reconciled"
	// ReasonReconcileFailed indicates the artifact failed to reconcile.
	ReasonReconcileFailed = "ReconcileFailed"
	// ReasonProgrammed indicates the artifact was programmed successfully.
	ReasonProgrammed = "Programmed"
	// ReasonProgramFailed indicates the artifact failed to program.
	ReasonProgramFailed = "ProgramFailed"
)

Condition reasons.

View Source
const (
	// MessageOCIArtifactPriorityChanged is the message when an OCI artifact priority changed and the file was renamed.
	MessageOCIArtifactPriorityChanged = "OCI artifact priority changed, file renamed"
	// MessageInlineArtifactPriorityChanged is the message when an inline artifact priority changed and the file was renamed.
	MessageInlineArtifactPriorityChanged = "Inline artifact priority changed, file renamed"
	// MessageConfigMapArtifactPriorityChanged is the message when a ConfigMap artifact priority changed and the file was renamed.
	MessageConfigMapArtifactPriorityChanged = "ConfigMap artifact priority changed, file renamed"
	// MessageConfigReconciled is the message when config is reconciled successfully.
	MessageConfigReconciled = "Config reconciled successfully"
	// MessagePluginReconciled is the message when plugin is reconciled successfully.
	MessagePluginReconciled = "Plugin reconciled successfully"
	// MessageRulesfileReconciled is the message when rulesfile is reconciled successfully.
	MessageRulesfileReconciled = "Rulesfile reconciled successfully"
	// MessagePluginArtifactsRemoved is the message when plugin artifacts are removed.
	MessagePluginArtifactsRemoved = "Plugin artifacts removed successfully"
	// MessageOCIArtifactStored is the message when OCI artifact is stored successfully.
	MessageOCIArtifactStored = "OCI artifact stored successfully"
	// MessageOCIArtifactUpdated is the message when OCI artifact is updated successfully.
	MessageOCIArtifactUpdated = "OCI artifact updated successfully"
	// MessageOCIArtifactRemoved is the message when OCI artifact is removed from the filesystem.
	MessageOCIArtifactRemoved = "OCI artifact removed from filesystem"
	// MessageInlineArtifactStored is the message when an inline artifact is stored successfully.
	MessageInlineArtifactStored = "Inline artifact stored successfully"
	// MessageInlineArtifactUpdated is the message when an inline artifact is updated successfully.
	MessageInlineArtifactUpdated = "Inline artifact updated successfully"
	// MessageInlineArtifactRemoved is the message when an inline artifact is removed from the filesystem.
	MessageInlineArtifactRemoved = "Inline artifact removed from filesystem"
	// MessageConfigMapArtifactStored is the message when a ConfigMap artifact is stored successfully.
	MessageConfigMapArtifactStored = "ConfigMap artifact stored successfully"
	// MessageConfigMapArtifactUpdated is the message when a ConfigMap artifact is updated successfully.
	MessageConfigMapArtifactUpdated = "ConfigMap artifact updated successfully"
	// MessageConfigMapArtifactRemoved is the message when a ConfigMap artifact is removed from the filesystem.
	MessageConfigMapArtifactRemoved = "ConfigMap artifact removed from filesystem"
	// MessageProgrammed is the message when the artifact is programmed successfully.
	MessageProgrammed = "All artifacts sources were programmed successfully"
	// MessageReferencesResolved is the message when all references are resolved successfully.
	MessageReferencesResolved = "All references were resolved successfully"
)

Condition messages.

View Source
const (
	// MessageFormatConfigStoreFailed is the format for config store failure message.
	MessageFormatConfigStoreFailed = "Failed to store config: %s"
	// MessageFormatOCIArtifactStoreFailed is the format for OCI artifact store failure message.
	MessageFormatOCIArtifactStoreFailed = "Failed to store OCI artifact: %s"
	// MessageFormatPluginArtifactsRemoveFailed is the format for plugin artifacts remove failure message.
	MessageFormatPluginArtifactsRemoveFailed = "Failed to remove plugin artifacts: %s"
	// MessageFormatConfigMapRulesStoreFailed is the format for ConfigMap rules store failure message.
	MessageFormatConfigMapRulesStoreFailed = "Failed to store ConfigMap rules: %s"
	// MessageFormatConfigMapConfigStoreFailed is the format for ConfigMap config store failure message.
	MessageFormatConfigMapConfigStoreFailed = "Failed to store ConfigMap config: %s"
	// MessageFormatInlineRulesStoreFailed is the format for inline rules store failure message.
	MessageFormatInlineRulesStoreFailed = "Failed to store inline rules: %s"
	// MessageFormatReferenceResolutionFailed is the format for Reference resolution failure message.
	MessageFormatReferenceResolutionFailed = "Failed to resolve Reference: %s"
	// MessageFormatReferenceResolved is the format for Reference resolved message.
	MessageFormatReferenceResolved = "Reference %q resolved successfully"
	// MessageFormatInlinePluginConfigStoreFailed is the format for inline plugin config store failure message.
	MessageFormatInlinePluginConfigStoreFailed = "Failed to store inline plugin config: %v"
)

Condition message formats (for use with fmt.Sprintf).

View Source
const (
	// DefaultRegistry is the default OCI registry hostname.
	DefaultRegistry = "ghcr.io"
)

Variables

This section is empty.

Functions

func RecordNormal added in v0.2.0

func RecordNormal(r events.EventRecorder, obj runtime.Object, reason, message string)

RecordNormal records a Normal event on obj with the given reason and message.

func RecordStoreEvent added in v0.2.0

func RecordStoreEvent(r events.EventRecorder, obj runtime.Object, action StoreAction, medium Medium)

RecordStoreEvent records a Normal event for a store operation based on the action and medium. No event is recorded for StoreActionNone or StoreActionUnchanged.

func RecordWarning added in v0.2.0

func RecordWarning(r events.EventRecorder, obj runtime.Object, reason, messageFmt string, args ...any)

RecordWarning records a Warning event on obj with the given reason and formatted message.

func ResolveReference added in v0.2.0

func ResolveReference(artifact *commonv1alpha1.OCIArtifact) string

ResolveReference builds the full OCI reference string from an OCIArtifact. Defaults to "ghcr.io" when no registry name is specified and "latest" when no tag is set.

func ResolveRegistryOptions added in v0.2.0

func ResolveRegistryOptions(artifact *commonv1alpha1.OCIArtifact) *puller.RegistryOptions

ResolveRegistryOptions builds a RegistryOptions from the registry configuration of an OCIArtifact. Returns nil when no transport configuration is present (use system defaults: HTTPS with system CAs).

Types

type File

type File struct {
	Path     string // Full Path on filesystem
	Medium   Medium // How the artifact is stored/distributed
	Priority int32  // Priority when created
}

File represents a tracked file for any artifact type.

type Manager

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

Manager manages the lifecycle of artifacts on the filesystem.

func NewManager

func NewManager(cl client.Client, namespace string) *Manager

NewManager creates a new manager.

func NewManagerWithOptions added in v0.2.0

func NewManagerWithOptions(cl client.Client, namespace string, opts ...ManagerOption) *Manager

NewManagerWithOptions creates a new manager with custom options (for testing).

func (*Manager) CheckReferenceResolution added in v0.2.0

func (am *Manager) CheckReferenceResolution(ctx context.Context, namespace, name string, obj client.Object) error

CheckReferenceResolution checks if a specific Kubernetes resource exists. Returns an error if the resource does not exist or cannot be retrieved.

func (*Manager) Path added in v0.2.0

func (am *Manager) Path(name string, artifactPriority int32, medium Medium, artifactType Type) string

Path returns the artifact path using the manager's configurable directories.

func (*Manager) RemoveAll

func (am *Manager) RemoveAll(ctx context.Context, name string) error

RemoveAll removes all artifacts for a given instance name.

func (*Manager) StoreFromConfigMap added in v0.2.0

func (am *Manager) StoreFromConfigMap(ctx context.Context, name, namespace string, artifactPriority int32, configMapRef *commonv1alpha1.ConfigMapRef, artifactType Type) (StoreAction, error)

StoreFromConfigMap stores an artifact from a ConfigMap to the local filesystem. The ConfigMap is fetched from the specified namespace (typically the same namespace as the Rulesfile CR).

func (*Manager) StoreFromInLineYaml

func (am *Manager) StoreFromInLineYaml(ctx context.Context, name string, artifactPriority int32, data *string, artifactType Type) (StoreAction, error)

StoreFromInLineYaml stores an artifact from an inline YAML to the local filesystem.

func (*Manager) StoreFromOCI

func (am *Manager) StoreFromOCI(ctx context.Context, name string, artifactPriority int32, artifactType Type, artifact *commonv1alpha1.OCIArtifact) (StoreAction, error)

StoreFromOCI stores an artifact from an OCI registry to the local filesystem.

type ManagerOption added in v0.2.0

type ManagerOption func(*Manager)

ManagerOption is a function that configures a Manager.

func WithConfigDir added in v0.2.0

func WithConfigDir(dir string) ManagerOption

WithConfigDir overrides the directory used to store config artifacts (default: mounts.ConfigDirPath). Useful in tests to redirect output to a temporary directory.

func WithFS added in v0.2.0

func WithFS(fileSystem filesystem.FileSystem) ManagerOption

WithFS sets a filesystem.

func WithOCIPuller added in v0.2.0

func WithOCIPuller(p puller.Puller) ManagerOption

WithOCIPuller sets a OCI puller.

func WithPluginDir added in v0.2.0

func WithPluginDir(dir string) ManagerOption

WithPluginDir overrides the directory used to store plugin artifacts (default: mounts.PluginDirPath). Useful in tests to redirect output to a temporary directory.

func WithRulesfileDir added in v0.2.0

func WithRulesfileDir(dir string) ManagerOption

WithRulesfileDir overrides the directory used to store rulesfile artifacts (default: mounts.RulesfileDirPath). Useful in tests to redirect output to a temporary directory.

type Medium

type Medium string

Medium represents how the artifact is distributed.

const (
	// MediumInline represents an inline artifact.
	MediumInline Medium = "inline"
	// MediumOCI represents an OCI artifact.
	MediumOCI Medium = "oci"
	// MediumConfigMap represents an artifact from a ConfigMap.
	MediumConfigMap Medium = "configmap"
)

type StoreAction added in v0.2.0

type StoreAction string

StoreAction represents the operation performed by a Store method.

const (
	// StoreActionNone means the input was absent and no existing artifact was found; no filesystem change occurred.
	StoreActionNone StoreAction = "None"
	// StoreActionRemoved means a previously stored artifact was removed from the filesystem.
	StoreActionRemoved StoreAction = "Removed"
	// StoreActionAdded means a new artifact was written to the filesystem for the first time.
	StoreActionAdded StoreAction = "Added"
	// StoreActionUpdated means an existing artifact was replaced because its content changed.
	StoreActionUpdated StoreAction = "Updated"
	// StoreActionUnchanged means the artifact already existed and was up-to-date; nothing was written.
	StoreActionUnchanged StoreAction = "Unchanged"
	// StoreActionPriorityChanged means the artifact content is unchanged but the priority changed;
	// the file was moved/renamed to reflect the new load order.
	StoreActionPriorityChanged StoreAction = "PriorityChanged"
)

type Type

type Type string

Type represents different types of artifacts.

const (
	// TypeRulesfile represents a rulesFile artifact.
	TypeRulesfile Type = "rulesfile"
	// TypePlugin represents a plugin artifact.
	TypePlugin Type = "plugin"
	// TypeConfig represents a config artifact.
	TypeConfig Type = "config"
)

Jump to

Keyboard shortcuts

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