Skip to content

Commit 36584ef

Browse files
author
caiweidong
committed
Call GetSnapshotStatus to check snapshot status
1 parent f59b58d commit 36584ef

File tree

2 files changed

+34
-48
lines changed

2 files changed

+34
-48
lines changed

pkg/controller/snapshot_controller.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import (
7272
// this snapshot. After that, the controller will keep checking the snapshot status
7373
// though csi snapshot calls. When the snapshot is ready to use, the controller set
7474
// the status "Bound" to true to indicate the snapshot is bound and ready to use.
75-
// If the createtion failed for any reason, the Error status is set accordingly.
75+
// If the creation failed for any reason, the Error status is set accordingly.
7676
// In alpha version, the controller not retry to create the snapshot after it failed.
7777
// In the future version, a retry policy will be added.
7878

@@ -560,16 +560,14 @@ func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatusOperation(sn
560560
var timestamp int64
561561
var size int64
562562
var readyToUse = false
563-
class, volume, _, snapshotterCredentials, err := ctrl.getCreateSnapshotInput(snapshot)
564-
if err != nil {
565-
return nil, fmt.Errorf("failed to get input parameters to create snapshot %s: %q", snapshot.Name, err)
566-
}
567-
driverName, snapshotID, timestamp, size, readyToUse, err := ctrl.handler.CreateSnapshot(snapshot, volume, class.Parameters, snapshotterCredentials)
563+
564+
readyToUse, timestamp, size, err = ctrl.handler.GetSnapshotStatus(content)
568565
if err != nil {
569-
glog.Errorf("checkandUpdateBoundSnapshotStatusOperation: failed to call create snapshot to check whether the snapshot is ready to use %q", err)
566+
glog.Errorf("checkandUpdateBoundSnapshotStatusOperation: failed to call list snapshot to check whether the" +
567+
" snapshot is ready to use %q", err)
570568
return nil, err
571569
}
572-
glog.V(5).Infof("checkandUpdateBoundSnapshotStatusOperation: driver %s, snapshotId %s, timestamp %d, size %d, readyToUse %t", driverName, snapshotID, timestamp, size, readyToUse)
570+
glog.V(5).Infof("checkandUpdateBoundSnapshotStatusOperation: timestamp %d, size %d, readyToUse %t", timestamp, size, readyToUse)
573571

574572
if timestamp == 0 {
575573
timestamp = time.Now().UnixNano()

pkg/controller/snapshot_ready_test.go

+28-40
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controller
1818

1919
import (
2020
"errors"
21+
"fmt"
2122
"testing"
2223
"time"
2324

@@ -72,17 +73,12 @@ func TestSync(t *testing.T) {
7273
initialClaims: newClaimArray("claim2-3", "pvc-uid2-3", "1Gi", "volume2-3", v1.ClaimBound, &classEmpty),
7374
initialVolumes: newVolumeArray("volume2-3", "pv-uid2-3", "pv-handle2-3", "1Gi", "pvc-uid2-3", "claim2-3", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
7475
initialSecrets: []*v1.Secret{secret()},
75-
expectedCreateCalls: []createCall{
76+
expectedListCalls: []listCall{
7677
{
77-
snapshotName: "snapshot-snapuid2-3",
78-
volume: newVolume("volume2-3", "pv-uid2-3", "pv-handle2-3", "1Gi", "pvc-uid2-3", "claim2-3", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
79-
parameters: class5Parameters,
80-
secrets: map[string]string{"foo": "bar"},
78+
snapshotID: "sid2-3",
8179
// information to return
82-
driverName: mockDriverName,
83-
snapshotId: "sid2-3",
84-
timestamp: timeNow,
8580
readyToUse: false,
81+
createTime: timeNow,
8682
},
8783
},
8884
errors: noerrors,
@@ -107,42 +103,38 @@ func TestSync(t *testing.T) {
107103
initialClaims: newClaimArray("claim2-5", "pvc-uid2-5", "1Gi", "volume2-5", v1.ClaimBound, &classEmpty),
108104
initialVolumes: newVolumeArray("volume2-5", "pv-uid2-5", "pv-handle2-5", "1Gi", "pvc-uid2-5", "claim2-5", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
109105
initialSecrets: []*v1.Secret{secret()},
110-
expectedCreateCalls: []createCall{
106+
expectedListCalls: []listCall{
111107
{
112-
snapshotName: "snapshot-snapuid2-5",
113-
volume: newVolume("volume2-5", "pv-uid2-5", "pv-handle2-5", "1Gi", "pvc-uid2-5", "claim2-5", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
114-
parameters: class5Parameters,
115-
secrets: map[string]string{"foo": "bar"},
108+
snapshotID: "sid2-5",
116109
// information to return
117-
driverName: mockDriverName,
118-
snapshotId: "sid2-5",
119-
timestamp: timeNow,
120110
readyToUse: true,
111+
createTime: timeNow,
121112
},
122113
},
114+
123115
errors: noerrors,
124116
test: testSyncSnapshot,
125117
},
126118
{
127-
name: "2-7 - snapshot and content bound, csi driver get status error",
128-
initialContents: newContentArray("content2-7", validSecretClass, "sid2-7", "vuid2-7", "volume2-7", "snapuid2-7", "snap2-7", &deletePolicy, nil, nil, false),
129-
expectedContents: newContentArray("content2-7", validSecretClass, "sid2-7", "vuid2-7", "volume2-7", "snapuid2-7", "snap2-7", &deletePolicy, nil, nil, false),
130-
initialSnapshots: newSnapshotArray("snap2-7", validSecretClass, "content2-7", "snapuid2-7", "claim2-7", false, nil, metaTimeNow, nil),
131-
expectedSnapshots: newSnapshotArray("snap2-7", validSecretClass, "content2-7", "snapuid2-7", "claim2-7", false, newVolumeError("Failed to check and update snapshot: mock create snapshot error"), metaTimeNow, nil),
132-
expectedEvents: []string{"Warning SnapshotCheckandUpdateFailed"},
133-
initialClaims: newClaimArray("claim2-7", "pvc-uid2-7", "1Gi", "volume2-7", v1.ClaimBound, &classEmpty),
134-
initialVolumes: newVolumeArray("volume2-7", "pv-uid2-7", "pv-handle2-7", "1Gi", "pvc-uid2-7", "claim2-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
135-
initialSecrets: []*v1.Secret{secret()},
136-
expectedCreateCalls: []createCall{
119+
name: "2-7 - snapshot and content bound, csi driver get status error",
120+
initialContents: newContentArray("content2-7", validSecretClass, "sid2-7", "vuid2-7", "volume2-7", "snapuid2-7", "snap2-7", &deletePolicy, nil, nil, false),
121+
expectedContents: newContentArray("content2-7", validSecretClass, "sid2-7", "vuid2-7", "volume2-7", "snapuid2-7", "snap2-7", &deletePolicy, nil, nil, false),
122+
initialSnapshots: newSnapshotArray("snap2-7", validSecretClass, "content2-7", "snapuid2-7", "claim2-7", false, nil, metaTimeNow, nil),
123+
expectedSnapshots: newSnapshotArray("snap2-7", validSecretClass, "content2-7", "snapuid2-7", "claim2-7",
124+
false, newVolumeError("Failed to check and update snapshot: "+fmt.Sprintf(
125+
"failed to list snapshot content %s: %q", "content2-7", "mock list snapshot error")), metaTimeNow, nil),
126+
expectedEvents: []string{"Warning SnapshotCheckandUpdateFailed"},
127+
initialClaims: newClaimArray("claim2-7", "pvc-uid2-7", "1Gi", "volume2-7", v1.ClaimBound, &classEmpty),
128+
initialVolumes: newVolumeArray("volume2-7", "pv-uid2-7", "pv-handle2-7", "1Gi", "pvc-uid2-7", "claim2-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
129+
initialSecrets: []*v1.Secret{secret()},
130+
expectedListCalls: []listCall{
137131
{
138-
snapshotName: "snapshot-snapuid2-7",
139-
volume: newVolume("volume2-7", "pv-uid2-7", "pv-handle2-7", "1Gi", "pvc-uid2-7", "claim2-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
140-
parameters: class5Parameters,
141-
secrets: map[string]string{"foo": "bar"},
132+
snapshotID: "sid2-7",
142133
// information to return
143-
err: errors.New("mock create snapshot error"),
134+
err: errors.New("mock list snapshot error"),
144135
},
145136
},
137+
146138
errors: noerrors,
147139
test: testSyncSnapshot,
148140
},
@@ -156,20 +148,16 @@ func TestSync(t *testing.T) {
156148
initialClaims: newClaimArray("claim2-8", "pvc-uid2-8", "1Gi", "volume2-8", v1.ClaimBound, &classEmpty),
157149
initialVolumes: newVolumeArray("volume2-8", "pv-uid2-8", "pv-handle2-8", "1Gi", "pvc-uid2-8", "claim2-8", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
158150
initialSecrets: []*v1.Secret{secret()},
159-
expectedCreateCalls: []createCall{
151+
expectedListCalls: []listCall{
160152
{
161-
snapshotName: "snapshot-snapuid2-8",
162-
volume: newVolume("volume2-8", "pv-uid2-8", "pv-handle2-8", "1Gi", "pvc-uid2-8", "claim2-8", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
163-
parameters: class5Parameters,
164-
secrets: map[string]string{"foo": "bar"},
153+
snapshotID: "sid2-8",
165154
// information to return
166-
driverName: mockDriverName,
167-
size: defaultSize,
168-
snapshotId: "sid2-8",
169-
timestamp: timeNow,
170155
readyToUse: true,
156+
createTime: timeNow,
157+
size: defaultSize,
171158
},
172159
},
160+
173161
errors: []reactorError{
174162
// Inject error to the first client.VolumesnapshotV1alpha1().VolumeSnapshots().Update call.
175163
// All other calls will succeed.

0 commit comments

Comments
 (0)