Skip to content

Commit c0b308c

Browse files
author
Cheng Pan
committed
Using provisioner name as resizer name
1 parent 11eb8af commit c0b308c

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

pkg/resizer/csi_resizer.go

+23-16
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ const (
4242
resizerSecretNameKey = "csi.storage.k8s.io/resizer-secret-name"
4343
resizerSecretNamespaceKey = "csi.storage.k8s.io/resizer-secret-namespace"
4444

45-
// In-tree resizer populates the key with the value as the storage plugin name
4645
// If CSI migration is enabled, the value will be CSI driver name
4746
// Otherwise, it will be in-tree storage plugin name
48-
volumeResizerKey = "volume.kubernetes.io/storage-resizer"
47+
volumeResizerKey = "volume.beta.kubernetes.io/storage-provisioner"
4948
)
5049

5150
var (
@@ -149,23 +148,26 @@ func (r *csiResizer) CanSupport(pv *v1.PersistentVolume, pvc *v1.PersistentVolum
149148
// It supports both CSI volume and migrated in-tree volume
150149
func (r *csiResizer) Resize(pv *v1.PersistentVolume, requestSize resource.Quantity) (resource.Quantity, bool, error) {
151150
oldSize := pv.Spec.Capacity[v1.ResourceStorage]
152-
var err error
153151

154-
if csitranslationlib.IsMigratedCSIDriverByName(r.name) {
155-
// handle migrated in-tree volume
156-
pv, err = csitranslationlib.TranslateInTreePVToCSI(pv)
157-
if err != nil {
158-
return oldSize, false, fmt.Errorf("failed to translate persistent volume: %v", err)
152+
var volumeID string
153+
if pv.Spec.CSI != nil {
154+
// handle CSI volume
155+
source := pv.Spec.CSI
156+
volumeID = source.VolumeHandle
157+
} else {
158+
if csitranslationlib.IsMigratedCSIDriverByName(r.name) {
159+
// handle migrated in-tree volume
160+
csiPV, err := csitranslationlib.TranslateInTreePVToCSI(pv)
161+
if err != nil {
162+
return oldSize, false, fmt.Errorf("failed to translate persistent volume: %v", err)
163+
}
164+
volumeID = csiPV.Spec.CSI.VolumeHandle
165+
} else {
166+
// non-migrated in-tree volume
167+
return oldSize, false, fmt.Errorf("volume %v is not migrated to CSI", pv.Name)
159168
}
160169
}
161170

162-
source := pv.Spec.CSI
163-
if source == nil {
164-
// in-tree volume that is not migrated yet
165-
return oldSize, false, fmt.Errorf("volume %v is not migrated to CSI", pv.Name)
166-
}
167-
volumeID := source.VolumeHandle
168-
169171
if len(volumeID) == 0 {
170172
return oldSize, false, errors.New("empty volume handle")
171173
}
@@ -194,7 +196,12 @@ func (r *csiResizer) Resize(pv *v1.PersistentVolume, requestSize resource.Quanti
194196
if err != nil {
195197
return oldSize, nodeResizeRequired, err
196198
}
197-
return *resource.NewQuantity(newSizeBytes, resource.BinarySI), nodeResizeRequired, err
199+
200+
if pv.Spec.VolumeMode == nil || *pv.Spec.VolumeMode == v1.PersistentVolumeFilesystem {
201+
return *resource.NewQuantity(newSizeBytes, resource.BinarySI), nodeResizeRequired, err
202+
}
203+
204+
return *resource.NewQuantity(newSizeBytes, resource.BinarySI), false, err
198205
}
199206

200207
func getDriverName(client csi.Client, timeout time.Duration) (string, error) {

pkg/resizer/csi_resizer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func createPVC(resizerName string) *v1.PersistentVolumeClaim {
203203
Name: "testPVC",
204204
Namespace: "test",
205205
Annotations: map[string]string{
206-
"volume.kubernetes.io/storage-resizer": resizerName,
206+
volumeResizerKey: resizerName,
207207
},
208208
},
209209
Spec: v1.PersistentVolumeClaimSpec{

0 commit comments

Comments
 (0)