apiserver

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: Apache-2.0 Imports: 37 Imported by: 0

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

View Source
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

func NewAPIServer(config Config) (*APIServer, error)

NewAPIServer creates a new API server instance with the provided config.

func (*APIServer) GetConfig

func (s *APIServer) GetConfig() *rest.Config

GetConfig returns a REST config for accessing the API server.

func (*APIServer) GetScheme

func (s *APIServer) GetScheme() *runtime.Scheme

GetScheme returns the scheme used by the API server.

func (*APIServer) GetServerAddress

func (s *APIServer) GetServerAddress() string

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) Start

func (s *APIServer) Start(ctx context.Context) error

Start initiates the API server lifecycle. It blocks.

func (*APIServer) UnregisterAPIGroup

func (s *APIServer) UnregisterAPIGroup(group string)

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

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

Get retrieves a single object by name.

func (*ClientDelegatedStorage) GetSingularName

func (s *ClientDelegatedStorage) GetSingularName() string

SingularNameProvider returns singular name of resources.

func (*ClientDelegatedStorage) List

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

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

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.

func (*CompositeCodec) Encode

func (c *CompositeCodec) Encode(obj runtime.Object, w io.Writer) error

Encode overrides the embedded codec's Encode method.

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.

func (*Config) String

func (c *Config) String() string

String returns the status for the API server.

type GroupGVKs

type GroupGVKs = map[string]map[schema.GroupVersionKind]bool

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

type StorageProvider func(*runtime.Scheme, generic.RESTOptionsGetter) (rest.Storage, error)

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.

Jump to

Keyboard shortcuts

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