Handle Secrets in CreateSnapshot

This PR adds handling for Secrets in CreateSnapshot.
This commit is contained in:
xing-yang
2018-08-09 14:05:29 -07:00
committed by Xing Yang
parent 2663b1351f
commit 8a08d423c4
4 changed files with 142 additions and 8 deletions

View File

@@ -77,6 +77,9 @@ const pvcKind = "PersistentVolumeClaim"
const IsDefaultSnapshotClassAnnotation = "snapshot.storage.kubernetes.io/is-default-class"
const snapshotterSecretNameKey = "csiSnapshotterSecretName"
const snapshotterSecretNamespaceKey = "csiSnapshotterSecretNamespace"
// syncContent deals with one key off the queue. It returns false when it's time to quit.
func (ctrl *CSISnapshotController) syncContent(content *crdv1.VolumeSnapshotContent) error {
glog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]", content.Name)
@@ -476,7 +479,20 @@ func (ctrl *CSISnapshotController) createSnapshotOperation(snapshot *crdv1.Volum
return nil, err
}
driverName, snapshotID, timestamp, csiSnapshotStatus, err := ctrl.handler.CreateSnapshot(snapshot, volume, class.Parameters)
// Create VolumeSnapshotContent name
contentName := GetSnapshotContentNameForSnapshot(snapshot)
// Resolve snapshotting secret credentials.
snapshotterSecretRef, err := GetSecretReference(snapshotterSecretNameKey, snapshotterSecretNamespaceKey, class.Parameters, contentName, nil)
if err != nil {
return nil, err
}
snapshotterCredentials, err := GetCredentials(ctrl.client, snapshotterSecretRef)
if err != nil {
return nil, err
}
driverName, snapshotID, timestamp, csiSnapshotStatus, err := ctrl.handler.CreateSnapshot(snapshot, volume, class.Parameters, snapshotterCredentials)
if err != nil {
return nil, fmt.Errorf("Failed to take snapshot of the volume, %s: %q", volume.Name, err)
}
@@ -489,7 +505,6 @@ func (ctrl *CSISnapshotController) createSnapshotOperation(snapshot *crdv1.Volum
}
// Create VolumeSnapshotContent in the database
contentName := GetSnapshotContentNameForSnapshot(snapshot)
volumeRef, err := ref.GetReference(scheme.Scheme, volume)
snapshotContent := &crdv1.VolumeSnapshotContent{