Documentation ¶
Index ¶
- Constants
- Variables
- func ControllerRevisionName(prefix string, hash string) string
- func DeepHashObject(hasher hash.Hash, objectToWrite interface{})
- func EqualRevision(lhs *apps.ControllerRevision, rhs *apps.ControllerRevision) bool
- func FindEqualRevisions(revisions []*apps.ControllerRevision, needle *apps.ControllerRevision) []*apps.ControllerRevision
- func GenerateDeleteOwnerRefStrategicMergeBytes(dependentUID types.UID, ownerUIDs []types.UID, finalizers ...string) ([]byte, error)
- func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)
- func GetPodConditionFromList(conditions []v1.PodCondition, conditionType v1.PodConditionType) (int, *v1.PodCondition)
- func GetPodFromTemplate(template *v1.PodTemplateSpec, parentObject runtime.Object, ...) (*v1.Pod, error)
- func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition
- func HashControllerRevision(revision *apps.ControllerRevision, probe *int32) string
- func IsPodReady(pod *v1.Pod) bool
- func IsPodReadyConditionTrue(status v1.PodStatus) bool
- func NewControllerRevision(parent metav1.Object, parentKind schema.GroupVersionKind, ...) (*apps.ControllerRevision, error)
- func RecheckDeletionTimestamp(getObject func(context.Context) (metav1.Object, error)) func(context.Context) error
- func SortControllerRevisions(revisions []*apps.ControllerRevision)
- func UpdatePodCondition(status *v1.PodStatus, condition *v1.PodCondition) bool
- type BaseControllerRefManager
- type PodControlInterface
- type PodControllerRefManager
- type RealPodControl
- func (r RealPodControl) CreatePods(ctx context.Context, namespace string, template *v1.PodTemplateSpec, ...) error
- func (r RealPodControl) CreatePodsWithGenerateName(ctx context.Context, namespace string, template *v1.PodTemplateSpec, ...) error
- func (r RealPodControl) DeletePod(ctx context.Context, namespace string, podID string, object runtime.Object) error
- func (r RealPodControl) PatchPod(ctx context.Context, namespace, name string, data []byte) error
Constants ¶
const ( // FailedCreatePodReason is added in an event and in a replica set condition // when a pod for a replica set is failed to be created. FailedCreatePodReason = "FailedCreate" // SuccessfulCreatePodReason is added in an event when a pod for a replica set // is successfully created. SuccessfulCreatePodReason = "SuccessfulCreate" // FailedDeletePodReason is added in an event and in a replica set condition // when a pod for a replica set is failed to be deleted. FailedDeletePodReason = "FailedDelete" // SuccessfulDeletePodReason is added in an event when a pod for a replica set // is successfully deleted. SuccessfulDeletePodReason = "SuccessfulDelete" )
Reasons for pod events
const ControllerRevisionHashLabel = "controller.kubernetes.io/hash"
ControllerRevisionHashLabel is the label used to indicate the hash value of a ControllerRevision's Data.
Variables ¶
var ValidatePodName = apimachineryvalidation.NameIsDNSSubdomain
ValidatePodName can be used to check whether the given pod name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.
Functions ¶
func ControllerRevisionName ¶
ControllerRevisionName returns the Name for a ControllerRevision in the form prefix-hash. If the length of prefix is greater than 223 bytes, it is truncated to allow for a name that is no larger than 253 bytes.
func DeepHashObject ¶
DeepHashObject writes specified object to hash using the spew library which follows pointers and prints actual values of the nested objects ensuring the hash does not change when a pointer changes.
func EqualRevision ¶
func EqualRevision(lhs *apps.ControllerRevision, rhs *apps.ControllerRevision) bool
EqualRevision returns true if lhs and rhs are either both nil, or both point to non-nil ControllerRevisions that contain semantically equivalent data. Otherwise this method returns false.
func FindEqualRevisions ¶
func FindEqualRevisions(revisions []*apps.ControllerRevision, needle *apps.ControllerRevision) []*apps.ControllerRevision
FindEqualRevisions returns all ControllerRevisions in revisions that are equal to needle using EqualRevision as the equality test. The returned slice preserves the order of revisions.
func GetPodCondition ¶
func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)
GetPodCondition extracts the provided condition from the given status and returns that. Returns nil and -1 if the condition is not present, and the index of the located condition.
func GetPodConditionFromList ¶
func GetPodConditionFromList(conditions []v1.PodCondition, conditionType v1.PodConditionType) (int, *v1.PodCondition)
GetPodConditionFromList extracts the provided condition from the given list of condition and returns the index of the condition and the condition. Returns -1 and nil if the condition is not present.
func GetPodFromTemplate ¶
func GetPodFromTemplate(template *v1.PodTemplateSpec, parentObject runtime.Object, controllerRef *metav1.OwnerReference) (*v1.Pod, error)
func GetPodReadyCondition ¶
func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition
GetPodReadyCondition extracts the pod ready condition from the given status and returns that. Returns nil if the condition is not present.
func HashControllerRevision ¶
func HashControllerRevision(revision *apps.ControllerRevision, probe *int32) string
HashControllerRevision hashes the contents of revision's Data using FNV hashing. If probe is not nil, the byte value of probe is added written to the hash as well. The returned hash will be a safe encoded string to avoid bad words.
func IsPodReady ¶
IsPodReady returns true if a pod is ready; false otherwise.
func IsPodReadyConditionTrue ¶
IsPodReadyConditionTrue returns true if a pod is ready; false otherwise.
func NewControllerRevision ¶
func NewControllerRevision(parent metav1.Object, parentKind schema.GroupVersionKind, templateLabels map[string]string, data runtime.RawExtension, revision int64, collisionCount *int32) (*apps.ControllerRevision, error)
NewControllerRevision returns a ControllerRevision with a ControllerRef pointing to parent and indicating that parent is of parentKind. The ControllerRevision has labels matching template labels, contains Data equal to data, and has a Revision equal to revision. The collisionCount is used when creating the name of the ControllerRevision so the name is likely unique. If the returned error is nil, the returned ControllerRevision is valid. If the returned error is not nil, the returned ControllerRevision is invalid for use.
func RecheckDeletionTimestamp ¶
func RecheckDeletionTimestamp(getObject func(context.Context) (metav1.Object, error)) func(context.Context) error
RecheckDeletionTimestamp returns a CanAdopt() function to recheck deletion.
The CanAdopt() function calls getObject() to fetch the latest value, and denies adoption attempts if that object has a non-nil DeletionTimestamp.
func SortControllerRevisions ¶
func SortControllerRevisions(revisions []*apps.ControllerRevision)
SortControllerRevisions sorts revisions by their Revision.
func UpdatePodCondition ¶
func UpdatePodCondition(status *v1.PodStatus, condition *v1.PodCondition) bool
UpdatePodCondition updates existing pod condition or creates a new one. Sets LastTransitionTime to now if the status has changed. Returns true if pod condition has changed or has been added.
Types ¶
type BaseControllerRefManager ¶
type BaseControllerRefManager struct { Controller metav1.Object Selector labels.Selector CanAdoptFunc func(ctx context.Context) error // contains filtered or unexported fields }
func (*BaseControllerRefManager) CanAdopt ¶
func (m *BaseControllerRefManager) CanAdopt(ctx context.Context) error
func (*BaseControllerRefManager) ClaimObject ¶
func (m *BaseControllerRefManager) ClaimObject(ctx context.Context, obj metav1.Object, match func(metav1.Object) bool, adopt, release func(context.Context, metav1.Object) error) (bool, error)
ClaimObject tries to take ownership of an object for this controller.
It will reconcile the following:
- Adopt orphans if the match function returns true.
- Release owned objects if the match function returns false.
A non-nil error is returned if some form of reconciliation was attempted and failed. Usually, controllers should try again later in case reconciliation is still needed.
If the error is nil, either the reconciliation succeeded, or no reconciliation was necessary. The returned boolean indicates whether you now own the object.
No reconciliation will be attempted if the controller is being deleted.
type PodControlInterface ¶
type PodControlInterface interface { // CreatePods creates new pods according to the spec, and sets object as the pod's controller. CreatePods(ctx context.Context, namespace string, template *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference) error // CreatePodsWithGenerateName creates new pods according to the spec, sets object as the pod's controller and sets pod's generateName. CreatePodsWithGenerateName(ctx context.Context, namespace string, template *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference, generateName string) error // DeletePod deletes the pod identified by podID. DeletePod(ctx context.Context, namespace string, podID string, object runtime.Object) error // PatchPod patches the pod. PatchPod(ctx context.Context, namespace, name string, data []byte) error }
PodControlInterface is an interface that knows how to add or delete pods created as an interface to allow testing.
type PodControllerRefManager ¶
type PodControllerRefManager struct { BaseControllerRefManager // contains filtered or unexported fields }
func NewPodControllerRefManager ¶
func NewPodControllerRefManager( podControl PodControlInterface, controller metav1.Object, selector labels.Selector, controllerKind schema.GroupVersionKind, canAdopt func(ctx context.Context) error, finalizers ...string, ) *PodControllerRefManager
NewPodControllerRefManager returns a PodControllerRefManager that exposes methods to manage the controllerRef of pods.
The CanAdopt() function can be used to perform a potentially expensive check (such as a live GET from the API server) prior to the first adoption. It will only be called (at most once) if an adoption is actually attempted. If CanAdopt() returns a non-nil error, all adoptions will fail.
NOTE: Once CanAdopt() is called, it will not be called again by the same
PodControllerRefManager instance. Create a new instance if it makes sense to check CanAdopt() again (e.g. in a different sync pass).
func (*PodControllerRefManager) AdoptPod ¶
AdoptPod sends a patch to take control of the pod. It returns the error if the patching fails.
func (*PodControllerRefManager) ClaimPods ¶
func (m *PodControllerRefManager) ClaimPods(ctx context.Context, pods []*v1.Pod, filters ...func(*v1.Pod) bool) ([]*v1.Pod, error)
ClaimPods tries to take ownership of a list of Pods.
It will reconcile the following:
- Adopt orphans if the selector matches.
- Release owned objects if the selector no longer matches.
Optional: If one or more filters are specified, a Pod will only be claimed if all filters return true.
A non-nil error is returned if some form of reconciliation was attempted and failed. Usually, controllers should try again later in case reconciliation is still needed.
If the error is nil, either the reconciliation succeeded, or no reconciliation was necessary. The list of Pods that you now own is returned.
func (*PodControllerRefManager) ReleasePod ¶
ReleasePod sends a patch to free the pod from the control of the controller. It returns the error if the patching fails. 404 and 422 errors are ignored.
type RealPodControl ¶
type RealPodControl struct { KubeClient clientset.Interface Recorder record.EventRecorder }
RealPodControl is the default implementation of PodControlInterface.
func (RealPodControl) CreatePods ¶
func (r RealPodControl) CreatePods(ctx context.Context, namespace string, template *v1.PodTemplateSpec, controllerObject runtime.Object, controllerRef *metav1.OwnerReference) error
func (RealPodControl) CreatePodsWithGenerateName ¶
func (r RealPodControl) CreatePodsWithGenerateName(ctx context.Context, namespace string, template *v1.PodTemplateSpec, controllerObject runtime.Object, controllerRef *metav1.OwnerReference, generateName string) error