Documentation
¶
Index ¶
- func GetObjectListFromOwner(ctx context.Context, client ctrlclient.Client, owner ctrlclient.Object, ...) error
- func GetOwnerFromObject(ctx context.Context, client ctrlclient.Client, obj ctrlclient.Object, ...) error
- func ObjectRef(client ctrlclient.Client, obj ctrlclient.Object) *corev1.ObjectReference
- type PatchHelper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetObjectListFromOwner ¶
func GetObjectListFromOwner(ctx context.Context, client ctrlclient.Client, owner ctrlclient.Object, objList ctrlclient.ObjectList, opts ...ctrlclient.ListOption) error
GetObjectListFromOwner filters a list of Kubernetes objects to include only those owned by a specified resource. It inspects each object's OwnerReferences to find a match based on the specified owner's Group and Kind.
Parameters: - ctx: Context for the API request. - client: The Kubernetes client to list and fetch resources. - owner: The owner object to match against. - objList: The empty list of objects to be filtered (must implement ctrlclient.ObjectList). - opts: Additional options for listing the objects.
Returns: - error: An error if the list cannot be retrieved, parsed, or filtered.
Behavior: - Filters objList.Items to retain only objects whose OwnerReferences match the provided owner. - Updates objList.Items in place to include only matching items.
func GetOwnerFromObject ¶
func GetOwnerFromObject(ctx context.Context, client ctrlclient.Client, obj ctrlclient.Object, owner ctrlclient.Object) error
GetOwnerFromObject retrieves the owner object of a given resource by inspecting the OwnerReferences field. It searches for an owner that matches the specified type and group. If the owner is found, it populates the 'owner' parameter with the retrieved object.
Parameters: - ctx: Context for the API request. - client: The Kubernetes client to fetch resources. - obj: The resource object whose owner is being queried. - owner: An empty object of the desired owner type that will be populated upon success.
Returns: - error: An error if the owner cannot be found or fetched.
func ObjectRef ¶
func ObjectRef(client ctrlclient.Client, obj ctrlclient.Object) *corev1.ObjectReference
ObjectRef creates an ObjectReference for the given Kubernetes object. It takes a runtime.Scheme and a ctrlclient.Object as parameters and returns a pointer to a corev1.ObjectReference. If it fails to get the GroupVersionKind (GVK) of the object, it logs an error and returns nil.
Parameters:
- obj: A ctrlclient.Object for which the ObjectReference is created.
Returns:
- A pointer to a corev1.ObjectReference containing the Kind, APIVersion, Name, and Namespace of the given object, or nil if an error occurs.
Types ¶
type PatchHelper ¶
type PatchHelper struct {
// contains filtered or unexported fields
}
PatchHelper is a utility struct that provides methods to help with patching Kubernetes objects. It contains a client for interacting with the Kubernetes API server, and a map of helpers for different GroupVersionKinds to facilitate patch operations.
func NewPatchHelper ¶
func NewPatchHelper(client ctrlclient.Client, obj ...ctrlclient.Object) (*PatchHelper, error)
NewPatchHelper creates a new PatchHelper instance for the given runtime client. It accepts a variable number of ctrlclient.Object and creates a patch.Helper for each object. The function returns a pointer to a PatchHelper and an error if any occurs during the creation of patch helpers.
Parameters: - client: The ctrlclient.Client to be used for creating patch helpers. - obj: A variadic parameter of ctrlclient.Object for which patch helpers will be created.
Returns: - *PatchHelper: A pointer to the created PatchHelper instance. - error: An error if any occurs during the creation of patch helpers.
func (*PatchHelper) Patch ¶
func (p *PatchHelper) Patch(ctx context.Context, obj ...ctrlclient.Object) error
Patch applies the patch operation to the provided objects. It iterates over the given objects, determines their GroupVersionKind (GVK), and applies the corresponding patch helper for each object.
Parameters:
ctx - The context for the patch operation. obj - A variadic list of ctrlclient.Object to be patched.
Returns:
An error if any of the patch operations fail, otherwise nil.