Documentation
¶
Overview ¶
Package pluginmgr manages installed lfed plugins.
A plugin lives in $XDG_DATA_HOME/lfed/plugins/<name>/ as the binary lfed-<name> and the manifest lfed-plugin.json. the lfed CLI reads manifests for listing and help. It executes a plugin only to run it, to complete its arguments, or to read its manifest at install time.
Index ¶
- Constants
- func BinaryName(name string) string
- func CheckLfedVersion(requires, running string) error
- func Complete(ctx context.Context, f *cmdutil.Factory, name string, args []string) error
- func Dir() (string, error)
- func Env(lfedVersion string, ctx contexts.Context, token string, mode output.Mode, ...) []string
- func Exec(ctx context.Context, f *cmdutil.Factory, p Installed, args []string) error
- func ExitCode(err error) int
- func Remove(name string) error
- func Run(ctx context.Context, f *cmdutil.Factory, name string, args []string) error
- type ExitError
- type IncompatibleError
- type Installed
- type NoReleaseError
- type NotFoundError
- type Options
- type Source
- type UpgradeResult
Constants ¶
const ( // ArtifactType marks a per-platform plugin manifest. ArtifactType = "application/vnd.linuxfoundation.ed.cli.plugin.v1" // LayerMediaType is the single layer: a tar.gz holding lfed-<name>. LayerMediaType = "application/vnd.linuxfoundation.ed.cli.plugin.layer.v1.tar+gzip" // AnnotationName on the index is the plugin name. AnnotationName = "org.linuxfoundation.ed.cli.plugin.name" // AnnotationRequiresLfed on the index mirrors the manifest requires_lfed // range, so the lfed CLI can pick a compatible version before pulling. AnnotationRequiresLfed = "org.linuxfoundation.ed.cli.plugin.requires_lfed" )
OCI artifact contract. The release workflow in p3-platform writes these; the lfed CLI reads them. Both sides MUST change together.
const ( SourcePath = "path" SourceOCI = "oci" )
Source types stored in lfed-plugin.json.
const DefaultRegistry = "ghcr.io/lf-certification/lfed-cli-plugins"
DefaultRegistry is the OCI repository prefix a bare plugin name resolves against. LFED_PLUGIN_REGISTRY overrides it.
const ManifestFile = "lfed-plugin.json"
ManifestFile is the manifest name inside a plugin directory.
Variables ¶
This section is empty.
Functions ¶
func BinaryName ¶
BinaryName returns the executable name of a plugin.
func CheckLfedVersion ¶
CheckLfedVersion verifies that the running lfed version satisfies the requires_lfed range. A pre-release tag such as 0.1.0-dev is ignored so development builds pass release ranges. Failure yields *IncompatibleError; the name is filled by the caller when it is known.
func Complete ¶
Complete runs `lfed-<name> __complete args...` for shell completion. The plugin's completion output passes through unchanged. No token is resolved: completion MUST NOT prompt for the keyring or fail on auth.
func Env ¶
func Env(lfedVersion string, ctx contexts.Context, token string, mode output.Mode, reexec string) []string
Env returns the six LFED_* variables of the plugin contract. The base URL has no trailing slash; contexts.Context.APIBaseURL guarantees that. LFED_DEBUG is not set here: it passes through from the operator's environment, so a plugin sees exactly what the CLI saw.
func Exec ¶
Exec runs the plugin binary with args and the contract environment. Streams pass through. --yes is appended when the CLI flag is set and args do not already carry it. A non-zero exit returns *ExitError.
The token is best effort. When it cannot be resolved, LFED_TOKEN is exported empty and the plugin asks `LFED_REEXEC auth token` when it needs one (sdk/auth.Token). That keeps --help and read-only paths working while logged out; the login hint appears at first API use.
func ExitCode ¶
ExitCode maps an error to the lfed CLI exit code: 0 for nil, the plugin's code for *ExitError, 2 for *NotFoundError and *IncompatibleError, else 1.
Types ¶
type ExitError ¶
type ExitError struct {
Code int
}
ExitError carries a plugin's non-zero exit code. main exits with Code and prints nothing; the plugin already reported the failure.
type IncompatibleError ¶
IncompatibleError reports a plugin whose requires_lfed range excludes the running lfed CLI. the lfed CLI exits 2.
func (*IncompatibleError) Error ¶
func (e *IncompatibleError) Error() string
type Installed ¶
type Installed struct {
Manifest sdkplugin.Manifest
// Source is where the plugin came from. Zero for installs that predate
// source tracking.
Source Source
// Dir is the plugin directory: <plugins>/<name>.
Dir string
// Binary is the executable path: <plugins>/<name>/lfed-<name>.
Binary string
}
Installed is one plugin found in the plugin directory.
func Install ¶
Install installs the plugin named by arg (see ParseSource) and returns it. The binary is staged in the plugin directory, asked for __metadata, validated against f.Version, then moved into place together with lfed-plugin.json. An existing install of the same name is replaced.
type NoReleaseError ¶
type NoReleaseError struct {
Ref string
Running string
// Newest is the highest version seen and its requires_lfed range.
// Empty when the repository has no semver tags.
Newest, Requires string
}
NoReleaseError reports an OCI repository with no version the running lfed accepts. The lfed CLI exits 2.
func (*NoReleaseError) Error ¶
func (e *NoReleaseError) Error() string
type NotFoundError ¶
NotFoundError reports a word that is neither a core command nor an installed plugin. The lfed CLI exits 2. Suggestions, when the caller filled them, are close command words.
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
type Options ¶
type Options struct {
// Reserved are core command words. A plugin with one of these names
// could never be dispatched, so Install refuses it.
Reserved []string
}
Options tune Install.
type Source ¶
type Source struct {
Type string `json:"type"`
// Path is the absolute path given to `lfed plugin install`. Type path only.
Path string `json:"path,omitempty"`
// Ref is the OCI repository without a tag, e.g.
// ghcr.io/lf-certification/lfed-cli-plugins/cluster. Type oci only.
Ref string `json:"ref,omitempty"`
// Version is the OCI tag installed, or the tag requested before
// resolution. Empty means "highest compatible". Type oci only.
Version string `json:"version,omitempty"`
}
Source records where a plugin was installed from. `lfed plugin upgrade` re-resolves an OCI source; a path source can only be reinstalled.
func ParseSource ¶
ParseSource classifies an install argument. The rule follows Go's import path convention so a name never shadows a directory:
./x ../x /x ~/x -> local path (file or Go main package directory) name[@version] -> OCI artifact under the default registry host/path[:tag] -> OCI artifact at a full reference
A relative directory without ./ is rejected. The error names the fix.
type UpgradeResult ¶
type UpgradeResult struct {
Name string `json:"name"`
From string `json:"from"`
// To is the version that is or would be installed. Equal to From when
// the plugin is current. Empty when the source cannot be upgraded.
To string `json:"to,omitempty"`
Upgraded bool `json:"upgraded"`
// Note explains a skip: current, dry run, or a non-upgradable source.
Note string `json:"note,omitempty"`
}
UpgradeResult is the outcome for one plugin.
func Upgrade ¶
func Upgrade(ctx context.Context, f *cmdutil.Factory, names []string, dryRun bool, opts Options) ([]UpgradeResult, error)
Upgrade re-resolves every named plugin, or every installed plugin when names is empty, and installs a newer compatible OCI version when one exists. Path sources and installs without a recorded source are reported, not changed. dryRun resolves without installing.