testing

package
v1.16.13-rc.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrVersionConflict = errors.New("VersionError")

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

Functions

This section is empty.

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:

  • Latest version of claims volumes saved by the controller.
  • Queue of all saves (to simulate "volume/claim updated" events). This queue contains all intermediate state of an object - e.g. a claim.VolumeName is updated first and claim.Phase second. This queue will then contain both updates as separate entries.
  • Number of changes since the last call to VolumeReactor.syncAll().
  • Optionally, volume and claim fake watchers which should be the same ones used by the controller. Any time an event function like deleteVolumeEvent is called to simulate an event, the reactor's stores are updated and the controller is sent the event via the fake watcher.
  • Optionally, list of error that should be returned by reactor, simulating etcd / API server failures. These errors are evaluated in order and every error is returned only once. I.e. when the reactor finds matching ReactorError, it return appropriate error and removes the ReactorError from the list.

func NewVolumeReactor

func NewVolumeReactor(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 added in v1.16.0

func (r *VolumeReactor) MarkVolumeAvailable(name string)

MarkVolumeAvailable marks a PV available by name.

func (*VolumeReactor) PopChange

func (r *VolumeReactor) PopChange() 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(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.

Jump to

Keyboard shortcuts

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