modagent

package
v16.3.0-rc6 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The field manager name for the ones agentk owns, see
	// https://kubernetes.io/docs/reference/using-api/server-side-apply/#field-management
	FieldManager = "agentk"
)

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)
	GetGitLabExternalUrl(ctx context.Context) (url.URL, error)
}

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 *entity.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
	// IsProducingLeaderModules returns if the modules that this Factory produces are leader modules or not.
	// A leader module must only be run once across all agent replicas.
	IsProducingLeaderModules() bool
	// 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 Module

type Module interface {
	// Run runs the module.
	// Run must block until the context signals done or the cfg channel is closed. Run must not return before that.
	// 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 is responsible that it acts according to the received configuration, even if that is just to wait for
	// a new one.
	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

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

type Worker

type Worker interface {
	Run(context.Context)
}

type WorkerFactory

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

type WorkerManager

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

func NewWorkerManager

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

func (*WorkerManager[C]) ApplyConfiguration

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

func (*WorkerManager[C]) StopAllWorkers

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

Jump to

Keyboard shortcuts

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