client

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateOrUpdate added in v0.8.1

func CreateOrUpdate(ctx context.Context, client ctrlclient.Client, obj ctrlclient.Object) (mutation bool, err error)

CreateOrUpdate creates or updates an object in the Kubernetes cluster. It takes the following parameters: - ctx: The context.Context object for the operation. - obj: The object to be created or updated. - client: The Kubernetes client used to interact with the cluster. It returns a boolean value indicating whether the object was mutated and an error, if any. The function first checks if the object exists in the cluster. If it doesn't, a new object is created. If the object already exists, it calculates the patch to match the existing object and the desired object. If the patch is not empty, it updates the object with the patch. The function also preserves certain fields and annotations during the update process. If any error occurs during the creation or update, it is returned along with the mutation status. Parameters:

  • ctx: The context for the operation.
  • client: The Kubernetes client used to interact with the cluster.
  • obj: The object to create or update.

Returns:

  • mutation: A boolean indicating whether a mutation occurred.
  • error: An error if the operation fails, otherwise nil.

func GetObjectGVK

func GetObjectGVK(schema *runtime.Scheme, obj ctrlclient.Object) (*schema.GroupVersionKind, error)

GetObjectGVK returns the GroupVersionKind (GVK) of the provided object. It retrieves the GVK by using the scheme.Scheme.ObjectKinds function. If the GVK is not found or there is an error retrieving it, an error is returned.

Types

type Client

type Client struct {
	Client ctrlclient.Client

	OwnerReference ctrlclient.Object
}

func NewClient added in v0.8.0

func NewClient(client ctrlclient.Client, ownerReference ctrlclient.Object) *Client

NewClient returns a new instance of the Client struct. It accepts a control client `client` and an owner reference `ownerReference`.

func (*Client) CreateOrUpdate

func (c *Client) CreateOrUpdate(ctx context.Context, obj ctrlclient.Object) (mutation bool, err error)

CreateOrUpdate creates or updates an object in the Kubernetes cluster. It takes the following parameters: - ctx: The context.Context object for the operation. - obj: The object to be created or updated. - client: The Kubernetes client used to interact with the cluster. It returns a boolean value indicating whether the object was mutated and an error, if any. The function first checks if the object exists in the cluster. If it doesn't, a new object is created. If the object already exists, it calculates the patch to match the existing object and the desired object. If the patch is not empty, it updates the object with the patch. The function also preserves certain fields and annotations during the update process. If any error occurs during the creation or update, it is returned along with the mutation status. Parameters:

  • ctx: The context for the operation.
  • obj: The object to create or update.

Returns:

  • mutation: A boolean indicating whether a mutation occurred.
  • error: An error if the operation fails, otherwise nil.

func (*Client) Get

Get wrapped Get method for the client, and provides logging for the operation when it fails. Parameters:

  • ctx: The context for the operation.
  • key: The key of the object to retrieve.
  • obj: The object to retrieve.
  • opts: Additional options for the operation.

Returns:

  • error: An error if the operation fails, otherwise nil.

func (*Client) GetCtrlClient

func (c *Client) GetCtrlClient() ctrlclient.Client

GetCtrlClient returns the control client associated with the client.

func (*Client) GetCtrlScheme

func (c *Client) GetCtrlScheme() *runtime.Scheme

GetCtrlScheme returns the control scheme used by the client.

func (*Client) GetOwnerName

func (c *Client) GetOwnerName() string

GetOwnerName returns the name of the owner reference.

func (*Client) GetOwnerNamespace

func (c *Client) GetOwnerNamespace() string

GetOwnerNamespace returns the namespace of the owner reference.

func (*Client) GetOwnerReference

func (c *Client) GetOwnerReference() ctrlclient.Object

GetOwnerReference returns the owner reference of the client.

func (*Client) GetWithObject added in v0.10.0

func (c *Client) GetWithObject(ctx context.Context, obj ctrlclient.Object, opts ...ctrlclient.GetOption) error

func (*Client) GetWithOwnerNamespace added in v0.10.0

func (c *Client) GetWithOwnerNamespace(ctx context.Context, name string, obj ctrlclient.Object, opts ...ctrlclient.GetOption) error

func (*Client) SetOwnerReference

func (c *Client) SetOwnerReference(obj ctrlclient.Object, gvk *schema.GroupVersionKind) error

SetOwnerReference sets the owner reference for the given object. If the object doesn't have a namespace, it skips setting the owner reference and returns nil. If the client's OwnerReference is nil, it skips setting the owner reference and returns nil. Otherwise, it sets the owner reference using the ctrl.SetControllerReference function. It logs an error if setting the owner reference fails. Finally, it logs a message indicating that the owner reference has been set for the object. Parameters:

  • obj: The object for which to set the owner reference.
  • gvk: The GroupVersionKind of the object.

Returns:

  • error: An error if setting the owner reference fails, otherwise nil.

Jump to

Keyboard shortcuts

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