Documentation
¶
Overview ¶
Package clientutils provides utilities for working with the client package of controller-runtime.
Index ¶
- Variables
- func CreateMultiple(ctx context.Context, c client.Client, objs []client.Object, ...) error
- func CreateMultipleFromFile(ctx context.Context, c client.Client, filename string, ...) ([]unstructured.Unstructured, error)
- func DeleteMultiple(ctx context.Context, c client.Client, objs []client.Object, ...) error
- func DeleteMultipleFromFile(ctx context.Context, c client.Client, filename string, ...) error
- func GetMultiple(ctx context.Context, c client.Client, reqs []GetRequest) error
- func GetMultipleFromFile(ctx context.Context, c client.Client, filename string) ([]unstructured.Unstructured, error)
- func IgnoreAlreadyExists(err error) error
- func ListAndFilter(ctx context.Context, c client.Client, list client.ObjectList, ...) error
- func ListAndFilterControlledBy(ctx context.Context, c client.Client, owner client.Object, ...) error
- func ObjectRefSetReferencesGetRequest(scheme *runtime.Scheme, s ObjectRefSet, req GetRequest) (bool, error)
- func ObjectRefSetReferencesObject(scheme *runtime.Scheme, s ObjectRefSet, obj client.Object) (bool, error)
- func ObjectsFromGetRequests(reqs []GetRequest) []client.Object
- func ObjectsFromPatchRequests(reqs []PatchRequest) []client.Object
- func PatchMultiple(ctx context.Context, c client.Client, reqs []PatchRequest, ...) error
- func PatchMultipleFromFile(ctx context.Context, c client.Client, filename string, ...) ([]unstructured.Unstructured, error)
- type CreateOrUseOperationResult
- func CreateOrUse(ctx context.Context, c client.Client, objects []client.Object, ...) (CreateOrUseOperationResult, []client.Object, error)
- func CreateOrUseWithList(ctx context.Context, c client.Client, list client.ObjectList, ...) (CreateOrUseOperationResult, error)
- func CreateOrUseWithObjectSlicePointer(ctx context.Context, c client.Client, slicePtr interface{}, obj client.Object, ...) (CreateOrUseOperationResult, error)
- type GetRequest
- type GetRequestSet
- type ObjectRef
- func ObjectRefFromGetRequest(scheme *runtime.Scheme, req GetRequest) (ObjectRef, error)
- func ObjectRefFromObject(scheme *runtime.Scheme, obj client.Object) (ObjectRef, error)
- func ObjectRefsFromGetRequests(scheme *runtime.Scheme, reqs []GetRequest) ([]ObjectRef, error)
- func ObjectRefsFromObjects(scheme *runtime.Scheme, objs []client.Object) ([]ObjectRef, error)
- type ObjectRefSet
- type PatchProvider
- type PatchRequest
- type SharedFieldIndexer
- func (s *SharedFieldIndexer) IndexField(ctx context.Context, obj client.Object, field string) error
- func (s *SharedFieldIndexer) MustRegister(obj client.Object, field string, extractValue client.IndexerFunc)
- func (s *SharedFieldIndexer) Register(obj client.Object, field string, extractValue client.IndexerFunc) error
Constants ¶
This section is empty.
Variables ¶
var ApplyAll = apply{}
ApplyAll provides client.Apply for any given object.
Functions ¶
func CreateMultiple ¶
func CreateMultiple(ctx context.Context, c client.Client, objs []client.Object, opts ...client.CreateOption) error
CreateMultiple creates multiple objects using the given client and options.
func CreateMultipleFromFile ¶
func CreateMultipleFromFile(ctx context.Context, c client.Client, filename string, opts ...client.CreateOption) ([]unstructured.Unstructured, error)
CreateMultipleFromFile creates multiple objects by reading the given file as unstructured objects and then creating the read objects using the given client and options.
func DeleteMultiple ¶
func DeleteMultiple(ctx context.Context, c client.Client, objs []client.Object, opts ...client.DeleteOption) error
DeleteMultiple deletes multiple given client.Object objects using the given client.DeleteOption options.
func DeleteMultipleFromFile ¶
func DeleteMultipleFromFile(ctx context.Context, c client.Client, filename string, opts ...client.DeleteOption) error
DeleteMultipleFromFile deletes all client.Object objects from the given file with the given client.DeleteOption options.
func GetMultiple ¶
GetMultiple gets multiple objects using the given client. The results are written back into the given GetRequest.
func GetMultipleFromFile ¶
func GetMultipleFromFile(ctx context.Context, c client.Client, filename string) ([]unstructured.Unstructured, error)
GetMultipleFromFile creates multiple objects by reading the given file as unstructured objects and then creating the read objects using the given client and options.
func IgnoreAlreadyExists ¶
IgnoreAlreadyExists returns nil if the given error matches apierrors.IsAlreadyExists.
func ListAndFilter ¶ added in v0.3.5
func ListAndFilter(ctx context.Context, c client.Client, list client.ObjectList, filterFunc func(object client.Object) (bool, error), opts ...client.ListOption) error
ListAndFilter is a shorthand for doing a client.Client.List followed by filtering the list's elements with the given function.
func ListAndFilterControlledBy ¶ added in v0.3.5
func ListAndFilterControlledBy(ctx context.Context, c client.Client, owner client.Object, list client.ObjectList, opts ...client.ListOption) error
ListAndFilterControlledBy is a shorthand for doing a client.List followed by filtering the list's elements using metautils.IsControlledBy.
func ObjectRefSetReferencesGetRequest ¶
func ObjectRefSetReferencesGetRequest(scheme *runtime.Scheme, s ObjectRefSet, req GetRequest) (bool, error)
ObjectRefSetReferencesGetRequest is a utility function to determine whether an ObjectRefSet contains a GetRequest.
func ObjectRefSetReferencesObject ¶
func ObjectRefSetReferencesObject(scheme *runtime.Scheme, s ObjectRefSet, obj client.Object) (bool, error)
ObjectRefSetReferencesObject is a utility function to determine whether an ObjectRefSet contains a client.Object.
func ObjectsFromGetRequests ¶
func ObjectsFromGetRequests(reqs []GetRequest) []client.Object
ObjectsFromGetRequests retrieves all client.Object objects from the given slice of GetRequest.
func ObjectsFromPatchRequests ¶
func ObjectsFromPatchRequests(reqs []PatchRequest) []client.Object
ObjectsFromPatchRequests extracts all client.Object objects from the given slice of PatchRequest.
func PatchMultiple ¶
func PatchMultiple(ctx context.Context, c client.Client, reqs []PatchRequest, opts ...client.PatchOption) error
PatchMultiple executes multiple PatchRequest with the given client.PatchOption.
func PatchMultipleFromFile ¶
func PatchMultipleFromFile( ctx context.Context, c client.Client, filename string, patchProvider PatchProvider, opts ...client.PatchOption, ) ([]unstructured.Unstructured, error)
PatchMultipleFromFile patches all objects from the given filename using the patchFor function. The returned unstructured.Unstructured objects contain the result of applying them.
Types ¶
type CreateOrUseOperationResult ¶ added in v0.3.5
type CreateOrUseOperationResult string
CreateOrUseOperationResult is the result of a CreateOrUse call.
const ( // CreateOrUseOperationResultUsed indicates that a match has been found and no object was created. CreateOrUseOperationResultUsed CreateOrUseOperationResult = "used" // CreateOrUseOperationResultCreated indicates that no match has been found and a new object was created. CreateOrUseOperationResultCreated CreateOrUseOperationResult = "created" // CreateOrUseOperationResultNone indicates that no match has been found / no object was created. CreateOrUseOperationResultNone CreateOrUseOperationResult = "unchanged" )
func CreateOrUse ¶ added in v0.3.5
func CreateOrUse(ctx context.Context, c client.Client, objects []client.Object, obj client.Object, matchFunc func() (bool, error), initFunc func() error) (CreateOrUseOperationResult, []client.Object, error)
CreateOrUse traverses through a slice of objects and tries to find a matching object using matchFunc. If it does, the matching object is set to the object and the function returns the other objects. If it matches multiple times, the winning object is the oldest. If it does not match, initFunc is called and the new object is created.
func CreateOrUseWithList ¶ added in v0.3.5
func CreateOrUseWithList(ctx context.Context, c client.Client, list client.ObjectList, obj client.Object, matchFunc func() (bool, error), initFunc func() error) (CreateOrUseOperationResult, error)
CreateOrUseWithList is a shorthand for using CreateOrUse with a client.ObjectList containing the objects. Caution: In contrast to CreateOrUse, if setting the list elements fails, the unmatched objects are unknown. The operation result will still reflect what happened.
func CreateOrUseWithObjectSlicePointer ¶ added in v0.3.5
func CreateOrUseWithObjectSlicePointer(ctx context.Context, c client.Client, slicePtr interface{}, obj client.Object, matchFunc func() (bool, error), initFunc func() error) (CreateOrUseOperationResult, error)
CreateOrUseWithObjectSlicePointer is a shorthand for using CreateOrUse with an object slice containing the objects. Caution: In contrast to CreateOrUse, if setting the slice elements fails, the unmatched objects are unknown. The operation result will still reflect what happened.
type GetRequest ¶
GetRequest is a request to get an object with the given key and object (that is later used to write the result into).
func GetRequestFromObject ¶
func GetRequestFromObject(obj client.Object) GetRequest
GetRequestFromObject converts the given client.Object to a GetRequest. Namespace and name should be present on the object.
func GetRequestsFromObjects ¶
func GetRequestsFromObjects(objs []client.Object) []GetRequest
GetRequestsFromObjects converts each client.Object into a GetRequest using GetRequestFromObject.
type GetRequestSet ¶
type GetRequestSet struct {
// contains filtered or unexported fields
}
GetRequestSet is a set of GetRequest.
Internally, the objects are differentiated by either being typed or unstructured. For unstructured objects, the group version kind they supply alongside their client.ObjectKey is used as identity. For typed objects, their element type (all typed objects *have* to be pointers to structs) alongside their client.ObjectKey is used as identity. If a typed object is *not* a pointer to a struct, a panic will happen.
func NewGetRequestSet ¶
func NewGetRequestSet(items ...GetRequest) *GetRequestSet
NewGetRequestSet creates a new set of GetRequest.
Internally, the objects are differentiated by either being typed or unstructured. For unstructured objects, the group version kind they supply alongside their client.ObjectKey is used as identity. For typed objects, their element type (all typed objects *have* to be pointers to structs) alongside their client.ObjectKey is used as identity. If a typed object is *not* a pointer to a struct, a panic will happen.
func (*GetRequestSet) Delete ¶
func (s *GetRequestSet) Delete(items ...GetRequest)
Delete deletes the given items from the set, if they were present.
func (*GetRequestSet) Has ¶
func (s *GetRequestSet) Has(item GetRequest) bool
Has checks if the given item is present in the set.
func (*GetRequestSet) Insert ¶
func (s *GetRequestSet) Insert(items ...GetRequest)
Insert inserts the given items into the set.
func (*GetRequestSet) Iterate ¶
func (s *GetRequestSet) Iterate(f func(GetRequest) (cont bool))
Iterate iterates through the get requests of this set using the given function. If the function returns true (i.e. stop), the iteration is canceled.
func (*GetRequestSet) List ¶
func (s *GetRequestSet) List() []GetRequest
List returns all GetRequests of this set.
type ObjectRef ¶
ObjectRef references an object regardless of its version.
func ObjectRefFromGetRequest ¶
func ObjectRefFromGetRequest(scheme *runtime.Scheme, req GetRequest) (ObjectRef, error)
ObjectRefFromGetRequest creates a new ObjectRef from the given GetRequest.
func ObjectRefFromObject ¶
ObjectRefFromObject creates a new ObjectRef from the given client.Object.
func ObjectRefsFromGetRequests ¶
func ObjectRefsFromGetRequests(scheme *runtime.Scheme, reqs []GetRequest) ([]ObjectRef, error)
ObjectRefsFromGetRequests creates a list of ObjectRef from the given list of GetRequest.
type ObjectRefSet ¶
type ObjectRefSet map[ObjectRef]struct{}
ObjectRefSet is a set of ObjectRef references.
func NewObjectRefSet ¶
func NewObjectRefSet(items ...ObjectRef) ObjectRefSet
NewObjectRefSet creates a new ObjectRefSet with the given set.
func ObjectRefSetFromGetRequestSet ¶
func ObjectRefSetFromGetRequestSet(scheme *runtime.Scheme, s2 *GetRequestSet) (ObjectRefSet, error)
ObjectRefSetFromGetRequestSet creates a new ObjectRefSet from the given GetRequestSet.
func ObjectRefSetFromObjects ¶
ObjectRefSetFromObjects creates a new ObjectRefSet from the given list of client.Object.
func (ObjectRefSet) Delete ¶
func (s ObjectRefSet) Delete(items ...ObjectRef)
Delete deletes the given items from the set, if present.
func (ObjectRefSet) Has ¶
func (s ObjectRefSet) Has(item ObjectRef) bool
Has checks if the given item is present in the set.
func (ObjectRefSet) Insert ¶
func (s ObjectRefSet) Insert(items ...ObjectRef)
Insert inserts the given items into the set.
type PatchProvider ¶
PatchProvider retrieves a patch for any given object.
type PatchRequest ¶
PatchRequest is the request to patch an object with a patch.
func PatchRequestFromObjectAndProvider ¶
func PatchRequestFromObjectAndProvider(obj client.Object, provider PatchProvider) PatchRequest
PatchRequestFromObjectAndProvider is a shorthand to create a PatchRequest using a client.Object and PatchProvider.
func PatchRequestsFromObjectsAndProvider ¶
func PatchRequestsFromObjectsAndProvider(objs []client.Object, provider PatchProvider) []PatchRequest
PatchRequestsFromObjectsAndProvider converts all client.Object objects to PatchRequest using PatchRequestFromObjectAndProvider.
type SharedFieldIndexer ¶ added in v0.3.2
type SharedFieldIndexer struct {
// contains filtered or unexported fields
}
SharedFieldIndexer allows registering and calling field index functions shared by different users.
func NewSharedFieldIndexer ¶ added in v0.3.2
func NewSharedFieldIndexer(indexer client.FieldIndexer, scheme *runtime.Scheme) *SharedFieldIndexer
NewSharedFieldIndexer creates a new SharedFieldIndexer.
func (*SharedFieldIndexer) IndexField ¶ added in v0.3.2
IndexField calls a registered client.IndexerFunc for the given client.Object and field. If the object / field is unknown or its GVK could not be determined, it errors.
func (*SharedFieldIndexer) MustRegister ¶ added in v0.3.2
func (s *SharedFieldIndexer) MustRegister(obj client.Object, field string, extractValue client.IndexerFunc)
MustRegister registers the client.IndexerFunc for the given client.Object and field.
func (*SharedFieldIndexer) Register ¶ added in v0.3.2
func (s *SharedFieldIndexer) Register(obj client.Object, field string, extractValue client.IndexerFunc) error
Register registers the client.IndexerFunc for the given client.Object and field.