file

package
v0.0.231 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: Apache-2.0 Imports: 58 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpenDynamicThreshold     = 50
	EndpointDynamicThreshold = 100
)
View Source
const (
	DefaultStorageRoot       = "/data"
	GobExt                   = ".g"
	MetadataExt              = ".m"
	SchemaVersion            = int64(1)
	StorageV1Beta1ApiVersion = "spdx.softwarecomposition.kubescape.io/v1beta1"
)
View Source
const (
	MinSizeToReport = 30 * 1024 * 1024 // 30MB
)

Variables

View Source
var (
	ObjectCompletedError = errors.New("object is completed")
	ObjectTooLargeError  = errors.New("object is too large")
)
View Source
var (
	ErrMetadataNotFound = errors.New("metadata not found")
)
View Source
var (
	Workloads = mapset.NewSet[string]([]string{
		"cronjob",
		"daemonset",
		"deployment",
		"job",
		"replicaset",
		"statefulset",
	}...) // FIXME put in a configmap
)

Functions

func DeflateLabelSelectorRequirement added in v0.0.199

func DeflateLabelSelectorRequirement(in []metav1.LabelSelectorRequirement) []metav1.LabelSelectorRequirement

func DeflateRulePolicies added in v0.0.135

func DeflateSortString added in v0.0.135

func DeflateSortString(in []string) []string

func DeflateStringer added in v0.0.118

func DeflateStringer[T Stringer](in []T) []T

func DeleteMetadata added in v0.0.137

func DeleteMetadata(conn *sqlite.Conn, path string, metadata runtime.Object) error

DeleteMetadata deletes metadata for the given path and unmarshals the deleted metadata into the provided runtime.Object.

func DeleteTimeSeriesContainerEntries added in v0.0.199

func DeleteTimeSeriesContainerEntries(conn *sqlite.Conn, path string) error

DeleteTimeSeriesContainerEntries deletes all time series entries for a completed container.

func IsPayloadFile added in v0.0.137

func IsPayloadFile(path string) bool

IsPayloadFile returns true if a given file at `path` is an object payload file, else false

func KeysToPath added in v0.0.231

func KeysToPath(prefix, root, kind, ns, name string) string

func ListTimeSeriesContainers added in v0.0.199

func ListTimeSeriesContainers(conn *sqlite.Conn, path string) (map[string][]softwarecomposition.TimeSeriesContainers, error)

ListTimeSeriesContainers retrieves time series containers for a given path.

func ListTimeSeriesExpired added in v0.0.228

func ListTimeSeriesExpired(conn *sqlite.Conn, d time.Duration) ([]string, error)

ListTimeSeriesExpired cleans up time series containers which are older than d.

func ListTimeSeriesWithData added in v0.0.228

func ListTimeSeriesWithData(conn *sqlite.Conn) ([]string, error)

ListTimeSeriesWithData retrieves all time series keys that have data.

func NewApplicationProfileStorage added in v0.0.199

func NewApplicationProfileStorage(realStore StorageQuerier) storage.Interface

func NewConfigurationScanSummaryStorage added in v0.0.18

func NewConfigurationScanSummaryStorage(realStore StorageQuerier) storage.Interface

func NewGeneratedNetworkPolicyStorage added in v0.0.33

func NewGeneratedNetworkPolicyStorage(realStore StorageQuerier, nnStore storage.Interface) storage.Interface

func NewKubernetesClient added in v0.0.199

func NewKubernetesClient() (*kubernetes.Clientset, error)

func NewNetworkNeighborhoodStorage added in v0.0.199

func NewNetworkNeighborhoodStorage(realStore StorageQuerier) storage.Interface

func NewPool added in v0.0.137

func NewPool(path string, size int) *sqlitemigration.Pool

NewPool creates a new SQLite connection pool at the given path. It returns an error if the connection cannot be opened or the database cannot be initialized. It is your responsibility to call conn.Close() when you no longer need conn.

func NewTestPool added in v0.0.137

func NewTestPool(dir string) *sqlitemigration.Pool

NewTestPool creates a new temporary SQLite connection (for testing only).

func NewVulnerabilitySummaryStorage added in v0.0.20

func NewVulnerabilitySummaryStorage(realStore StorageQuerier) storage.Interface

func PathToKeys added in v0.0.231

func PathToKeys(path string) (string, string, string, string, string)

func ReadMetadata added in v0.0.137

func ReadMetadata(conn *sqlite.Conn, path string) ([]byte, error)

ReadMetadata reads metadata for the given path and returns it as a byte slice.

func ReplaceTimeSeriesContainerEntries added in v0.0.199

func ReplaceTimeSeriesContainerEntries(conn *sqlite.Conn, path, seriesID string, deleteTimeSeries []string, newTimeSeries []softwarecomposition.TimeSeriesContainers) error

ReplaceTimeSeriesContainerEntries replaces time series entries for a given path and seriesID.

func SplitProfileName added in v0.0.231

func SplitProfileName(profileName string) (name string, tsSuffix string)

func WriteJSON added in v0.0.137

func WriteJSON(conn *sqlite.Conn, path string, metadataJSON []byte) error

WriteJSON writes the given JSON metadata to the database for the specified path.

func WriteTimeSeriesEntry added in v0.0.199

func WriteTimeSeriesEntry(conn *sqlite.Conn, kind, namespace, name, seriesID, tsSuffix, reportTimestamp, status, completion, previousReportTimestamp string, hasData bool) error

WriteTimeSeriesEntry writes a time series entry to the database.

Types

type ApplicationProfileProcessor added in v0.0.66

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

func NewApplicationProfileProcessor added in v0.0.121

func NewApplicationProfileProcessor(cfg config.Config) *ApplicationProfileProcessor

func (*ApplicationProfileProcessor) AfterCreate added in v0.0.199

func (*ApplicationProfileProcessor) PreSave added in v0.0.66

func (*ApplicationProfileProcessor) SetStorage added in v0.0.143

func (a *ApplicationProfileProcessor) SetStorage(containerProfileStorage ContainerProfileStorage)

type ApplicationProfileStorage added in v0.0.199

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

func (ApplicationProfileStorage) CompactRevision added in v0.0.221

func (a ApplicationProfileStorage) CompactRevision() int64

func (ApplicationProfileStorage) Create added in v0.0.199

func (a ApplicationProfileStorage) Create(ctx context.Context, key string, obj, out runtime.Object, ttl uint64) error

func (ApplicationProfileStorage) Delete added in v0.0.199

func (a ApplicationProfileStorage) Delete(ctx context.Context, key string, out runtime.Object, preconditions *storage.Preconditions, validateDeletion storage.ValidateObjectFunc, cachedExistingObject runtime.Object, opts storage.DeleteOptions) error

func (ApplicationProfileStorage) Get added in v0.0.199

func (ApplicationProfileStorage) GetCurrentResourceVersion added in v0.0.199

func (a ApplicationProfileStorage) GetCurrentResourceVersion(_ context.Context) (uint64, error)

func (ApplicationProfileStorage) GetList added in v0.0.199

func (ApplicationProfileStorage) GuaranteedUpdate added in v0.0.199

func (a ApplicationProfileStorage) GuaranteedUpdate(ctx context.Context, key string, destination runtime.Object, ignoreNotFound bool, preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, cachedExistingObject runtime.Object) error

func (ApplicationProfileStorage) ReadinessCheck added in v0.0.199

func (a ApplicationProfileStorage) ReadinessCheck() error

func (ApplicationProfileStorage) RequestWatchProgress added in v0.0.199

func (a ApplicationProfileStorage) RequestWatchProgress(ctx context.Context) error

func (ApplicationProfileStorage) SetKeysFunc added in v0.0.221

func (a ApplicationProfileStorage) SetKeysFunc(_ storage.KeysFunc)

func (ApplicationProfileStorage) Stats added in v0.0.221

func (ApplicationProfileStorage) Versioner added in v0.0.199

func (ApplicationProfileStorage) Watch added in v0.0.199

type ConfigurationScanSummaryStorage added in v0.0.18

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

ConfigurationScanSummaryStorage offers a storage solution for ConfigurationScanSummary objects, implementing custom business logic for these objects and using the underlying default storage implementation.

func (*ConfigurationScanSummaryStorage) CompactRevision added in v0.0.221

func (s *ConfigurationScanSummaryStorage) CompactRevision() int64

func (ConfigurationScanSummaryStorage) Count added in v0.0.18

func (ConfigurationScanSummaryStorage) Count(key string) (int64, error)

Count is not supported for immutable objects. Objects are generated on the fly and not stored.

func (ConfigurationScanSummaryStorage) Create added in v0.0.18

func (ConfigurationScanSummaryStorage) Create(_ context.Context, key string, _, _ runtime.Object, _ uint64) error

Create is not supported for immutable objects. Objects are generated on the fly and not stored.

func (ConfigurationScanSummaryStorage) Delete added in v0.0.18

func (ConfigurationScanSummaryStorage) Delete(_ context.Context, key string, _ runtime.Object, _ *storage.Preconditions, _ storage.ValidateObjectFunc, _ runtime.Object, _ storage.DeleteOptions) error

Delete is not supported for immutable objects. Objects are generated on the fly and not stored.

func (*ConfigurationScanSummaryStorage) Get added in v0.0.18

Get generates and returns a single ConfigurationScanSummary object for a namespace

func (*ConfigurationScanSummaryStorage) GetCurrentResourceVersion added in v0.0.199

func (s *ConfigurationScanSummaryStorage) GetCurrentResourceVersion(_ context.Context) (uint64, error)

func (*ConfigurationScanSummaryStorage) GetList added in v0.0.18

GetList generates and returns a list of ConfigurationScanSummary objects for the cluster

func (ConfigurationScanSummaryStorage) GuaranteedUpdate added in v0.0.18

func (ConfigurationScanSummaryStorage) GuaranteedUpdate(_ context.Context, key string, _ runtime.Object, _ bool, _ *storage.Preconditions, _ storage.UpdateFunc, _ runtime.Object) error

GuaranteedUpdate is not supported for immutable objects. Objects are generated on the fly and not stored.

func (ConfigurationScanSummaryStorage) ReadinessCheck added in v0.0.174

func (ConfigurationScanSummaryStorage) ReadinessCheck() error

func (ConfigurationScanSummaryStorage) RequestWatchProgress added in v0.0.42

func (ConfigurationScanSummaryStorage) RequestWatchProgress(context.Context) error

RequestWatchProgress fulfills the storage.Interface

It’s function is only relevant to etcd.

func (*ConfigurationScanSummaryStorage) SetKeysFunc added in v0.0.221

func (*ConfigurationScanSummaryStorage) Stats added in v0.0.221

func (ConfigurationScanSummaryStorage) Versioner added in v0.0.18

func (ConfigurationScanSummaryStorage) Versioner() storage.Versioner

Versioner Returns fixed versioner associated with this interface.

func (ConfigurationScanSummaryStorage) Watch added in v0.0.18

func (ConfigurationScanSummaryStorage) Watch(_ context.Context, _ string, _ storage.ListOptions) (watch.Interface, error)

Watch is not supported for immutable objects. Objects are generated on the fly and not stored.

type ContainerProfileProcessor added in v0.0.199

type ContainerProfileProcessor struct {
	CleanupHandler          *ResourcesCleanupHandler
	CleanupInterval         time.Duration
	DefaultNamespace        string
	DeleteThreshold         time.Duration
	Interval                time.Duration
	LastCleanup             time.Time
	MaxContainerProfileSize int
	ContainerProfileStorage ContainerProfileStorage
}

func NewContainerProfileProcessor added in v0.0.199

func NewContainerProfileProcessor(cfg config.Config, cleanupHandler *ResourcesCleanupHandler) *ContainerProfileProcessor

func (*ContainerProfileProcessor) AfterCreate added in v0.0.199

func (a *ContainerProfileProcessor) AfterCreate(ctx context.Context, object runtime.Object) error

AfterCreate is called after a TS ContainerProfile is created to store metadata.

func (*ContainerProfileProcessor) ConsolidateTimeSeries added in v0.0.231

func (a *ContainerProfileProcessor) ConsolidateTimeSeries(ctx context.Context) error

ConsolidateTimeSeries processes all time series data, handling expired and active series separately.

The function runs in two phases: 1. Process expired time series (past deleteThreshold) - marked as Completed/Partial 2. Process active time series with data - follow normal completion flow

Expired time series are always marked as Completed/Partial unless they were already Completed/Full, ensuring incomplete profiles don't remain in a Learning state indefinitely.

func (*ContainerProfileProcessor) PreSave added in v0.0.199

func (a *ContainerProfileProcessor) PreSave(ctx context.Context, object runtime.Object) error

func (*ContainerProfileProcessor) SetStorage added in v0.0.199

func (a *ContainerProfileProcessor) SetStorage(containerProfileStorage ContainerProfileStorage)

type ContainerProfileStorage added in v0.0.231

type ContainerProfileStorage interface {
	TransactionManager
	TimeSeriesOperations

	// DeleteContainerProfile deletes a container profile by key.
	DeleteContainerProfile(ctx context.Context, key string) error

	// GetContainerProfile retrieves a complete container profile by key.
	GetContainerProfile(ctx context.Context, key string) (softwarecomposition.ContainerProfile, error)

	// GetContainerProfileMetadata retrieves only the metadata of a container profile.
	// This is more efficient when only metadata is needed.
	GetContainerProfileMetadata(ctx context.Context, key string) (softwarecomposition.ContainerProfile, error)

	// GetSbom retrieves an SBOM by key.
	// Returns storage.ErrCodeKeyNotFound if not found or not implemented.
	GetSbom(ctx context.Context, key string) (softwarecomposition.SBOMSyft, error)

	// GetTsContainerProfile retrieves a time-series container profile.
	// This bypasses locking mechanisms used by GetContainerProfile.
	GetTsContainerProfile(ctx context.Context, key string) (softwarecomposition.ContainerProfile, error)

	// SaveContainerProfile creates or updates a container profile.
	SaveContainerProfile(ctx context.Context, key string, profile *softwarecomposition.ContainerProfile) error

	// UpdateApplicationProfile updates the application profile associated with a container profile.
	UpdateApplicationProfile(ctx context.Context, key, prefix, root, namespace, slug, wlid string, instanceID interface{ GetStringNoContainer() string }, profile *softwarecomposition.ContainerProfile, creationTimestamp metav1.Time, getAggregatedData GetAggregatedDataFunc) error

	// UpdateNetworkNeighborhood updates the network neighborhood associated with a container profile.
	UpdateNetworkNeighborhood(ctx context.Context, key, prefix, root, namespace, slug, wlid string, instanceID interface{ GetStringNoContainer() string }, profile *softwarecomposition.ContainerProfile, creationTimestamp metav1.Time, getAggregatedData GetAggregatedDataFunc) error
}

ContainerProfileStorage defines the storage operations for container profiles. This interface abstracts the underlying database implementation, allowing different backends (SQLite, PostgreSQL, etc.) to be used interchangeably.

Connection Management: - The database connection is stored in the context using context.WithValue with key connKey - Call BeginTransaction to acquire a connection and get a context with the connection embedded - All data operations extract the connection from the context - Use the cleanup function returned by BeginTransaction to return the connection to the pool

Example usage:

storage := NewContainerProfileStorageImpl(storageImpl, pool)
ctx, cleanup, err := storage.WithConnection(ctx)
if err != nil { ... }
defer cleanup()

err = storage.SaveContainerProfile(ctx, key, profile)
if err != nil { ... }

// For transactions (savepoints):
endFn, err := storage.BeginTransaction(ctx)
if err != nil { ... }
err = doSomeWork(ctx)
endFn(&err) // commits if err is nil, rolls back otherwise

type ContainerProfileStorageImpl added in v0.0.231

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

ContainerProfileStorageImpl implements ContainerProfileStorage using SQLite as the backend.

func NewContainerProfileStorageImpl added in v0.0.231

func NewContainerProfileStorageImpl(storageImpl *StorageImpl, pool *sqlitemigration.Pool) *ContainerProfileStorageImpl

NewContainerProfileStorageImpl creates a new SQLite-backed ContainerProfileStorage.

func (*ContainerProfileStorageImpl) BeginTransaction added in v0.0.231

func (c *ContainerProfileStorageImpl) BeginTransaction(ctx context.Context) (func(*error), error)

BeginTransaction starts a SQLite transaction (savepoint) and returns a function to commit or rollback based on the error state.

func (*ContainerProfileStorageImpl) DeleteContainerProfile added in v0.0.231

func (c *ContainerProfileStorageImpl) DeleteContainerProfile(ctx context.Context, key string) error

func (*ContainerProfileStorageImpl) DeleteTimeSeriesContainerEntries added in v0.0.231

func (c *ContainerProfileStorageImpl) DeleteTimeSeriesContainerEntries(ctx context.Context, key string) error

func (*ContainerProfileStorageImpl) GetContainerProfile added in v0.0.231

func (*ContainerProfileStorageImpl) GetContainerProfileMetadata added in v0.0.231

func (c *ContainerProfileStorageImpl) GetContainerProfileMetadata(ctx context.Context, key string) (softwarecomposition.ContainerProfile, error)

func (*ContainerProfileStorageImpl) GetSbom added in v0.0.231

func (*ContainerProfileStorageImpl) GetStorageImpl added in v0.0.231

func (c *ContainerProfileStorageImpl) GetStorageImpl() *StorageImpl

func (*ContainerProfileStorageImpl) GetTsContainerProfile added in v0.0.231

func (*ContainerProfileStorageImpl) ListTimeSeriesContainers added in v0.0.231

func (*ContainerProfileStorageImpl) ListTimeSeriesExpired added in v0.0.231

func (c *ContainerProfileStorageImpl) ListTimeSeriesExpired(ctx context.Context, threshold time.Duration) ([]string, error)

func (*ContainerProfileStorageImpl) ListTimeSeriesWithData added in v0.0.231

func (c *ContainerProfileStorageImpl) ListTimeSeriesWithData(ctx context.Context) ([]string, error)

func (*ContainerProfileStorageImpl) ReplaceTimeSeriesContainerEntries added in v0.0.231

func (c *ContainerProfileStorageImpl) ReplaceTimeSeriesContainerEntries(ctx context.Context, key, seriesID string, deleteTimeSeries []string, newTimeSeries []softwarecomposition.TimeSeriesContainers) error

func (*ContainerProfileStorageImpl) SaveContainerProfile added in v0.0.231

func (c *ContainerProfileStorageImpl) SaveContainerProfile(ctx context.Context, key string, profile *softwarecomposition.ContainerProfile) error

func (*ContainerProfileStorageImpl) UpdateApplicationProfile added in v0.0.231

func (c *ContainerProfileStorageImpl) UpdateApplicationProfile(ctx context.Context, key, prefix, root, namespace, slug, wlid string, instanceID interface{ GetStringNoContainer() string }, profile *softwarecomposition.ContainerProfile, creationTimestamp metav1.Time, getAggregatedData GetAggregatedDataFunc) error

func (*ContainerProfileStorageImpl) UpdateNetworkNeighborhood added in v0.0.231

func (c *ContainerProfileStorageImpl) UpdateNetworkNeighborhood(ctx context.Context, key, prefix, root, namespace, slug, wlid string, instanceID interface{ GetStringNoContainer() string }, profile *softwarecomposition.ContainerProfile, creationTimestamp metav1.Time, getAggregatedData GetAggregatedDataFunc) error

func (*ContainerProfileStorageImpl) WithConnection added in v0.0.231

func (c *ContainerProfileStorageImpl) WithConnection(ctx context.Context) (context.Context, func(), error)

WithConnection acquires a connection from the pool and returns a new context with the connection embedded, plus a cleanup function to return the connection to the pool.

func (*ContainerProfileStorageImpl) WriteTimeSeriesEntry added in v0.0.231

func (c *ContainerProfileStorageImpl) WriteTimeSeriesEntry(ctx context.Context, kind, namespace, name, seriesID, tsSuffix, reportTimestamp, status, completion, previousReportTimestamp string, hasData bool) error

type DefaultProcessor added in v0.0.66

type DefaultProcessor struct {
}

func (DefaultProcessor) AfterCreate added in v0.0.199

func (d DefaultProcessor) AfterCreate(_ context.Context, _ runtime.Object) error

func (DefaultProcessor) PreSave added in v0.0.66

func (DefaultProcessor) SetStorage added in v0.0.143

func (d DefaultProcessor) SetStorage(_ ContainerProfileStorage)

type DirectIOReader added in v0.0.121

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

DirectIOReader is a reader that reads data from the underlying reader using direct I/O.

func NewDirectIOReader added in v0.0.121

func NewDirectIOReader(rd io.Reader) *DirectIOReader

func (*DirectIOReader) Read added in v0.0.121

func (d *DirectIOReader) Read(p []byte) (int, error)

func (*DirectIOReader) ReadByte added in v0.0.121

func (d *DirectIOReader) ReadByte() (byte, error)

type DirectIOWriter added in v0.0.127

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

DirectIOWriter is a writer that writes data to the underlying writer using direct I/O.

func NewDirectIOWriter added in v0.0.127

func NewDirectIOWriter(wr afero.File) *DirectIOWriter

func (*DirectIOWriter) Close added in v0.0.127

func (d *DirectIOWriter) Close() error

func (*DirectIOWriter) Write added in v0.0.127

func (d *DirectIOWriter) Write(p []byte) (int, error)

type GeneratedNetworkPolicyStorage added in v0.0.33

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

GeneratedNetworkPolicyStorage offers a storage solution for GeneratedNetworkPolicy objects, implementing custom business logic for these objects and using the underlying default storage implementation.

func (*GeneratedNetworkPolicyStorage) CompactRevision added in v0.0.221

func (s *GeneratedNetworkPolicyStorage) CompactRevision() int64

func (GeneratedNetworkPolicyStorage) Count added in v0.0.33

func (GeneratedNetworkPolicyStorage) Count(key string) (int64, error)

Count is not supported for immutable objects. Objects are generated on the fly and not stored.

func (GeneratedNetworkPolicyStorage) Create added in v0.0.33

func (GeneratedNetworkPolicyStorage) Create(_ context.Context, key string, _, _ runtime.Object, _ uint64) error

Create is not supported for immutable objects. Objects are generated on the fly and not stored.

func (GeneratedNetworkPolicyStorage) Delete added in v0.0.33

func (GeneratedNetworkPolicyStorage) Delete(_ context.Context, key string, _ runtime.Object, _ *storage.Preconditions, _ storage.ValidateObjectFunc, _ runtime.Object, _ storage.DeleteOptions) error

Delete is not supported for immutable objects. Objects are generated on the fly and not stored.

func (*GeneratedNetworkPolicyStorage) Get added in v0.0.33

Get generates and returns a single GeneratedNetworkPolicy object

func (*GeneratedNetworkPolicyStorage) GetCurrentResourceVersion added in v0.0.199

func (s *GeneratedNetworkPolicyStorage) GetCurrentResourceVersion(_ context.Context) (uint64, error)

func (*GeneratedNetworkPolicyStorage) GetList added in v0.0.33

GetList generates and returns a list of GeneratedNetworkPolicy objects for the given namespace

func (GeneratedNetworkPolicyStorage) GuaranteedUpdate added in v0.0.33

func (GeneratedNetworkPolicyStorage) GuaranteedUpdate(_ context.Context, key string, _ runtime.Object, _ bool, _ *storage.Preconditions, _ storage.UpdateFunc, _ runtime.Object) error

GuaranteedUpdate is not supported for immutable objects. Objects are generated on the fly and not stored.

func (GeneratedNetworkPolicyStorage) ReadinessCheck added in v0.0.174

func (GeneratedNetworkPolicyStorage) ReadinessCheck() error

func (GeneratedNetworkPolicyStorage) RequestWatchProgress added in v0.0.42

func (GeneratedNetworkPolicyStorage) RequestWatchProgress(context.Context) error

RequestWatchProgress fulfills the storage.Interface

It’s function is only relevant to etcd.

func (*GeneratedNetworkPolicyStorage) SetKeysFunc added in v0.0.221

func (*GeneratedNetworkPolicyStorage) Stats added in v0.0.221

func (GeneratedNetworkPolicyStorage) Versioner added in v0.0.33

func (GeneratedNetworkPolicyStorage) Versioner() storage.Versioner

Versioner Returns fixed versioner associated with this interface.

func (GeneratedNetworkPolicyStorage) Watch added in v0.0.33

func (GeneratedNetworkPolicyStorage) Watch(_ context.Context, _ string, _ storage.ListOptions) (watch.Interface, error)

Watch is not supported for immutable objects. Objects are generated on the fly and not stored.

type GetAggregatedDataFunc added in v0.0.231

type GetAggregatedDataFunc func(ctx context.Context, key string, parts map[string]string) (status string, completion string, checksum string)

GetAggregatedDataFunc is a callback function for computing aggregated profile data. It takes a context, key, and parts map, returning status, completion, and checksum. The context should contain the database connection (via context.WithValue with key connKey).

type KubernetesAPI added in v0.0.199

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

func NewKubernetesAPI added in v0.0.199

func NewKubernetesAPI(cfg config.Config, client *kubernetes.Clientset) *KubernetesAPI

func (*KubernetesAPI) FetchResources added in v0.0.199

func (h *KubernetesAPI) FetchResources(ns string) (ResourceMaps, error)

FetchResources builds a map of running resources in the cluster needed for cleanup

func (*KubernetesAPI) ListNamespaces added in v0.0.214

func (h *KubernetesAPI) ListNamespaces(conn *sqlite.Conn) ([]string, error)

type NetworkNeighborhoodProcessor added in v0.0.81

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

func NewNetworkNeighborhoodProcessor added in v0.0.121

func NewNetworkNeighborhoodProcessor(cfg config.Config) *NetworkNeighborhoodProcessor

func (NetworkNeighborhoodProcessor) AfterCreate added in v0.0.199

func (NetworkNeighborhoodProcessor) PreSave added in v0.0.81

func (NetworkNeighborhoodProcessor) SetStorage added in v0.0.143

type NetworkNeighborhoodStorage added in v0.0.199

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

func (NetworkNeighborhoodStorage) CompactRevision added in v0.0.221

func (a NetworkNeighborhoodStorage) CompactRevision() int64

func (NetworkNeighborhoodStorage) Create added in v0.0.199

func (a NetworkNeighborhoodStorage) Create(ctx context.Context, key string, obj, out runtime.Object, ttl uint64) error

func (NetworkNeighborhoodStorage) Delete added in v0.0.199

func (a NetworkNeighborhoodStorage) Delete(ctx context.Context, key string, out runtime.Object, preconditions *storage.Preconditions, validateDeletion storage.ValidateObjectFunc, cachedExistingObject runtime.Object, opts storage.DeleteOptions) error

func (NetworkNeighborhoodStorage) Get added in v0.0.199

func (NetworkNeighborhoodStorage) GetCurrentResourceVersion added in v0.0.199

func (a NetworkNeighborhoodStorage) GetCurrentResourceVersion(_ context.Context) (uint64, error)

func (NetworkNeighborhoodStorage) GetList added in v0.0.199

func (NetworkNeighborhoodStorage) GuaranteedUpdate added in v0.0.199

func (a NetworkNeighborhoodStorage) GuaranteedUpdate(ctx context.Context, key string, destination runtime.Object, ignoreNotFound bool, preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, cachedExistingObject runtime.Object) error

func (NetworkNeighborhoodStorage) ReadinessCheck added in v0.0.199

func (a NetworkNeighborhoodStorage) ReadinessCheck() error

func (NetworkNeighborhoodStorage) RequestWatchProgress added in v0.0.199

func (a NetworkNeighborhoodStorage) RequestWatchProgress(ctx context.Context) error

func (NetworkNeighborhoodStorage) SetKeysFunc added in v0.0.221

func (a NetworkNeighborhoodStorage) SetKeysFunc(_ storage.KeysFunc)

func (NetworkNeighborhoodStorage) Stats added in v0.0.221

func (NetworkNeighborhoodStorage) Versioner added in v0.0.199

func (NetworkNeighborhoodStorage) Watch added in v0.0.199

type PartialObjectMetadata added in v0.0.199

type PartialObjectMetadata struct {
	metav1.TypeMeta
	metav1.ObjectMeta
}

PartialObjectMetadata is a generic representation of any object with ObjectMeta. It allows clients to get access to a particular ObjectMeta schema without knowing the details of the version.

func (PartialObjectMetadata) DeepCopyObject added in v0.0.199

func (p PartialObjectMetadata) DeepCopyObject() runtime.Object

type Processor added in v0.0.66

type Processor interface {
	AfterCreate(ctx context.Context, object runtime.Object) error
	PreSave(ctx context.Context, object runtime.Object) error
	SetStorage(storageImpl ContainerProfileStorage)
}

type ResourceMaps added in v0.0.199

type ResourceMaps struct {
	// CLUSTER level
	RunningContainerImageIds mapset.Set[string]
	RunningInstanceIds       mapset.Set[string]
	// NAMESPACE level
	RunningTemplateHash          mapset.Set[string]
	RunningWlidsToContainerNames *maps.SafeMap[string, mapset.Set[string]]
}

ResourceMaps is a map of running resources in the cluster, based on these maps we can decide which files to delete

type ResourcesCleanupHandler added in v0.0.199

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

func NewResourcesCleanupHandler added in v0.0.199

func NewResourcesCleanupHandler(appFs afero.Fs, root string, pool *sqlitemigration.Pool, watchDispatcher *WatchDispatcher, interval time.Duration, defaultNamespace string, fetcher ResourcesFetcher, relevancyEnabled bool) *ResourcesCleanupHandler

func (*ResourcesCleanupHandler) CleanupTask added in v0.0.199

func (h *ResourcesCleanupHandler) CleanupTask(ctx context.Context, resourceToKindHandler map[string][]TypeCleanupHandlerFunc) error

func (*ResourcesCleanupHandler) RunCleanupTask added in v0.0.199

func (h *ResourcesCleanupHandler) RunCleanupTask(ctx context.Context)

type ResourcesFetcher added in v0.0.199

type ResourcesFetcher interface {
	FetchResources(ns string) (ResourceMaps, error)
	ListNamespaces(conn *sqlite.Conn) ([]string, error)
}

type StorageImpl

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

StorageImpl offers a common interface for object marshaling/unmarshaling operations and hides all the storage-related operations behind it.

func (*StorageImpl) CalculateChecksum added in v0.0.135

func (s *StorageImpl) CalculateChecksum(in runtime.Object) (string, error)

func (*StorageImpl) CompactRevision added in v0.0.221

func (s *StorageImpl) CompactRevision() int64

func (*StorageImpl) Count

func (s *StorageImpl) Count(key string) (int64, error)

Count returns number of different entries under the key (generally being path prefix).

func (*StorageImpl) Create

func (s *StorageImpl) Create(ctx context.Context, key string, obj, metaOut runtime.Object, _ uint64) error

Create adds a new object at a key unless it already exists. 'ttl' is time-to-live in seconds (and is ignored). If no error is returned and out is not nil, out will be set to the read value from database.

func (*StorageImpl) CreateWithConn added in v0.0.199

func (s *StorageImpl) CreateWithConn(ctx context.Context, conn *sqlite.Conn, key string, obj, metaOut runtime.Object, _ uint64) error

func (*StorageImpl) Delete

Delete removes the specified key and returns the value that existed at that spot. If key didn't exist, it will return NotFound storage error. If 'cachedExistingObject' is non-nil, it can be used as a suggestion about the current version of the object to avoid read operation from storage to get it. However, the implementations have to retry in case suggestion is stale.

func (*StorageImpl) DeleteWithConn added in v0.0.199

func (*StorageImpl) Get

func (s *StorageImpl) Get(ctx context.Context, key string, opts storage.GetOptions, objPtr runtime.Object) error

Get unmarshals object found at key into objPtr. On a not found error, will either return a zero object of the requested type, or an error, depending on 'opts.ignoreNotFound'. Treats empty responses and nil response nodes exactly like a not found error. The returned contents may be delayed, but it is guaranteed that they will match 'opts.ResourceVersion' according 'opts.ResourceVersionMatch'.

func (*StorageImpl) GetByCluster added in v0.0.18

func (s *StorageImpl) GetByCluster(ctx context.Context, apiVersion, kind string, listObj runtime.Object) error

GetByCluster returns all objects in a given cluster, given their api version and kind.

func (*StorageImpl) GetByNamespace added in v0.0.18

func (s *StorageImpl) GetByNamespace(ctx context.Context, apiVersion, kind, namespace string, listObj runtime.Object) error

GetByNamespace returns all objects in a given namespace, given their api version and kind.

func (*StorageImpl) GetCurrentResourceVersion added in v0.0.199

func (s *StorageImpl) GetCurrentResourceVersion(_ context.Context) (uint64, error)

func (*StorageImpl) GetList

func (s *StorageImpl) GetList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error

GetList unmarshalls objects found at key into a *List api object (an object that satisfies runtime.IsList definition). If 'opts.Recursive' is false, 'key' is used as an exact match. If `opts.Recursive' is true, 'key' is used as a prefix. The returned contents may be delayed, but it is guaranteed that they will match 'opts.ResourceVersion' according 'opts.ResourceVersionMatch'. GetList only returns metadata for the objects, not the objects themselves.

func (*StorageImpl) GetListWithConn added in v0.0.199

func (s *StorageImpl) GetListWithConn(ctx context.Context, conn *sqlite.Conn, key string, opts storage.ListOptions, listObj runtime.Object) error

func (*StorageImpl) GetWithConn added in v0.0.199

func (s *StorageImpl) GetWithConn(ctx context.Context, conn *sqlite.Conn, key string, opts storage.GetOptions, objPtr runtime.Object) error

func (*StorageImpl) GuaranteedUpdate

func (s *StorageImpl) GuaranteedUpdate(
	ctx context.Context, key string, metaOut runtime.Object, ignoreNotFound bool,
	preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, cachedExistingObject runtime.Object) error

GuaranteedUpdate keeps calling 'tryUpdate()' to update key 'key' (of type 'destination') retrying the update until success if there is index conflict. Note that object passed to tryUpdate may change across invocations of tryUpdate() if other writers are simultaneously updating it, so tryUpdate() needs to take into account the current contents of the object when deciding how the update object should look. If the key doesn't exist, it will return NotFound storage error if ignoreNotFound=false else `destination` will be set to the zero value of its type. If the eventual successful invocation of `tryUpdate` returns an output with the same serialized contents as the input, it won't perform any update, but instead set `destination` to an object with those contents. If 'cachedExistingObject' is non-nil, it can be used as a suggestion about the current version of the object to avoid read operation from storage to get it. However, the implementations have to retry in case suggestion is stale.

Example:

s := /* implementation of Interface */ err := s.GuaranteedUpdate(

 "myKey", &MyType{}, true, preconditions,
 func(input runtime.Object, res ResponseMeta) (runtime.Object, *uint64, error) {
   // Before each invocation of the user defined function, "input" is reset to
   // current contents for "myKey" in database.
   curr := input.(*MyType)  // Guaranteed to succeed.

   // Make the modification
   curr.Counter++

   // Return the modified object - return an error to stop iterating. Return
   // a uint64 to alter the TTL on the object, or nil to keep it the same value.
   return cur, nil, nil
}, cachedExistingObject

)

func (*StorageImpl) GuaranteedUpdateWithConn added in v0.0.199

func (s *StorageImpl) GuaranteedUpdateWithConn(
	ctx context.Context, conn *sqlite.Conn, key string, metaOut runtime.Object, ignoreNotFound bool,
	preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, cachedExistingObject runtime.Object, checksum string) error

func (*StorageImpl) ReadinessCheck added in v0.0.174

func (s *StorageImpl) ReadinessCheck() error

func (*StorageImpl) RequestWatchProgress added in v0.0.42

func (s *StorageImpl) RequestWatchProgress(context.Context) error

RequestWatchProgress fulfills the storage.Interface

Its function is only relevant to etcd.

func (*StorageImpl) SetKeysFunc added in v0.0.221

func (s *StorageImpl) SetKeysFunc(_ storage.KeysFunc)

func (*StorageImpl) Stats added in v0.0.221

func (s *StorageImpl) Stats(_ context.Context) (storage.Stats, error)

func (*StorageImpl) Versioner

func (s *StorageImpl) Versioner() storage.Versioner

Versioner Returns Versioner associated with this interface.

func (*StorageImpl) Watch

Watch begins watching the specified key. Events are decoded into API objects, and any items selected by 'p' are sent down to returned watch.Interface. resourceVersion may be used to specify what version to begin watching, which should be the current resourceVersion, and no longer rv+1 (e.g. reconnecting without missing any updates). If resource version is "0", this interface will get current object at given key and send it in an "ADDED" event, before watch starts.

type StorageQuerier added in v0.0.18

type StorageQuerier interface {
	storage.Interface
	CalculateChecksum(in runtime.Object) (string, error)
	GetByNamespace(ctx context.Context, apiVersion, kind, namespace string, listObj runtime.Object) error
	GetByCluster(ctx context.Context, apiVersion, kind string, listObj runtime.Object) error
}

StorageQuerier wraps the storage.Interface and adds some extra methods which are used by the storage implementation.

func NewStorageImpl

func NewStorageImpl(appFs afero.Fs, root string, pool *sqlitemigration.Pool, watchDispatcher *WatchDispatcher, scheme *runtime.Scheme) StorageQuerier

func NewStorageImplWithCollector added in v0.0.66

func NewStorageImplWithCollector(appFs afero.Fs, root string, conn *sqlitemigration.Pool, watchDispatcher *WatchDispatcher, scheme *runtime.Scheme, processor Processor) StorageQuerier

type Stringer added in v0.0.66

type Stringer interface {
	String() string
}

type TimeSeriesOperations added in v0.0.231

type TimeSeriesOperations interface {
	// ListTimeSeriesExpired returns keys for time series entries older than the given duration.
	// These represent profiles that have exceeded their tracking threshold.
	ListTimeSeriesExpired(ctx context.Context, threshold time.Duration) ([]string, error)

	// ListTimeSeriesWithData returns keys for all time series entries that have pending data.
	ListTimeSeriesWithData(ctx context.Context) ([]string, error)

	// ListTimeSeriesContainers retrieves time series container information for a given key.
	// Returns a map of seriesID to slice of TimeSeriesContainers.
	ListTimeSeriesContainers(ctx context.Context, key string) (map[string][]softwarecomposition.TimeSeriesContainers, error)

	// DeleteTimeSeriesContainerEntries removes all time series entries for a given key.
	DeleteTimeSeriesContainerEntries(ctx context.Context, key string) error

	// ReplaceTimeSeriesContainerEntries replaces time series entries for a given key and seriesID.
	// It deletes entries in deleteTimeSeries and inserts newTimeSeries.
	ReplaceTimeSeriesContainerEntries(ctx context.Context, key, seriesID string, deleteTimeSeries []string, newTimeSeries []softwarecomposition.TimeSeriesContainers) error
}

TimeSeriesOperations defines operations for managing time series data. These operations are used for tracking container profile versions over time.

type TransactionManager added in v0.0.231

type TransactionManager interface {
	// WithConnection acquires a connection from the pool and returns a new context
	// with the connection embedded, plus a cleanup function to return the connection to the pool.
	// The cleanup function is safe to call multiple times.
	// Usage:
	//   ctx, cleanup, err := storage.WithConnection(ctx)
	//   if err != nil { return err }
	//   defer cleanup()
	//   // ... do work with ctx ...
	WithConnection(ctx context.Context) (context.Context, func(), error)

	// BeginTransaction starts a SQLite transaction (savepoint) and returns a function
	// to commit or rollback based on the error state.
	// The connection must already be in the context (from WithConnection).
	// Returns a function that must be called with the error pointer to commit or rollback the savepoint.
	// Usage:
	//   endFn, err := storage.BeginTransaction(ctx)
	//   if err != nil { return err }
	//   err = doSomeWork(ctx)
	//   endFn(&err) // commits savepoint if err is nil, rolls back otherwise
	BeginTransaction(ctx context.Context) (endFunc func(*error), err error)
}

TransactionManager handles database connection and transaction lifecycle. Implementations should manage connection pooling and transaction semantics appropriate for their backend.

The connection is stored in the context using context.WithValue with key connKey. All storage methods extract the connection from the context.

type TypeCleanupHandlerFunc added in v0.0.199

type TypeCleanupHandlerFunc func(kind, path string, metadata *metav1.ObjectMeta, resourceMaps ResourceMaps) bool

type TypeDeleteFunc added in v0.0.199

type TypeDeleteFunc func(appFs afero.Fs, path string)

type VulnerabilitySummaryStorage added in v0.0.20

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

VulnerabilitySummaryStorage implements a storage for vulnerability summaries.

It provides vulnerability summaries for scopes like namespace and cluster. To get these summaries, the storage fetches existing stored VulnerabilitySummary objects and aggregates them on the fly.

func (*VulnerabilitySummaryStorage) CompactRevision added in v0.0.221

func (s *VulnerabilitySummaryStorage) CompactRevision() int64

func (VulnerabilitySummaryStorage) Count added in v0.0.20

func (VulnerabilitySummaryStorage) Count(key string) (int64, error)

Count is not supported for immutable objects. Objects are generated on the fly and not stored.

func (VulnerabilitySummaryStorage) Create added in v0.0.20

func (VulnerabilitySummaryStorage) Create(_ context.Context, key string, _, _ runtime.Object, _ uint64) error

Create is not supported for immutable objects. Objects are generated on the fly and not stored.

func (VulnerabilitySummaryStorage) Delete added in v0.0.20

func (VulnerabilitySummaryStorage) Delete(_ context.Context, key string, _ runtime.Object, _ *storage.Preconditions, _ storage.ValidateObjectFunc, _ runtime.Object, _ storage.DeleteOptions) error

Delete is not supported for immutable objects. Objects are generated on the fly and not stored.

func (*VulnerabilitySummaryStorage) Get added in v0.0.20

func (*VulnerabilitySummaryStorage) GetCurrentResourceVersion added in v0.0.199

func (s *VulnerabilitySummaryStorage) GetCurrentResourceVersion(_ context.Context) (uint64, error)

func (*VulnerabilitySummaryStorage) GetList added in v0.0.20

func (VulnerabilitySummaryStorage) GuaranteedUpdate added in v0.0.20

func (VulnerabilitySummaryStorage) GuaranteedUpdate(_ context.Context, key string, _ runtime.Object, _ bool, _ *storage.Preconditions, _ storage.UpdateFunc, _ runtime.Object) error

GuaranteedUpdate is not supported for immutable objects. Objects are generated on the fly and not stored.

func (VulnerabilitySummaryStorage) ReadinessCheck added in v0.0.174

func (VulnerabilitySummaryStorage) ReadinessCheck() error

func (VulnerabilitySummaryStorage) RequestWatchProgress added in v0.0.42

func (VulnerabilitySummaryStorage) RequestWatchProgress(context.Context) error

RequestWatchProgress fulfills the storage.Interface

It’s function is only relevant to etcd.

func (*VulnerabilitySummaryStorage) SetKeysFunc added in v0.0.221

func (s *VulnerabilitySummaryStorage) SetKeysFunc(_ storage.KeysFunc)

func (*VulnerabilitySummaryStorage) Stats added in v0.0.221

func (VulnerabilitySummaryStorage) Versioner added in v0.0.20

func (VulnerabilitySummaryStorage) Versioner() storage.Versioner

Versioner Returns fixed versioner associated with this interface.

func (VulnerabilitySummaryStorage) Watch added in v0.0.20

func (VulnerabilitySummaryStorage) Watch(_ context.Context, _ string, _ storage.ListOptions) (watch.Interface, error)

Watch is not supported for immutable objects. Objects are generated on the fly and not stored.

type WatchDispatcher added in v0.0.160

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

WatchDispatcher dispatches events to registered watches

TODO(ttimonen): There's currently no way to gracefully take down WatchDispatcher without leaking a goroutine.

func NewWatchDispatcher added in v0.0.160

func NewWatchDispatcher() *WatchDispatcher

func (*WatchDispatcher) Added added in v0.0.160

func (wd *WatchDispatcher) Added(key string, metaOut, obj runtime.Object)

Added dispatches an "Added" event to appropriate watchers

func (*WatchDispatcher) Deleted added in v0.0.160

func (wd *WatchDispatcher) Deleted(key string, metaOut runtime.Object)

Deleted dispatches a "Deleted" event to appropriate watchers

func (*WatchDispatcher) Modified added in v0.0.160

func (wd *WatchDispatcher) Modified(key string, metaOut, obj runtime.Object)

Modified dispatches a "Modified" event to appropriate watchers

func (*WatchDispatcher) Register added in v0.0.160

func (wd *WatchDispatcher) Register(key string, w *watcher)

Register registers a watcher for a given key

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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