device

package
v1.3.0-rc1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CountByOrgAndStatusResult

type CountByOrgAndStatusResult struct {
	OrgID  string
	Status string
	Fleet  string
	Count  int64
}

CountByOrgAndStatusResult holds the result of the group by query for organization and status.

type DeviceListParams

type DeviceListParams struct {
	store.ListParams
	CveID *string // Filter devices by CVE ID (join vulnerability_findings; selectors use devices.*)
}

DeviceListParams extends store.ListParams with device-specific filter options.

type DeviceStatusType

type DeviceStatusType string

DeviceStatusType represents the type of device status to query

const (
	DeviceStatusTypeSummary     DeviceStatusType = "summary"
	DeviceStatusTypeApplication DeviceStatusType = "application"
	DeviceStatusTypeUpdate      DeviceStatusType = "update"
)

func (DeviceStatusType) String

func (d DeviceStatusType) String() string

String returns the string representation of the status type

func (DeviceStatusType) Validate

func (d DeviceStatusType) Validate() error

Validate ensures the status type is valid

type DeviceStore

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

func (*DeviceStore) CompletionCounts

func (s *DeviceStore) CompletionCounts(ctx context.Context, orgId uuid.UUID, owner string, templateVersion string, updateTimeout *time.Duration) ([]domain.DeviceCompletionCount, error)

CompletionCounts is used for finding if a rollout batch is complete or to set the success percentage of the batch. The result is a count of devices grouped by some fields: - rendered_template_version: taken from the annotation 'device-controller/renderedTemplateVersion' - summary_status: taken from the field 'status.summary.status' - updating_reason: it is the reason field from a condition having type 'Updating' - same_rendered_version: it is the result of comparison for equality between the annotation 'device-controller/renderedVersion' and the field 'status.config.renderedVersion' - update_timed_out: it is a boolean value indicating if the update of the device has been timed out

func (*DeviceStore) Count

func (s *DeviceStore) Count(ctx context.Context, orgId uuid.UUID, listParams store.ListParams) (int64, error)

func (*DeviceStore) CountByLabels

func (s *DeviceStore) CountByLabels(ctx context.Context, orgId uuid.UUID, listParams store.ListParams, groupBy []string) ([]map[string]any, error)

CountByLabels is used for rollout policy disruption budget to provide device count values grouped by the label values.

func (*DeviceStore) CountByOrgAndStatus

func (s *DeviceStore) CountByOrgAndStatus(ctx context.Context, orgId *uuid.UUID, statusType DeviceStatusType, groupByFleet bool) ([]CountByOrgAndStatusResult, error)

CountByOrgAndStatus returns the count of devices grouped by org_id and status.

func (*DeviceStore) Create

func (s *DeviceStore) Create(ctx context.Context, orgId uuid.UUID, resource *domain.Device, eventCallback store.EventCallback) (*domain.Device, error)

func (*DeviceStore) CreateOrUpdate

func (s *DeviceStore) CreateOrUpdate(ctx context.Context, orgId uuid.UUID, resource *domain.Device, fieldsToUnset []string, validationCallback DeviceStoreValidationCallback, eventCallback store.EventCallback) (*domain.Device, bool, error)

func (*DeviceStore) DecommissionDevice

func (s *DeviceStore) DecommissionDevice(ctx context.Context, orgId uuid.UUID, name string, decom domain.DeviceDecommission, eventCallback store.EventCallback) (*domain.Device, error)

func (*DeviceStore) Delete

func (s *DeviceStore) Delete(ctx context.Context, orgId uuid.UUID, name string, eventCallback store.EventCallback) (bool, error)

func (*DeviceStore) Get

func (s *DeviceStore) Get(ctx context.Context, orgId uuid.UUID, name string) (*domain.Device, error)

func (*DeviceStore) GetLastSeen

func (s *DeviceStore) GetLastSeen(ctx context.Context, orgId uuid.UUID, name string) (*time.Time, error)

func (*DeviceStore) GetRendered

func (s *DeviceStore) GetRendered(ctx context.Context, orgId uuid.UUID, name string, knownRenderedVersion *string, consoleGrpcEndpoint string) (*domain.Device, error)

func (*DeviceStore) GetRepositoryRefs

func (s *DeviceStore) GetRepositoryRefs(ctx context.Context, orgId uuid.UUID, name string) (*domain.RepositoryList, error)

func (*DeviceStore) GetWithTimestamp

func (s *DeviceStore) GetWithTimestamp(ctx context.Context, orgId uuid.UUID, name string) (*domain.Device, error)

func (*DeviceStore) Healthcheck

func (s *DeviceStore) Healthcheck(ctx context.Context, orgId uuid.UUID, names []string) error

func (*DeviceStore) InitialMigration

func (s *DeviceStore) InitialMigration(ctx context.Context) error

func (*DeviceStore) Labels

func (s *DeviceStore) Labels(ctx context.Context, orgId uuid.UUID, listParams store.ListParams) (domain.LabelList, error)

func (*DeviceStore) List

func (s *DeviceStore) List(ctx context.Context, orgId uuid.UUID, listParams DeviceListParams) (*domain.DeviceList, error)

func (*DeviceStore) ListConnectivityChanged

func (s *DeviceStore) ListConnectivityChanged(ctx context.Context, orgId uuid.UUID, listParams store.ListParams, cutoffTime time.Time) (*domain.DeviceList, error)

func (*DeviceStore) ListDevicesByAppCatalogItemRef

func (s *DeviceStore) ListDevicesByAppCatalogItemRef(ctx context.Context, orgId uuid.UUID, catalog string, item string, listParams store.ListParams) (*domain.DeviceList, error)

func (*DeviceStore) ListDevicesByOsCatalogItemRef

func (s *DeviceStore) ListDevicesByOsCatalogItemRef(ctx context.Context, orgId uuid.UUID, catalog string, item string, listParams store.ListParams) (*domain.DeviceList, error)

func (*DeviceStore) ListDevicesByServiceCondition

func (s *DeviceStore) ListDevicesByServiceCondition(ctx context.Context, orgId uuid.UUID, conditionType string, conditionStatus string, listParams store.ListParams) (*domain.DeviceList, error)

func (*DeviceStore) ListDevicesByVolumeCatalogItemRef

func (s *DeviceStore) ListDevicesByVolumeCatalogItemRef(ctx context.Context, orgId uuid.UUID, catalog string, item string, listParams store.ListParams) (*domain.DeviceList, error)

func (*DeviceStore) MarkRolloutSelection

func (s *DeviceStore) MarkRolloutSelection(ctx context.Context, orgId uuid.UUID, listParams store.ListParams, limit *int) error

MarkRolloutSelection marks all devices that can be filtered by the list params. If limit is provided then the number of marked devices will not be greater than the provided limit.

func (*DeviceStore) MutateAnnotation

func (s *DeviceStore) MutateAnnotation(ctx context.Context, orgId uuid.UUID, name string, key string, mutate func(current string) (string, error)) error

func (*DeviceStore) OverwriteRepositoryRefs

func (s *DeviceStore) OverwriteRepositoryRefs(ctx context.Context, orgId uuid.UUID, name string, repositoryNames ...string) error

func (*DeviceStore) ProcessAwaitingReconnectAnnotation

func (s *DeviceStore) ProcessAwaitingReconnectAnnotation(ctx context.Context, orgId uuid.UUID, deviceName string, deviceReportedVersion *string) (bool, error)

ProcessAwaitingReconnectAnnotation processes the AwaitingReconnect annotation for a specific device This is called from GetRenderedDevice when a device connects and has the awaiting-reconnect annotation Returns true if the device was moved to conflict paused state, false otherwise

func (*DeviceStore) RemoveConflictPausedAnnotation

func (s *DeviceStore) RemoveConflictPausedAnnotation(ctx context.Context, orgId uuid.UUID, listParams store.ListParams) (int64, []string, error)

RemoveConflictPausedAnnotation removes the conflictPaused annotation from all devices matching the selector Returns the count of affected devices and their IDs

func (*DeviceStore) SetIntegrationTestCreateOrUpdateCallback

func (s *DeviceStore) SetIntegrationTestCreateOrUpdateCallback(c store.IntegrationTestCallback)

func (*DeviceStore) SetOutOfDate

func (s *DeviceStore) SetOutOfDate(ctx context.Context, orgId uuid.UUID, owner string) error

func (*DeviceStore) SetServiceConditions

func (s *DeviceStore) SetServiceConditions(ctx context.Context, orgId uuid.UUID, name string, conditions []domain.Condition, callback ServiceConditionsCallback) error

func (*DeviceStore) Summary

func (s *DeviceStore) Summary(ctx context.Context, orgId uuid.UUID, listParams store.ListParams) (*domain.DevicesSummary, error)

func (*DeviceStore) UnmarkRolloutSelection

func (s *DeviceStore) UnmarkRolloutSelection(ctx context.Context, orgId uuid.UUID, fleetName string) error

UnmarkRolloutSelection unmarks all previously marked devices for rollout in a fleet

func (*DeviceStore) Update

func (s *DeviceStore) Update(ctx context.Context, orgId uuid.UUID, resource *domain.Device, fieldsToUnset []string, validationCallback DeviceStoreValidationCallback, eventCallback store.EventCallback) (*domain.Device, error)

func (*DeviceStore) UpdateAnnotations

func (s *DeviceStore) UpdateAnnotations(ctx context.Context, orgId uuid.UUID, name string, annotations map[string]string, deleteKeys []string) error

func (*DeviceStore) UpdateRendered

func (s *DeviceStore) UpdateRendered(ctx context.Context, orgId uuid.UUID, name, renderedConfig, renderedApplications, specHash, osImage string, configFingerprints []domain.DependencySyncConfigRefStatus, forceUpdate bool, mutateStatus RenderedStatusMutator) (string, error)

func (*DeviceStore) UpdateStatus

func (s *DeviceStore) UpdateStatus(ctx context.Context, orgId uuid.UUID, resource *domain.Device, eventCallback store.EventCallback, previous *domain.Device) (*domain.Device, error)

type DeviceStoreValidationCallback

type DeviceStoreValidationCallback func(ctx context.Context, before *domain.Device, after *domain.Device) error

type RenderedStatusMutator

type RenderedStatusMutator func(device *domain.Device) bool

RenderedStatusMutator recomputes server-side status on a device that already has the next rendered-version annotations applied. It returns true when status should be persisted in the same CAS UPDATE as the rendered fields. Invoked on every retry.

type ServiceConditionsCallback

type ServiceConditionsCallback func(ctx context.Context, orgId uuid.UUID, device *domain.Device, oldConditions, newConditions []domain.Condition)

type Store

type Store interface {
	InitialMigration(ctx context.Context) error

	// Exposed to users
	Create(ctx context.Context, orgId uuid.UUID, device *domain.Device, eventCallback store.EventCallback) (*domain.Device, error)
	Update(ctx context.Context, orgId uuid.UUID, device *domain.Device, fieldsToUnset []string, validationCallback DeviceStoreValidationCallback, eventCallback store.EventCallback) (*domain.Device, error)
	CreateOrUpdate(ctx context.Context, orgId uuid.UUID, device *domain.Device, fieldsToUnset []string, validationCallback DeviceStoreValidationCallback, eventCallback store.EventCallback) (*domain.Device, bool, error)
	Get(ctx context.Context, orgId uuid.UUID, name string) (*domain.Device, error)
	List(ctx context.Context, orgId uuid.UUID, listParams DeviceListParams) (*domain.DeviceList, error)
	Labels(ctx context.Context, orgId uuid.UUID, listParams store.ListParams) (domain.LabelList, error)
	Delete(ctx context.Context, orgId uuid.UUID, name string, eventCallback store.EventCallback) (bool, error)
	// UpdateStatus persists device status. When previous is non-nil it is used as the
	// pre-update snapshot for event callbacks and the store does not re-fetch the device.
	UpdateStatus(ctx context.Context, orgId uuid.UUID, device *domain.Device, eventCallback store.EventCallback, previous *domain.Device) (*domain.Device, error)
	GetRendered(ctx context.Context, orgId uuid.UUID, name string, knownRenderedVersion *string, consoleGrpcEndpoint string) (*domain.Device, error)
	Healthcheck(ctx context.Context, orgId uuid.UUID, names []string) error
	ProcessAwaitingReconnectAnnotation(ctx context.Context, orgId uuid.UUID, deviceName string, deviceReportedVersion *string) (bool, error)
	GetLastSeen(ctx context.Context, orgId uuid.UUID, name string) (*time.Time, error)

	// Used internally
	UpdateAnnotations(ctx context.Context, orgId uuid.UUID, name string, annotations map[string]string, deleteKeys []string) error
	MutateAnnotation(ctx context.Context, orgId uuid.UUID, name string, key string, mutate func(current string) (string, error)) error
	UpdateRendered(ctx context.Context, orgId uuid.UUID, name, renderedConfig, renderedApplications, specHash, osImage string, configFingerprints []domain.DependencySyncConfigRefStatus, forceUpdate bool, mutateStatus RenderedStatusMutator) (string, error)
	SetServiceConditions(ctx context.Context, orgId uuid.UUID, name string, conditions []domain.Condition, callback ServiceConditionsCallback) error
	DecommissionDevice(ctx context.Context, orgId uuid.UUID, name string, decom domain.DeviceDecommission, eventCallback store.EventCallback) (*domain.Device, error)
	OverwriteRepositoryRefs(ctx context.Context, orgId uuid.UUID, name string, repositoryNames ...string) error
	GetRepositoryRefs(ctx context.Context, orgId uuid.UUID, name string) (*domain.RepositoryList, error)
	RemoveConflictPausedAnnotation(ctx context.Context, orgId uuid.UUID, listParams store.ListParams) (int64, []string, error)
	SetOutOfDate(ctx context.Context, orgId uuid.UUID, owner string) error
	ListConnectivityChanged(ctx context.Context, orgId uuid.UUID, listParams store.ListParams, cutoffTime time.Time) (*domain.DeviceList, error)
	GetWithTimestamp(ctx context.Context, orgId uuid.UUID, name string) (*domain.Device, error)

	// Used only by rollout
	Count(ctx context.Context, orgId uuid.UUID, listParams store.ListParams) (int64, error)
	UnmarkRolloutSelection(ctx context.Context, orgId uuid.UUID, fleetName string) error
	MarkRolloutSelection(ctx context.Context, orgId uuid.UUID, listParams store.ListParams, limit *int) error
	CompletionCounts(ctx context.Context, orgId uuid.UUID, owner string, templateVersion string, updateTimeout *time.Duration) ([]domain.DeviceCompletionCount, error)
	CountByLabels(ctx context.Context, orgId uuid.UUID, listParams store.ListParams, groupBy []string) ([]map[string]any, error)
	Summary(ctx context.Context, orgId uuid.UUID, listParams store.ListParams) (*domain.DevicesSummary, error)

	// Used by fleet selector
	ListDevicesByServiceCondition(ctx context.Context, orgId uuid.UUID, conditionType string, conditionStatus string, listParams store.ListParams) (*domain.DeviceList, error)

	// Used by catalog
	ListDevicesByOsCatalogItemRef(ctx context.Context, orgId uuid.UUID, catalog string, item string, listParams store.ListParams) (*domain.DeviceList, error)
	ListDevicesByAppCatalogItemRef(ctx context.Context, orgId uuid.UUID, catalog string, item string, listParams store.ListParams) (*domain.DeviceList, error)
	ListDevicesByVolumeCatalogItemRef(ctx context.Context, orgId uuid.UUID, catalog string, item string, listParams store.ListParams) (*domain.DeviceList, error)

	// Used by tests
	SetIntegrationTestCreateOrUpdateCallback(store.IntegrationTestCallback)
	CountByOrgAndStatus(ctx context.Context, orgId *uuid.UUID, statusType DeviceStatusType, groupByFleet bool) ([]CountByOrgAndStatusResult, error)
}

func NewDeviceStore

func NewDeviceStore(db *gorm.DB, log logrus.FieldLogger) Store

Jump to

Keyboard shortcuts

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