Documentation
¶
Overview ¶
Package apiserver implements a Kubernetes API extension server that provides REST endpoints for Δ-controller view resources.
The API server extends the Kubernetes API server pattern to serve custom view resources dynamically. It provides a complete REST API implementation with support for standard Kubernetes operations (GET, LIST, CREATE, UPDATE, DELETE, WATCH) on view objects.
Key components:
- APIServer: Main server struct that handles HTTP requests and routing.
- ClientDelegatedStorage: Storage implementation that delegates to controller-runtime clients.
- CompositeCodec: Custom encoding/decoding for view objects.
- Registry: Dynamic API group and resource registration.
The server supports both secure (HTTPS) and insecure (HTTP) modes, with configurable authentication and authorization. It integrates with the composite client system to serve view objects from the view cache while delegating native Kubernetes resources to the standard API server.
Example usage:
config := apiserver.Config{ DelegatingClient: client, UseHTTP: true, Logger: logger, } server, _ := apiserver.NewAPIServer(config) return server.Start(ctx)
Index ¶
- Constants
- type APIServer
- func (s *APIServer) GetConfig() *rest.Config
- func (s *APIServer) GetScheme() *runtime.Scheme
- func (s *APIServer) GetServerAddress() string
- func (s *APIServer) RegisterAPIGroup(group string, gvks []schema.GroupVersionKind) error
- func (s *APIServer) RegisterGVKs(gvks []schema.GroupVersionKind) error
- func (s *APIServer) Start(ctx context.Context) error
- func (s *APIServer) UnregisterAPIGroup(group string)
- func (s *APIServer) UnregisterGVKs(gvks []schema.GroupVersionKind)
- type ClientDelegatedStorage
- func (s *ClientDelegatedStorage) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error)
- func (s *ClientDelegatedStorage) Create(ctx context.Context, obj runtime.Object, ...) (runtime.Object, error)
- func (s *ClientDelegatedStorage) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, ...) (runtime.Object, bool, error)
- func (s *ClientDelegatedStorage) DeleteCollection(ctx context.Context, deleteValidation rest.ValidateObjectFunc, ...) (runtime.Object, error)
- func (s *ClientDelegatedStorage) Destroy()
- func (s *ClientDelegatedStorage) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error)
- func (s *ClientDelegatedStorage) GetSingularName() string
- func (s *ClientDelegatedStorage) List(ctx context.Context, options *metainternalversion.ListOptions) (runtime.Object, error)
- func (s *ClientDelegatedStorage) NamespaceScoped() bool
- func (s *ClientDelegatedStorage) New() runtime.Object
- func (s *ClientDelegatedStorage) NewList() runtime.Object
- func (s *ClientDelegatedStorage) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, ...) (runtime.Object, bool, error)
- func (s *ClientDelegatedStorage) Watch(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
- type CompositeCodec
- type CompositeCodecFactory
- func (f *CompositeCodecFactory) CodecForVersions(encoder runtime.Encoder, decoder runtime.Decoder, ...) runtime.Codec
- func (f *CompositeCodecFactory) DecoderToVersion(decoder runtime.Decoder, gv runtime.GroupVersioner) runtime.Decoder
- func (f *CompositeCodecFactory) EncoderForVersion(encoder runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder
- func (f *CompositeCodecFactory) SupportedMediaTypes() []runtime.SerializerInfo
- type Config
- type GroupGVKs
- type RESTOptionsGetter
- type Resource
- type StorageProvider
Constants ¶
const DefaultAPIServerPort = 18443
DefaultAPIServerPort defines the default port used for the API server.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIServer ¶
type APIServer struct {
// contains filtered or unexported fields
}
APIServer manages a Kubernetes API server with dynamic GVK registration. Currently all view resources per each running operator are available via the API server. Only view resources can be queried, native Kubernetes API groups (e.g., "core/v1" and "apps/v1") must be queried from the native Kubernetes API server.
func NewAPIServer ¶
NewAPIServer creates a new API server instance with the provided config.
func (*APIServer) GetServerAddress ¶
GetServerAddress returns the address and the port of the running API server.
func (*APIServer) RegisterAPIGroup ¶
func (s *APIServer) RegisterAPIGroup(group string, gvks []schema.GroupVersionKind) error
RegisterAPIGroup installs an API group with all its registered GVKs to the API server.
func (*APIServer) RegisterGVKs ¶
func (s *APIServer) RegisterGVKs(gvks []schema.GroupVersionKind) error
RegisterGVKs registers a set of GVks with the embedded API server. Divides the GVKs per group, checks if none of the groups have already been registered, and registers each group and the corresponding GVKs.
func (*APIServer) UnregisterAPIGroup ¶
UnregisterGVK removes an API group with all its registered GVKs.
func (*APIServer) UnregisterGVKs ¶
func (s *APIServer) UnregisterGVKs(gvks []schema.GroupVersionKind)
UnregisterGVKs unregisters a set of GVks.
type ClientDelegatedStorage ¶
type ClientDelegatedStorage struct {
// contains filtered or unexported fields
}
Clientdelegatedstorage implements REST storage by delegating all operations to a controller-runtime client.
func (*ClientDelegatedStorage) ConvertToTable ¶
func (s *ClientDelegatedStorage) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error)
ConvertToTable converts objects to table format for kubectl output.
func (*ClientDelegatedStorage) Create ¶
func (s *ClientDelegatedStorage) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error)
Create creates a new object.
func (*ClientDelegatedStorage) Delete ¶
func (s *ClientDelegatedStorage) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions) (runtime.Object, bool, error)
Delete deletes an object.
func (*ClientDelegatedStorage) DeleteCollection ¶
func (s *ClientDelegatedStorage) DeleteCollection(ctx context.Context, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions, listOptions *metainternalversion.ListOptions) (runtime.Object, error)
DeleteCollection deletes a collection of objects.
func (*ClientDelegatedStorage) Destroy ¶
func (s *ClientDelegatedStorage) Destroy()
Destroy cleans up any resources (no-op for client-delegated storage).
func (*ClientDelegatedStorage) Get ¶
func (s *ClientDelegatedStorage) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error)
Get retrieves a single object by name.
func (*ClientDelegatedStorage) GetSingularName ¶
func (s *ClientDelegatedStorage) GetSingularName() string
SingularNameProvider returns singular name of resources.
func (*ClientDelegatedStorage) List ¶
func (s *ClientDelegatedStorage) List(ctx context.Context, options *metainternalversion.ListOptions) (runtime.Object, error)
List retrieves a list of objects.
func (*ClientDelegatedStorage) NamespaceScoped ¶
func (s *ClientDelegatedStorage) NamespaceScoped() bool
NamespaceScoped returns true if the resource is namespace-scoped.
func (*ClientDelegatedStorage) New ¶
func (s *ClientDelegatedStorage) New() runtime.Object
New returns a new empty object for this resource.
func (*ClientDelegatedStorage) NewList ¶
func (s *ClientDelegatedStorage) NewList() runtime.Object
NewList returns a new empty list object for this resource.
func (*ClientDelegatedStorage) Update ¶
func (s *ClientDelegatedStorage) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error)
Update updates an existing object.
func (*ClientDelegatedStorage) Watch ¶
func (s *ClientDelegatedStorage) Watch(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error)
Watch returns a watch interface for the resource.
type CompositeCodec ¶
type CompositeCodec struct { runtime.Codec // embed the default codec // contains filtered or unexported fields }
CompositeCodec embeds a runtime.Codec and overrides Encode for view objects.
func NewCompositeCodec ¶
func NewCompositeCodec(defaultCodec runtime.Codec, encoder runtime.Encoder) *CompositeCodec
NewCompositeCodec creates a new composite codec.
type CompositeCodecFactory ¶
type CompositeCodecFactory struct {
// contains filtered or unexported fields
}
CompositeCodecFactory implements a factory that creates composite codecs.
func NewCompositeCodecFactory ¶
func NewCompositeCodecFactory(defaultFactory serializer.CodecFactory, scheme *runtime.Scheme) *CompositeCodecFactory
NewCompositeCodecFactory creates a new composite codec factory.
func (*CompositeCodecFactory) CodecForVersions ¶
func (f *CompositeCodecFactory) CodecForVersions(encoder runtime.Encoder, decoder runtime.Decoder, encode runtime.GroupVersioner, decode runtime.GroupVersioner) runtime.Codec
CodecForVersions implements serializer.CodecFactory.
func (*CompositeCodecFactory) DecoderToVersion ¶
func (f *CompositeCodecFactory) DecoderToVersion(decoder runtime.Decoder, gv runtime.GroupVersioner) runtime.Decoder
DecoderToVersion returns a decoder that ensures objects being read by the provided serializer are in the provided group version by default.
func (*CompositeCodecFactory) EncoderForVersion ¶
func (f *CompositeCodecFactory) EncoderForVersion(encoder runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder
EncoderForVersion returns an encoder that ensures objects being written to the provided serializer are in the provided group version.
func (*CompositeCodecFactory) SupportedMediaTypes ¶
func (f *CompositeCodecFactory) SupportedMediaTypes() []runtime.SerializerInfo
SupportedMediaTypes is the media types supported for reading and writing single objects.
type Config ¶
type Config struct { *genericapiserver.RecommendedConfig // Addr is the server address. Addr *net.TCPAddr // UseHTTP switches the API server to insecure serving mode. UseHTTP bool // DelegatingClient allows to inject a controller runtime client into the API server that // will be used by the server to serve requests. DelegatingClient client.Client // DiscoveryClient allows to inject a REST discovery client into the API server. Used // mostly for testing. DiscoveryClient composite.ViewDiscoveryInterface // Logger provides a logger for the API server. Logger logr.Logger }
Config defines the configuration for the embedded API server.
func NewDefaultConfig ¶
func NewDefaultConfig(addr string, port int, client client.Client, insecure bool, log logr.Logger) (Config, error)
NewDefaultConfig creates an API server configuration with sensible defaults, either using secure serving (HTTPS) or insecure serving (HTTP) that can be used for testing.
type RESTOptionsGetter ¶
type RESTOptionsGetter struct{}
RESTOptionsGetter provides basic REST options for custom storage.
func (*RESTOptionsGetter) GetRESTOptions ¶
func (r *RESTOptionsGetter) GetRESTOptions(resource schema.GroupResource, example runtime.Object) (generic.RESTOptions, error)
type Resource ¶
type Resource struct { // GVK is the GroupVersionKind for the resource. GVK schema.GroupVersionKind // APIResource is the discovered API resource def for a native object. APIResource *metav1.APIResource // HasStatus is true if the resource has a status field. HasStatus bool }
Resource defines a native or a view resource type for sources and targets.
type StorageProvider ¶
StorageProvider is our own type alias, replacing builderrest.ResourceHandlerProvider.
func NewClientDelegatedStorage ¶
func NewClientDelegatedStorage(delegatingClient client.Client, resource *Resource, log logr.Logger) StorageProvider
NewClientDelegatedStorage creates a new storage provider that delegates to controller-runtime client.