workerproto

package
v0.0.0-...-30d97dc Latest Latest
Warning

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

Go to latest
Published: May 14, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

This package contains an implementation of worker-runner's worker protocol.

It is used to communicate with worker-runner in order to signal shutdown, log and refresh credentials, for example.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddGracefulTermination

func AddGracefulTermination(c *Communicator) <-chan bool

AddGracefulTermination adds worker support for being asked to exit gracefully.

func AddLogger

func AddLogger(c *Communicator, parent logr.Logger) logr.Logger

AddLogger adds logger support to the communicator.

This must be called before Run() is called on the communicator.

func AddRemoteShutdown

func AddRemoteShutdown(c *Communicator) func() error

AddRemoteShutdown adds worker support for being remotely shutdown by the runner.

func Parse

func Parse(log logr.Logger, r io.Reader, f ProtoHandler) error

Parse is a low-level function used to parse the input stream for a workerproto.

func Write

func Write(w io.Writer, packet interface{}) error

Write is a low-level transport function which writes a single workerproto message to an output stream.

Types

type Communicator

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

Communicator runs a duplex stream to the worker-runner.

func NewCommunicator

func NewCommunicator(log logr.Logger, isWorker bool) *Communicator

NewCommunicator creates a new communicator given the log and whather the communicator should act as the worker or runner.

Run must be called with the input and output streams to manage the communicator.

func (*Communicator) AddCapability

func (c *Communicator) AddCapability(cap string)

AddCapability marks this communicator as supporting a given capability.

It must not be called after Run() has been called.

func (*Communicator) AddHandler

func (c *Communicator) AddHandler(packetType string, handler MessageHandler)

AddHandler adds a handler for a given packet type.

It must not be called after Run() has been called.

func (*Communicator) HasCapability

func (c *Communicator) HasCapability(cap string) bool

HasCapability returns true if both ends support a capability.

func (*Communicator) Run

func (c *Communicator) Run(r io.Reader, w io.Writer) error

Run this communicator until the streams are closed or an error occurs.

func (*Communicator) Send

func (c *Communicator) Send(packet interface{}) error

Send a packet over the communicator.

type MessageHandler

type MessageHandler = func(packet []byte) error

MessageHandler is used to implement a single workerproto packet.

type ProtoHandler

type ProtoHandler = func(packetType string, msg []byte) error

ProtoHandler is used by the low-level transport code to handle messages from an input stream.

Jump to

Keyboard shortcuts

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