tasks

package
v1.2.0-rc1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ItemsPerPage           = 1000
	EventProcessingTimeout = 10 * time.Second
	AckTimeout             = 5 * time.Second
)
View Source
const (
	// DeviceConnectionPollingInterval is the interval at which the device connection status task runs (disconnection and reconnection).
	DeviceConnectionPollingInterval = 2 * time.Minute
	DeviceConnectionTaskName        = "device-connection"
)
View Source
const (
	// EventCleanupPollingInterval is the interval at which the event cleanup task runs.
	EventCleanupPollingInterval = 10 * time.Minute
	EventCleanupTaskName        = "event-cleanup"
)
View Source
const (
	// VulnerabilitySyncInterval is the default interval between Trustify sync runs.
	VulnerabilitySyncInterval = 15 * time.Minute
	VulnerabilitySyncTaskName = "vulnerability-sync"
)
View Source
const RepoTesterTaskName = "repository-tester"
View Source
const ResourceSyncTaskName = "resourcesync"

Variables

View Source
var (
	ErrUnknownConfigName      = errors.New("failed to find configuration item name")
	ErrUnknownApplicationType = errors.New("unknown application type")
)

Functions

func CloneGitRepo

func CloneGitRepo(repo *domain.Repository, revision *string, depth *int, cfg *config.Config) (billy.Filesystem, string, error)

func CloneGitRepoToIgnition added in v0.4.0

func CloneGitRepoToIgnition(repo *domain.Repository, revision string, path string, cfg *config.Config) (*config_latest_types.Config, string, error)

func ConvertFileSystemToIgnition

func ConvertFileSystemToIgnition(mfs billy.Filesystem, path string) (*config_latest_types.Config, error)

ConvertFileSystemToIgnition converts a filesystem to an ignition config The filesystem is expected to be a git repo, and the path is the root of the repo The function will recursively walk the filesystem and add all files to the ignition config In case user provides file path we will add file as "/file-name" In case user provides folder we will drop folder path add all files and subfolder with subfolder paths, like Example: ConvertFileSystemToIgnition(mfs, "/test-path) will go through all subfolder and files and build ignition paths like /etc/motd, /etc/config/file.yaml The function will return an error if the path does not exist or if there is an error reading the filesystem

func EmitInternalTaskFailedEvent added in v0.10.0

func EmitInternalTaskFailedEvent(ctx context.Context, orgID uuid.UUID, errorMessage string, originalEvent domain.Event, serviceHandler service.Service)

func GetAuth

func GetAuth(repository *domain.Repository, cfg *config.Config) (transport.AuthMethod, error)

Read repository's ssh/http config and create transport.AuthMethod. If no ssh/http config is defined a nil is returned.

func GitLsRemote added in v1.2.0

func GitLsRemote(ctx context.Context, repoURL string, refs []string, auth transport.AuthMethod) (map[string]string, error)

GitLsRemote resolves one or more git refs (branch name, tag name, or full ref path) to their commit SHAs without cloning the repository. A single remote.List call is made regardless of how many refs are requested. The returned map contains only the refs that were found. Error messages are sanitized to prevent credential leakage.

func LaunchConsumers

func LaunchConsumers(ctx context.Context,
	queuesProvider queues.Provider,
	serviceHandler service.Service,
	k8sClient k8sclient.K8SClient,
	kvStore kvstore.KVStore,
	cfg *config.Config,
	numConsumers, threadsPerConsumer int,
	workerMetrics *worker.WorkerCollector) error

func NeedsSyncToHash added in v0.6.0

func NeedsSyncToHash(rs *domain.ResourceSync, hash string) bool

NeedsSyncToHash returns true if the resource needs to be synced to the given hash.

func ReplaceParametersInString added in v1.2.0

func ReplaceParametersInString(s string, device *domain.Device) (string, error)

Types

type API

type API interface {
	Test()
}

type CVEEventEmitter added in v1.2.0

type CVEEventEmitter interface {
	CreateEvent(ctx context.Context, orgId uuid.UUID, event *domain.Event)
}

CVEEventEmitter creates CVE lifecycle events.

type CheckpointStore added in v1.2.0

type CheckpointStore interface {
	Set(ctx context.Context, consumer string, key string, value []byte) error
	Get(ctx context.Context, consumer string, key string) ([]byte, error)
	GetDatabaseTime(ctx context.Context) (time.Time, error)
}

CheckpointStore provides checkpoint read/write for snapshot tracking.

type ConfigRefFingerprint added in v1.2.0

type ConfigRefFingerprint struct {
	ConfigProviderName string
	Fingerprint        string
}

ConfigRefFingerprint holds the fingerprint captured for one config provider at render time.

type DependencySyncGit added in v1.2.0

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

func NewDependencySyncGit added in v1.2.0

func NewDependencySyncGit(log logrus.FieldLogger, serviceHandler service.Service,
	cfg *config.Config, metrics *periodic.DependencySyncCollector) *DependencySyncGit

func (*DependencySyncGit) Poll added in v1.2.0

func (d *DependencySyncGit) Poll(ctx context.Context, orgId uuid.UUID)

type DependencySyncHttp added in v1.2.0

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

func NewDependencySyncHttp added in v1.2.0

func NewDependencySyncHttp(log logrus.FieldLogger, serviceHandler service.Service,
	cfg *config.Config, metrics *periodic.DependencySyncCollector) *DependencySyncHttp

func (*DependencySyncHttp) Poll added in v1.2.0

func (d *DependencySyncHttp) Poll(ctx context.Context, orgId uuid.UUID)

type DependencySyncSecret added in v1.2.0

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

DependencySyncSecret manages a K8s Secret SharedInformer that detects changes to labeled secrets and emits DependencyChangeDetected events for affected fleets/devices.

func NewDependencySyncSecret added in v1.2.0

func NewDependencySyncSecret(log logrus.FieldLogger, serviceHandler service.Service, releaseNamespace string, metrics *periodic.DependencySyncCollector) *DependencySyncSecret

func (*DependencySyncSecret) IsInformerConnected added in v1.2.0

func (d *DependencySyncSecret) IsInformerConnected() bool

func (*DependencySyncSecret) Run added in v1.2.0

func (d *DependencySyncSecret) Run(ctx context.Context, clientset kubernetes.Interface)

Run starts the SharedInformerFactory watching labeled secrets and blocks until ctx is cancelled. Intended to be called as a goroutine.

type DeviceConnection added in v1.1.0

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

func NewDeviceConnection added in v1.1.0

func NewDeviceConnection(log logrus.FieldLogger, serviceHandler service.Service) *DeviceConnection

func (*DeviceConnection) Poll added in v1.1.0

func (t *DeviceConnection) Poll(ctx context.Context, orgID uuid.UUID)

Poll checks the status of devices and updates connection state (e.g. disconnection and reconnection) based on device liveness.

type DeviceRenderLogic

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

func NewDeviceRenderLogic

func NewDeviceRenderLogic(log logrus.FieldLogger, serviceHandler service.Service, k8sClient k8sclient.K8SClient, kvStore kvstore.KVStore, cfg *config.Config, orgId uuid.UUID, event domain.Event) DeviceRenderLogic

func (*DeviceRenderLogic) RenderDevice

func (t *DeviceRenderLogic) RenderDevice(ctx context.Context) error

type EventCleanup added in v0.7.0

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

func NewEventCleanup added in v0.7.0

func NewEventCleanup(log logrus.FieldLogger, serviceHandler service.Service, retentionPeriod util.Duration) *EventCleanup

func (*EventCleanup) Poll added in v0.7.0

func (t *EventCleanup) Poll(ctx context.Context)

Poll checks deletes events older than the configured retention period

type FindingStoreUpsertLister added in v1.2.0

type FindingStoreUpsertLister interface {
	ListDeployedImageDigests(ctx context.Context) ([]string, error)
	// UpsertFindings inserts or updates vulnerability findings and returns the findings
	// that were actually inserted or had their severity/status changed.
	UpsertFindings(ctx context.Context, findings []model.VulnerabilityFinding) ([]model.ChangedFinding, error)
	// ComputeAllCVEActions computes all CVE event actions from changed findings and device image changes.
	ComputeAllCVEActions(ctx context.Context, changedFindings []model.ChangedFinding, lastSnapshot time.Time) ([]model.CVEEventAction, error)
	// BatchUpdateOpenEvents applies CVE event actions to device_open_cve_events using batch INSERT/UPDATE/DELETE.
	BatchUpdateOpenEvents(ctx context.Context, actions []model.CVEEventAction) ([]model.CVEEventAction, error)
}

FindingStoreUpsertLister is the subset of VulnerabilityFinding the sync task depends on for Trustify ingestion.

type FleetRolloutsLogic

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

func NewFleetRolloutsLogic

func NewFleetRolloutsLogic(log logrus.FieldLogger, serviceHandler service.Service, orgId uuid.UUID, event domain.Event) FleetRolloutsLogic

func (FleetRolloutsLogic) RolloutDevice

func (f FleetRolloutsLogic) RolloutDevice(ctx context.Context) error

The device's owner was changed, roll out if necessary

func (FleetRolloutsLogic) RolloutFleet

func (f FleetRolloutsLogic) RolloutFleet(ctx context.Context) error

func (*FleetRolloutsLogic) SetItemsPerPage

func (f *FleetRolloutsLogic) SetItemsPerPage(items int)

type FleetSelectorMatchingLogic

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

func NewFleetSelectorMatchingLogic

func NewFleetSelectorMatchingLogic(log logrus.FieldLogger, serviceHandler service.Service, orgId uuid.UUID, event domain.Event) FleetSelectorMatchingLogic

func (FleetSelectorMatchingLogic) DeviceLabelsUpdated added in v0.9.0

func (f FleetSelectorMatchingLogic) DeviceLabelsUpdated(ctx context.Context) error

func (FleetSelectorMatchingLogic) FleetSelectorUpdated added in v0.9.0

func (f FleetSelectorMatchingLogic) FleetSelectorUpdated(ctx context.Context) error

Iterate devices that match the fleet's selector and set owners/conditions as necessary

func (*FleetSelectorMatchingLogic) SetItemsPerPage

func (f *FleetSelectorMatchingLogic) SetItemsPerPage(items int32)

type FleetValidateLogic

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

func NewFleetValidateLogic

func NewFleetValidateLogic(log logrus.FieldLogger, serviceHandler service.Service, k8sClient k8sclient.K8SClient, orgId uuid.UUID, event domain.Event) FleetValidateLogic

func (*FleetValidateLogic) CreateNewTemplateVersionIfFleetValid

func (t *FleetValidateLogic) CreateNewTemplateVersionIfFleetValid(ctx context.Context) error

type FleetValidationResult added in v0.9.0

type FleetValidationResult struct {
	Fleet *domain.Fleet
	Error error
}

FleetValidationResult holds the result of fleet validation

type GenericResourceMap added in v0.9.0

type GenericResourceMap map[string]interface{}

func RemoveIgnoredFields added in v0.9.0

func RemoveIgnoredFields(resource GenericResourceMap, ignorePaths []string) GenericResourceMap

type GitRepoTester

type GitRepoTester struct {
}

func (*GitRepoTester) TestAccess

func (r *GitRepoTester) TestAccess(repository *domain.Repository) error

type HttpRepoTester added in v0.3.0

type HttpRepoTester struct {
}

func (*HttpRepoTester) TestAccess added in v0.3.0

func (r *HttpRepoTester) TestAccess(repository *domain.Repository) error

type OciRepoTester added in v1.1.0

type OciRepoTester struct {
}

func (*OciRepoTester) TestAccess added in v1.1.0

func (r *OciRepoTester) TestAccess(repository *domain.Repository) error

type PopulateDependencyRefsLogic added in v1.2.0

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

func NewPopulateDependencyRefsLogic added in v1.2.0

func NewPopulateDependencyRefsLogic(log logrus.FieldLogger, serviceHandler service.Service, orgId uuid.UUID) PopulateDependencyRefsLogic

func (PopulateDependencyRefsLogic) HandleDeletion added in v1.2.0

func (p PopulateDependencyRefsLogic) HandleDeletion(ctx context.Context, event domain.Event) error

HandleDeletion cleans up all dependency_refs for a deleted fleet or device.

func (PopulateDependencyRefsLogic) PopulateForDevice added in v1.2.0

func (p PopulateDependencyRefsLogic) PopulateForDevice(ctx context.Context, deviceName string) error

func (PopulateDependencyRefsLogic) PopulateForFleet added in v1.2.0

func (p PopulateDependencyRefsLogic) PopulateForFleet(ctx context.Context, fleetName string) error

type ProcessingStats added in v0.9.0

type ProcessingStats struct {
	TotalDevicesProcessed int
	TotalErrors           int
}

ProcessingStats holds the results of fleet selector processing

type QueueMaintenanceTask added in v0.10.0

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

QueueMaintenanceTask handles queue maintenance operations including: - Processing timed out messages - Retrying failed messages - Checkpoint advancement based on in-flight task completion tracking

func NewQueueMaintenanceTask added in v0.10.0

func NewQueueMaintenanceTask(log logrus.FieldLogger, serviceHandler service.Service, queuesProvider queues.Provider, workerClient worker_client.WorkerClient, workerMetrics *worker.WorkerCollector) *QueueMaintenanceTask

NewQueueMaintenanceTask creates a new queue maintenance task

func (*QueueMaintenanceTask) Execute added in v0.10.0

func (t *QueueMaintenanceTask) Execute(ctx context.Context) error

Execute runs the queue maintenance task (system-wide, no organization context needed)

type RenderItem added in v0.3.0

type RenderItem interface {
	MarshalJSON() ([]byte, error)
}

type RepoTester

type RepoTester struct {
	RepoTesterMapper RepoTesterMapping
	// contains filtered or unexported fields
}

func NewRepoTester

func NewRepoTester(log logrus.FieldLogger, serviceHandler service.Service, repoTesterMapper RepoTesterMapping) *RepoTester

func (*RepoTester) SetAccessCondition

func (r *RepoTester) SetAccessCondition(ctx context.Context, orgId uuid.UUID, repository *domain.Repository, err error) error

func (*RepoTester) TestRepositories

func (r *RepoTester) TestRepositories(ctx context.Context, orgId uuid.UUID)

type RepoTesterMapping added in v1.1.0

type RepoTesterMapping func(repository *domain.Repository) TypeSpecificRepoTester

RepoTesterMapping maps a repository to its appropriate TypeSpecificRepoTester. Returns nil if the repository type is unsupported.

type RepositoryUpdateLogic

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

func NewRepositoryUpdateLogic

func NewRepositoryUpdateLogic(log logrus.FieldLogger, serviceHandler service.Service, orgId uuid.UUID, event domain.Event) RepositoryUpdateLogic

func (*RepositoryUpdateLogic) HandleRepositoryUpdate

func (t *RepositoryUpdateLogic) HandleRepositoryUpdate(ctx context.Context) error

type ResourceSync

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

func NewResourceSync

func NewResourceSync(serviceHandler service.Service, log logrus.FieldLogger, cfg *config.Config, ignoreResourceUpdates []string) *ResourceSync

func (*ResourceSync) GetRepositoryAndValidateAccess added in v0.9.0

func (r *ResourceSync) GetRepositoryAndValidateAccess(ctx context.Context, orgId uuid.UUID, rs *domain.ResourceSync) (*domain.Repository, error)

GetRepositoryAndValidateAccess gets the repository and validates it's accessible

func (*ResourceSync) ParseFleetsFromResources added in v0.9.0

func (r *ResourceSync) ParseFleetsFromResources(resources []GenericResourceMap, resourceName string) ([]*domain.Fleet, error)

ParseFleetsFromResources parses fleets from generic resources

func (*ResourceSync) Poll

func (r *ResourceSync) Poll(ctx context.Context, orgId uuid.UUID)

func (*ResourceSync) SyncCatalogItems added in v1.1.0

func (r *ResourceSync) SyncCatalogItems(ctx context.Context, log logrus.FieldLogger, orgId uuid.UUID, rs *domain.ResourceSync, items []*domain.CatalogItem, resourceName string) ([]string, error)

SyncCatalogItems creates/updates catalog items and returns the list of stale item keys to delete. Deletion is handled separately by the caller to ensure correct dependency ordering (CatalogItems must be deleted before Catalogs).

func (*ResourceSync) SyncCatalogs added in v1.1.0

func (r *ResourceSync) SyncCatalogs(ctx context.Context, log logrus.FieldLogger, orgId uuid.UUID, rs *domain.ResourceSync, catalogs []*domain.Catalog, resourceName string) ([]string, error)

SyncCatalogs creates/updates catalogs and returns the list of stale catalog names to delete. Deletion is handled separately by the caller to ensure correct dependency ordering (CatalogItems must be deleted before Catalogs).

func (*ResourceSync) SyncFleets added in v0.9.0

func (r *ResourceSync) SyncFleets(ctx context.Context, log logrus.FieldLogger, orgId uuid.UUID, rs *domain.ResourceSync, fleets []*domain.Fleet, resourceName string) error

SyncFleets syncs the fleets to the service

type TypeSpecificRepoTester

type TypeSpecificRepoTester interface {
	TestAccess(repository *domain.Repository) error
}

func DefaultRepoTesterMapping added in v1.1.0

func DefaultRepoTesterMapping(repository *domain.Repository) TypeSpecificRepoTester

DefaultRepoTesterMapping returns the appropriate TypeSpecificRepoTester based on the repository spec. Returns nil if the repository type is unsupported.

type VulnerabilitySync added in v1.2.0

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

VulnerabilitySync queries Trustify for CVE findings for each unique OS image digest currently deployed across all devices, and upserts the results into the vulnerability_findings table.

func NewVulnerabilitySync added in v1.2.0

func NewVulnerabilitySync(
	log logrus.FieldLogger,
	vulnClient trustifyv2.VulnerabilityClient,
	findingStore FindingStoreUpsertLister,
	checkpoint CheckpointStore,
	eventEmitter CVEEventEmitter,
) *VulnerabilitySync

func (*VulnerabilitySync) Poll added in v1.2.0

func (t *VulnerabilitySync) Poll(ctx context.Context)

Poll discovers all deployed image digests, fetches their CVE findings from Trustify, upserts the results, and emits CVE lifecycle events using a delta-based approach.

Jump to

Keyboard shortcuts

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