Skip to content

Commit 7f0070e

Browse files
authored
Merge pull request #74 from xing-yang/release-1.0
Cherry-picking commits from master to release-1.0 branch
2 parents 2e34d9b + bcc0ebd commit 7f0070e

15 files changed

+489
-139
lines changed

deploy/kubernetes/setup-csi-snapshotter.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ spec:
7272
serviceAccount: csi-snapshotter
7373
containers:
7474
- name: csi-provisioner
75-
image: quay.io/k8scsi/csi-provisioner:v0.4.0
75+
image: quay.io/k8scsi/csi-provisioner:v1.0.0
7676
args:
7777
- "--provisioner=csi-hostpath"
7878
- "--csi-address=$(ADDRESS)"
@@ -85,7 +85,7 @@ spec:
8585
- name: socket-dir
8686
mountPath: /csi
8787
- name: csi-snapshotter
88-
image: quay.io/k8scsi/csi-snapshotter:v0.4.0
88+
image: quay.io/k8scsi/csi-snapshotter:v1.0.0
8989
args:
9090
- "--csi-address=$(ADDRESS)"
9191
- "--connection-timeout=15s"
@@ -97,7 +97,7 @@ spec:
9797
- name: socket-dir
9898
mountPath: /csi
9999
- name: hostpath
100-
image: quay.io/k8scsi/hostpathplugin:v0.4.0
100+
image: quay.io/k8scsi/hostpathplugin:v1.0.0
101101
args:
102102
- "--v=5"
103103
- "--endpoint=$(CSI_ENDPOINT)"

pkg/apis/volumesnapshot/v1alpha1/types.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ type VolumeSnapshotStatus struct {
9696
// +optional
9797
RestoreSize *resource.Quantity `json:"restoreSize" protobuf:"bytes,2,opt,name=restoreSize"`
9898

99-
// Ready is set to true only if the snapshot is ready to use (e.g., finish uploading if
99+
// ReadyToUse is set to true only if the snapshot is ready to use (e.g., finish uploading if
100100
// there is an uploading phase) and also VolumeSnapshot and its VolumeSnapshotContent
101-
// bind correctly with each other. If any of the above condition is not true, Ready is
101+
// bind correctly with each other. If any of the above condition is not true, ReadyToUse is
102102
// set to false
103103
// +optional
104-
Ready bool `json:"ready" protobuf:"varint,3,opt,name=ready"`
104+
ReadyToUse bool `json:"readyToUse" protobuf:"varint,3,opt,name=readyToUse"`
105105

106106
// The last error encountered during create snapshot operation, if any.
107107
// This field must only be set by the entity completing the create snapshot
@@ -132,6 +132,11 @@ type VolumeSnapshotClass struct {
132132
// to the snapshotter.
133133
// +optional
134134
Parameters map[string]string `json:"parameters,omitempty" protobuf:"bytes,3,rep,name=parameters"`
135+
136+
// Optional: what happens to a snapshot content when released from its snapshot.
137+
// The default policy is Delete if not specified.
138+
// +optional
139+
DeletionPolicy *DeletionPolicy `json:"deletionPolicy,omitempty" protobuf:"bytes,4,opt,name=deletionPolicy"`
135140
}
136141

137142
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -195,6 +200,11 @@ type VolumeSnapshotContentSpec struct {
195200
// be used if it is available.
196201
// +optional
197202
VolumeSnapshotClassName *string `json:"snapshotClassName" protobuf:"bytes,4,opt,name=snapshotClassName"`
203+
204+
// Optional: what happens to a snapshot content when released from its snapshot. It will be set to Delete by default
205+
// if not specified
206+
// +optional
207+
DeletionPolicy *DeletionPolicy `json:"deletionPolicy" protobuf:"bytes,5,opt,name=deletionPolicy"`
198208
}
199209

200210
// VolumeSnapshotSource represents the actual location and type of the snapshot. Only one of its members may be specified.
@@ -232,3 +242,15 @@ type CSIVolumeSnapshotSource struct {
232242
// +optional
233243
RestoreSize *int64 `json:"restoreSize,omitempty" protobuf:"bytes,4,opt,name=restoreSize"`
234244
}
245+
246+
// DeletionPolicy describes a policy for end-of-life maintenance of volume snapshot contents
247+
type DeletionPolicy string
248+
249+
const (
250+
// VolumeSnapshotContentDelete means the snapshot content will be deleted from Kubernetes on release from its volume snapshot.
251+
VolumeSnapshotContentDelete DeletionPolicy = "Delete"
252+
253+
// VolumeSnapshotContentRetain means the snapshot will be left in its current state on release from its volume snapshot.
254+
// The default policy is Retain if not specified.
255+
VolumeSnapshotContentRetain DeletionPolicy = "Retain"
256+
)

pkg/apis/volumesnapshot/v1alpha1/zz_generated.deepcopy.go

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client/clientset/versioned/typed/volumesnapshot/v1alpha1/volumesnapshot.go

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client/clientset/versioned/typed/volumesnapshot/v1alpha1/volumesnapshotclass.go

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client/clientset/versioned/typed/volumesnapshot/v1alpha1/volumesnapshotcontent.go

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/csi_handler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (handler *csiHandler) DeleteSnapshot(content *crdv1.VolumeSnapshotContent,
7777

7878
err := handler.csiConnection.DeleteSnapshot(ctx, content.Spec.CSI.SnapshotHandle, snapshotterCredentials)
7979
if err != nil {
80-
return fmt.Errorf("failed to delete snapshot data %s: %q", content.Name, err)
80+
return fmt.Errorf("failed to delete snapshot content %s: %q", content.Name, err)
8181
}
8282

8383
return nil
@@ -92,7 +92,7 @@ func (handler *csiHandler) GetSnapshotStatus(content *crdv1.VolumeSnapshotConten
9292

9393
csiSnapshotStatus, timestamp, size, err := handler.csiConnection.GetSnapshotStatus(ctx, content.Spec.CSI.SnapshotHandle)
9494
if err != nil {
95-
return false, 0, 0, fmt.Errorf("failed to list snapshot data %s: %q", content.Name, err)
95+
return false, 0, 0, fmt.Errorf("failed to list snapshot content %s: %q", content.Name, err)
9696
}
9797
return csiSnapshotStatus, timestamp, size, nil
9898

pkg/controller/framework_test.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ type reactorError struct {
166166
error error
167167
}
168168

169+
func withSnapshotFinalizer(snapshot *crdv1.VolumeSnapshot) *crdv1.VolumeSnapshot {
170+
snapshot.ObjectMeta.Finalizers = append(snapshot.ObjectMeta.Finalizers, VolumeSnapshotFinalizer)
171+
return snapshot
172+
}
173+
174+
func withContentFinalizer(content *crdv1.VolumeSnapshotContent) *crdv1.VolumeSnapshotContent {
175+
content.ObjectMeta.Finalizers = append(content.ObjectMeta.Finalizers, VolumeSnapshotContentFinalizer)
176+
return content
177+
}
178+
169179
// React is a callback called by fake kubeClient from the controller.
170180
// In other words, every snapshot/content change performed by the controller ends
171181
// here.
@@ -744,7 +754,7 @@ func newTestController(kubeClient kubernetes.Interface, clientset clientset.Inte
744754
}
745755

746756
// newContent returns a new content with given attributes
747-
func newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToSnapshotUID, boundToSnapshotName string, size *int64, creationTime *int64) *crdv1.VolumeSnapshotContent {
757+
func newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToSnapshotUID, boundToSnapshotName string, deletionPolicy *crdv1.DeletionPolicy, size *int64, creationTime *int64, withFinalizer bool) *crdv1.VolumeSnapshotContent {
748758
content := crdv1.VolumeSnapshotContent{
749759
ObjectMeta: metav1.ObjectMeta{
750760
Name: name,
@@ -766,6 +776,7 @@ func newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToS
766776
UID: types.UID(volumeUID),
767777
Name: volumeName,
768778
},
779+
DeletionPolicy: deletionPolicy,
769780
},
770781
}
771782
if boundToSnapshotName != "" {
@@ -778,17 +789,20 @@ func newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToS
778789
}
779790
}
780791

792+
if withFinalizer {
793+
return withContentFinalizer(&content)
794+
}
781795
return &content
782796
}
783797

784-
func newContentArray(name, className, snapshotHandle, volumeUID, volumeName, boundToSnapshotUID, boundToSnapshotName string, size *int64, creationTime *int64) []*crdv1.VolumeSnapshotContent {
798+
func newContentArray(name, className, snapshotHandle, volumeUID, volumeName, boundToSnapshotUID, boundToSnapshotName string, deletionPolicy *crdv1.DeletionPolicy, size *int64, creationTime *int64, withFinalizer bool) []*crdv1.VolumeSnapshotContent {
785799
return []*crdv1.VolumeSnapshotContent{
786-
newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToSnapshotUID, boundToSnapshotName, size, creationTime),
800+
newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToSnapshotUID, boundToSnapshotName, deletionPolicy, size, creationTime, withFinalizer),
787801
}
788802
}
789803

790-
func newContentWithUnmatchDriverArray(name, className, snapshotHandle, volumeUID, volumeName, boundToSnapshotUID, boundToSnapshotName string, size *int64, creationTime *int64) []*crdv1.VolumeSnapshotContent {
791-
content := newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToSnapshotUID, boundToSnapshotName, size, creationTime)
804+
func newContentWithUnmatchDriverArray(name, className, snapshotHandle, volumeUID, volumeName, boundToSnapshotUID, boundToSnapshotName string, deletionPolicy *crdv1.DeletionPolicy, size *int64, creationTime *int64) []*crdv1.VolumeSnapshotContent {
805+
content := newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToSnapshotUID, boundToSnapshotName, deletionPolicy, size, creationTime, false)
792806
content.Spec.VolumeSnapshotSource.CSI.Driver = "fake"
793807
return []*crdv1.VolumeSnapshotContent{
794808
content,
@@ -814,13 +828,13 @@ func newSnapshot(name, className, boundToContent, snapshotUID, claimName string,
814828
},
815829
Status: crdv1.VolumeSnapshotStatus{
816830
CreationTime: creationTime,
817-
Ready: ready,
831+
ReadyToUse: ready,
818832
Error: err,
819833
RestoreSize: size,
820834
},
821835
}
822836

823-
return &snapshot
837+
return withSnapshotFinalizer(&snapshot)
824838
}
825839

826840
func newSnapshotArray(name, className, boundToContent, snapshotUID, claimName string, ready bool, err *storagev1beta1.VolumeError, creationTime *metav1.Time, size *resource.Quantity) []*crdv1.VolumeSnapshot {

0 commit comments

Comments
 (0)