api

package
v0.0.0-...-30a488d Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ArchAll     = types.ArchAll
	ArchAMD64   = types.ArchAMD64
	ArchAArch64 = types.ArchAArch64
	ArchX86     = types.ArchX86
)
View Source
const (
	// EventUpdateComplete indicates that the update process completed. It could
	// mean a successful or failed updated, depending on the result attached to
	// the event. This applies to all events.
	EventUpdateComplete = 3

	// EventUpdateDownloadStarted indicates that the instance started
	// downloading the update package.
	EventUpdateDownloadStarted = 13

	// EventUpdateDownloadFinished indicates that the update package was
	// downloaded.
	EventUpdateDownloadFinished = 14

	// EventUpdateInstalled indicates that the update package was installed.
	EventUpdateInstalled = 800
)
View Source
const (
	// ResultFailed indicates that the operation associated with the event
	// posted failed.
	ResultFailed = 0

	// ResultSuccess indicates that the operation associated with the event
	// posted succeeded.
	ResultSuccess = 1

	// ResultSuccessReboot also indicates a successful operation, but it's
	// meant only to be used along with events of EventUpdateComplete type.
	// It's important that instances use EventUpdateComplete events in
	// combination with ResultSuccessReboot to communicate a successful update
	// completed as it has a special meaning for Nebraska in order to adjust
	// properly the rollout policies and create activity entries.
	ResultSuccessReboot = 2
)
View Source
const (
	InstanceStatusUndefined     = types.InstanceStatusUndefined
	InstanceStatusUpdateGranted = types.InstanceStatusUpdateGranted
	InstanceStatusError         = types.InstanceStatusError
	InstanceStatusComplete      = types.InstanceStatusComplete
	InstanceStatusInstalled     = types.InstanceStatusInstalled
	InstanceStatusDownloaded    = types.InstanceStatusDownloaded
	InstanceStatusDownloading   = types.InstanceStatusDownloading
	InstanceStatusOnHold        = types.InstanceStatusOnHold
)
View Source
const (
	// PkgTypeFlatcar indicates that the package is a Flatcar update package
	PkgTypeFlatcar = types.PkgTypeFlatcar

	// PkgTypeDocker indicates that the package is a Docker container
	PkgTypeDocker = types.PkgTypeDocker

	// PkgTypeRocket indicates that the package is a Rocket container
	PkgTypeRocket = types.PkgTypeRocket

	// PkgTypeOther is the generic package type.
	PkgTypeOther = types.PkgTypeOther
)

Variables

View Source
var (

	// ErrNoRowsAffected indicates that no rows were affected in an update or
	// delete database operation.
	ErrNoRowsAffected = types.ErrNoRowsAffected

	// ErrInvalidSemver indicates that the provided semver version is not valid.
	ErrInvalidSemver = types.ErrInvalidSemver

	// ErrArchMismatch indicates that arches of two objects didn't
	// match (for example, for a package and channel)
	ErrArchMismatch = types.ErrArchMismatch
)
View Source
var (
	// ErrInvalidPackage error indicates that a package doesn't belong to the
	// application it was supposed to belong to.
	ErrInvalidPackage = types.ErrInvalidPackage

	// ErrBlacklistedChannel error indicates an attempt of creating/updating a
	// channel using a package that has blacklisted the channel.
	ErrBlacklistedChannel = types.ErrBlacklistedChannel
)
View Source
var (
	// ErrInvalidInstance indicates that the instance provided is not valid or
	// it doesn't exist.
	ErrInvalidInstance = errors.New("nebraska: invalid instance")

	// ErrInvalidApplicationOrGroup indicates that the application or group id
	// provided are not valid or related to each other.
	ErrInvalidApplicationOrGroup = types.ErrInvalidApplicationOrGroup

	// ErrInvalidEventTypeOrResult indicates that the event or result provided
	// are not valid (Nebraska only implements a subset of the Omaha protocol
	// events).
	ErrInvalidEventTypeOrResult = errors.New("nebraska: invalid event type or result")

	// ErrEventRegistrationFailed indicates that the event registration into
	// Nebraska failed.
	ErrEventRegistrationFailed = errors.New("nebraska: event registration failed")

	// ErrNoUpdateInProgress indicates that an event was received but there
	// wasn't an update in progress for the provided instance/application, so
	// it was rejected.
	ErrNoUpdateInProgress = errors.New("nebraska: no update in progress")

	// ErrFlatcarEventIgnored indicates that a Flatcar updater event was ignored.
	// This is a temporary solution to handle Flatcar specific behaviour.
	ErrFlatcarEventIgnored = errors.New("nebraska: flatcar event ignored")
)
View Source
var (
	// ErrInvalidChannel error indicates that a channel doesn't belong to the
	// application it was supposed to belong to.
	ErrInvalidChannel = types.ErrInvalidChannel

	// ErrExpectingValidTimezone error indicates that a valid timezone wasn't
	// provided when enabling the flag PolicyOfficeHours.
	ErrExpectingValidTimezone = types.ErrExpectingValidTimezone
)
View Source
var (
	// ErrBlacklistingChannel error indicates that the channel the package is
	// trying to blacklist is already pointing to the package.
	ErrBlacklistingChannel = types.ErrBlacklistingChannel

	// ErrPackageIsFloor error indicates that the package cannot be deleted
	// because it is marked as a floor version for one or more channels.
	ErrPackageIsFloor = types.ErrPackageIsFloor

	// ErrBlacklistingFloor error indicates that the package cannot be blacklisted
	// because it is marked as a floor version for the channel.
	ErrBlacklistingFloor = types.ErrBlacklistingFloor
)
View Source
var (
	// ErrRegisterInstanceFailed indicates that the instance registration did
	// not succeed.
	ErrRegisterInstanceFailed = errors.New("nebraska: register instance failed")

	// ErrUpdateInProgressOnInstance indicates that an update is currently in
	// progress on the instance requesting an update package, so the request
	// will be rejected.
	ErrUpdateInProgressOnInstance = errors.New("nebraska: update in progress on instance")

	// ErrNoPackageFound indicates that the group doesn't have a channel
	// assigned or that the channel doesn't have a package assigned.
	ErrNoPackageFound = dbreads.ErrNoPackageFound

	// ErrNoUpdatePackageAvailable indicates that the instance requesting the
	// update has already the latest version of the application.
	ErrNoUpdatePackageAvailable = errors.New("nebraska: no update package available")

	// ErrUpdateGrantFailed indicates that the update could not be granted
	// due to a database or internal error.
	ErrUpdateGrantFailed = errors.New("nebraska: failed to grant update")

	// ErrUpdatesDisabled indicates that updates are not enabled in the group.
	ErrUpdatesDisabled = errors.New("nebraska: updates disabled")

	// ErrGetUpdatesStatsFailed indicates that there was a problem getting the
	// updates stats of the group which are needed to enforce the rollout
	// policy.
	ErrGetUpdatesStatsFailed = errors.New("nebraska: get updates stats failed")

	// ErrMaxUpdatesPerPeriodLimitReached indicates that the maximum number of
	// updates per period has been reached.
	ErrMaxUpdatesPerPeriodLimitReached = errors.New("nebraska: max updates per period limit reached")

	// ErrMaxConcurrentUpdatesLimitReached indicates that the maximum number of
	// concurrent updates has been reached.
	ErrMaxConcurrentUpdatesLimitReached = errors.New("nebraska: max concurrent updates limit reached")

	// ErrMaxTimedOutUpdatesLimitReached indicates that limit of instances that
	// timed out while updating has been reached.
	ErrMaxTimedOutUpdatesLimitReached = errors.New("nebraska: max timed out updates limit reached")

	// ErrGrantingUpdate indicates that something went wrong while granting an
	// update.
	ErrGrantingUpdate = errors.New("nebraska: error granting update")
)
View Source
var ErrInvalidArch = types.ErrInvalidArch
View Source
var ErrPackageBlacklisted = types.ErrPackageBlacklisted
View Source
var ErrUpdatingPassword = types.ErrUpdatingPassword

Functions

func OptionDisableUpdatesOnFailedRollout

func OptionDisableUpdatesOnFailedRollout(api *API) error

OptionDisableUpdatesOnFailedRollout will modify API to disable updates on failed rollout.

func OptionInitDB

func OptionInitDB(api *API) error

OptionInitDB will initialize the database during the API instance creation, dropping all existing tables, which will force all migration scripts to be re-executed. Use with caution, this will DESTROY ALL YOUR DATA.

Types

type API

type API struct {
	*dbreads.Queries
	// contains filtered or unexported fields
}

API represents an api instance used to interact with Nebraska entities.

func New

func New(options ...func(*API) error) (*API, error)

New creates a new API instance, creates the underlying db connection.

func NewForTest

func NewForTest(options ...func(*API) error) (*API, error)

NewForTest creates a new API instance with given options and fills the database with sample data for testing purposes.

func NewWithMigrations

func NewWithMigrations(options ...func(*API) error) (*API, error)

NewWithMigrations creates a new API instance, creates the underlying db connection and applies all available db migrations.

func (*API) ClearUpdatesEnabledOverride

func (api *API) ClearUpdatesEnabledOverride(groupID string) error

ClearUpdatesEnabledOverride clears the local policy_updates_enabled override on the group_local row so the admin default on groups takes effect again on this node.

func (*API) Close

func (api *API) Close()

Close releases the connections to the database.

func (*API) GetUpdatePackage

func (api *API) GetUpdatePackage(inst Instance, instApp InstanceApplication) (*Package, error)

GetUpdatePackage returns an update package for the instance/application provided. The instance details and the application it's running will be registered in Nebraska (or updated if it's already registered).

func (*API) GetUpdatePackagesForSyncer

func (api *API) GetUpdatePackagesForSyncer(inst Instance, instApp InstanceApplication) ([]*Package, error)

GetUpdatePackagesForSyncer returns all packages (floors + target) for a syncer client

func (*API) MigrateDown

func (api *API) MigrateDown(version string) (int, error)

func (*API) Reads

func (api *API) Reads() *dbreads.Queries

Reads returns the shared read queries (dbreads.Queries) owned by this API instance.

func (*API) RegisterEvent

func (api *API) RegisterEvent(instanceID, appID, groupID string, etype, eresult int, previousVersion, errorCode string) error

RegisterEvent registers an event posted by an instance in Nebraska. The event will be bound to an application/group combination.

func (*API) RegisterInstance

func (api *API) RegisterInstance(inst Instance, instApp InstanceApplication) (*Instance, error)

RegisterInstance registers an instance into Nebraska.

func (*API) UpdateInstance

func (api *API) UpdateInstance(instanceID string, alias string) (*Instance, error)

func (*API) UpdateInstanceStats

func (api *API) UpdateInstanceStats(t *time.Time, duration *time.Duration) error

UpdateInstanceStats updates the instance_stats table with instances checked in during a given duration from a given time.

type Activity

type Activity = types.Activity

type ActivityQueryParams

type ActivityQueryParams = types.ActivityQueryParams

type AppInstancesPerChannelMetric

type AppInstancesPerChannelMetric = types.AppInstancesPerChannelMetric

type Application

type Application = types.Application

type Arch

type Arch = types.Arch

func ArchFromCoreosString

func ArchFromCoreosString(s string) (Arch, error)

func ArchFromOmahaString

func ArchFromOmahaString(s string) (Arch, error)

func ArchFromString

func ArchFromString(s string) (Arch, error)

type Channel

type Channel = types.Channel

type ChannelFloorInfo

type ChannelFloorInfo = types.ChannelFloorInfo

type ChannelPackageFloor

type ChannelPackageFloor = types.ChannelPackageFloor

type Event

type Event struct {
	ID              int         `db:"id" json:"id"`
	CreatedTs       time.Time   `db:"created_ts" json:"created_ts"`
	PreviousVersion null.String `db:"previous_version" json:"previous_version"`
	ErrorCode       null.String `db:"error_code" json:"error_code"`
	InstanceID      string      `db:"instance_id" json:"instance_id"`
	ApplicationID   string      `db:"application_id" json:"application_id"`
	EventTypeID     string      `db:"event_type_id" json:"event_type_id"`
}

Event represents an event posted by an instance to Nebraska.

type FailedUpdatesMetric

type FailedUpdatesMetric = types.FailedUpdatesMetric

type File

type File = types.File

type FlatcarAction

type FlatcarAction = types.FlatcarAction

type Group

type Group = types.Group

type GroupDescriptor

type GroupDescriptor = types.GroupDescriptor

type Instance

type Instance = types.Instance

type InstanceApplication

type InstanceApplication = types.InstanceApplication

func NewInstanceApplication

func NewInstanceApplication(appID, groupID, version string) InstanceApplication

NewInstanceApplication creates an InstanceApplication with the fields used for registration.

type InstanceStats

type InstanceStats = types.InstanceStats

type InstanceStatusHistoryEntry

type InstanceStatusHistoryEntry = types.InstanceStatusHistoryEntry

type InstancesQueryParams

type InstancesQueryParams = types.InstancesQueryParams

type InstancesStatusStats

type InstancesStatusStats = types.InstancesStatusStats

type InstancesWithTotal

type InstancesWithTotal = types.InstancesWithTotal

type Package

type Package = types.Package

type StatusVersionCountTimelineEntry

type StatusVersionCountTimelineEntry = types.StatusVersionCountTimelineEntry

type StringArray

type StringArray = types.StringArray

type Team

type Team = types.Team

type UpdatesStats

type UpdatesStats = types.UpdatesStats

type User

type User = types.User

type VersionBreakdownEntry

type VersionBreakdownEntry = types.VersionBreakdownEntry

type VersionCountMap

type VersionCountMap = types.VersionCountMap

type VersionCountTimelineEntry

type VersionCountTimelineEntry = types.VersionCountTimelineEntry

Directories

Path Synopsis
Package admin provides write operations for admin-managed tables (application, channel, package, groups, team, users).
Package admin provides write operations for admin-managed tables (application, channel, package, groups, team, users).
internal
dbreads
Package dbreads holds the shared read queries used by the api stack.
Package dbreads holds the shared read queries used by the api stack.
types
This file was taken from the pq project and is licensed under the terms of the MIT license: https://github.com/lib/pq Copyright (c) 2011-2013, 'pq' Contributors Portions Copyright (C) 2011 Blake Mizerany
This file was taken from the pq project and is licensed under the terms of the MIT license: https://github.com/lib/pq Copyright (c) 2011-2013, 'pq' Contributors Portions Copyright (C) 2011 Blake Mizerany

Jump to

Keyboard shortcuts

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