server

package
v0.0.0-...-623d1b0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2024 License: Apache-2.0 Imports: 29 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Target_name = map[int32]string{
		0: "Active",
		1: "Default",
	}
	Target_value = map[string]int32{
		"Active":  0,
		"Default": 1,
	}
)

Enum value maps for Target.

View Source
var (
	Action_name = map[int32]string{
		0: "NoAction",
		1: "Set",
		2: "Reset",
	}
	Action_value = map[string]int32{
		"NoAction": 0,
		"Set":      1,
		"Reset":    2,
	}
)

Enum value maps for Action.

View Source
var File_github_com_kralicky_protoconfig_server_types_proto protoreflect.FileDescriptor

Functions

func ApplyOptions

func ApplyOptions(dest any, opts ...Option) error

func CopyRevision

func CopyRevision[T Revisioner](dst, src T)

func DiffStat

func DiffStat(diff string, opts ...jsondiff.Options) string

func GetRevisionFieldIndex

func GetRevisionFieldIndex[T Revisioner]() int

func MarshalConfigJson

func MarshalConfigJson(t proto.Message) []byte

func RenderJsonDiff

func RenderJsonDiff[T proto.Message](old, new T, opts jsondiff.Options) (string, bool)

func SetRevision

func SetRevision[T Revisioner](t T, value int64, maybeTimestamp ...time.Time)

func UnsetRevision

func UnsetRevision[T Revisioner](t T)

Types

type Action

type Action int32
const (
	Action_NoAction Action = 0
	Action_Set      Action = 1
	Action_Reset    Action = 2
)

func (Action) Descriptor

func (Action) Descriptor() protoreflect.EnumDescriptor

func (Action) Enum

func (x Action) Enum() *Action

func (Action) EnumDescriptor deprecated

func (Action) EnumDescriptor() ([]byte, []int)

Deprecated: Use Action.Descriptor instead.

func (Action) Number

func (x Action) Number() protoreflect.EnumNumber

func (Action) String

func (x Action) String() string

func (Action) Type

func (Action) Type() protoreflect.EnumType

type BaseConfigServer

type BaseConfigServer[
	G GetRequestType,
	S SetRequestType[T],
	R ResetRequestType[T],
	H HistoryRequestType,
	HR HistoryResponseType[T],
	T ConfigType[T],
] struct {
	// contains filtered or unexported fields
}

Implements a subset of methods usually required by a server which uses a DefaultingConfigTracker to manage its configuration. These implementations should not vary between drivers, so they are provided here as a convenience.

func (*BaseConfigServer[G, S, R, H, HR, T]) Build

func (*BaseConfigServer[G, S, R, H, HR, T]) Build(
	defaultStore, activeStore storage.ValueStoreT[T],
	loadDefaultsFunc DefaultLoaderFunc[T],
) *BaseConfigServer[G, S, R, H, HR, T]

Returns a new instance of the BaseConfigServer with the defined type. Can be called from a nil pointer of the BaseConfigServer type. Example: var server *BaseConfigServer[...] server = server.Build()

func (*BaseConfigServer[G, S, R, H, HR, T]) Get

func (s *BaseConfigServer[G, S, R, H, HR, T]) Get(ctx context.Context, in G) (T, error)

func (*BaseConfigServer[G, S, R, H, HR, T]) GetDefault

func (s *BaseConfigServer[G, S, R, H, HR, T]) GetDefault(ctx context.Context, in G) (T, error)

func (*BaseConfigServer[G, S, R, H, HR, T]) History

func (s *BaseConfigServer[G, S, R, H, HR, T]) History(ctx context.Context, in H) (HR, error)

func (*BaseConfigServer[G, S, R, H, HR, T]) Reset

func (s *BaseConfigServer[G, S, R, H, HR, T]) Reset(ctx context.Context, in R) (*emptypb.Empty, error)

func (*BaseConfigServer[G, S, R, H, HR, T]) ResetDefault

func (s *BaseConfigServer[G, S, R, H, HR, T]) ResetDefault(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error)

func (*BaseConfigServer[G, S, R, H, HR, T]) ServerDryRun

func (s *BaseConfigServer[G, S, R, H, HR, T]) ServerDryRun(ctx context.Context, req DryRunRequestType[T]) (DryRunResults[T], error)

ServerDryRun sends a dry-run request to the tracker and returns the results in a generic wrapper type.

Because DryRun is an optional config server API, the request and response types are not part of the collection of required type parameters for this server. The typed request can be passed directly to ServerDryRun using the generic interface DryRunRequestType[T], which it will already implement if the request is well-formed. The corresponding response type can't be known at compile-time, so the caller will need to translate the generic response type DryRunResults[T] into the correct response type for the rpc.

This is typically most of the work required to implement a dry-run endpoint, but callers may wish to perform additional validation on the modified config before returning the dry-run response to the client using the typed dry-run response message.

If the config type has validation rules defined using protovalidate, they will be run against the modified config and included in this response.

func (*BaseConfigServer[G, S, R, H, HR, T]) Set

func (s *BaseConfigServer[G, S, R, H, HR, T]) Set(ctx context.Context, in S) (*emptypb.Empty, error)

func (*BaseConfigServer[G, S, R, H, HR, T]) SetDefault

func (s *BaseConfigServer[G, S, R, H, HR, T]) SetDefault(ctx context.Context, in S) (*emptypb.Empty, error)

func (*BaseConfigServer[G, S, R, H, HR, T]) Tracker

func (s *BaseConfigServer[G, S, R, H, HR, T]) Tracker() *DefaultingConfigTracker[T]

type BasicActiveServer

type BasicActiveServer[
	T ConfigType[T],
	G GetRequestType,
	S SetRequestType[T],
] interface {
	Get(context.Context, G) (T, error)
	Set(context.Context, S) (*emptypb.Empty, error)
}

type BasicDefaultServer

type BasicDefaultServer[
	T ConfigType[T],
	G GetRequestType,
	S SetRequestType[T],
] interface {
	GetDefault(context.Context, G) (T, error)
	SetDefault(context.Context, S) (*emptypb.Empty, error)
}

type BasicServer

type BasicServer[
	T ConfigType[T],
	G GetRequestType,
	S SetRequestType[T],
] interface {
	BasicDefaultServer[T, G, S]
	BasicActiveServer[T, G, S]
}

type Builder

type Builder[T any] func(ctx context.Context, opts ...Option) (T, error)

type Cache

type Cache[T any] interface {
	Register(name string, builder Builder[T])
	Unregister(name string)
	Get(name string) (Builder[T], bool)
	List() []string
	Range(func(name string, builder Builder[T]))
}

func NewCache

func NewCache[T any]() Cache[T]

type ClientContextInjector

type ClientContextInjector[T any] interface {
	NewClient(grpc.ClientConnInterface) T
	UnderlyingConn(T) grpc.ClientConnInterface
	ContextWithClient(context.Context, T) context.Context
	ClientFromContext(context.Context) (T, bool)
}

type ConfigServer

type ConfigServer[
	T ConfigType[T],
	G GetRequestType,
	S SetRequestType[T],
	R ResetRequestType[T],
	H HistoryRequestType,
	HR HistoryResponseType[T],
] interface {
	BasicServer[T, G, S]
	ResetServer[T, R]
	HistoryServer[T, H, HR]
}

type ConfigType

type ConfigType[T any] interface {
	proto.Message
	Revisioner
	SecretsRedactor[T]
}

type ContextKeyable

type ContextKeyable interface {
	proto.Message
	ContextKey() protoreflect.FieldDescriptor
}

type ContextKeyableConfigServer

type ContextKeyableConfigServer[
	G interface {
		GetRequestType
		ContextKeyable
	},
	S interface {
		SetRequestType[T]
		ContextKeyable
	},
	R interface {
		ResetRequestType[T]
		ContextKeyable
	},
	H interface {
		HistoryRequestType
		ContextKeyable
	},
	HR HistoryResponseType[T],
	T ConfigType[T],
] struct {
	// contains filtered or unexported fields
}

func (*ContextKeyableConfigServer[G, S, R, H, HR, T]) Build

func (*ContextKeyableConfigServer[G, S, R, H, HR, T]) Build(
	defaultStore storage.ValueStoreT[T],
	activeStore storage.KeyValueStoreT[T],
	loadDefaultsFunc DefaultLoaderFunc[T],
) *ContextKeyableConfigServer[G, S, R, H, HR, T]

Returns a new instance of the ContextKeyableConfigServer with the defined type. This is a conveience function to avoid repeating the type parameters.

func (*ContextKeyableConfigServer[G, S, R, H, HR, T]) Get

func (s *ContextKeyableConfigServer[G, S, R, H, HR, T]) Get(ctx context.Context, in G) (T, error)

func (*ContextKeyableConfigServer[G, S, R, H, HR, T]) GetDefault

func (s *ContextKeyableConfigServer[G, S, R, H, HR, T]) GetDefault(ctx context.Context, in G) (T, error)

func (*ContextKeyableConfigServer[G, S, R, H, HR, T]) History

func (s *ContextKeyableConfigServer[G, S, R, H, HR, T]) History(ctx context.Context, in H) (HR, error)

func (*ContextKeyableConfigServer[G, S, R, H, HR, T]) InjectContextKey

func (s *ContextKeyableConfigServer[G, S, R, H, HR, T]) InjectContextKey(ctx context.Context, in ContextKeyable) context.Context

func (*ContextKeyableConfigServer[G, S, R, H, HR, T]) Reset

func (s *ContextKeyableConfigServer[G, S, R, H, HR, T]) Reset(ctx context.Context, in R) (*emptypb.Empty, error)

func (*ContextKeyableConfigServer[G, S, R, H, HR, T]) ResetDefault

func (s *ContextKeyableConfigServer[G, S, R, H, HR, T]) ResetDefault(ctx context.Context, in *emptypb.Empty) (*emptypb.Empty, error)

func (*ContextKeyableConfigServer[G, S, R, H, HR, T]) ServerDryRun

func (s *ContextKeyableConfigServer[G, S, R, H, HR, T]) ServerDryRun(ctx context.Context, req interface {
	DryRunRequestType[T]
	ContextKeyable
},
) (DryRunResults[T], error)

func (*ContextKeyableConfigServer[G, S, R, H, HR, T]) Set

func (s *ContextKeyableConfigServer[G, S, R, H, HR, T]) Set(ctx context.Context, in S) (*emptypb.Empty, error)

func (*ContextKeyableConfigServer[G, S, R, H, HR, T]) SetDefault

func (s *ContextKeyableConfigServer[G, S, R, H, HR, T]) SetDefault(ctx context.Context, in S) (*emptypb.Empty, error)

type DefaultLoaderFunc

type DefaultLoaderFunc[T any] func(T)

type DefaultingConfigTracker

type DefaultingConfigTracker[T ConfigType[T]] struct {
	// contains filtered or unexported fields
}

func NewDefaultingActiveKeyedConfigTracker

func NewDefaultingActiveKeyedConfigTracker[T ConfigType[T]](
	defaultStore storage.ValueStoreT[T],
	activeStore storage.KeyValueStoreT[T],
	loadDefaultsFunc DefaultLoaderFunc[T],
) *DefaultingConfigTracker[T]

A config tracker that uses a single default store and many active stores, each with a unique key.

func NewDefaultingConfigTracker

func NewDefaultingConfigTracker[T ConfigType[T]](
	defaultStore, activeStore storage.ValueStoreT[T],
	loadDefaultsFunc DefaultLoaderFunc[T],
) *DefaultingConfigTracker[T]

func (*DefaultingConfigTracker[T]) ActiveStore

func (ct *DefaultingConfigTracker[T]) ActiveStore() storage.ValueStoreT[T]

func (*DefaultingConfigTracker[T]) Apply

func (ct *DefaultingConfigTracker[T]) Apply(ctx context.Context, newConfig T) error

Apply sets the active config by merging the given config onto the existing active config, or onto the default config if no active config has been set.

func (*DefaultingConfigTracker[T]) DryRun

func (*DefaultingConfigTracker[T]) DryRunApply

func (ct *DefaultingConfigTracker[T]) DryRunApply(ctx context.Context, newConfig T) (DryRunResults[T], error)

func (*DefaultingConfigTracker[T]) DryRunReset

func (ct *DefaultingConfigTracker[T]) DryRunReset(ctx context.Context, mask *fieldmaskpb.FieldMask, patch T, atRevision ...*corev1.Revision) (DryRunResults[T], error)

func (*DefaultingConfigTracker[T]) DryRunResetDefault

func (ct *DefaultingConfigTracker[T]) DryRunResetDefault(ctx context.Context, atRevision ...*corev1.Revision) (DryRunResults[T], error)

func (*DefaultingConfigTracker[T]) DryRunSetDefault

func (ct *DefaultingConfigTracker[T]) DryRunSetDefault(ctx context.Context, newDefault T) (DryRunResults[T], error)

func (*DefaultingConfigTracker[T]) Get

func (ct *DefaultingConfigTracker[T]) Get(ctx context.Context, atRevision ...*corev1.Revision) (T, error)

Returns the active config if it has been set, otherwise returns a "not found" error. An optional revision can be provided to get the config at a specific revision.

func (*DefaultingConfigTracker[T]) GetActiveOrDefault

func (ct *DefaultingConfigTracker[T]) GetActiveOrDefault(ctx context.Context, atRevision ...*corev1.Revision) (T, error)

Returns the active config if it has been set, otherwise returns the default config. The optional revision only applies to the active config; if it does not exist, the default config will always be at the latest revision.

func (*DefaultingConfigTracker[T]) GetDefault

func (ct *DefaultingConfigTracker[T]) GetDefault(ctx context.Context, atRevision ...*corev1.Revision) (T, error)

Gets the default config if one has been set, otherwise returns a new default config as defined by the type.

func (*DefaultingConfigTracker[T]) History

func (ct *DefaultingConfigTracker[T]) History(ctx context.Context, target Target, opts ...storage.HistoryOpt) ([]storage.KeyRevision[T], error)

func (*DefaultingConfigTracker[T]) Reset

func (ct *DefaultingConfigTracker[T]) Reset(ctx context.Context, mask *fieldmaskpb.FieldMask, patch T, atRevision ...*corev1.Revision) error

Restores the active config to match the default config. An optional field mask can be provided to specify which fields to keep from the current config. If a nil mask is given, the active config (potentially including history) is deleted from the underlying store. If a non-nil mask is given, the active config is only modified (preserving history), not deleted.

func (*DefaultingConfigTracker[T]) ResetDefault

func (ct *DefaultingConfigTracker[T]) ResetDefault(ctx context.Context, atRevision ...*corev1.Revision) error

Deletes the default config, leaving it unset. Subsequent calls to GetDefaultConfig will return a new default config as defined by the type.

func (*DefaultingConfigTracker[T]) SetDefault

func (ct *DefaultingConfigTracker[T]) SetDefault(ctx context.Context, newDefault T) error

Sets the default config directly. No merging is performed.

type DryRunClient

type DryRunClient[
	T ConfigType[T],
	D DryRunRequestType[T],
	DR DryRunResponseType[T],
] interface {
	DryRun(context.Context, D, ...grpc.CallOption) (DR, error)
}

type DryRunConfigServer

type DryRunConfigServer[
	T ConfigType[T],
	G GetRequestType,
	S SetRequestType[T],
	R ResetRequestType[T],
	H HistoryRequestType,
	HR HistoryResponseType[T],
	D DryRunRequestType[T],
	DR DryRunResponseType[T],
] interface {
	ConfigServer[T, G, S, R, H, HR]
	DryRunServer[T, D, DR]
}

type DryRunRequestType

type DryRunRequestType[
	T ConfigType[T],
] interface {
	proto.Message
	GetAction() Action
	GetTarget() Target
	GetSpec() T
	GetRevision() *corev1.Revision
	GetPatch() T
	GetMask() *fieldmaskpb.FieldMask
}

type DryRunResponseType

type DryRunResponseType[T ConfigType[T]] interface {
	proto.Message
	GetCurrent() T
	GetModified() T
	GetValidationErrors() *validate.Violations
}

type DryRunResults

type DryRunResults[T any] struct {
	Current          T
	Modified         T
	ValidationErrors *protovalidate.ValidationError
}

type DryRunServer

type DryRunServer[
	T ConfigType[T],
	D DryRunRequestType[T],
	DR DryRunResponseType[T],
] interface {
	DryRun(context.Context, D) (DR, error)
}

type GetClient

type GetClient[
	T ConfigType[T],
	G GetRequestType,
] interface {
	GetDefault(context.Context, G, ...grpc.CallOption) (T, error)
	Get(context.Context, G, ...grpc.CallOption) (T, error)
}

type GetRequest

type GetRequest struct {

	// If set, will return the config at the specified revision instead of
	// the current config.
	// This revision value can be obtained from the revision field of a
	// typed Get/GetDefault response, or from one of
	// the history entries in a typed History response.
	Revision *v1.Revision `protobuf:"bytes,1,opt,name=revision,proto3" json:"revision,omitempty"`
	// contains filtered or unexported fields
}

Get request options. See also: pkg/storage.GetOptions

func (*GetRequest) Descriptor deprecated

func (*GetRequest) Descriptor() ([]byte, []int)

Deprecated: Use GetRequest.ProtoReflect.Descriptor instead.

func (*GetRequest) FlagSet

func (in *GetRequest) FlagSet(prefix ...string) *pflag.FlagSet

func (*GetRequest) GetRevision

func (x *GetRequest) GetRevision() *v1.Revision

func (*GetRequest) ProtoMessage

func (*GetRequest) ProtoMessage()

func (*GetRequest) ProtoReflect

func (x *GetRequest) ProtoReflect() protoreflect.Message

func (*GetRequest) Reset

func (x *GetRequest) Reset()

func (*GetRequest) String

func (x *GetRequest) String() string

type GetRequestType

type GetRequestType interface {
	proto.Message
	flagutil.FlagSetter
	GetRevision() *corev1.Revision
}

Default constraint for a Get request. Not generic; the built-in message type server.GetRequest can be used for convenience

type HistoryClient

type HistoryClient[
	T ConfigType[T],
	H HistoryRequestType,
	HR HistoryResponseType[T],
] interface {
	History(context.Context, H, ...grpc.CallOption) (HR, error)
}

type HistoryRequest

type HistoryRequest struct {

	// The configuration type to return history for.
	Target Target `protobuf:"varint,1,opt,name=target,proto3,enum=server.Target" json:"target,omitempty"`
	// The latest modification revision to include in the returned history.
	Revision *v1.Revision `protobuf:"bytes,2,opt,name=revision,proto3" json:"revision,omitempty"`
	// If set, will include the values of the configuration in the response.
	// Otherwise, only the revision field of each entry will be populated.
	IncludeValues bool `protobuf:"varint,3,opt,name=includeValues,proto3" json:"includeValues,omitempty"`
	// contains filtered or unexported fields
}

History request options. See also: pkg/storage.HistoryOptions

func (*HistoryRequest) Descriptor deprecated

func (*HistoryRequest) Descriptor() ([]byte, []int)

Deprecated: Use HistoryRequest.ProtoReflect.Descriptor instead.

func (*HistoryRequest) FlagSet

func (in *HistoryRequest) FlagSet(prefix ...string) *pflag.FlagSet

func (*HistoryRequest) GetIncludeValues

func (x *HistoryRequest) GetIncludeValues() bool

func (*HistoryRequest) GetRevision

func (x *HistoryRequest) GetRevision() *v1.Revision

func (*HistoryRequest) GetTarget

func (x *HistoryRequest) GetTarget() Target

func (*HistoryRequest) ProtoMessage

func (*HistoryRequest) ProtoMessage()

func (*HistoryRequest) ProtoReflect

func (x *HistoryRequest) ProtoReflect() protoreflect.Message

func (*HistoryRequest) Reset

func (x *HistoryRequest) Reset()

func (*HistoryRequest) String

func (x *HistoryRequest) String() string

type HistoryRequestType

type HistoryRequestType interface {
	proto.Message
	flagutil.FlagSetter
	GetTarget() Target
	GetRevision() *corev1.Revision
	GetIncludeValues() bool
}

Default constraint for a History request. Not generic; the built-in message type server.HistoryRequest can be used for convenience

type HistoryResponseType

type HistoryResponseType[T ConfigType[T]] interface {
	proto.Message
	GetEntries() []T
}

type HistoryServer

type HistoryServer[
	T ConfigType[T],
	H HistoryRequestType,
	HR HistoryResponseType[T],
] interface {
	History(context.Context, H) (HR, error)
}

type ListType

type ListType[T any] interface {
	proto.Message
	GetItems() []T
}

type Option

type Option interface {
	Apply(dest any) error
}

func NewOption

func NewOption[T any](key string, value T) Option

type ResetActiveServer

type ResetActiveServer[
	T ConfigType[T],
	R ResetRequestType[T],
] interface {
	Reset(context.Context, R) (*emptypb.Empty, error)
}

type ResetClient

type ResetClient[
	T ConfigType[T],
	R ResetRequestType[T],
] interface {
	ResetDefault(context.Context, *emptypb.Empty, ...grpc.CallOption) (*emptypb.Empty, error)
	Reset(context.Context, R, ...grpc.CallOption) (*emptypb.Empty, error)
}

type ResetDefaultServer

type ResetDefaultServer[
	T ConfigType[T],
	R ResetRequestType[T],
] interface {
	ResetDefault(context.Context, *emptypb.Empty) (*emptypb.Empty, error)
}

type ResetRequestType

type ResetRequestType[T ConfigType[T]] interface {
	proto.Message
	GetRevision() *corev1.Revision
	GetMask() *fieldmaskpb.FieldMask
	GetPatch() T
}

type ResetServer

type ResetServer[
	T ConfigType[T],
	R ResetRequestType[T],
] interface {
	ResetDefaultServer[T, R]
	ResetActiveServer[T, R]
}

type Revisioner

type Revisioner interface {
	proto.Message
	GetRevision() *corev1.Revision
}

type SecretsRedactor

type SecretsRedactor[T any] interface {
	RedactSecrets()
	UnredactSecrets(T) error
}

type SetClient

type SetClient[
	T ConfigType[T],
	S SetRequestType[T],
] interface {
	SetDefault(context.Context, S, ...grpc.CallOption) (*emptypb.Empty, error)
	Set(context.Context, S, ...grpc.CallOption) (*emptypb.Empty, error)
}

type SetRequestType

type SetRequestType[T ConfigType[T]] interface {
	proto.Message
	GetSpec() T
}

type Target

type Target int32
const (
	Target_Active  Target = 0
	Target_Default Target = 1
)

func (Target) Descriptor

func (Target) Descriptor() protoreflect.EnumDescriptor

func (Target) Enum

func (x Target) Enum() *Target

func (Target) EnumDescriptor deprecated

func (Target) EnumDescriptor() ([]byte, []int)

Deprecated: Use Target.Descriptor instead.

func (Target) Number

func (x Target) Number() protoreflect.EnumNumber

func (Target) String

func (x Target) String() string

func (Target) Type

func (Target) Type() protoreflect.EnumType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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