modagent

package
v15.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InjectRpcApi

func InjectRpcApi(ctx context.Context, rpcApi RpcApi) context.Context

func StreamRpcApiInterceptor

func StreamRpcApiInterceptor(factory RpcApiFactory) grpc.StreamServerInterceptor

StreamRpcApiInterceptor returns a new stream server interceptor that augments connection context with a RpcApi.

func UnaryRpcApiInterceptor

func UnaryRpcApiInterceptor(factory RpcApiFactory) grpc.UnaryServerInterceptor

UnaryRpcApiInterceptor returns a new unary server interceptor that augments connection context with a RpcApi.

Types

type Api

type Api interface {
	modshared.Api
	MakeGitLabRequest(ctx context.Context, path string, opts ...GitLabRequestOption) (*GitLabResponse, error)
	GetAgentId(ctx context.Context) (int64, error)
	TryGetAgentId() (int64, bool)
}

Api provides the API for the module to use.

type Config

type Config struct {
	// Log can be used for logging from the module.
	// It should not be used for logging from gRPC API methods. Use grpctool.LoggerFromContext(ctx) instead.
	Log       *zap.Logger
	AgentMeta *modshared.AgentMeta
	Api       Api
	// K8sUtilFactory provides means to interact with the Kubernetes cluster agentk is running in.
	K8sUtilFactory util.Factory
	// KasConn is the gRPC connection to gitlab-kas.
	KasConn grpc.ClientConnInterface
	// Server is a gRPC server that can be used to expose API endpoints to gitlab-kas and/or GitLab.
	// This can be used to add endpoints in Factory.New.
	// Request handlers can obtain the per-request logger using grpctool.LoggerFromContext(requestContext).
	Server *grpc.Server
	// AgentName is a string "gitlab-agent". Can be used as a user agent, server name, service name, etc.
	AgentName string
	// ServiceAccountName is a string defined by default as "gitlab-agent".
	ServiceAccountName string
}

Config holds configuration for a Module.

type Factory

type Factory interface {
	modshared.Factory
	// New creates a new instance of a Module.
	New(*Config) (Module, error)
}

type GitLabRequestConfig

type GitLabRequestConfig struct {
	Method string
	Header http.Header
	Query  url.Values
	Body   io.ReadCloser
}

func ApplyRequestOptions

func ApplyRequestOptions(opts []GitLabRequestOption) (*GitLabRequestConfig, error)

type GitLabRequestOption

type GitLabRequestOption func(*GitLabRequestConfig) error

func WithJsonRequestBody

func WithJsonRequestBody(body interface{}) GitLabRequestOption

func WithRequestBody

func WithRequestBody(body io.Reader, contentType string) GitLabRequestOption

WithRequestBody specifies request body to send and HTTP Content-Type header if contentType is not empty. If body implements io.ReadCloser, its Close() method will be called once the data has been sent. If body is nil, no body or Content-Type header is sent.

func WithRequestHeader

func WithRequestHeader(header string, values ...string) GitLabRequestOption

func WithRequestMethod

func WithRequestMethod(method string) GitLabRequestOption

WithRequestMethod specifies request HTTP method.

func WithRequestQueryParam

func WithRequestQueryParam(key string, values ...string) GitLabRequestOption

type GitLabResponse

type GitLabResponse struct {
	Status     string // e.g. "200 OK"
	StatusCode int32  // e.g. 200
	Header     http.Header
	Body       io.ReadCloser
}

type LeaderModule added in v15.4.0

type LeaderModule interface {
	Module
	IsRunnableConfiguration(cfg *agentcfg.AgentConfiguration) bool
	// Run runs the module. It is invoked when both conditions are satisfied:
	// - agentk acquires the leader lock.
	// - IsRunnableConfiguration() returns true for a configuration.
	// The passed context signals done when the module should fully shut down, including when the lock is lost,
	// or when IsRunnableConfiguration() returns false.
	// cfg keeps supplying configuration while IsRunnableConfiguration() is returning true for new values.
	// Same module instance is used for multiple RunLeader() calls.
	// Otherwise, this API works exactly as Module.Run.
	Run(ctx context.Context, cfg <-chan *agentcfg.AgentConfiguration) error
}

type Module

type Module interface {
	// Run runs the module.
	// Run can block until the context signals done or return if there is nothing to do or if there was an error.
	// cfg is a channel that gets configuration updates sent to it. It's closed when the module should shut down.
	// cfg sends configuration objects that are shared and must not be mutated.
	// Module should make a copy if it needs to mutate the object.
	// Applying configuration may take time, the provided context may signal done if module should shut down.
	// cfg only provides the latest available configuration, intermediate configuration states are discarded.
	Run(ctx context.Context, cfg <-chan *agentcfg.AgentConfiguration) error
	// DefaultAndValidateConfiguration applies defaults and validates the passed configuration.
	// It is called each time on configuration update before sending it via the channel passed to Run().
	// cfg is a shared instance, module can mutate only the part of it that it owns and only inside of this method.
	DefaultAndValidateConfiguration(cfg *agentcfg.AgentConfiguration) error
	// Name returns module's name.
	Name() string
}

type RpcApi

type RpcApi interface {
	modshared.RpcApi
}

RpcApi provides the API for the module's gRPC handlers to use.

func RpcApiFromContext

func RpcApiFromContext(ctx context.Context) RpcApi

type RpcApiFactory

type RpcApiFactory func(ctx context.Context, method string) RpcApi

type WorkSource added in v15.7.0

type WorkSource[C proto.Message] interface {
	ID() string
	Configuration() C
}

type Worker added in v15.7.0

type Worker interface {
	Run(context.Context)
}

type WorkerFactory added in v15.7.0

type WorkerFactory[C proto.Message] interface {
	New(agentId int64, source WorkSource[C]) Worker
	SourcesFromConfiguration(*agentcfg.AgentConfiguration) []WorkSource[C]
}

type WorkerManager added in v15.7.0

type WorkerManager[C proto.Message] struct {
	// contains filtered or unexported fields
}

func NewWorkerManager added in v15.7.0

func NewWorkerManager[C proto.Message](log *zap.Logger, workerFactory WorkerFactory[C]) *WorkerManager[C]

func (*WorkerManager[C]) ApplyConfiguration added in v15.7.0

func (m *WorkerManager[C]) ApplyConfiguration(agentId int64, cfg *agentcfg.AgentConfiguration) error

func (*WorkerManager[C]) StopAllWorkers added in v15.7.0

func (m *WorkerManager[C]) StopAllWorkers()

Jump to

Keyboard shortcuts

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