Documentation
¶
Overview ¶
Package controller contains code for controllers (like the replication controller).
Index ¶
- Constants
- func GetPodFromTemplate(template *v1.PodTemplateSpec, parentObject runtime.Object, ...) (*v1.Pod, error)
- func RecheckDeletionTimestamp(getObject func() (metav1.Object, error)) func() error
- type BaseControllerRefManager
- type ControllerClientBuilder
- type FakePodControl
- func (f *FakePodControl) Clear()
- func (f *FakePodControl) CreatePods(namespace string, spec *v1.PodTemplateSpec, object runtime.Object) error
- func (f *FakePodControl) CreatePodsOnNode(nodeName, namespace string, template *v1.PodTemplateSpec, ...) error
- func (f *FakePodControl) CreatePodsWithControllerRef(namespace string, spec *v1.PodTemplateSpec, object runtime.Object, ...) error
- func (f *FakePodControl) DeletePod(namespace string, podID string, object runtime.Object) error
- func (f *FakePodControl) PatchPod(namespace, name string, data []byte) error
- type PodControlInterface
- type PodControllerRefManager
- type RealPodControl
- func (r RealPodControl) CreatePods(namespace string, template *v1.PodTemplateSpec, object runtime.Object) error
- func (r RealPodControl) CreatePodsOnNode(nodeName, namespace string, template *v1.PodTemplateSpec, ...) error
- func (r RealPodControl) CreatePodsWithControllerRef(namespace string, template *v1.PodTemplateSpec, ...) error
- func (r RealPodControl) DeletePod(namespace string, podID string, object runtime.Object) error
- func (r RealPodControl) PatchPod(namespace, name string, data []byte) error
- type SAControllerClientBuilder
- func (b SAControllerClientBuilder) Client(name string) (clientset.Interface, error)
- func (b SAControllerClientBuilder) ClientOrDie(name string) clientset.Interface
- func (b SAControllerClientBuilder) Config(name string) (*restclient.Config, error)
- func (b SAControllerClientBuilder) ConfigOrDie(name string) *restclient.Config
- type SimpleControllerClientBuilder
- func (b SimpleControllerClientBuilder) Client(name string) (clientset.Interface, error)
- func (b SimpleControllerClientBuilder) ClientOrDie(name string) clientset.Interface
- func (b SimpleControllerClientBuilder) Config(name string) (*restclient.Config, error)
- func (b SimpleControllerClientBuilder) ConfigOrDie(name string) *restclient.Config
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
Variables ¶
This section is empty.
Functions ¶
func GetPodFromTemplate ¶
func GetPodFromTemplate(template *v1.PodTemplateSpec, parentObject runtime.Object, controllerRef *metav1.OwnerReference) (*v1.Pod, error)
func RecheckDeletionTimestamp ¶
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.
Types ¶
type BaseControllerRefManager ¶
type BaseControllerRefManager struct { Controller metav1.Object Selector labels.Selector CanAdoptFunc func() error // contains filtered or unexported fields }
func (*BaseControllerRefManager) CanAdopt ¶
func (m *BaseControllerRefManager) CanAdopt() error
func (*BaseControllerRefManager) ClaimObject ¶
func (m *BaseControllerRefManager) ClaimObject(obj metav1.Object, match func(metav1.Object) bool, adopt, release func(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 ControllerClientBuilder ¶
type ControllerClientBuilder interface { Config(name string) (*restclient.Config, error) ConfigOrDie(name string) *restclient.Config Client(name string) (clientset.Interface, error) ClientOrDie(name string) clientset.Interface }
ControllerClientBuilder allows you to get clients and configs for controllers
type FakePodControl ¶
type FakePodControl struct { sync.Mutex Templates []v1.PodTemplateSpec ControllerRefs []metav1.OwnerReference DeletePodName []string Patches [][]byte Err error CreateLimit int CreateCallCount int }
func (*FakePodControl) Clear ¶
func (f *FakePodControl) Clear()
func (*FakePodControl) CreatePods ¶
func (f *FakePodControl) CreatePods(namespace string, spec *v1.PodTemplateSpec, object runtime.Object) error
func (*FakePodControl) CreatePodsOnNode ¶
func (f *FakePodControl) CreatePodsOnNode(nodeName, namespace string, template *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference) error
func (*FakePodControl) CreatePodsWithControllerRef ¶
func (f *FakePodControl) CreatePodsWithControllerRef(namespace string, spec *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference) error
type PodControlInterface ¶
type PodControlInterface interface { // CreatePods creates new pods according to the spec. CreatePods(namespace string, template *v1.PodTemplateSpec, object runtime.Object) error // CreatePodsOnNode creates a new pod according to the spec on the specified node, // and sets the ControllerRef. CreatePodsOnNode(nodeName, namespace string, template *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference) error // CreatePodsWithControllerRef creates new pods according to the spec, and sets object as the pod's controller. CreatePodsWithControllerRef(namespace string, template *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference) error // DeletePod deletes the pod identified by podID. DeletePod(namespace string, podID string, object runtime.Object) error // PatchPod patches the pod. PatchPod(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() error, ) *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 ¶
func (m *PodControllerRefManager) AdoptPod(pod *v1.Pod) error
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(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 ¶
func (m *PodControllerRefManager) ReleasePod(pod *v1.Pod) error
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(namespace string, template *v1.PodTemplateSpec, object runtime.Object) error
func (RealPodControl) CreatePodsOnNode ¶
func (r RealPodControl) CreatePodsOnNode(nodeName, namespace string, template *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference) error
func (RealPodControl) CreatePodsWithControllerRef ¶
func (r RealPodControl) CreatePodsWithControllerRef(namespace string, template *v1.PodTemplateSpec, controllerObject runtime.Object, controllerRef *metav1.OwnerReference) error
type SAControllerClientBuilder ¶
type SAControllerClientBuilder struct { // ClientConfig is a skeleton config to clone and use as the basis for each controller client ClientConfig *restclient.Config // CoreClient is used to provision service accounts if needed and watch for their associated tokens // to construct a controller client CoreClient v1core.CoreV1Interface // AuthenticationClient is used to check API tokens to make sure they are valid before // building a controller client from them AuthenticationClient v1authentication.AuthenticationV1Interface // Namespace is the namespace used to host the service accounts that will back the // controllers. It must be highly privileged namespace which normal users cannot inspect. Namespace string }
SAControllerClientBuilder is a ControllerClientBuilder that returns clients identifying as service accounts
func (SAControllerClientBuilder) Client ¶
func (b SAControllerClientBuilder) Client(name string) (clientset.Interface, error)
func (SAControllerClientBuilder) ClientOrDie ¶
func (b SAControllerClientBuilder) ClientOrDie(name string) clientset.Interface
func (SAControllerClientBuilder) Config ¶
func (b SAControllerClientBuilder) Config(name string) (*restclient.Config, error)
config returns a complete clientConfig for constructing clients. This is separate in anticipation of composition which means that not all clientsets are known here
func (SAControllerClientBuilder) ConfigOrDie ¶
func (b SAControllerClientBuilder) ConfigOrDie(name string) *restclient.Config
type SimpleControllerClientBuilder ¶
type SimpleControllerClientBuilder struct { // ClientConfig is a skeleton config to clone and use as the basis for each controller client ClientConfig *restclient.Config }
SimpleControllerClientBuilder returns a fixed client with different user agents
func (SimpleControllerClientBuilder) Client ¶
func (b SimpleControllerClientBuilder) Client(name string) (clientset.Interface, error)
func (SimpleControllerClientBuilder) ClientOrDie ¶
func (b SimpleControllerClientBuilder) ClientOrDie(name string) clientset.Interface
func (SimpleControllerClientBuilder) Config ¶
func (b SimpleControllerClientBuilder) Config(name string) (*restclient.Config, error)
func (SimpleControllerClientBuilder) ConfigOrDie ¶
func (b SimpleControllerClientBuilder) ConfigOrDie(name string) *restclient.Config