modagent

package
v14.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	KnownFeatures = map[Feature]string{}
)

Functions

func InjectRpcApi added in v14.2.0

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

func StreamRpcApiInterceptor added in v14.2.0

func StreamRpcApiInterceptor(factory RpcApiFactory) grpc.StreamServerInterceptor

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

func UnaryRpcApiInterceptor added in v14.2.0

func UnaryRpcApiInterceptor(factory RpcApiFactory) grpc.UnaryServerInterceptor

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

Types

type Api added in v14.2.0

type Api interface {
	modshared.Api
	MakeGitLabRequest(ctx context.Context, path string, opts ...GitLabRequestOption) (*GitLabResponse, error)
	ToggleFeature(feature Feature, enabled bool)
	SubscribeToFeatureStatus(feature Feature, cb SubscribeCb)
}

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
}

Config holds configuration for a Module.

type Factory

type Factory interface {
	// New creates a new instance of a Module.
	New(*Config) (Module, error)
	// Name returns module's name.
	Name() string
}

type Feature

type Feature int

Feature describes a particular feature that can be enabled or disabled by a module. If module is configured in a way that requires use of a feature, it should indicate that it needs the feature. All features are disabled by default.

const (
	// Invalid is an invalid sentinel value.
	// Treat default value as "invalid" to avoid accidental confusion.
	Invalid Feature = iota
)

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 added in v14.4.0

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 starts the module.
	// Run can block until the context is canceled or exit with nil if there is nothing to do.
	// cfg is a channel that gets configuration updates sent to it. It's closed when the module should shut down.
	// cfg is a shared instance, 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 added in v14.2.0

type RpcApi interface {
	modshared.RpcApi
}

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

func RpcApiFromContext added in v14.2.0

func RpcApiFromContext(ctx context.Context) RpcApi

type RpcApiFactory added in v14.2.0

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

type SubscribeCb

type SubscribeCb func(enabled bool)

Jump to

Keyboard shortcuts

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