version

package
v1.0.0-rc.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version is set at build time via ldflags
	Version = "dev"
	// BuildTime is set at build time via ldflags
	BuildTime = "unknown"
	// GitCommit is set at build time via ldflags
	GitCommit = "unknown"
)

Functions

func DeleteOTAReprovisionPending

func DeleteOTAReprovisionPending() error

DeleteOTAReprovisionPending removes pending reprovision state.

func GetBuildInfo

func GetBuildInfo() map[string]string

GetBuildInfo returns build information

func GetVersion

func GetVersion() string

GetVersion returns the agent version

func NormalizeVersionResponse

func NormalizeVersionResponse(raw map[string]any) (map[string]any, error)

NormalizeVersionResponse maps flat v3.8 or legacy nested controller version payloads to the internal action map consumed by ChangeVersion.

func ParseExpirationTimeMS

func ParseExpirationTimeMS(raw any) (time.Time, error)

ParseExpirationTimeMS parses controller expirationTime as Unix epoch milliseconds.

func ParseVersion

func ParseVersion(version string) (major, minor, patch int, suffix string)

ParseVersion parses a version string and returns components

func SetBuildInfo

func SetBuildInfo(version, buildTime, gitCommit string)

SetBuildInfo overrides build metadata (used in tests).

func SetOTAReprovisionPendingPath

func SetOTAReprovisionPendingPath(path string)

SetOTAReprovisionPendingPath overrides the pending file path (tests).

func TargetVersionFromAction

func TargetVersionFromAction(actionData map[string]any) string

TargetVersionFromAction resolves the controller target version with semver precedence.

func WriteOTAReprovisionPending

func WriteOTAReprovisionPending(key, command, targetVersion string, expiry time.Time) error

WriteOTAReprovisionPending persists pending reprovision state before detached install.sh.

Types

type Handler

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

Handler orchestrates controller-driven OTA via install.sh.

func GetInstance

func GetInstance() *Handler

GetInstance returns the singleton version handler.

func NewHandler

func NewHandler(manager *ReleaseManager) *Handler

NewHandler constructs a Handler with the given ReleaseManager.

func (*Handler) ChangeVersion

func (h *Handler) ChangeVersion(actionData map[string]any) error

ChangeVersion performs a controller-initiated upgrade or rollback.

func (*Handler) IsReadyToRollback

func (h *Handler) IsReadyToRollback() bool

IsReadyToRollback reports rollback readiness from previous-release and cache/url.

func (*Handler) IsReadyToRollbackWithAction

func (h *Handler) IsReadyToRollbackWithAction(actionData map[string]any) bool

IsReadyToRollbackWithAction reports rollback readiness for an optional controller target.

func (*Handler) IsReadyToUpgrade

func (h *Handler) IsReadyToUpgrade() bool

IsReadyToUpgrade reports upgrade readiness using GitHub latest as target.

func (*Handler) IsReadyToUpgradeWithAction

func (h *Handler) IsReadyToUpgradeWithAction(actionData map[string]any) bool

IsReadyToUpgradeWithAction reports upgrade readiness for an optional controller target.

func (*Handler) SetVersionRefreshFunc

func (h *Handler) SetVersionRefreshFunc(fn RefreshFunc)

SetVersionRefreshFunc configures a callback to re-fetch controller version metadata.

type InstallReceipt

type InstallReceipt struct {
	InstalledVersion string
	OS               string
	Arch             string
	ContainerEngine  string
	SourceURL        string
	InstalledAt      string
	InstallMethod    string
	BinarySHA256     string
}

InstallReceipt holds parsed install-receipt v1 fields.

type PendingOTAReprovision

type PendingOTAReprovision struct {
	ProvisionKey   string    `json:"provisionKey"`
	ExpirationTime time.Time `json:"expirationTime"`
	Command        string    `json:"command"`
	TargetVersion  string    `json:"targetVersion"`
}

PendingOTAReprovision holds controller OTA reprovision state written before install.sh runs.

func PendingFromAction

func PendingFromAction(actionData map[string]any) (*PendingOTAReprovision, error)

PendingFromAction builds pending state from a normalized version action map.

func ReadOTAReprovisionPending

func ReadOTAReprovisionPending() (*PendingOTAReprovision, error)

ReadOTAReprovisionPending reads pending reprovision state if present.

func (*PendingOTAReprovision) IsExpired

func (p *PendingOTAReprovision) IsExpired(now time.Time) bool

IsExpired reports whether the pending key is no longer valid (30s skew buffer).

func (*PendingOTAReprovision) NeedsPreflightRefresh

func (p *PendingOTAReprovision) NeedsPreflightRefresh(now time.Time) bool

NeedsPreflightRefresh reports whether the key is close enough to expiry to refresh before OTA.

type PreviousRelease

type PreviousRelease struct {
	PreviousVersion         string
	PreviousOS              string
	PreviousArch            string
	PreviousContainerEngine string
	PreviousDownloadURL     string
	PreviousBinarySHA256    string
	ConfigBackupPath        string
}

PreviousRelease holds parsed previous-release fields.

type RefreshFunc

type RefreshFunc func() (map[string]any, error)

RefreshFunc fetches a fresh controller version payload (used for OTA key refresh).

type ReleaseManager

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

ReleaseManager reads OTA state from install.sh receipt files and GitHub releases.

func NewReleaseManager

func NewReleaseManager(opts ...ReleaseManagerOption) *ReleaseManager

NewReleaseManager constructs a ReleaseManager with optional overrides.

func (*ReleaseManager) GetCandidateVersion

func (rm *ReleaseManager) GetCandidateVersion(actionData map[string]any) (string, error)

GetCandidateVersion resolves the controller target from action data or GitHub latest.

func (*ReleaseManager) GetInstalledVersion

func (rm *ReleaseManager) GetInstalledVersion() string

GetInstalledVersion returns receipt installed_version or the running build version.

func (*ReleaseManager) HasCachedBinary

func (rm *ReleaseManager) HasCachedBinary(version, osName, arch string) bool

HasCachedBinary reports whether rollback cache contains the previous binary.

func (*ReleaseManager) InstallScriptExists

func (rm *ReleaseManager) InstallScriptExists() bool

InstallScriptExists reports whether the bundled install script is present.

func (*ReleaseManager) InstallScriptPath

func (rm *ReleaseManager) InstallScriptPath() string

InstallScriptPath returns the bundled install script path.

func (*ReleaseManager) IsPreviousDownloadReachable

func (rm *ReleaseManager) IsPreviousDownloadReachable(url string) bool

IsPreviousDownloadReachable checks whether previous_download_url responds.

func (*ReleaseManager) PreviousReleaseExists

func (rm *ReleaseManager) PreviousReleaseExists() bool

PreviousReleaseExists reports whether a previous-release record is on disk.

func (*ReleaseManager) ReadInstallReceipt

func (rm *ReleaseManager) ReadInstallReceipt() (*InstallReceipt, error)

ReadInstallReceipt parses install-receipt v1 if present.

func (*ReleaseManager) ReadPreviousRelease

func (rm *ReleaseManager) ReadPreviousRelease() (*PreviousRelease, error)

ReadPreviousRelease parses previous-release if present.

type ReleaseManagerOption

type ReleaseManagerOption func(*ReleaseManager)

ReleaseManagerOption configures a ReleaseManager.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ReleaseManagerOption

WithHTTPClient overrides the HTTP client (tests).

func WithPaths

func WithPaths(installScript, receiptFile, previousFile, cacheDir string) ReleaseManagerOption

WithPaths overrides default on-disk OTA paths (tests).

func WithRunningVersion

func WithRunningVersion(fn func() string) ReleaseManagerOption

WithRunningVersion overrides the running agent version source (tests).

type VersionCommand

type VersionCommand string //nolint:revive // exported API

VersionCommand represents a version change command.

const (
	VersionCommandUpgrade  VersionCommand = "UPGRADE"
	VersionCommandRollback VersionCommand = "ROLLBACK"
)

func ParseVersionCommand

func ParseVersionCommand(actionData map[string]any) (VersionCommand, error)

ParseVersionCommand parses version command from JSON.

Jump to

Keyboard shortcuts

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