client

package
v0.0.0-...-d87ec40 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 17 Imported by: 131

Documentation

Overview

Package client provides a client that can be configured to point to a kubernetes cluster's kube-api and creates requests for a specified kubernetes resource. Package client also contains functions for a sharedclientfactory which manages the multiple clients needed to interact with multiple kubernetes resource types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNamespaced

func IsNamespaced(gvr schema.GroupVersionResource, mapper meta.RESTMapper) (bool, error)

IsNamespaced determines if the give GroupVersionResource is namespaced using the given RESTMapper. returns true if namespaced and an error if the scope could not be determined.

Types

type Client

type Client struct {
	// Default RESTClient
	RESTClient rest.Interface
	// Config that can be used to build a RESTClient with custom options
	Config rest.Config

	Namespaced bool
	GVR        schema.GroupVersionResource
	// contains filtered or unexported fields
}

Client performs CRUD like operations on a specific GVR.

func NewClient

func NewClient(gvr schema.GroupVersionResource, kind string, namespaced bool, client rest.Interface, defaultTimeout time.Duration) *Client

NewClient will create a client for the given GroupResourceVersion and Kind. If namespaced is set to true all request will be sent with the scoped to a namespace. The namespaced option can be changed after creation with the client.Namespace variable. defaultTimeout will be used to set the timeout for all request from this client. The value of 0 is used to specify an infinite timeout. request will return if the provided context is canceled regardless of the value of defaultTimeout. Changing the value of client.GVR after it's creation of NewClient will not affect future request.

func (*Client) Create

func (c *Client) Create(ctx context.Context, namespace string, obj, result runtime.Object, opts metav1.CreateOptions) (err error)

Create will attempt create the provided object in the given namespace (if client.Namespaced is set to true). Create will then attempt to unmarshal the created object from the response into the provide result object. If the returned response object is of type Status and has .Status != StatusSuccess, the additional information in Status will be used to enrich the error.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error

Delete will attempt to delete the resource with the matching name in the given namespace (if client.Namespaced is set to true).

func (*Client) DeleteCollection

func (c *Client) DeleteCollection(ctx context.Context, namespace string, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error

DeleteCollection will attempt to delete all resource the given namespace (if client.Namespaced is set to true).

func (*Client) Get

func (c *Client) Get(ctx context.Context, namespace, name string, result runtime.Object, options metav1.GetOptions) (err error)

Get will attempt to find the requested resource with the given name in the given namespace (if client.Namespaced is set to true). Get will then attempt to unmarshal the response into the provide result object. If the returned response object is of type Status and has .Status != StatusSuccess, the additional information in Status will be used to enrich the error.

func (*Client) List

func (c *Client) List(ctx context.Context, namespace string, result runtime.Object, opts metav1.ListOptions) (err error)

List will attempt to find resources in the given namespace (if client.Namespaced is set to true). List will then attempt to unmarshal the response into the provide result object. If the returned response object is of type Status and has .Status != StatusSuccess, the additional information in Status will be used to enrich the error.

func (*Client) Patch

func (c *Client) Patch(ctx context.Context, namespace, name string, pt types.PatchType, data []byte, result runtime.Object, opts metav1.PatchOptions, subresources ...string) (err error)

Patch attempts to patch the existing resource with the provided data and patchType that matches the given name in the given namespace (if client.Namespaced is set to true). Patch will then attempt to unmarshal the updated object from the response into the provide result object. If the returned response object is of type Status and has .Status != StatusSuccess, the additional information in Status will be used to enrich the error.

func (*Client) Update

func (c *Client) Update(ctx context.Context, namespace string, obj, result runtime.Object, opts metav1.UpdateOptions) (err error)

Update will attempt update the provided object in the given namespace (if client.Namespaced is set to true). Update will then attempt to unmarshal the updated object from the response into the provide result object. If the returned response object is of type Status and has .Status != StatusSuccess, the additional information in Status will be used to enrich the error.

func (*Client) UpdateStatus

func (c *Client) UpdateStatus(ctx context.Context, namespace string, obj, result runtime.Object, opts metav1.UpdateOptions) (err error)

UpdateStatus will attempt update the status on the provided object in the given namespace (if client.Namespaced is set to true). UpdateStatus will then attempt to unmarshal the updated object from the response into the provide result object. If the returned response object is of type Status and has .Status != StatusSuccess, the additional information in Status will be used to enrich the error.

func (*Client) Watch

func (c *Client) Watch(ctx context.Context, namespace string, opts metav1.ListOptions) (watch.Interface, error)

Watch will attempt to start a watch request with the kube-apiserver for resources in the given namespace (if client.Namespaced is set to true). Results will be streamed too the returned watch.Interface. The returned watch.Interface is determine by *("k8s.io/client-go/rest").Request.Watch

func (*Client) WithAgent

func (c *Client) WithAgent(userAgent string) (*Client, error)

WithAgent attempts to return a copy of the Client but with a new restClient created with the passed in userAgent.

func (*Client) WithImpersonation

func (c *Client) WithImpersonation(impersonate rest.ImpersonationConfig) (*Client, error)

WithImpersonation attempts to return a copy of the Client but with a new restClient created with the passed in impersonation configuration.

type Mutator

type Mutator func(*Client) (*Client, error)

Mutator is function that takes in a client and returns a new mutated client.

type SharedClientFactory

type SharedClientFactory interface {
	ForKind(gvk schema.GroupVersionKind) (*Client, error)
	ForResource(gvr schema.GroupVersionResource, namespaced bool) (*Client, error)
	ForResourceKind(gvr schema.GroupVersionResource, kind string, namespaced bool) *Client
	NewObjects(gvk schema.GroupVersionKind) (runtime.Object, runtime.Object, error)
	GVKForObject(obj runtime.Object) (schema.GroupVersionKind, error)
	GVKForResource(gvr schema.GroupVersionResource) (schema.GroupVersionKind, error)
	IsNamespaced(gvk schema.GroupVersionKind) (bool, error)
	ResourceForGVK(gvk schema.GroupVersionKind) (schema.GroupVersionResource, bool, error)
	IsHealthy(ctx context.Context) bool
}

func NewSharedClientFactory

func NewSharedClientFactory(config *rest.Config, opts *SharedClientFactoryOptions) (_ SharedClientFactory, err error)

func NewSharedClientFactoryForConfig

func NewSharedClientFactoryForConfig(config *rest.Config) (SharedClientFactory, error)

func NewSharedClientFactoryWithAgent

func NewSharedClientFactoryWithAgent(userAgent string, clientFactory SharedClientFactory) SharedClientFactory

NewSharedClientFactoryWithAgent returns a sharedClientFactory that is equivalent to client factory with the addition that it will augment returned clients from ForKind, ForResource, and ForResourceKind with the passed user agent.

func NewSharedClientFactoryWithImpersonation

func NewSharedClientFactoryWithImpersonation(impersonate rest.ImpersonationConfig, clientFactory SharedClientFactory) SharedClientFactory

NewSharedClientFactoryWithImpersonation returns a sharedClientFactory that is equivalent to client factory with the addition that it will augment returned clients from ForKind, ForResource, and ForResourceKind with the passed impersonation config.

type SharedClientFactoryOptions

type SharedClientFactoryOptions struct {
	Mapper meta.RESTMapper
	Scheme *runtime.Scheme
}

Jump to

Keyboard shortcuts

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