control

package
v1.4.7-rc10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FailedCreatePodReason is added in an event and in a job condition
	// when a pod for a replica set is failed to be created.
	FailedCreatePodReason = "FailedCreatePod"
	// SuccessfulCreatePodReason is added in an event when a pod for a job
	// is successfully created.
	SuccessfulCreatePodReason = "SuccessfulCreatePod"
	// FailedDeletePodReason is added in an event and in a job condition
	// when a pod for a replica set is failed to be deleted.
	FailedDeletePodReason = "FailedDeletePod"
	// SuccessfulDeletePodReason is added in an event when a pod for a job
	// is successfully deleted.
	SuccessfulDeletePodReason = "SuccessfulDeletePod"
)

Reasons for pod events

View Source
const (
	// FailedCreateServiceReason is added in an event and in a job controller condition
	// when a service for a job is failed to be created.
	FailedCreateServiceReason = "FailedCreateService"
	// SuccessfulCreateServiceReason is added in an event when a service for a job
	// is successfully created.
	SuccessfulCreateServiceReason = "SuccessfulCreateService"
	// FailedDeleteServiceReason is added in an event and in a job condition
	// when a service for a job is failed to be deleted.
	FailedDeleteServiceReason = "FailedDeleteService"
	// SuccessfulDeleteServiceReason is added in an event when a service for a job
	// is successfully deleted.
	SuccessfulDeleteServiceReason = "SuccessfulDeleteService"
)

Variables

This section is empty.

Functions

func GetPodFromTemplate

func GetPodFromTemplate(template *v1.PodTemplateSpec, parentObject runtime.Object, controllerRef *metav1.OwnerReference) (*v1.Pod, error)

func GetServiceFromTemplate

func GetServiceFromTemplate(template *v1.Service, parentObject runtime.Object, controllerRef *metav1.OwnerReference) (*v1.Service, error)

func ValidateControllerRef

func ValidateControllerRef(controllerRef *metav1.OwnerReference) error

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 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

func (*FakePodControl) DeletePod

func (f *FakePodControl) DeletePod(namespace string, podID string, object runtime.Object) error

func (*FakePodControl) PatchPod

func (f *FakePodControl) PatchPod(namespace, name string, data []byte) error

type FakeServiceControl

type FakeServiceControl struct {
	sync.Mutex
	Templates         []v1.Service
	ControllerRefs    []metav1.OwnerReference
	DeleteServiceName []string
	Patches           [][]byte
	Err               error
	CreateLimit       int
	CreateCallCount   int
}

func (*FakeServiceControl) Clear

func (f *FakeServiceControl) Clear()

func (*FakeServiceControl) CreateServices

func (f *FakeServiceControl) CreateServices(namespace string, service *v1.Service, object runtime.Object) error

func (*FakeServiceControl) CreateServicesWithControllerRef

func (f *FakeServiceControl) CreateServicesWithControllerRef(namespace string, service *v1.Service, object runtime.Object, controllerRef *metav1.OwnerReference) error

func (*FakeServiceControl) DeleteService

func (f *FakeServiceControl) DeleteService(namespace string, serviceID string, object runtime.Object) error

func (*FakeServiceControl) PatchService

func (f *FakeServiceControl) PatchService(namespace, name string, data []byte) 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 PodGroupControlInterface

type PodGroupControlInterface interface {
	// NewEmptyPodGroup returns an empty PodGroup.
	NewEmptyPodGroup() client.Object
	// GetPodGroup gets the PodGroup identified by namespace and name.
	GetPodGroup(namespace string, name string) (metav1.Object, error)
	// DeletePodGroup deletes the PodGroup identified by namespace and name.
	DeletePodGroup(namespace string, name string) error
	// UpdatePodGroup updates a PodGroup.
	UpdatePodGroup(podGroup client.Object) error
	// CreatePodGroup creates a new PodGroup with PodGroup spec fill function.
	CreatePodGroup(podGroup client.Object) error
	// DelayPodCreationDueToPodGroup determines whether it should delay Pod Creation.
	DelayPodCreationDueToPodGroup(pg metav1.Object) bool
	// DecoratePodTemplateSpec decorates PodTemplateSpec.
	// If the PodTemplateSpec has SchedulerName set, this method will Not override.
	DecoratePodTemplateSpec(pts *corev1.PodTemplateSpec, job metav1.Object, rtype string)
	// GetSchedulerName returns the name of the gang scheduler.
	GetSchedulerName() string
}

PodGroupControlInterface is an interface that knows how to add or delete PodGroups created as an interface to allow testing.

func NewSchedulerPluginsControl

func NewSchedulerPluginsControl(c client.Client, schedulerName string) PodGroupControlInterface

NewSchedulerPluginsControl returns a SchedulerPluginsControl

func NewVolcanoControl

func NewVolcanoControl(vci volcanoclient.Interface) PodGroupControlInterface

NewVolcanoControl returns a VolcanoControl

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

func (RealPodControl) DeletePod

func (r RealPodControl) DeletePod(namespace string, podID string, object runtime.Object) error

func (RealPodControl) PatchPod

func (r RealPodControl) PatchPod(namespace, name string, data []byte) error

type RealServiceControl

type RealServiceControl struct {
	KubeClient clientset.Interface
	Recorder   record.EventRecorder
}

RealServiceControl is the default implementation of ServiceControlInterface.

func (RealServiceControl) CreateServices

func (r RealServiceControl) CreateServices(namespace string, service *v1.Service, object runtime.Object) error

func (RealServiceControl) CreateServicesWithControllerRef

func (r RealServiceControl) CreateServicesWithControllerRef(namespace string, service *v1.Service, controllerObject runtime.Object, controllerRef *metav1.OwnerReference) error

func (RealServiceControl) DeleteService

func (r RealServiceControl) DeleteService(namespace, serviceID string, object runtime.Object) error

DeleteService deletes the service identified by serviceID.

func (RealServiceControl) PatchService

func (r RealServiceControl) PatchService(namespace, name string, data []byte) error

type SchedulerPluginsControl

type SchedulerPluginsControl struct {
	Client        client.Client
	SchedulerName string
}

SchedulerPluginsControl is the implementation of PodGroupControlInterface with scheduler-plugins.

func (*SchedulerPluginsControl) CreatePodGroup

func (s *SchedulerPluginsControl) CreatePodGroup(podGroup client.Object) error

func (*SchedulerPluginsControl) DecoratePodTemplateSpec

func (s *SchedulerPluginsControl) DecoratePodTemplateSpec(pts *corev1.PodTemplateSpec, job metav1.Object, _ string)

func (*SchedulerPluginsControl) DelayPodCreationDueToPodGroup

func (s *SchedulerPluginsControl) DelayPodCreationDueToPodGroup(pg metav1.Object) bool

func (*SchedulerPluginsControl) DeletePodGroup

func (s *SchedulerPluginsControl) DeletePodGroup(namespace, name string) error

func (*SchedulerPluginsControl) GetPodGroup

func (s *SchedulerPluginsControl) GetPodGroup(namespace, name string) (metav1.Object, error)

func (*SchedulerPluginsControl) GetSchedulerName

func (s *SchedulerPluginsControl) GetSchedulerName() string

func (*SchedulerPluginsControl) NewEmptyPodGroup

func (s *SchedulerPluginsControl) NewEmptyPodGroup() client.Object

func (*SchedulerPluginsControl) UpdatePodGroup

func (s *SchedulerPluginsControl) UpdatePodGroup(podGroup client.Object) error

type ServiceControlInterface

type ServiceControlInterface interface {
	// CreateServices creates new Services according to the spec.
	CreateServices(namespace string, service *v1.Service, object runtime.Object) error
	// CreateServicesWithControllerRef creates new services according to the spec, and sets object as the service's controller.
	CreateServicesWithControllerRef(namespace string, service *v1.Service, object runtime.Object, controllerRef *metav1.OwnerReference) error
	// PatchService patches the service.
	PatchService(namespace, name string, data []byte) error
	// DeleteService deletes the service identified by serviceID.
	DeleteService(namespace, serviceID string, object runtime.Object) error
}

ServiceControlInterface is an interface that knows how to add or delete Services created as an interface to allow testing.

type ServiceControllerRefManager

type ServiceControllerRefManager struct {
	BaseControllerRefManager
	// contains filtered or unexported fields
}

func NewServiceControllerRefManager

func NewServiceControllerRefManager(
	serviceControl ServiceControlInterface,
	ctr metav1.Object,
	selector labels.Selector,
	controllerKind schema.GroupVersionKind,
	canAdopt func() error,
) *ServiceControllerRefManager

NewServiceControllerRefManager returns a ServiceControllerRefManager that exposes methods to manage the controllerRef of services.

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

ServiceControllerRefManager instance. Create a new instance if it makes
sense to check canAdopt() again (e.g. in a different sync pass).

func (*ServiceControllerRefManager) AdoptService

func (m *ServiceControllerRefManager) AdoptService(service *v1.Service) error

AdoptService sends a patch to take control of the service. It returns the error if the patching fails.

func (*ServiceControllerRefManager) ClaimServices

func (m *ServiceControllerRefManager) ClaimServices(services []*v1.Service, filters ...func(*v1.Service) bool) ([]*v1.Service, error)

ClaimServices tries to take ownership of a list of Services.

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 Service 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 Services that you now own is returned.

func (*ServiceControllerRefManager) ReleaseService

func (m *ServiceControllerRefManager) ReleaseService(service *v1.Service) error

ReleaseService sends a patch to free the service from the control of the controller. It returns the error if the patching fails. 404 and 422 errors are ignored.

type VolcanoControl

type VolcanoControl struct {
	Client volcanoclient.Interface
}

VolcanoControl is the implementation of PodGroupControlInterface with volcano.

func (*VolcanoControl) CreatePodGroup

func (v *VolcanoControl) CreatePodGroup(podGroup client.Object) error

func (*VolcanoControl) DecoratePodTemplateSpec

func (v *VolcanoControl) DecoratePodTemplateSpec(pts *corev1.PodTemplateSpec, job metav1.Object, rtype string)

func (*VolcanoControl) DelayPodCreationDueToPodGroup

func (v *VolcanoControl) DelayPodCreationDueToPodGroup(pg metav1.Object) bool

func (*VolcanoControl) DeletePodGroup

func (v *VolcanoControl) DeletePodGroup(namespace string, name string) error

func (*VolcanoControl) GetPodGroup

func (v *VolcanoControl) GetPodGroup(namespace string, name string) (metav1.Object, error)

func (*VolcanoControl) GetSchedulerName

func (v *VolcanoControl) GetSchedulerName() string

func (*VolcanoControl) NewEmptyPodGroup

func (v *VolcanoControl) NewEmptyPodGroup() client.Object

func (*VolcanoControl) UpdatePodGroup

func (v *VolcanoControl) UpdatePodGroup(podGroup client.Object) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL