luci: go.chromium.org/luci/cipd/client/cipd/plugin Index | Files | Directories

package plugin

import "go.chromium.org/luci/cipd/client/cipd/plugin"

Package plugin implements the basic infrastructure for CIPD plugins.

Index

Package Files

doc.go host.go run.go

Variables

var ErrTerminated = errors.Reason("terminated with 0 exit code").Err()

ErrTerminated is returned by Process.Err() if the plugin process exited with 0 exit code.

func Run Uses

func Run(ctx context.Context, stdin io.ReadCloser, run RunLoop) error

Run connects to the host and calls `run`.

Blocks until the stdin closes (which indicates the plugin should terminate).

type Controller Uses

type Controller struct {
    Admissions protocol.AdmissionsServer // non-nil for deployment admission plugins
}

Controller lives in the host process and manages communication with a plugin.

Each instance of a plugin has a Controller associated with it. The controller exposes a subset of gRPC services that the particular plugin is allowed to call. That way it's possible to have different kinds of plugins by exposing different services to them.

type Host Uses

type Host struct {
    ServiceURL string           // URL of the CIPD repository ("https://...") used by the client
    Repository RepositoryClient // a subset of api.RepositoryClient available to plugins
    // contains filtered or unexported fields
}

Host launches plugin subprocesses and accepts connections from them.

func (*Host) Close Uses

func (h *Host) Close(ctx context.Context)

Close terminates all plugins and releases all resources.

Waits for the plugins to terminate gracefully. On context deadline kills them with SIGKILL.

func (*Host) LaunchPlugin Uses

func (h *Host) LaunchPlugin(ctx context.Context, args []string, ctrl *Controller) (*Process, error)

LaunchPlugin launches a plugin subprocesses.

Does not wait for it to connect. Returns a handle that can be used to control the process.

Uses the given context for logging from the plugin.

type Process Uses

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

Process represents a plugin subprocess.

func (*Process) Done Uses

func (p *Process) Done() <-chan struct{}

Done returns a channel that closes when the plugin terminates.

func (*Process) Err Uses

func (p *Process) Err() error

Err returns an error if the plugin terminated (gracefully or not).

Valid only if Done() is already closed, nil otherwise.

func (*Process) Terminate Uses

func (p *Process) Terminate(ctx context.Context) error

Terminate tries to gracefully terminate the plugin process, killing it with SIGKILL on the context expiration or after 5 sec.

Returns the same value as Err(). Does nothing if the process is already terminated.

type RepositoryClient Uses

type RepositoryClient interface {
    // Lists metadata entries attached to an instance.
    ListMetadata(ctx context.Context, in *api.ListMetadataRequest, opts ...grpc.CallOption) (*api.ListMetadataResponse, error)
}

RepositoryClient is a subset of api.RepositoryClient available to plugins.

type RunLoop Uses

type RunLoop func(context.Context, *grpc.ClientConn) error

RunLoop executes some concrete plugin logic.

It should run some kind of a loop until the context is canceled. It happens when the host decides to terminate the plugin.

Any logging done on this context goes to the host.

Directories

PathSynopsis
admissionPackage admission implements CIPD deployment admission plugins.
admission/example
protocolPackage protocol hosts protobuf messages for the CIPD plugin system.

Package plugin imports 24 packages (graph) and is imported by 2 packages. Updated 2020-11-27. Refresh now. Tools for package owners.