Documentation ¶
Overview ¶
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- type ReactorError
- type VolumeReactor
- func (r *VolumeReactor) AddClaim(claim *v1.PersistentVolumeClaim)
- func (r *VolumeReactor) AddClaimBoundToVolume(claim *v1.PersistentVolumeClaim)
- func (r *VolumeReactor) AddClaimEvent(claim *v1.PersistentVolumeClaim)
- func (r *VolumeReactor) AddClaims(claims []*v1.PersistentVolumeClaim)
- func (r *VolumeReactor) AddVolume(volume *v1.PersistentVolume)
- func (r *VolumeReactor) AddVolumes(volumes []*v1.PersistentVolume)
- func (r *VolumeReactor) CheckClaims(expectedClaims []*v1.PersistentVolumeClaim) error
- func (r *VolumeReactor) CheckVolumes(expectedVolumes []*v1.PersistentVolume) error
- func (r *VolumeReactor) DeleteClaimEvent(claim *v1.PersistentVolumeClaim)
- func (r *VolumeReactor) DeleteVolume(name string)
- func (r *VolumeReactor) DeleteVolumeEvent(volume *v1.PersistentVolume)
- func (r *VolumeReactor) GetChangeCount() int
- func (r *VolumeReactor) MarkVolumeAvailable(name string)
- func (r *VolumeReactor) PopChange() interface{}
- func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Object, err error)
- func (r *VolumeReactor) SyncAll()
- func (r *VolumeReactor) Watch(gvr schema.GroupVersionResource, ns string) (watch.Interface, error)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (r *VolumeReactor) Watch(gvr schema.GroupVersionResource, ns string) (watch.Interface, error)
Watch watches objects from the VolumeReactor. Watch returns a channel which will push added / modified / deleted object.