k8s

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 23 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepCopyObject

func DeepCopyObject(in interface{}) runtime.Object

DeepCopyObject is an implementation of the receiver method required for implementing runtime.Object.

func ValidateNamespace

func ValidateNamespace(namespace string) error

ValidateNamespace validates that `namespace` is a valid Kubernetes namespace name.

Types

type Client

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

Client is a kubernetes-specific implementation of resource.Client, using custom resource definitions. A Client is specific to the Schema it was created with. New Clients should only be created via the ClientRegistry.ClientFor method.

func (*Client) Create

func (c *Client) Create(ctx context.Context, identifier resource.Identifier, obj resource.Object,
	options resource.CreateOptions) (resource.Object, error)

Create creates a new resource, and returns the resulting created resource

func (*Client) CreateInto

func (c *Client) CreateInto(ctx context.Context, identifier resource.Identifier, obj resource.Object,
	_ resource.CreateOptions, into resource.Object) error

CreateInto creates a new resource, and marshals the resulting created resource into `into`

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, identifier resource.Identifier) error

Delete deletes the specified resource

func (*Client) Get

func (c *Client) Get(ctx context.Context, identifier resource.Identifier) (resource.Object, error)

Get gets a resource of the client's internal Schema-derived kind, with the provided identifier

func (*Client) GetInto

func (c *Client) GetInto(ctx context.Context, identifier resource.Identifier, into resource.Object) error

GetInto gets a resource of the client's internal Schema-derived kind, with the provided identifier, and marshals it into `into`

func (*Client) List

func (c *Client) List(ctx context.Context, namespace string, options resource.ListOptions) (
	resource.ListObject, error)

List lists resources in the provided namespace. For resources with a schema.Scope() of ClusterScope, `namespace` must be resource.NamespaceAll

func (*Client) ListInto

func (c *Client) ListInto(ctx context.Context, namespace string, options resource.ListOptions,
	into resource.ListObject) error

ListInto lists resources in the provided namespace, and unmarshals the response into the provided resource.ListObject

func (*Client) Patch

func (c *Client) Patch(ctx context.Context, identifier resource.Identifier, patch resource.PatchRequest,
	options resource.PatchOptions) (resource.Object, error)

Patch performs a JSON Patch on the provided resource, and returns the updated object

func (*Client) PatchInto

func (c *Client) PatchInto(ctx context.Context, identifier resource.Identifier, patch resource.PatchRequest,
	options resource.PatchOptions, into resource.Object) error

PatchInto performs a JSON Patch on the provided resource, and marshals the updated version into the `into` field

func (*Client) RESTClient

func (c *Client) RESTClient() rest.Interface

RESTClient returns the underlying rest.Interface used to communicate with kubernetes

func (*Client) Update

func (c *Client) Update(ctx context.Context, identifier resource.Identifier, obj resource.Object,
	options resource.UpdateOptions) (resource.Object, error)

Update updates the provided resource, and returns the updated resource from kubernetes

func (*Client) UpdateInto

func (c *Client) UpdateInto(ctx context.Context, identifier resource.Identifier, obj resource.Object,
	options resource.UpdateOptions, into resource.Object) error

UpdateInto updates the provided resource, and marshals the updated resource from kubernetes into `into`

func (*Client) Watch

func (c *Client) Watch(ctx context.Context, namespace string, options resource.WatchOptions) (
	resource.WatchResponse, error)

Watch makes a watch request for the namespace, and returns a WatchResponse which wraps a kubernetes watch.Interface. The underlying watch.Interface can be accessed using KubernetesWatch()

type ClientConfig

type ClientConfig struct {
	// CustomMetadataIsAnyType tells the Client if the custom metadata of an object can be of any type, or is limited to only strings.
	// By default, this is false, with which the client will assume custom metadata is only a string type,
	// and not invoke reflection to turn the type into a string when encoding to the underlying kubernetes annotation storage.
	// If set to true, the client will use reflection to get the type of each custom metadata field,
	// and convert it into a string (structs and lists will be converted into stringified JSON).
	// Keep in mind that the metadata bytes blob used in unmarshaling will always have custom metadata as string types,
	// regardless of how this value is set, so make sure your resource.Object implementations can handle
	// turning strings into non-string types when unmarshaling if you plan to have custom metadata keys which have non-string values.
	CustomMetadataIsAnyType bool
}

ClientConfig is the configuration object for creating Clients.

func DefaultClientConfig

func DefaultClientConfig() ClientConfig

DefaultClientConfig returns a ClientConfig using defaults that assume you have used the SDK codegen tooling

type ClientRegistry

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

ClientRegistry implements resource.ClientGenerator, and keeps a cache of kubernetes clients based on GroupVersion (the largest unit a kubernetes rest.RESTClient can work with).

func NewClientRegistry

func NewClientRegistry(kubeCconfig rest.Config, clientConfig ClientConfig) *ClientRegistry

NewClientRegistry returns a new ClientRegistry which will make Client structs using the provided rest.Config

func (*ClientRegistry) ClientFor

func (c *ClientRegistry) ClientFor(sch resource.Schema) (resource.Client, error)

ClientFor returns a Client with the underlying rest.Interface being a cached one for the Schema's GroupVersion. If no such client is cached, it creates a new one with the stored config.

type CustomResourceDefinition

type CustomResourceDefinition struct {
	metav1.TypeMeta   `json:",inline" yaml:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
	Spec              CustomResourceDefinitionSpec `json:"spec"`
}

CustomResourceDefinition is the kubernetes-API-compliant representation of a Custom Resource Definition

func (*CustomResourceDefinition) DeepCopyObject

func (crd *CustomResourceDefinition) DeepCopyObject() runtime.Object

DeepCopyObject implements runtime.Object.

type CustomResourceDefinitionSpec

type CustomResourceDefinitionSpec struct {
	Group    string                                `json:"group" yaml:"group"`
	Versions []CustomResourceDefinitionSpecVersion `json:"versions" yaml:"versions"`
	Names    CustomResourceDefinitionSpecNames     `json:"names" yaml:"names"`
	Scope    string                                `json:"scope" yaml:"scope"`
}

CustomResourceDefinitionSpec is the body or spec of a kubernetes Custom Resource Definition

type CustomResourceDefinitionSpecNames

type CustomResourceDefinitionSpecNames struct {
	Kind   string `json:"kind" yaml:"kind"`
	Plural string `json:"plural" yaml:"plural"`
}

CustomResourceDefinitionSpecNames is the struct representing the names (kind and plural) of a kubernetes CRD

type CustomResourceDefinitionSpecVersion

type CustomResourceDefinitionSpecVersion struct {
	Name         string         `json:"name" yaml:"name"`
	Served       bool           `json:"served" yaml:"served"`
	Storage      bool           `json:"storage" yaml:"storage"`
	Schema       map[string]any `json:"schema" yaml:"schema"`
	Subresources map[string]any `json:"subresources,omitempty" yaml:"subresources,omitempty"`
}

CustomResourceDefinitionSpecVersion is the representation of a specific version of a CRD, as part of the overall spec

type GenericJSONDecoder

type GenericJSONDecoder struct {
}

GenericJSONDecoder implements runtime.Serializer and works with Untyped* objects to implement runtime.Object

func (*GenericJSONDecoder) Decode

Decode decodes the provided data into UntypedWatchObject or UntypedObjectWrapper

func (*GenericJSONDecoder) Encode

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

Encode json-encodes the provided object

func (*GenericJSONDecoder) Identifier

func (*GenericJSONDecoder) Identifier() runtime.Identifier

Identifier returns "generic-json-decoder"

type GenericNegotiatedSerializer

type GenericNegotiatedSerializer struct {
}

GenericNegotiatedSerializer implements runtime.NegotiatedSerializer and allows for JSON serialization and deserialization of resource.Object. Since it is generic, and has no schema information, wrapped objects are returned which require a call to `Into` to marshal into an actual resource.Object.

func (*GenericNegotiatedSerializer) DecoderToVersion

DecoderToVersion returns a GenericJSONDecoder

func (*GenericNegotiatedSerializer) EncoderForVersion

EncoderForVersion returns the `serializer` input

func (*GenericNegotiatedSerializer) SupportedMediaTypes

func (*GenericNegotiatedSerializer) SupportedMediaTypes() []runtime.SerializerInfo

SupportedMediaTypes returns the JSON supported media type with a GenericJSONDecoder and kubernetes JSON Framer.

type ResourceManager

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

ResourceManager is a struct that implements resource.Manager, allowing a user to manage Schemas as Custom Resource Definitions in kubernetes.

func NewManager

func NewManager(cfg rest.Config) (*ResourceManager, error)

NewManager creates a new ResourceManager

func (*ResourceManager) RegisterSchema

func (m *ResourceManager) RegisterSchema(ctx context.Context, schema resource.Schema,
	options resource.RegisterSchemaOptions) error

RegisterSchema converts a Schema to a Custom Resource Definition, then attempts to create it in kubernetes. If a CRD already exists for the name, it checks to see if this is a new version and attempts to update the CRD with the new version.

func (*ResourceManager) WaitForAvailability

func (m *ResourceManager) WaitForAvailability(ctx context.Context, schema resource.Schema) error

WaitForAvailability polls the kubernetes API server every second until it gets a successful response for the Schema's CRD name

type SchemalessClient

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

SchemalessClient implements resource.SchemalessClient and allows for working with Schemas as kubernetes Custom Resource Definitions without being tied to a particular Schema (or GroupVerson). Since the largest unit a kubernetes rest.Interface can work with is a GroupVersion, SchemalessClient is actually an arbitrary number of kubernetes REST clients under-the-hood.

func (*SchemalessClient) Create

Create creates a new resource, and marshals the storage response (the created object) into the `into` field.

func (*SchemalessClient) Delete

func (s *SchemalessClient) Delete(ctx context.Context, identifier resource.FullIdentifier) error

Delete deletes a resource identified by identifier

func (*SchemalessClient) Get

Get gets a resource from kubernetes with the Kind and GroupVersion determined from the FullIdentifier, using the namespace and name in FullIdentifier. If identifier.Plural is present, it will use that, otherwise, LOWER(identifier.Kind) + s is used for the resource. The returned resource is marshaled into `into`.

func (*SchemalessClient) List

func (s *SchemalessClient) List(ctx context.Context, identifier resource.FullIdentifier,
	options resource.ListOptions, into resource.ListObject, exampleListItem resource.Object) error

List lists all resources that satisfy identifier, ignoring `Name`. The response is marshaled into `into`

func (*SchemalessClient) Patch

Patch performs a JSON Patch on the provided resource, and marshals the updated version into the `into` field

func (*SchemalessClient) Update

Update updates an existing resource, and marshals the updated version into the `into` field

func (*SchemalessClient) Watch

Watch watches all resources that satisfy the identifier, ignoring `Name`. The WatchResponse's WatchEvent Objects are created by unmarshaling into an object created by calling example.Copy().

type ServerResponseError

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

ServerResponseError represents an HTTP error from the kubernetes control plane. It contains the underlying error returned by the kubernetes go client, and the status code returned from the API.

func NewServerResponseError

func NewServerResponseError(err error, statusCode int) *ServerResponseError

NewServerResponseError creates a new instance of ServerResponseError

func (*ServerResponseError) Error

func (s *ServerResponseError) Error() string

Error returns the Error() of the underlying kubernetes client error

func (*ServerResponseError) StatusCode

func (s *ServerResponseError) StatusCode() int

StatusCode returns the status code returned by the kubernetes API associated with this error

func (*ServerResponseError) Unwrap

func (s *ServerResponseError) Unwrap() error

Unwrap returns the underlying kubernetes go client error

type TypedObjectWrapper

type TypedObjectWrapper struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata"`
	// contains filtered or unexported fields
}

TypedObjectWrapper wraps a resource.Object in a runtime.Object interface, and exposes a ResourceObject() method to get the wrapped object.

func (*TypedObjectWrapper) DeepCopyObject

func (o *TypedObjectWrapper) DeepCopyObject() runtime.Object

DeepCopyObject copies the object

func (*TypedObjectWrapper) ResourceObject

func (o *TypedObjectWrapper) ResourceObject() resource.Object

ResourceObject returns the wrapped resource.Object

type UntypedObjectWrapper

type UntypedObjectWrapper struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata"`
	// contains filtered or unexported fields
}

UntypedObjectWrapper wraps bytes which can be marshaled into a resource.Object, but only if provided an example object to marshal into. It implements runtime.Object, and exposes Into() to marshal the bytes into a concrete type.

func (*UntypedObjectWrapper) DeepCopyObject

func (o *UntypedObjectWrapper) DeepCopyObject() runtime.Object

DeepCopyObject copies the object

func (*UntypedObjectWrapper) Into

func (o *UntypedObjectWrapper) Into(into resource.Object) error

Into unmarshals the wrapped object bytes into the provided resource.Object, using the same unmarshal logic that Client and SchemalessClient use

type UntypedWatchObject

type UntypedWatchObject struct {
	metav1.TypeMeta
	Type   string          `json:"type"`
	Object json.RawMessage `json:"object"`
}

UntypedWatchObject implements runtime.Object, and keeps the Object part of a kubernetes watch event as bytes when unmarshaled, so that it can later be marshaled into a concrete type with Into().

func (*UntypedWatchObject) DeepCopyObject

func (w *UntypedWatchObject) DeepCopyObject() runtime.Object

DeepCopyObject copies the object

func (*UntypedWatchObject) Into

func (w *UntypedWatchObject) Into(into resource.Object) error

Into unmarshals the wrapped object bytes into the provided resource.Object, using the same unmarshal logic that Client and SchemalessClient use

type WatchResponse

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

WatchResponse wraps a kubernetes watch.Interface in order to implement resource.WatchResponse. The underlying watch.Interface can be accessed with KubernetesWatch().

func (*WatchResponse) KubernetesWatch

func (w *WatchResponse) KubernetesWatch() watch.Interface

KubernetesWatch returns the underlying watch.Interface. Calling this method will shut down the translation channel between the watch.Interface and ResultChan(). Using both KubernetesWatch() and ResultChan() simultaneously is not supported, and may result in undefined behavior.

func (*WatchResponse) Stop

func (w *WatchResponse) Stop()

Stop stops the translation channel between the kubernetes watch.Interface, and stops the continued watch request encapsulated by the watch.Interface.

func (*WatchResponse) WatchEvents

func (w *WatchResponse) WatchEvents() <-chan resource.WatchEvent

WatchEvents returns a channel that receives watch events. All calls to this method will return the same channel. This channel will stop receiving events if KubernetesWatch() is called, as that halts the event translation process. If Stop() is called, ths channel is closed.

Jump to

Keyboard shortcuts

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