package testing

import "k8s.io/kubernetes/pkg/controller/volume/persistentvolume/testing"

Index

Variables

var ErrVersionConflict = errors.New("VersionError")

ErrVersionConflict is the error returned when resource version of requested object conflicts with the object in storage.

Types

type ReactorError

type ReactorError struct {
	Verb     string
	Resource string
	Error    error
}

ReactorError is an error that is returned by test reactor (=simulated etcd+/API server) when an action performed by the reactor matches given verb ("get", "update", "create", "delete" or "*"") on given resource ("persistentvolumes", "persistentvolumeclaims" or "*").

type VolumeReactor

type VolumeReactor struct {
	// contains filtered or unexported fields
}

VolumeReactor is a core.Reactor that simulates etcd and API server. It stores:

func NewVolumeReactor

func NewVolumeReactor(ctx context.Context, client *fake.Clientset, fakeVolumeWatch, fakeClaimWatch *watch.FakeWatcher, errors []ReactorError) *VolumeReactor

NewVolumeReactor creates a volume reactor.

func (*VolumeReactor) AddClaim

func (r *VolumeReactor) AddClaim(claim *v1.PersistentVolumeClaim)

AddClaim adds a PVC into VolumeReactor.

func (*VolumeReactor) AddClaimBoundToVolume

func (r *VolumeReactor) AddClaimBoundToVolume(claim *v1.PersistentVolumeClaim)

AddClaimBoundToVolume adds a PVC and binds it to corresponding PV.

func (*VolumeReactor) AddClaimEvent

func (r *VolumeReactor) AddClaimEvent(claim *v1.PersistentVolumeClaim)

AddClaimEvent simulates that a claim has been deleted in etcd and the controller receives 'claim added' event.

func (*VolumeReactor) AddClaims

func (r *VolumeReactor) AddClaims(claims []*v1.PersistentVolumeClaim)

AddClaims adds PVCs into VolumeReactor.

func (*VolumeReactor) AddVolume

func (r *VolumeReactor) AddVolume(volume *v1.PersistentVolume)

AddVolume adds a PV into VolumeReactor.

func (*VolumeReactor) AddVolumes

func (r *VolumeReactor) AddVolumes(volumes []*v1.PersistentVolume)

AddVolumes adds PVs into VolumeReactor.

func (*VolumeReactor) CheckClaims

func (r *VolumeReactor) CheckClaims(expectedClaims []*v1.PersistentVolumeClaim) error

CheckClaims compares all expectedClaims with set of claims at the end of the test and reports differences.

func (*VolumeReactor) CheckVolumes

func (r *VolumeReactor) CheckVolumes(expectedVolumes []*v1.PersistentVolume) error

CheckVolumes compares all expectedVolumes with set of volumes at the end of the test and reports differences.

func (*VolumeReactor) DeleteClaimEvent

func (r *VolumeReactor) DeleteClaimEvent(claim *v1.PersistentVolumeClaim)

DeleteClaimEvent simulates that a claim has been deleted in etcd and the controller receives 'claim deleted' event.

func (*VolumeReactor) DeleteVolume

func (r *VolumeReactor) DeleteVolume(name string)

DeleteVolume deletes a PV by name.

func (*VolumeReactor) DeleteVolumeEvent

func (r *VolumeReactor) DeleteVolumeEvent(volume *v1.PersistentVolume)

DeleteVolumeEvent simulates that a volume has been deleted in etcd and the controller receives 'volume deleted' event.

func (*VolumeReactor) GetChangeCount

func (r *VolumeReactor) GetChangeCount() int

GetChangeCount returns changes since last sync.

func (*VolumeReactor) MarkVolumeAvailable

func (r *VolumeReactor) MarkVolumeAvailable(name string)

MarkVolumeAvailable marks a PV available by name.

func (*VolumeReactor) PopChange

func (r *VolumeReactor) PopChange(ctx context.Context) interface{}

PopChange returns one recorded updated object, either *v1.PersistentVolume or *v1.PersistentVolumeClaim. Returns nil when there are no changes.

func (*VolumeReactor) React

func (r *VolumeReactor) React(ctx context.Context, action core.Action) (handled bool, ret runtime.Object, err error)

React is a callback called by fake kubeClient from the controller. In other words, every claim/volume change performed by the controller ends here. This callback checks versions of the updated objects and refuse those that are too old (simulating real etcd). All updated objects are stored locally to keep track of object versions and to evaluate test results. All updated objects are also inserted into changedObjects queue and optionally sent back to the controller via its watchers.

func (*VolumeReactor) SyncAll

func (r *VolumeReactor) SyncAll()

SyncAll simulates the controller periodic sync of volumes and claim. It simply adds all these objects to the internal queue of updates. This method should be used when the test manually calls syncClaim/syncVolume. Test that use real controller loop (ctrl.Run()) will get periodic sync automatically.

func (*VolumeReactor) Watch

Watch watches objects from the VolumeReactor. Watch returns a channel which will push added / modified / deleted object.

Source Files

testing.go

Version
v1.33.0 (latest)
Published
Apr 23, 2025
Platform
linux/amd64
Imports
16 packages
Last checked
3 hours ago

Tools for package owners.