Class ModelExtensions
Adds convenient extensions for Kubernetes objects.
Inherited Members
Namespace: k8s.Models
Assembly: KubernetesClient.dll
Syntax
public static class ModelExtensions
Methods
View SourceAddFinalizer(IMetadata<V1ObjectMeta>, string)
Adds the given finalizer to a Kubernetes object if it doesn't already exist.
Declaration
public static bool AddFinalizer(this IMetadata<V1ObjectMeta> obj, string finalizer)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| string | finalizer | the finalizer |
Returns
| Type | Description |
|---|---|
| bool | Returns true if the finalizer was added and false if it already existed. |
AddOwnerReference(IMetadata<V1ObjectMeta>, V1OwnerReference)
Adds an owner reference to the object. No attempt is made to ensure the reference is correct or fits with the other references.
Declaration
public static void AddOwnerReference(this IMetadata<V1ObjectMeta> obj, V1OwnerReference ownerRef)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| V1OwnerReference | ownerRef | the owner reference to the object |
Annotations(IMetadata<V1ObjectMeta>)
Gets the annotations of a Kubernetes object.
Declaration
public static IDictionary<string, string> Annotations(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| IDictionary<string, string> | a dictionary of the annotations |
ApiGroup(IKubernetesObject)
Extracts the Kubernetes API group from the ApiVersion.
Declaration
public static string ApiGroup(this IKubernetesObject obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IKubernetesObject | obj | the kubernetes client IKubernetesObject |
Returns
| Type | Description |
|---|---|
| string | api group from server |
ApiGroupAndVersion(IKubernetesObject)
Splits the Kubernetes API version into the group and version.
Declaration
public static (string, string) ApiGroupAndVersion(this IKubernetesObject obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IKubernetesObject | obj | the kubernetes client IKubernetesObject |
Returns
| Type | Description |
|---|---|
| (string, string) | api group and version from server |
ApiGroupVersion(IKubernetesObject)
Extracts the Kubernetes API version (excluding the group) from the ApiVersion.
Declaration
public static string ApiGroupVersion(this IKubernetesObject obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IKubernetesObject | obj | the kubernetes client IKubernetesObject |
Returns
| Type | Description |
|---|---|
| string | api group version from server |
Continue(IMetadata<V1ListMeta>)
Gets the continuation token version of a Kubernetes list.
Declaration
public static string Continue(this IMetadata<V1ListMeta> list)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ListMeta> | list | Kubernetes list |
Returns
| Type | Description |
|---|---|
| string | continuation token |
CreationTimestamp(IMetadata<V1ObjectMeta>)
Gets the creation time of a Kubernetes object, or null if it hasn't been created yet.
Declaration
public static DateTime? CreationTimestamp(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| DateTime? | creation time of a Kubernetes object, null if it hasn't been created yet. |
DeletionTimestamp(IMetadata<V1ObjectMeta>)
Gets the deletion time of a Kubernetes object, or null if it hasn't been scheduled for deletion.
Declaration
public static DateTime? DeletionTimestamp(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| DateTime? | the deletion time of a Kubernetes object, or null if it hasn't been scheduled for deletion. |
EnsureAnnotations(V1ObjectMeta)
Ensures that the Annotations field is not null, and returns it.
Declaration
public static IDictionary<string, string> EnsureAnnotations(this V1ObjectMeta meta)
Parameters
| Type | Name | Description |
|---|---|---|
| V1ObjectMeta | meta | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| IDictionary<string, string> | the annotations in a Dictionary |
EnsureFinalizers(V1ObjectMeta)
Ensures that the Finalizers field is not null, and returns it.
Declaration
public static IList<string> EnsureFinalizers(this V1ObjectMeta meta)
Parameters
| Type | Name | Description |
|---|---|---|
| V1ObjectMeta | meta | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| IList<string> | the list of finalizers |
EnsureLabels(V1ObjectMeta)
Ensures that the Labels field is not null, and returns it.
Declaration
public static IDictionary<string, string> EnsureLabels(this V1ObjectMeta meta)
Parameters
| Type | Name | Description |
|---|---|---|
| V1ObjectMeta | meta | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| IDictionary<string, string> | the dictionary of labels |
EnsureMetadata(IMetadata<V1ListMeta>)
Ensures that the V1ListMeta metadata field is set, and returns it.
Declaration
public static V1ListMeta EnsureMetadata(this IMetadata<V1ListMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ListMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| V1ListMeta | the metadata V1ListMeta |
EnsureMetadata(IMetadata<V1ObjectMeta>)
Ensures that the V1ObjectMeta metadata field is set, and returns it.
Declaration
public static V1ObjectMeta EnsureMetadata(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| V1ObjectMeta | the metadata field V1ObjectMeta |
Finalizers(IMetadata<V1ObjectMeta>)
Gets the Finalizers of a Kubernetes object.
Declaration
public static IList<string> Finalizers(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| IList<string> | Metadata.Finalizers of V1ObjectMeta |
FindOwnerReference(IMetadata<V1ObjectMeta>, Predicate<V1OwnerReference>)
Gets the index of the V1OwnerReference that matches the given predicate, or -1 if no such reference could be found.
Declaration
public static int FindOwnerReference(this IMetadata<V1ObjectMeta> obj, Predicate<V1OwnerReference> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| Predicate<V1OwnerReference> | predicate | a Predicate<T> to test owner reference |
Returns
| Type | Description |
|---|---|
| int | the index of the V1OwnerReference that matches the given object, or -1 if no such reference could be found. |
FindOwnerReference(IMetadata<V1ObjectMeta>, IKubernetesObject<V1ObjectMeta>)
Gets the index of the V1OwnerReference that matches the given object, or -1 if no such reference could be found.
Declaration
public static int FindOwnerReference(this IMetadata<V1ObjectMeta> obj, IKubernetesObject<V1ObjectMeta> owner)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| IKubernetesObject<V1ObjectMeta> | owner | the owner of the objectV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| int | the index of the V1OwnerReference that matches the given object, or -1 if no such reference could be found. |
Generation(IMetadata<V1ObjectMeta>)
Gets the generation a Kubernetes object.
Declaration
public static long? Generation(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| long? | the Metadata.Generation of object metaV1ObjectMeta |
GetAnnotation(IMetadata<V1ObjectMeta>, string)
Returns the given annotation from a Kubernetes object or null if the annotation was not found.
Declaration
public static string GetAnnotation(this IMetadata<V1ObjectMeta> obj, string key)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| string | key | the key of the annotation |
Returns
| Type | Description |
|---|---|
| string | the content of the annotation |
GetApiGroupAndVersion(IKubernetesObject, out string, out string)
Splits the Kubernetes API version into the group and version.
Declaration
public static void GetApiGroupAndVersion(this IKubernetesObject obj, out string group, out string version)
Parameters
| Type | Name | Description |
|---|---|---|
| IKubernetesObject | obj | the kubernetes client IKubernetesObject |
| string | group | api group output var |
| string | version | api group version output var |
GetController(IMetadata<V1ObjectMeta>)
Gets the V1OwnerReference for the controller of this object, or null if it couldn't be found.
Declaration
public static V1OwnerReference GetController(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| V1OwnerReference | the V1OwnerReference for the controller of this object, or null if it couldn't be found. |
GetLabel(IMetadata<V1ObjectMeta>, string)
Returns the given label from a Kubernetes object or null if the label was not found.
Declaration
public static string GetLabel(this IMetadata<V1ObjectMeta> obj, string key)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| string | key | the key of the label |
Returns
| Type | Description |
|---|---|
| string | content of the label |
GetOwnerReference(IMetadata<V1ObjectMeta>, Predicate<V1OwnerReference>)
Gets the V1OwnerReference that matches the given predicate, or null if no matching reference exists.
Declaration
public static V1OwnerReference GetOwnerReference(this IMetadata<V1ObjectMeta> obj, Predicate<V1OwnerReference> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| Predicate<V1OwnerReference> | predicate | a Predicate<T> to test owner reference |
Returns
| Type | Description |
|---|---|
| V1OwnerReference | the V1OwnerReference that matches the given object, or null if no matching reference exists. |
GetOwnerReference(IMetadata<V1ObjectMeta>, IKubernetesObject<V1ObjectMeta>)
Gets V1OwnerReference that matches the given object, or null if no matching reference exists.
Declaration
public static V1OwnerReference GetOwnerReference(this IMetadata<V1ObjectMeta> obj, IKubernetesObject<V1ObjectMeta> owner)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| IKubernetesObject<V1ObjectMeta> | owner | the owner of the objectV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| V1OwnerReference | the V1OwnerReference that matches the given object, or null if no matching reference exists. |
HasFinalizer(IMetadata<V1ObjectMeta>, string)
Determines whether the Kubernetes object has the given finalizer.
Declaration
public static bool HasFinalizer(this IMetadata<V1ObjectMeta> obj, string finalizer)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| string | finalizer | the finalizer |
Returns
| Type | Description |
|---|---|
| bool | true if object has the finalizer |
IsOwnedBy(IMetadata<V1ObjectMeta>, IKubernetesObject<V1ObjectMeta>)
Determines whether one object is owned by another.
Declaration
public static bool IsOwnedBy(this IMetadata<V1ObjectMeta> obj, IKubernetesObject<V1ObjectMeta> owner)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| IKubernetesObject<V1ObjectMeta> | owner | the owner of the objectV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| bool | true if owned by obj |
Labels(IMetadata<V1ObjectMeta>)
Gets the labels of a Kubernetes object.
Declaration
public static IDictionary<string, string> Labels(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| IDictionary<string, string> | labels of the object in a Dictionary |
Matches(V1ObjectReference, IKubernetesObject<V1ObjectMeta>)
Determines whether an object reference references the given object.
Declaration
public static bool Matches(this V1ObjectReference objref, IKubernetesObject<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| V1ObjectReference | objref | the object referenceV1ObjectReference |
| IKubernetesObject<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| bool | true if the object reference references the given object. |
Matches(V1OwnerReference, IKubernetesObject<V1ObjectMeta>)
Determines whether an owner reference references the given object.
Declaration
public static bool Matches(this V1OwnerReference owner, IKubernetesObject<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| V1OwnerReference | owner | the object referenceV1ObjectReference |
| IKubernetesObject<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| bool | true if the owner reference references the given object |
Name(IMetadata<V1ObjectMeta>)
Gets the name of a Kubernetes object.
Declaration
public static string Name(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| string | the name of the Kubernetes object |
Namespace(IMetadata<V1ObjectMeta>)
Gets the namespace of a Kubernetes object.
Declaration
public static string Namespace(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| string | the namespace of the Kubernetes object |
Namespace(V1ObjectMeta)
Gets the namespace from Kubernetes metadata.
Declaration
public static string Namespace(this V1ObjectMeta meta)
Parameters
| Type | Name | Description |
|---|---|---|
| V1ObjectMeta | meta | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| string | the namespace from Kubernetes metadata |
OwnerReferences(IMetadata<V1ObjectMeta>)
Gets the owner references of a Kubernetes object.
Declaration
public static IList<V1OwnerReference> OwnerReferences(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| IList<V1OwnerReference> | all owner reference in a list of the Kubernetes object |
RemoveFinalizer(IMetadata<V1ObjectMeta>, string)
Removes the given finalizer from a Kubernetes object if it exists.
Declaration
public static bool RemoveFinalizer(this IMetadata<V1ObjectMeta> obj, string finalizer)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| string | finalizer | the finalizer |
Returns
| Type | Description |
|---|---|
| bool | Returns true if the finalizer was removed and false if it didn't exist. |
RemoveOwnerReference(IMetadata<V1ObjectMeta>, IKubernetesObject<V1ObjectMeta>)
Removes the first V1OwnerReference that matches the given object and returns it, or returns null if no matching reference could be found.
Declaration
public static V1OwnerReference RemoveOwnerReference(this IMetadata<V1ObjectMeta> obj, IKubernetesObject<V1ObjectMeta> owner)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| IKubernetesObject<V1ObjectMeta> | owner | the owner of the objectV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| V1OwnerReference | the first V1OwnerReference that matches the given object |
RemoveOwnerReferences(IMetadata<V1ObjectMeta>, Predicate<V1OwnerReference>)
Removes all owner references that match the given predicate, and returns true if any were removed.
Declaration
public static bool RemoveOwnerReferences(this IMetadata<V1ObjectMeta> obj, Predicate<V1OwnerReference> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| Predicate<V1OwnerReference> | predicate | a Predicate<T> to test owner reference |
Returns
| Type | Description |
|---|---|
| bool | true if any were removed |
RemoveOwnerReferences(IMetadata<V1ObjectMeta>, IKubernetesObject<V1ObjectMeta>)
Removes all owner references that match the given object, and returns true if any were removed.
Declaration
public static bool RemoveOwnerReferences(this IMetadata<V1ObjectMeta> obj, IKubernetesObject<V1ObjectMeta> owner)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| IKubernetesObject<V1ObjectMeta> | owner | the owner of the objectV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| bool | true if any were removed |
ResourceVersion(IMetadata<V1ListMeta>)
Gets the resource version of a Kubernetes list.
Declaration
public static string ResourceVersion(this IMetadata<V1ListMeta> list)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ListMeta> | list | the object meta listV1ListMeta |
Returns
| Type | Description |
|---|---|
| string | resource version |
ResourceVersion(IMetadata<V1ObjectMeta>)
Gets the resource version of a Kubernetes object.
Declaration
public static string ResourceVersion(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| string | the resource version of a Kubernetes object |
SetAnnotation(IMetadata<V1ObjectMeta>, string, string)
Sets or removes an annotation on a Kubernetes object.
Declaration
public static void SetAnnotation(this IMetadata<V1ObjectMeta> obj, string key, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| string | key | the key of the annotationV1ObjectMeta |
| string | value | the value of the annotation, null to remove itV1ObjectMeta |
SetLabel(IMetadata<V1ObjectMeta>, string, string)
Sets or removes a label on a Kubernetes object.
Declaration
public static void SetLabel(this IMetadata<V1ObjectMeta> obj, string key, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
| string | key | the key of the labelV1ObjectMeta |
| string | value | the value of the label, null to remove itV1ObjectMeta |
SetNamespace(V1ObjectMeta, string)
Sets the namespace from Kubernetes metadata.
Declaration
public static void SetNamespace(this V1ObjectMeta meta, string ns)
Parameters
| Type | Name | Description |
|---|---|---|
| V1ObjectMeta | meta | the object metaV1ObjectMeta |
| string | ns | the namespace |
Uid(IMetadata<V1ObjectMeta>)
Gets the unique ID of a Kubernetes object.
Declaration
public static string Uid(this IMetadata<V1ObjectMeta> obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IMetadata<V1ObjectMeta> | obj | the object metaV1ObjectMeta |
Returns
| Type | Description |
|---|---|
| string | the unique ID of a Kubernetes object |