util

package
v0.2.3-alpha1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ASCIIEqualFold added in v0.2.0

func ASCIIEqualFold(s, t string) bool

func AgentVersionsMatch added in v0.2.2

func AgentVersionsMatch(a, b string) bool

AgentVersionsMatch compares two agent versions, tolerating a leading "v" on either side ("v1.2.3" refers to the release tagged "1.2.3" and vice versa).

This is deliberately tag identity, not semver precedence: at least one side is always a raw tag name from the configured releases endpoint, which is not guaranteed to be valid semver. golang.org/x/mod/semver's Compare treats all invalid version strings as equal to one another and ignores build metadata, either of which would produce false matches when deciding whether a stored tool already has the desired version.

func CopySlogValuesToNewCtx added in v0.2.0

func CopySlogValuesToNewCtx(sourceCtx, destCtx context.Context) context.Context

func DetectFileType added in v0.2.0

func DetectFileType(data []byte) string

DetectFileType detects the MIME type from file content

func FetchTools added in v0.2.0

func GetCloudConfigSpecFromExtraSpecs added in v0.2.0

func GetCloudConfigSpecFromExtraSpecs(extraSpecs json.RawMessage) (cloudconfig.CloudConfigSpec, error)

func GetSlogValuesFromContext added in v0.2.0

func GetSlogValuesFromContext(ctx context.Context) []slog.Attr

func GetTmpFileHandle added in v0.2.0

func GetTmpFileHandle(baseDir string) (*os.File, error)

func IsChecksumAsset added in v0.2.2

func IsChecksumAsset(name string) bool

IsChecksumAsset returns true for release assets that only carry a checksum of another asset (e.g. foo.sha256). These are not agent binaries and are redundant in asset listings, which surface the digests directly.

func MarshalReleaseIndex added in v0.2.2

func MarshalReleaseIndex(index AgentReleaseIndex) ([]byte, error)

MarshalReleaseIndex serializes an AgentReleaseIndex for storage on the controller.

func MaybeAddWrapperToExtraSpecs added in v0.2.0

func MaybeAddWrapperToExtraSpecs(ctx context.Context, param commonParams.BootstrapInstance) commonParams.BootstrapInstance

func MergeTools added in v0.2.2

MergeTools merges two sets of runner tools on their OS/arch combo. An entry in override replaces the base entry for the same combo, and combos only override knows about are kept.

It lets the tools metadata URL configured on an endpoint take precedence over what the forge API reports, while keeping the combos only the forge publishes. Within either set, the first entry for a combo wins.

Note: This does not check versions of tools from the override URL. If the 3td party tools URL serves outdated tools, GARM does not check. Runners using tools that are too old, may not be able to connect to GitHub.

func ParseGARMAgentAssetName added in v0.2.0

func ParseGARMAgentAssetName(name string) (osType, osArch string, err error)

ParseGARMAgentAssetName parses a garm-agent asset name to extract OS type and architecture

func ScaleSetPseudoPoolID added in v0.2.2

func ScaleSetPseudoPoolID(entityID string, scaleSetID uint) string

ScaleSetPseudoPoolID derives a stable, UUID-shaped pseudo pool ID for a scale set, from the forge entity ID and the internal scale set database ID. Both inputs are immutable, so the result never changes for the lifetime of the scale set and always fits within provider tag/label length limits.

func ToolsFromRelease added in v0.2.2

func ToolsFromRelease(release GitHubRelease) map[string]params.GARMAgentTool

ToolsFromRelease extracts the GARM agent tools of a single release, indexed by "os_type/os_arch". Assets that do not look like agent binaries (checksum files, unrelated files) are skipped.

func WithSlogContext added in v0.2.0

func WithSlogContext(ctx context.Context, attrs ...slog.Attr) context.Context

Types

type AgentReleaseIndex added in v0.2.2

type AgentReleaseIndex struct {
	SourceURL string         `json:"source_url"`
	Releases  GitHubReleases `json:"releases"`
}

AgentReleaseIndex is the cached list of garm-agent releases fetched from the controller's GARMAgentReleasesURL. The source URL is stored alongside the releases so that changing the URL on the controller invalidates the cached index.

func ParseReleaseIndex added in v0.2.2

func ParseReleaseIndex(data []byte) (AgentReleaseIndex, error)

ParseReleaseIndex parses a cached AgentReleaseIndex blob as stored on the controller.

type GitHubRelease added in v0.2.0

type GitHubRelease struct {
	TagName    string               `json:"tag_name"`
	Name       string               `json:"name"`
	TarballURL string               `json:"tarball_url"`
	Assets     []GitHubReleaseAsset `json:"assets"`
	Prerelease bool                 `json:"prerelease"`
	// Body is the description of the release.
	Body string `json:"body"`
}

GitHubRelease represents a GitHub release

func FindAgentRelease added in v0.2.2

func FindAgentRelease(releases GitHubReleases, version string) (GitHubRelease, bool)

FindAgentRelease returns the release whose tag matches the given version (see AgentVersionsMatch).

func LatestRelease added in v0.2.2

func LatestRelease(releases GitHubReleases) (GitHubRelease, bool)

LatestRelease returns the newest stable release from a release index, falling back to the newest release when only pre-releases exist. Releases are expected in the order the API returns them: newest first.

It is used both for garm-agent releases and for the runner tools published at an endpoint tools metadata URL.

func ParseRelease added in v0.2.2

func ParseRelease(data []byte) (GitHubRelease, error)

ParseRelease parses a single GitHub release object.

func ResolveAgentRelease added in v0.2.2

func ResolveAgentRelease(releases GitHubReleases, version string) (release GitHubRelease, found bool)

ResolveAgentRelease picks the release the controller should use from a release index. An empty version or "latest" resolves to the latest release (see LatestRelease); any other version selects the release with the matching tag. When the requested version is not present in the index, the latest release is returned and found is false — callers decide whether to warn or attempt a targeted fetch, but there is always a usable release as long as the index is not empty.

type GitHubReleaseAsset added in v0.2.0

type GitHubReleaseAsset struct {
	ID            uint      `json:"id"`
	Name          string    `json:"name"`
	Size          uint      `json:"size"`
	DownloadCount uint      `json:"download_count"`
	CreatedAt     time.Time `json:"created_at"`
	Digest        string    `json:"digest"`
	DownloadURL   string    `json:"browser_download_url"`
}

GitHubReleaseAsset represents an asset from a GitHub release

type GitHubReleases added in v0.2.0

type GitHubReleases []GitHubRelease

GitHubReleases represents an array of GitHub releases

func ParseReleaseList added in v0.2.2

func ParseReleaseList(data []byte) (GitHubReleases, error)

ParseReleaseList parses the response of a GitHub-compatible /releases endpoint. The data must be a JSON array of releases, each carrying a tag_name; anything else is an error. Single release objects (e.g. from a /releases/latest endpoint) are intentionally not accepted: the releases URL is validated when it is configured on the controller.

type SlogMultiHandler added in v0.2.0

type SlogMultiHandler struct {
	Handlers []slog.Handler
}

func (*SlogMultiHandler) Enabled added in v0.2.0

func (m *SlogMultiHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*SlogMultiHandler) Handle added in v0.2.0

func (m *SlogMultiHandler) Handle(ctx context.Context, r slog.Record) error

func (*SlogMultiHandler) WithAttrs added in v0.2.0

func (m *SlogMultiHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*SlogMultiHandler) WithGroup added in v0.2.0

func (m *SlogMultiHandler) WithGroup(name string) slog.Handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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