device

package
v1.3.0-rc3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasWithTimestamp

func HasWithTimestamp(opts ...MutateOption) bool

HasWithTimestamp reports whether opts include WithTimestamp (for tests/fakes).

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 DeviceApplyFunc

type DeviceApplyFunc func(m *DeviceMutation) error

DeviceApplyFunc mutates m in place on every Mutate attempt.

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 DeviceMutation

type DeviceMutation struct {
	Device   *domain.Device
	Rendered *DeviceRendered
}

DeviceMutation is the unit apply mutates. Handlers decide all field changes. Device is nil on the create path until apply assigns it.

func (*DeviceMutation) Clone

func (*DeviceMutation) RequireExisting

func (m *DeviceMutation) RequireExisting() error

RequireExisting returns ErrResourceNotFound when Device is nil (create path). Update-only callers should invoke this at the start of apply.

func (*DeviceMutation) Resource

func (m *DeviceMutation) Resource() *domain.Device

func (*DeviceMutation) SetResource

func (m *DeviceMutation) SetResource(device *domain.Device)

type DeviceRendered

type DeviceRendered struct {
	Config       string
	Applications string
	OsImage      string
}

DeviceRendered holds rendered_* column values not represented on domain.Device. When set on DeviceMutation, Mutate persists them and bumps render_timestamp.

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, device *domain.Device, rendered *DeviceRendered) (*domain.Device, error)

Create inserts a device. No events; callers fire their own callbacks. rendered is optional storage-only column data (nil on normal creates).

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) Mutate

func (s *DeviceStore) Mutate(ctx context.Context, orgId uuid.UUID, name string, previous *domain.Device, apply DeviceApplyFunc, opts ...MutateOption) (*domain.Device, *domain.Device, bool, error)

Mutate loads the named device (or uses previous on the first attempt), runs apply, and persists via GenericStore.Mutate using Create / Update. Missing devices are created (apply must set Device); existing ones are updated. The caller is responsible for firing any event callback using the returned before/updated/created values. WithTimestamp() makes loads use a single devices⟕device_timestamps query so Status.LastSeen is set (required before UpdateServiceSideStatus).

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, before, device *domain.Device, rendered *DeviceRendered) (bool, error)

Update writes a device update. Returns retry=true on lost optimistic lock / deadlock. rendered is optional; when nil, rendered_* columns are left unchanged.

func (*DeviceStore) UpdateAnnotations

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

UpdateAnnotations merges annotations via Mutate.

func (*DeviceStore) UpdateStatus

func (s *DeviceStore) UpdateStatus(ctx context.Context, orgId uuid.UUID, device *domain.Device, previous *domain.Device) (*domain.Device, *domain.Device, error)

UpdateStatus writes only status + resource_version so service_conditions (SpecValid, DependencySync, …) are left intact. previous is optional (first attempt).

type MutateOption

type MutateOption func(*mutateConfig)

MutateOption configures DeviceStore.Mutate.

func WithTimestamp

func WithTimestamp() MutateOption

WithTimestamp loads the device via GetWithTimestamp (devices ⟕ device_timestamps) so Status.LastSeen is populated. Use when apply will call UpdateServiceSideStatus.

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 inserts a device. Duplicate names return ErrDuplicateName.
	// rendered is optional storage-only column data (nil on normal creates).
	// No events; the caller fires its own callback.
	Create(ctx context.Context, orgId uuid.UUID, device *domain.Device, rendered *DeviceRendered) (*domain.Device, error)
	// Mutate loads (or uses previous once), runs apply, and persists via Create / Update.
	// If the device does not exist, m.Device is nil and apply must assign it (create);
	// otherwise apply mutates a clone. Returns created and the pre-mutation snapshot so
	// the caller can fire its own event callback; Mutate itself never calls one.
	// Create-only API callers should use Create instead. Update-only callers should call
	// m.RequireExisting() in apply.
	// Pass WithTimestamp() when apply will run UpdateServiceSideStatus (needs LastSeen).
	Mutate(ctx context.Context, orgId uuid.UUID, name string, previous *domain.Device, apply DeviceApplyFunc, opts ...MutateOption) (updated *domain.Device, before *domain.Device, created bool, err error)
	// UpdateStatus writes status + resource_version only (service_conditions unchanged).
	// previous is optional (first attempt only). No events; caller uses before/updated.
	UpdateStatus(ctx context.Context, orgId uuid.UUID, device *domain.Device, previous *domain.Device) (updated *domain.Device, before *domain.Device, err error)
	// UpdateAnnotations merges annotations (and applies deleteKeys) via Mutate.
	UpdateAnnotations(ctx context.Context, orgId uuid.UUID, name string, annotations map[string]string, deleteKeys []string) 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)
	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
	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