revamp find content logic to fix 290 291 292

add snapshot source validation in syncSnapshot
add content source validation in syncContent
This commit is contained in:
xiangqian
2020-04-12 22:47:54 -07:00
parent ed6cd4a7ec
commit 45324b7a67
7 changed files with 796 additions and 507 deletions

View File

@@ -683,7 +683,7 @@ func (r *snapshotReactor) modifyContentEvent(content *crdv1.VolumeSnapshotConten
}
}
// addSnapshotEvent simulates that a snapshot has been deleted in etcd and the
// addSnapshotEvent simulates that a snapshot has been created in etcd and the
// controller receives 'snapshot added' event.
func (r *snapshotReactor) addSnapshotEvent(snapshot *crdv1.VolumeSnapshot) {
r.lock.Lock()
@@ -795,13 +795,11 @@ func newContent(contentName, boundToSnapshotUID, boundToSnapshotName, snapshotHa
}
if volumeHandle != "" {
content.Spec.Source = crdv1.VolumeSnapshotContentSource{
VolumeHandle: &volumeHandle,
}
} else if desiredSnapshotHandle != "" {
content.Spec.Source = crdv1.VolumeSnapshotContentSource{
SnapshotHandle: &desiredSnapshotHandle,
}
content.Spec.Source.VolumeHandle = &volumeHandle
}
if desiredSnapshotHandle != "" {
content.Spec.Source.SnapshotHandle = &desiredSnapshotHandle
}
if boundToSnapshotName != "" {
@@ -916,13 +914,10 @@ func newSnapshot(
}
if pvcName != "" {
snapshot.Spec.Source = crdv1.VolumeSnapshotSource{
PersistentVolumeClaimName: &pvcName,
}
} else if targetContentName != "" {
snapshot.Spec.Source = crdv1.VolumeSnapshotSource{
VolumeSnapshotContentName: &targetContentName,
}
snapshot.Spec.Source.PersistentVolumeClaimName = &pvcName
}
if targetContentName != "" {
snapshot.Spec.Source.VolumeSnapshotContentName = &targetContentName
}
if withAllFinalizers {
return withSnapshotFinalizers([]*crdv1.VolumeSnapshot{&snapshot}, utils.VolumeSnapshotAsSourceFinalizer, utils.VolumeSnapshotBoundFinalizer)[0]