Documentation
¶
Index ¶
- Variables
- func DeleteOTAReprovisionPending() error
- func GetBuildInfo() map[string]string
- func GetVersion() string
- func NormalizeVersionResponse(raw map[string]any) (map[string]any, error)
- func ParseExpirationTimeMS(raw any) (time.Time, error)
- func ParseVersion(version string) (major, minor, patch int, suffix string)
- func SetBuildInfo(version, buildTime, gitCommit string)
- func SetOTAReprovisionPendingPath(path string)
- func TargetVersionFromAction(actionData map[string]any) string
- func WriteOTAReprovisionPending(key, command, targetVersion string, expiry time.Time) error
- type Handler
- func (h *Handler) ChangeVersion(actionData map[string]any) error
- func (h *Handler) IsReadyToRollback() bool
- func (h *Handler) IsReadyToRollbackWithAction(actionData map[string]any) bool
- func (h *Handler) IsReadyToUpgrade() bool
- func (h *Handler) IsReadyToUpgradeWithAction(actionData map[string]any) bool
- func (h *Handler) SetVersionRefreshFunc(fn RefreshFunc)
- type InstallReceipt
- type PendingOTAReprovision
- type PreviousRelease
- type RefreshFunc
- type ReleaseManager
- func (rm *ReleaseManager) GetCandidateVersion(actionData map[string]any) (string, error)
- func (rm *ReleaseManager) GetInstalledVersion() string
- func (rm *ReleaseManager) HasCachedBinary(version, osName, arch string) bool
- func (rm *ReleaseManager) InstallScriptExists() bool
- func (rm *ReleaseManager) InstallScriptPath() string
- func (rm *ReleaseManager) IsPreviousDownloadReachable(url string) bool
- func (rm *ReleaseManager) PreviousReleaseExists() bool
- func (rm *ReleaseManager) ReadInstallReceipt() (*InstallReceipt, error)
- func (rm *ReleaseManager) ReadPreviousRelease() (*PreviousRelease, error)
- type ReleaseManagerOption
- type VersionCommand
Constants ¶
This section is empty.
Variables ¶
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 NormalizeVersionResponse ¶
NormalizeVersionResponse maps flat v3.8 or legacy nested controller version payloads to the internal action map consumed by ChangeVersion.
func ParseExpirationTimeMS ¶
ParseExpirationTimeMS parses controller expirationTime as Unix epoch milliseconds.
func ParseVersion ¶
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 ¶
TargetVersionFromAction resolves the controller target version with semver precedence.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler orchestrates controller-driven OTA via install.sh.
func NewHandler ¶
func NewHandler(manager *ReleaseManager) *Handler
NewHandler constructs a Handler with the given ReleaseManager.
func (*Handler) ChangeVersion ¶
ChangeVersion performs a controller-initiated upgrade or rollback.
func (*Handler) IsReadyToRollback ¶
IsReadyToRollback reports rollback readiness from previous-release and cache/url.
func (*Handler) IsReadyToRollbackWithAction ¶
IsReadyToRollbackWithAction reports rollback readiness for an optional controller target.
func (*Handler) IsReadyToUpgrade ¶
IsReadyToUpgrade reports upgrade readiness using GitHub latest as target.
func (*Handler) IsReadyToUpgradeWithAction ¶
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 ¶
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.