catalog

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: Apache-2.0 Imports: 14 Imported by: 10

Documentation

Overview

Package catalog provides the Catalog and corresponding builders.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GVHToPath

func GVHToPath(gvh GroupVersionHook, name string) string

GVHToPath calculates the path for a given GroupVersionHook. This func is aligned with Kubernetes paths for cluster-wide resources, e.g.: /apis/storage.k8s.io/v1/storageclasses/standard. Note: name is only appended if set, e.g. the Discovery hook does not have a name.

func HookName

func HookName(hookFunc Hook) string

HookName returns the name of the runtime hook. Note: The name of the hook is the name of the hookFunc.

Types

type Builder

type Builder struct {
	// GroupVersion is the GroupVersion used when registering
	// Hooks and OpenAPIDefinitions.
	GroupVersion schema.GroupVersion
	// contains filtered or unexported fields
}

Builder builds a Catalog to allow mappings between Go types and the corresponding GroupVersionHooks, metadata and OpenAPIDefinitions.

func (*Builder) AddToCatalog

func (bld *Builder) AddToCatalog(catalog *Catalog) error

AddToCatalog adds all registered Hooks with their request and response types and metadata and the OpenAPIDefinitions to the catalog.

func (*Builder) Build

func (bld *Builder) Build() (*Catalog, error)

Build returns a new Catalog containing all registered Hooks with their request and response types and metadata and the OpenAPIDefinitions.

func (*Builder) Register

func (bld *Builder) Register(f func(*runtime.Scheme) error)

Register adds a scheme setup function to the schemeBuilder. Note: This function is used by generated conversion code. If we would just expose the func from the embedded schemeBuilder directly it would not work because it is nil at that time and appending to a nil schemeBuilder doesn't propagate to our Builder.

func (*Builder) RegisterHook

func (bld *Builder) RegisterHook(hookFunc Hook, hookMeta *HookMeta) *Builder

RegisterHook registers a Hook with its request and response types and metadata. The passed in hookFunc must have the following type: func(*RequestType,*ResponseType) The name of the func becomes the "hook" field of the GroupVersionHook.

func (*Builder) RegisterOpenAPIDefinitions

func (bld *Builder) RegisterOpenAPIDefinitions(getter OpenAPIDefinitionsGetter) *Builder

RegisterOpenAPIDefinitions registers a func returning the OpenAPIDefinitions for request and response types of all Runtime Hooks of a given group version. NOTE: The OpenAPIDefinitionsGetter funcs in the API packages are generated by openapi-gen.

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

Catalog contains all information about RuntimeHooks defined in Cluster API, including mappings between RuntimeHook functions and the corresponding GroupVersionHooks, metadata and OpenAPIDefinitions.

func New

func New() *Catalog

New creates a new Catalog.

func (*Catalog) AddHook

func (c *Catalog) AddHook(gv schema.GroupVersion, hookFunc Hook, hookMeta *HookMeta)

AddHook adds a RuntimeHook function and its request and response types with the gv GroupVersion. The passed in hookFunc must have the following type: func(*RequestType,*ResponseType) The name of the func becomes the "Hook" in GroupVersionHook. GroupVersion must not have empty fields.

func (*Catalog) AddOpenAPIDefinitions

func (c *Catalog) AddOpenAPIDefinitions(getter OpenAPIDefinitionsGetter)

AddOpenAPIDefinitions adds an OpenAPIDefinitionsGetter.

func (*Catalog) Convert

func (c *Catalog) Convert(in, out interface{}, context interface{}) error

Convert will attempt to convert in into out. Both must be pointers. Returns an error if the conversion isn't possible.

func (*Catalog) GroupVersionHook

func (c *Catalog) GroupVersionHook(hookFunc Hook) (GroupVersionHook, error)

GroupVersionHook returns the GVH of the hookFunc or an error if hook is not a function or not registered.

func (*Catalog) GroupVersionKind

func (c *Catalog) GroupVersionKind(obj runtime.Object) (schema.GroupVersionKind, error)

GroupVersionKind returns the GVK of the object or an error if the object is not a pointer or not registered.

func (*Catalog) IsHookRegistered

func (c *Catalog) IsHookRegistered(gvh GroupVersionHook) bool

IsHookRegistered returns true if the GroupVersionHook is registered with the catalog.

func (*Catalog) NewRequest

func (c *Catalog) NewRequest(hook GroupVersionHook) (runtime.Object, error)

NewRequest returns a request object for a GroupVersionHook.

func (*Catalog) NewResponse

func (c *Catalog) NewResponse(hook GroupVersionHook) (runtime.Object, error)

NewResponse returns a response object for a GroupVersionHook.

func (*Catalog) OpenAPI

func (c *Catalog) OpenAPI(version string) (*spec3.OpenAPI, error)

OpenAPI generates and returns the OpenAPI spec.

func (*Catalog) Request

Request returns the GroupVersionKind of the request of a GroupVersionHook.

func (*Catalog) Response

func (c *Catalog) Response(hook GroupVersionHook) (schema.GroupVersionKind, error)

Response returns the GroupVersionKind of the response of a GroupVersionHook.

func (*Catalog) ValidateRequest

func (c *Catalog) ValidateRequest(hook GroupVersionHook, obj runtime.Object) error

ValidateRequest validates a request object. Specifically it validates that the GVK of an object matches the GVK of the request of the Hook.

func (*Catalog) ValidateResponse

func (c *Catalog) ValidateResponse(hook GroupVersionHook, obj runtime.Object) error

ValidateResponse validates a response object. Specifically it validates that the GVK of an object matches the GVK of the response of the Hook.

type GroupHook

type GroupHook struct {
	Group string
	Hook  string
}

GroupHook represents Group and Hook of a GroupVersionHook. This can be used instead of GroupVersionHook when Version should not be used.

func (GroupHook) String

func (gh GroupHook) String() string

String returns a string representation of a GroupHook.

type GroupVersionHook

type GroupVersionHook struct {
	Group   string
	Version string
	Hook    string
}

GroupVersionHook unambiguously identifies a Hook.

func (GroupVersionHook) Empty

func (gvh GroupVersionHook) Empty() bool

Empty returns true if group, version and hook are empty.

func (GroupVersionHook) GroupHook

func (gvh GroupVersionHook) GroupHook() GroupHook

GroupHook returns the GroupHook of a GroupVersionHook.

func (GroupVersionHook) GroupVersion

func (gvh GroupVersionHook) GroupVersion() schema.GroupVersion

GroupVersion returns the GroupVersion of a GroupVersionHook.

func (GroupVersionHook) String

func (gvh GroupVersionHook) String() string

String returns a string representation of a GroupVersionHook.

type Hook

type Hook interface{}

Hook is a marker interface for a RuntimeHook function. RuntimeHook functions should be defined as a: func(*RequestType, *ResponseType). The name of the func should be the name of the hook.

type HookMeta

type HookMeta struct {
	// Summary of the hook.
	Summary string

	// Description of the hook.
	Description string

	// Tags of the hook.
	Tags []string

	// Deprecated signals if the hook is deprecated.
	Deprecated bool

	// Singleton signals if the hook can only be implemented once on a
	// Runtime Extension, e.g. like the Discovery hook.
	Singleton bool
}

HookMeta holds metadata for a Hook, which is used to generate the OpenAPI definition for a Hook.

type OpenAPIDefinitionsGetter

type OpenAPIDefinitionsGetter func(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition

OpenAPIDefinitionsGetter defines a func which returns OpenAPI definitions for all request and response types of a GroupVersion. NOTE: The OpenAPIDefinitionsGetter funcs in the API packages are generated by openapi-gen.

Jump to

Keyboard shortcuts

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