clientadapter

package
v0.0.0-...-1670326 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControlledJobClient

type ControlledJobClient interface {
	// GetControlledJob gets the controlled job represented by the given
	// request (namespace and name).
	//
	// ok will be true if the controlled job was successfully found.
	//
	// If the given controlled job is not found that error will be
	// swallowed - ok false and a nil error will be returned.
	//
	// In all other error cases, ok false and the error will be returned.
	//
	// In other words, the ok result will be true if the controlledJob was
	// successfully found and will be false otherwise, whether err is nil or not
	GetControlledJob(ctx context.Context, namespacedName types.NamespacedName) (controlledJob *batch.ControlledJob, ok bool, err error)

	// UpdateControlledJob updates the specification of the given controlledjob in the cluster.
	//
	// It will return any error returned by the underlying implementation.
	UpdateControlledJob(ctx context.Context, controlledJob *batch.ControlledJob) error

	// UpdateStatus updates just the status of the given controlledjob in the cluster.
	//
	// It will return any error returned by the underlying implementation.
	UpdateStatus(ctx context.Context, controlledJob *batch.ControlledJob) error

	// ListJobsForControlledJob finds all jobs in the same namespace as namespacedName.Namespace
	// which are owned by the controlled job named namespacedName.Name.
	//
	// The implmentation takes care of the logic to determine which jobs are owned by the
	// ControlledJob.
	//
	// It will return any error returned by the underlying implementation.
	ListJobsForControlledJob(ctx context.Context, namespacedName types.NamespacedName) (kbatch.JobList, error)

	// CreateJob creates the given job on the cluster, which will then take care
	// of spinning up a Pod to run it and manage its runtime.
	//
	// It will return any error returned by the underlying implementation
	CreateJob(ctx context.Context, job *kbatch.Job) error

	// SuspendJob will mark a Job as suspended. This will cause the associated Pods to be killed with SIGTERM
	//
	// It will return any error returned by the underlying implementation
	SuspendJob(ctx context.Context, job *kbatch.Job) error

	// UnsuspendJob will resume a suspended job. This will cause a new Pod to be started up to run the Job
	//
	// It will return any error returned by the underlying implementation
	UnsuspendJob(ctx context.Context, job *kbatch.Job) error

	// DeleteJob removes the given job from the cluster, which will cause the
	// underlying pod (if any) to be killed.
	//
	// If the given job is not found that error will be
	// swallowed - a nil error will be returned.
	//
	// In all other error cases, the underlying error will be returned.
	//
	// The caller can choose the deletion propagation. Foreground will block until the underlying Pods have been
	// terminated and deleted before returning
	DeleteJob(ctx context.Context, job *kbatch.Job, propagation metav1.DeletionPropagation) error
}

ControlledJobClient is a facade interface to hide the complexity of the sigs.k8s.io/controller-runtime/pkg/client interface for our usages. To make it more injectable and mockable

func NewFromClient

func NewFromClient(impl client.Client) ControlledJobClient

NewFromClient wraps the given controller-runtime client in our adapter

type ControlledJobClientMock

type ControlledJobClientMock struct {
	// CreateJobFunc mocks the CreateJob method.
	CreateJobFunc func(ctx context.Context, job *kbatch.Job) error

	// DeleteJobFunc mocks the DeleteJob method.
	DeleteJobFunc func(ctx context.Context, job *kbatch.Job, propagation metav1.DeletionPropagation) error

	// GetControlledJobFunc mocks the GetControlledJob method.
	GetControlledJobFunc func(ctx context.Context, namespacedName types.NamespacedName) (*batch.ControlledJob, bool, error)

	// ListJobsForControlledJobFunc mocks the ListJobsForControlledJob method.
	ListJobsForControlledJobFunc func(ctx context.Context, namespacedName types.NamespacedName) (kbatch.JobList, error)

	// SuspendJobFunc mocks the SuspendJob method.
	SuspendJobFunc func(ctx context.Context, job *kbatch.Job) error

	// UnsuspendJobFunc mocks the UnsuspendJob method.
	UnsuspendJobFunc func(ctx context.Context, job *kbatch.Job) error

	// UpdateControlledJobFunc mocks the UpdateControlledJob method.
	UpdateControlledJobFunc func(ctx context.Context, controlledJob *batch.ControlledJob) error

	// UpdateStatusFunc mocks the UpdateStatus method.
	UpdateStatusFunc func(ctx context.Context, controlledJob *batch.ControlledJob) error
	// contains filtered or unexported fields
}

ControlledJobClientMock is a mock implementation of ControlledJobClient.

func TestSomethingThatUsesControlledJobClient(t *testing.T) {

	// make and configure a mocked ControlledJobClient
	mockedControlledJobClient := &ControlledJobClientMock{
		CreateJobFunc: func(ctx context.Context, job *kbatch.Job) error {
			panic("mock out the CreateJob method")
		},
		DeleteJobFunc: func(ctx context.Context, job *kbatch.Job, propagation metav1.DeletionPropagation) error {
			panic("mock out the DeleteJob method")
		},
		GetControlledJobFunc: func(ctx context.Context, namespacedName types.NamespacedName) (*batch.ControlledJob, bool, error) {
			panic("mock out the GetControlledJob method")
		},
		ListJobsForControlledJobFunc: func(ctx context.Context, namespacedName types.NamespacedName) (kbatch.JobList, error) {
			panic("mock out the ListJobsForControlledJob method")
		},
		SuspendJobFunc: func(ctx context.Context, job *kbatch.Job) error {
			panic("mock out the SuspendJob method")
		},
		UnsuspendJobFunc: func(ctx context.Context, job *kbatch.Job) error {
			panic("mock out the UnsuspendJob method")
		},
		UpdateControlledJobFunc: func(ctx context.Context, controlledJob *batch.ControlledJob) error {
			panic("mock out the UpdateControlledJob method")
		},
		UpdateStatusFunc: func(ctx context.Context, controlledJob *batch.ControlledJob) error {
			panic("mock out the UpdateStatus method")
		},
	}

	// use mockedControlledJobClient in code that requires ControlledJobClient
	// and then make assertions.

}

func (*ControlledJobClientMock) CreateJob

func (mock *ControlledJobClientMock) CreateJob(ctx context.Context, job *kbatch.Job) error

CreateJob calls CreateJobFunc.

func (*ControlledJobClientMock) CreateJobCalls

func (mock *ControlledJobClientMock) CreateJobCalls() []struct {
	Ctx context.Context
	Job *kbatch.Job
}

CreateJobCalls gets all the calls that were made to CreateJob. Check the length with:

len(mockedControlledJobClient.CreateJobCalls())

func (*ControlledJobClientMock) DeleteJob

func (mock *ControlledJobClientMock) DeleteJob(ctx context.Context, job *kbatch.Job, propagation metav1.DeletionPropagation) error

DeleteJob calls DeleteJobFunc.

func (*ControlledJobClientMock) DeleteJobCalls

func (mock *ControlledJobClientMock) DeleteJobCalls() []struct {
	Ctx         context.Context
	Job         *kbatch.Job
	Propagation metav1.DeletionPropagation
}

DeleteJobCalls gets all the calls that were made to DeleteJob. Check the length with:

len(mockedControlledJobClient.DeleteJobCalls())

func (*ControlledJobClientMock) GetControlledJob

func (mock *ControlledJobClientMock) GetControlledJob(ctx context.Context, namespacedName types.NamespacedName) (*batch.ControlledJob, bool, error)

GetControlledJob calls GetControlledJobFunc.

func (*ControlledJobClientMock) GetControlledJobCalls

func (mock *ControlledJobClientMock) GetControlledJobCalls() []struct {
	Ctx            context.Context
	NamespacedName types.NamespacedName
}

GetControlledJobCalls gets all the calls that were made to GetControlledJob. Check the length with:

len(mockedControlledJobClient.GetControlledJobCalls())

func (*ControlledJobClientMock) ListJobsForControlledJob

func (mock *ControlledJobClientMock) ListJobsForControlledJob(ctx context.Context, namespacedName types.NamespacedName) (kbatch.JobList, error)

ListJobsForControlledJob calls ListJobsForControlledJobFunc.

func (*ControlledJobClientMock) ListJobsForControlledJobCalls

func (mock *ControlledJobClientMock) ListJobsForControlledJobCalls() []struct {
	Ctx            context.Context
	NamespacedName types.NamespacedName
}

ListJobsForControlledJobCalls gets all the calls that were made to ListJobsForControlledJob. Check the length with:

len(mockedControlledJobClient.ListJobsForControlledJobCalls())

func (*ControlledJobClientMock) SuspendJob

func (mock *ControlledJobClientMock) SuspendJob(ctx context.Context, job *kbatch.Job) error

SuspendJob calls SuspendJobFunc.

func (*ControlledJobClientMock) SuspendJobCalls

func (mock *ControlledJobClientMock) SuspendJobCalls() []struct {
	Ctx context.Context
	Job *kbatch.Job
}

SuspendJobCalls gets all the calls that were made to SuspendJob. Check the length with:

len(mockedControlledJobClient.SuspendJobCalls())

func (*ControlledJobClientMock) UnsuspendJob

func (mock *ControlledJobClientMock) UnsuspendJob(ctx context.Context, job *kbatch.Job) error

UnsuspendJob calls UnsuspendJobFunc.

func (*ControlledJobClientMock) UnsuspendJobCalls

func (mock *ControlledJobClientMock) UnsuspendJobCalls() []struct {
	Ctx context.Context
	Job *kbatch.Job
}

UnsuspendJobCalls gets all the calls that were made to UnsuspendJob. Check the length with:

len(mockedControlledJobClient.UnsuspendJobCalls())

func (*ControlledJobClientMock) UpdateControlledJob

func (mock *ControlledJobClientMock) UpdateControlledJob(ctx context.Context, controlledJob *batch.ControlledJob) error

UpdateControlledJob calls UpdateControlledJobFunc.

func (*ControlledJobClientMock) UpdateControlledJobCalls

func (mock *ControlledJobClientMock) UpdateControlledJobCalls() []struct {
	Ctx           context.Context
	ControlledJob *batch.ControlledJob
}

UpdateControlledJobCalls gets all the calls that were made to UpdateControlledJob. Check the length with:

len(mockedControlledJobClient.UpdateControlledJobCalls())

func (*ControlledJobClientMock) UpdateStatus

func (mock *ControlledJobClientMock) UpdateStatus(ctx context.Context, controlledJob *batch.ControlledJob) error

UpdateStatus calls UpdateStatusFunc.

func (*ControlledJobClientMock) UpdateStatusCalls

func (mock *ControlledJobClientMock) UpdateStatusCalls() []struct {
	Ctx           context.Context
	ControlledJob *batch.ControlledJob
}

UpdateStatusCalls gets all the calls that were made to UpdateStatus. Check the length with:

len(mockedControlledJobClient.UpdateStatusCalls())

type ControllerClientAdapter

type ControllerClientAdapter struct {
	client.Client
}

ControllerClientAdapter implements the ControlledJobClient interface by adapting the provided controller-runtime client

func (*ControllerClientAdapter) CreateJob

func (c *ControllerClientAdapter) CreateJob(ctx context.Context, job *kbatch.Job) error

func (*ControllerClientAdapter) DeleteJob

func (c *ControllerClientAdapter) DeleteJob(ctx context.Context, job *kbatch.Job, propagation metav1.DeletionPropagation) error

func (*ControllerClientAdapter) GetControlledJob

func (c *ControllerClientAdapter) GetControlledJob(ctx context.Context, namespacedName types.NamespacedName) (controlledJob *batch.ControlledJob, ok bool, err error)

func (*ControllerClientAdapter) ListJobsForControlledJob

func (c *ControllerClientAdapter) ListJobsForControlledJob(ctx context.Context, namespacedName types.NamespacedName) (childJobs kbatch.JobList, err error)

func (*ControllerClientAdapter) SuspendJob

func (c *ControllerClientAdapter) SuspendJob(ctx context.Context, job *kbatch.Job) error

func (*ControllerClientAdapter) UnsuspendJob

func (c *ControllerClientAdapter) UnsuspendJob(ctx context.Context, job *kbatch.Job) error

func (*ControllerClientAdapter) UpdateControlledJob

func (c *ControllerClientAdapter) UpdateControlledJob(ctx context.Context, controlledJob *batch.ControlledJob) error

func (*ControllerClientAdapter) UpdateStatus

func (c *ControllerClientAdapter) UpdateStatus(ctx context.Context, controlledJob *batch.ControlledJob) error

Jump to

Keyboard shortcuts

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