plugin

package
v0.8.0-alpha.5-cloud Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultIndexURI   = "https://github.com/apecloud/block-index.git"
	DefaultIndexName  = "default"
	KrewIndexURI      = "https://github.com/kubernetes-sigs/krew-index.git"
	KrewIndexName     = "krew"
	ManifestExtension = ".yaml"
	PluginKind        = "Plugin"
)

Variables

View Source
var (
	ErrIsAlreadyInstalled = errors.New("can't install, the newest version is already installed")
	ErrIsNotInstalled     = errors.New("plugin is not installed")
	ErrIsAlreadyUpgraded  = errors.New("can't upgrade, the newest version is already installed")
)
View Source
var SupportAPIVersion = []string{
	"krew.googlecontainertools.github.com/v1alpha2",
}
View Source
var (
	ValidPluginFilenamePrefixes = []string{"kbcli", "kubectl"}
)

Functions

func AddIndex

func AddIndex(paths *Paths, name, url string) error

AddIndex initializes a new index to install plugins from.

func CanonicalPluginName

func CanonicalPluginName(in string) (string, string)

CanonicalPluginName resolves a plugin's index and name from input string. If an index is not specified, the default index name is assumed.

func DeleteIndex

func DeleteIndex(paths *Paths, name string) error

DeleteIndex removes specified index name. If index does not exist, returns an error that can be tested by os.IsNotExist.

func EnsureDirs

func EnsureDirs(paths ...string) error

func InitPlugin

func InitPlugin()

func Install

func Install(p *Paths, plugin Plugin, indexName string, opts InstallOpts) error

Install downloads and installs a plugin. The operation tries to keep the plugin dir in a healthy state if it fails during the process.

func IsSubPath

func IsSubPath(basePath, subPath string) (string, bool)

IsSubPath checks if the extending path is an extension of the basePath, it will return the extending path elements. Both paths have to be absolute or have the same root directory. The remaining path elements

func NewPluginCmd

func NewPluginCmd(streams genericiooptions.IOStreams) *cobra.Command

func NewPluginDescribeCmd

func NewPluginDescribeCmd(streams genericiooptions.IOStreams) *cobra.Command

func NewPluginIndexAddCmd

func NewPluginIndexAddCmd(streams genericiooptions.IOStreams) *cobra.Command

func NewPluginIndexCmd

func NewPluginIndexCmd(streams genericiooptions.IOStreams) *cobra.Command

func NewPluginIndexDeleteCmd

func NewPluginIndexDeleteCmd(streams genericiooptions.IOStreams) *cobra.Command

func NewPluginIndexListCmd

func NewPluginIndexListCmd(streams genericiooptions.IOStreams) *cobra.Command

func NewPluginIndexPrinter

func NewPluginIndexPrinter(out io.Writer) *printer.TablePrinter

func NewPluginIndexUpdateCmd

func NewPluginIndexUpdateCmd(streams genericiooptions.IOStreams) *cobra.Command

func NewPluginInstallCmd

func NewPluginInstallCmd(streams genericiooptions.IOStreams) *cobra.Command

func NewPluginListCmd

func NewPluginListCmd(streams genericiooptions.IOStreams) *cobra.Command

func NewPluginPrinter

func NewPluginPrinter(out io.Writer) *printer.TablePrinter

func NewPluginSearchCmd

func NewPluginSearchCmd(streams genericiooptions.IOStreams) *cobra.Command

func NewPluginSearchPrinter

func NewPluginSearchPrinter(out io.Writer) *printer.TablePrinter

func NewPluginUninstallCmd

func NewPluginUninstallCmd(_ genericiooptions.IOStreams) *cobra.Command

func NewPluginUpgradeCmd

func NewPluginUpgradeCmd(streams genericiooptions.IOStreams) *cobra.Command

func ReplaceBase

func ReplaceBase(path, old, replacement string) (string, error)

ReplaceBase returns a replacement path with replacement as a base of the path instead of the old base. a/b/c, a, d -> d/b/c

func StoreReceipt

func StoreReceipt(receipt Receipt, dest string) error

func Upgrade

func Upgrade(p *Paths, plugin Plugin, indexName string) error

Upgrade reinstalls and deletes the old plugin. The operation tries to keep dir in a healthy state if it fails during the process.

func ValidatePlugin

func ValidatePlugin(name string, p Plugin) error

Types

type CommandOverrideVerifier

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

func (*CommandOverrideVerifier) Verify

func (v *CommandOverrideVerifier) Verify(path string) []error

Verify implements PathVerifier and determines if a given path is valid depending on whether it overwrites an existing kbcli command path, or a previously seen plugin.

type FileOperation

type FileOperation struct {
	From string `json:"from,omitempty"`
	To   string `json:"to,omitempty"`
}

FileOperation specifies a file copying operation from plugin archive to the installation directory.

type Index

type Index struct {
	Name string
	URL  string
}

func ListIndexes

func ListIndexes(paths *Paths) ([]Index, error)

ListIndexes returns a slice of Index objects. The path argument is used as the base path of the index.

type InstallOpts

type InstallOpts struct {
	ArchiveFileOverride string
}

type OSArchPair

type OSArchPair struct {
	OS, Arch string
}

OSArchPair is wrapper around operating system and architecture

func OSArch

func OSArch() OSArchPair

OSArch returns the OS/arch combination to be used on the current system. It can be overridden by setting KREW_OS and/or KREW_ARCH environment variables.

func (OSArchPair) String

func (p OSArchPair) String() string

String converts environment into a string

type PathVerifier

type PathVerifier interface {
	Verify(path string) []error
}

PathVerifier receives a path and validates it.

type Paths

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

func GetKbcliPluginPath

func GetKbcliPluginPath() *Paths

func NewPaths

func NewPaths(base string) *Paths

func (*Paths) BasePath

func (p *Paths) BasePath() string

func (*Paths) BinPath

func (p *Paths) BinPath() string

func (*Paths) IndexBase

func (p *Paths) IndexBase() string

func (*Paths) IndexPath

func (p *Paths) IndexPath(name string) string

func (*Paths) IndexPluginsPath

func (p *Paths) IndexPluginsPath(name string) []string

func (*Paths) InstallPath

func (p *Paths) InstallPath() string

func (*Paths) InstallReceiptsPath

func (p *Paths) InstallReceiptsPath() string

func (*Paths) PluginInstallPath

func (p *Paths) PluginInstallPath(plugin string) string

func (*Paths) PluginInstallReceiptPath

func (p *Paths) PluginInstallReceiptPath(plugin string) string

func (*Paths) PluginVersionInstallPath

func (p *Paths) PluginVersionInstallPath(plugin, version string) string

type Platform

type Platform struct {
	URI    string `json:"uri,omitempty"`
	Sha256 string `json:"sha256,omitempty"`

	Selector *metav1.LabelSelector `json:"selector,omitempty"`
	Files    []FileOperation       `json:"files"`

	// Bin specifies the path to the plugin executable.
	// The path is relative to the root of the installation folder.
	// The binary will be linked after all FileOperations are executed.
	Bin string `json:"bin"`
}

Platform describes how to perform an installation on a specific platform and how to match the target platform (os, arch).

func GetMatchingPlatform

func GetMatchingPlatform(platforms []Platform) (Platform, bool, error)

GetMatchingPlatform finds the platform spec in the specified plugin that matches the os/arch of the current machine (can be overridden via KREW_OS and/or KREW_ARCH).

type Plugin

type Plugin struct {
	metav1.TypeMeta   `json:",inline" yaml:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata"`

	Spec PluginSpec `json:"spec"`
}

func LoadPluginByName

func LoadPluginByName(pluginsDirs []string, pluginName string) (Plugin, error)

LoadPluginByName loads plugin from index repository

func LoadPluginListFromFS

func LoadPluginListFromFS(pluginDirs []string) ([]Plugin, error)

LoadPluginListFromFS will parse and retrieve all plugin files.

func ReadPluginFromFile

func ReadPluginFromFile(path string) (Plugin, error)

type PluginIndexOptions

type PluginIndexOptions struct {
	IndexName string
	URL       string

	genericiooptions.IOStreams
}

func (*PluginIndexOptions) AddIndex

func (o *PluginIndexOptions) AddIndex() error

func (*PluginIndexOptions) DeleteIndex

func (o *PluginIndexOptions) DeleteIndex() error

func (*PluginIndexOptions) ListIndex

func (o *PluginIndexOptions) ListIndex() error

func (*PluginIndexOptions) UpdateIndex

func (o *PluginIndexOptions) UpdateIndex() error

type PluginInstallOption

type PluginInstallOption struct {
	genericiooptions.IOStreams
	// contains filtered or unexported fields
}

func (*PluginInstallOption) Complete

func (o *PluginInstallOption) Complete(names []string) error

func (*PluginInstallOption) Install

func (o *PluginInstallOption) Install() error

type PluginListOptions

type PluginListOptions struct {
	Verifier PathVerifier

	PluginPaths []string

	genericiooptions.IOStreams
}

func (*PluginListOptions) Complete

func (o *PluginListOptions) Complete(cmd *cobra.Command) error

func (*PluginListOptions) ListPlugins

func (o *PluginListOptions) ListPlugins() ([]string, []error)

func (*PluginListOptions) Run

func (o *PluginListOptions) Run() error

type PluginSpec

type PluginSpec struct {
	Version          string `json:"version,omitempty"`
	ShortDescription string `json:"shortDescription,omitempty"`
	Description      string `json:"description,omitempty"`
	Caveats          string `json:"caveats,omitempty"`
	Homepage         string `json:"homepage,omitempty"`

	Platforms []Platform `json:"platforms,omitempty"`
}

PluginSpec is the plugin specification.

type Receipt

type Receipt struct {
	Plugin `json:",inline" yaml:",inline"`

	Status ReceiptStatus `json:"status"`
}

Receipt describes a plugin receipt file.

func GetInstalledPluginReceipts

func GetInstalledPluginReceipts(receiptsDir string) ([]Receipt, error)

GetInstalledPluginReceipts returns a list of receipts.

func NewReceipt

func NewReceipt(plugin Plugin, indexName string, timestamp metav1.Time) Receipt

NewReceipt returns a new receipt with the given plugin and index name.

func ReadReceiptFromFile

func ReadReceiptFromFile(path string) (Receipt, error)

type ReceiptStatus

type ReceiptStatus struct {
	Source SourceIndex `json:"source"`
}

ReceiptStatus contains information about the installed plugin.

type SourceIndex

type SourceIndex struct {
	// Name is the configured name of an index a plugin was installed from.
	Name string `json:"name"`
}

SourceIndex contains information about the index a plugin was installed from.

type UpgradeOptions

type UpgradeOptions struct {
	genericiooptions.IOStreams
	// contains filtered or unexported fields
}

func (*UpgradeOptions) Complete

func (o *UpgradeOptions) Complete(args []string) error

func (*UpgradeOptions) Run

func (o *UpgradeOptions) Run() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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