Skip to content

Commit 52234a7

Browse files
Merge pull request kubernetes-csi#106 from jsafrane/rebase-v0.5.0
Rebase to v0.5.0
2 parents 2c57909 + d3aa7e6 commit 52234a7

File tree

18 files changed

+1249
-887
lines changed

18 files changed

+1249
-887
lines changed

CHANGELOG-0.5.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog since v0.4.0
2+
3+
## New Features
4+
5+
- Ability to customize PVC workqueue retry interval ([#75](https://github.com/kubernetes-csi/external-resizer/pull/75), [@zuzzas](https://github.com/zuzzas))
6+
7+
## Other Notable Changes
8+
9+
- - Pass volume capability to ControllerExpandVolume RPC call ([#70](https://github.com/kubernetes-csi/external-resizer/pull/70), [@gnufied](https://github.com/gnufied))

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If your repo has certain guidelines for contribution, put them here ahead of the
1414

1515
- [Contributor License Agreement](https://git.k8s.io/community/CLA.md) Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests
1616
- [Kubernetes Contributor Guide](http://git.k8s.io/community/contributors/guide) - Main contributor documentation, or you can just jump directly to the [contributing section](http://git.k8s.io/community/contributors/guide#contributing)
17-
- [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet.md) - Common resources for existing developers
17+
- [Contributor Cheat Sheet](https://github.com/kubernetes/community/blob/master/contributors/guide/contributor-cheatsheet/README.md) - Common resources for existing developers
1818

1919
## Mentorship
2020

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ This information reflects the head of this branch.
1616

1717
| Compatible with CSI Version | Container Image | Recommended K8s Version |
1818
| ------------------------------------------------------------------------------------------ | -------------------------------| --------------- |
19-
| [CSI Spec v1.1.0](https://github.com/container-storage-interface/spec/releases/tag/v1.1.0) | quay.io/k8scsi/csi-resizer | 1.16 |
19+
| [CSI Spec v1.2.0](https://github.com/container-storage-interface/spec/releases/tag/v1.2.0) | quay.io/k8scsi/csi-resizer | 1.16 |
20+
2021

2122

2223
## Feature status
@@ -47,6 +48,10 @@ Note that the external-resizer does not scale with more replicas. Only one exter
4748

4849
* `--csiTimeout <duration>`: Timeout of all calls to CSI driver. It should be set to value that accommodates majority of `ControllerExpandVolume` calls. 15 seconds is used by default.
4950

51+
* `--retry-interval-start`: The starting value of the exponential backoff for failures. 1 second is used by default.
52+
53+
* `--retry-interval-max`: The exponential backoff maximum value. 5 minutes is used by default.
54+
5055
* `--workers <num>`: Number of simultaneously running `ControllerExpandVolume` operations. Default value is `10`.
5156

5257
* `--metrics-address`: The TCP network address where the prometheus metrics endpoint will run (example: `:8080` which corresponds to port 8080 on local host). The default is empty string, which means metrics endpoint is disabled.

cmd/csi-resizer/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"flag"
2222
"fmt"
23+
"k8s.io/client-go/util/workqueue"
2324
"os"
2425
"time"
2526

@@ -43,6 +44,9 @@ var (
4344
csiTimeout = flag.Duration("csiTimeout", 15*time.Second, "Timeout for waiting for CSI driver socket.")
4445
showVersion = flag.Bool("version", false, "Show version")
4546

47+
retryIntervalStart = flag.Duration("retry-interval-start", time.Second, "Initial retry interval of failed volume resize. It exponentially increases with each failure, up to retry-interval-max.")
48+
retryIntervalMax = flag.Duration("retry-interval-max", 5*time.Minute, "Maximum retry interval of failed volume resize.")
49+
4650
enableLeaderElection = flag.Bool("leader-election", false, "Enable leader election.")
4751
leaderElectionNamespace = flag.String("leader-election-namespace", "", "Namespace where the leader election resource lives. Defaults to the pod namespace if not set.")
4852

@@ -82,7 +86,9 @@ func main() {
8286
}
8387

8488
resizerName := csiResizer.Name()
85-
rc := controller.NewResizeController(resizerName, csiResizer, kubeClient, *resyncPeriod, informerFactory)
89+
rc := controller.NewResizeController(resizerName, csiResizer, kubeClient, *resyncPeriod, informerFactory,
90+
workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax),
91+
)
8692
run := func(ctx context.Context) {
8793
informerFactory.Start(wait.NeverStop)
8894
rc.Run(*workers, ctx)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/kubernetes-csi/external-resizer
33
go 1.12
44

55
require (
6-
github.com/container-storage-interface/spec v1.1.0
6+
github.com/container-storage-interface/spec v1.2.0
77
github.com/imdario/mergo v0.3.7 // indirect
88
github.com/kubernetes-csi/csi-lib-utils v0.7.0
99
google.golang.org/grpc v1.26.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA
2424
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
2525
github.com/container-storage-interface/spec v1.1.0 h1:qPsTqtR1VUPvMPeK0UnCZMtXaKGyyLPG8gj/wG6VqMs=
2626
github.com/container-storage-interface/spec v1.1.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
27+
github.com/container-storage-interface/spec v1.2.0 h1:bD9KIVgaVKKkQ/UbVUY9kCaH/CJbhNxe0eeB4JeJV2s=
28+
github.com/container-storage-interface/spec v1.2.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
2729
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2830
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2931
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

pkg/controller/controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ func NewResizeController(
6565
resizer resizer.Resizer,
6666
kubeClient kubernetes.Interface,
6767
resyncPeriod time.Duration,
68-
informerFactory informers.SharedInformerFactory) ResizeController {
68+
informerFactory informers.SharedInformerFactory,
69+
pvcRateLimiter workqueue.RateLimiter) ResizeController {
6970
pvInformer := informerFactory.Core().V1().PersistentVolumes()
7071
pvcInformer := informerFactory.Core().V1().PersistentVolumeClaims()
7172

@@ -76,7 +77,7 @@ func NewResizeController(
7677
v1.EventSource{Component: fmt.Sprintf("external-resizer %s", name)})
7778

7879
claimQueue := workqueue.NewNamedRateLimitingQueue(
79-
workqueue.DefaultControllerRateLimiter(), fmt.Sprintf("%s-pvc", name))
80+
pvcRateLimiter, fmt.Sprintf("%s-pvc", name))
8081

8182
ctrl := &resizeController{
8283
name: name,

pkg/controller/controller_test.go

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package controller
33
import (
44
"context"
55
"fmt"
6+
"k8s.io/client-go/util/workqueue"
67
"testing"
78
"time"
89

@@ -21,14 +22,17 @@ import (
2122
)
2223

2324
func TestController(t *testing.T) {
25+
blockVolumeMode := v1.PersistentVolumeBlock
26+
fsVolumeMode := v1.PersistentVolumeFilesystem
2427
for _, test := range []struct {
2528
Name string
2629
PVC *v1.PersistentVolumeClaim
2730
PV *v1.PersistentVolume
2831

29-
CreateObjects bool
30-
NodeResize bool
31-
CallCSIExpand bool
32+
CreateObjects bool
33+
NodeResize bool
34+
CallCSIExpand bool
35+
expectBlockVolume bool
3236
}{
3337
{
3438
Name: "Invalid key",
@@ -55,36 +59,45 @@ func TestController(t *testing.T) {
5559
{
5660
Name: "pv claimref does not have pvc UID",
5761
PVC: createPVC(2, 1),
58-
PV: createPV(1, "testPVC" /*pvcName*/, "test" /*pvcNamespace*/, "foobaz" /*pvcUID*/),
62+
PV: createPV(1, "testPVC" /*pvcName*/, "test" /*pvcNamespace*/, "foobaz" /*pvcUID*/, &fsVolumeMode),
5963
CallCSIExpand: false,
6064
},
6165
{
6266
Name: "pv claimref does not have PVC namespace",
6367
PVC: createPVC(2, 1),
64-
PV: createPV(1, "testPVC" /*pvcName*/, "test1" /*pvcNamespace*/, "foobar" /*pvcUID*/),
68+
PV: createPV(1, "testPVC" /*pvcName*/, "test1" /*pvcNamespace*/, "foobar" /*pvcUID*/, &fsVolumeMode),
6569
CallCSIExpand: false,
6670
},
6771
{
6872
Name: "pv claimref is nil",
6973
PVC: createPVC(2, 1),
70-
PV: createPV(1, "" /*pvcName*/, "test1" /*pvcNamespace*/, "foobar" /*pvcUID*/),
74+
PV: createPV(1, "" /*pvcName*/, "test1" /*pvcNamespace*/, "foobar" /*pvcUID*/, &fsVolumeMode),
7175
CallCSIExpand: false,
7276
},
7377
{
7478
Name: "Resize PVC, no FS resize",
7579
PVC: createPVC(2, 1),
76-
PV: createPV(1, "testPVC", "test", "foobar"),
80+
PV: createPV(1, "testPVC", "test", "foobar", &fsVolumeMode),
7781
CreateObjects: true,
7882
CallCSIExpand: true,
7983
},
8084
{
8185
Name: "Resize PVC with FS resize",
8286
PVC: createPVC(2, 1),
83-
PV: createPV(1, "testPVC", "test", "foobar"),
87+
PV: createPV(1, "testPVC", "test", "foobar", &fsVolumeMode),
8488
CreateObjects: true,
8589
NodeResize: true,
8690
CallCSIExpand: true,
8791
},
92+
{
93+
Name: "Block Resize PVC with FS resize",
94+
PVC: createPVC(2, 1),
95+
PV: createPV(1, "testPVC", "test", "foobar", &blockVolumeMode),
96+
CreateObjects: true,
97+
NodeResize: true,
98+
CallCSIExpand: true,
99+
expectBlockVolume: true,
100+
},
88101
} {
89102
client := csi.NewMockClient("mock", test.NodeResize, true, true)
90103
driverName, _ := client.GetDriverName(context.TODO())
@@ -123,7 +136,7 @@ func TestController(t *testing.T) {
123136
t.Fatalf("Test %s: Unable to create resizer: %v", test.Name, err)
124137
}
125138

126-
controller := NewResizeController(driverName, csiResizer, kubeClient, time.Second, informerFactory)
139+
controller := NewResizeController(driverName, csiResizer, kubeClient, time.Second, informerFactory, workqueue.DefaultControllerRateLimiter())
127140
err = controller.(*resizeController).syncPVC(fmt.Sprintf("%s/%s", test.PVC.Namespace, test.PVC.Name))
128141
if err != nil {
129142
t.Fatalf("Test %s: Unexpected error: %v", test.Name, err)
@@ -137,6 +150,16 @@ func TestController(t *testing.T) {
137150
if !test.CallCSIExpand && expandCallCount > 0 {
138151
t.Fatalf("for %s: expected no csi expand call, received csi expansion request", test.Name)
139152
}
153+
154+
usedCapability := client.GetCapability()
155+
156+
if test.CallCSIExpand && test.expectBlockVolume && usedCapability.GetBlock() == nil {
157+
t.Errorf("For %s: expected block accesstype got: %v", test.Name, usedCapability)
158+
}
159+
160+
if test.CallCSIExpand && !test.expectBlockVolume && usedCapability.GetMount() == nil {
161+
t.Errorf("For %s: expected mount accesstype got: %v", test.Name, usedCapability)
162+
}
140163
}
141164
}
142165

@@ -180,14 +203,15 @@ func createPVC(requestGB, capacityGB int) *v1.PersistentVolumeClaim {
180203
}
181204
}
182205

183-
func createPV(capacityGB int, pvcName, pvcNamespace string, pvcUID types.UID) *v1.PersistentVolume {
206+
func createPV(capacityGB int, pvcName, pvcNamespace string, pvcUID types.UID, volumeMode *v1.PersistentVolumeMode) *v1.PersistentVolume {
184207
capacity := quantityGB(capacityGB)
185208

186209
pv := &v1.PersistentVolume{
187210
ObjectMeta: metav1.ObjectMeta{
188211
Name: "testPV",
189212
},
190213
Spec: v1.PersistentVolumeSpec{
214+
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
191215
Capacity: map[v1.ResourceName]resource.Quantity{
192216
v1.ResourceStorage: capacity,
193217
},
@@ -197,6 +221,7 @@ func createPV(capacityGB int, pvcName, pvcNamespace string, pvcUID types.UID) *v
197221
VolumeHandle: "foo",
198222
},
199223
},
224+
VolumeMode: volumeMode,
200225
},
201226
}
202227
if len(pvcName) > 0 {

pkg/csi/client.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type Client interface {
4848

4949
// Expand expands the volume to a new size at least as big as requestBytes.
5050
// It returns the new size and whether the volume need expand operation on the node.
51-
Expand(ctx context.Context, volumeID string, requestBytes int64, secrets map[string]string) (int64, bool, error)
51+
Expand(ctx context.Context, volumeID string, requestBytes int64, secrets map[string]string, capability *csi.VolumeCapability) (int64, bool, error)
5252
}
5353

5454
// New creates a new CSI client.
@@ -120,11 +120,13 @@ func (c *client) Expand(
120120
ctx context.Context,
121121
volumeID string,
122122
requestBytes int64,
123-
secrets map[string]string) (int64, bool, error) {
123+
secrets map[string]string,
124+
capability *csi.VolumeCapability) (int64, bool, error) {
124125
req := &csi.ControllerExpandVolumeRequest{
125-
Secrets: secrets,
126-
VolumeId: volumeID,
127-
CapacityRange: &csi.CapacityRange{RequiredBytes: requestBytes},
126+
Secrets: secrets,
127+
VolumeId: volumeID,
128+
CapacityRange: &csi.CapacityRange{RequiredBytes: requestBytes},
129+
VolumeCapability: capability,
128130
}
129131
resp, err := c.ctrlClient.ControllerExpandVolume(ctx, req)
130132
if err != nil {

pkg/csi/mock_client.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package csi
22

3-
import "context"
3+
import (
4+
"context"
5+
6+
"github.com/container-storage-interface/spec/lib/go/csi"
7+
)
48

59
func NewMockClient(
610
name string,
@@ -23,6 +27,7 @@ type MockClient struct {
2327
supportsPluginControllerService bool
2428
expandCalled int
2529
usedSecrets map[string]string
30+
usedCapability *csi.VolumeCapability
2631
}
2732

2833
func (c *MockClient) GetDriverName(context.Context) (string, error) {
@@ -45,17 +50,23 @@ func (c *MockClient) Expand(
4550
ctx context.Context,
4651
volumeID string,
4752
requestBytes int64,
48-
secrets map[string]string) (int64, bool, error) {
53+
secrets map[string]string,
54+
capability *csi.VolumeCapability) (int64, bool, error) {
4955
// TODO: Determine whether the operation succeeds or fails by parameters.
5056
c.expandCalled++
5157
c.usedSecrets = secrets
58+
c.usedCapability = capability
5259
return requestBytes, c.supportsNodeResize, nil
5360
}
5461

5562
func (c *MockClient) GetExpandCount() int {
5663
return c.expandCalled
5764
}
5865

66+
func (c *MockClient) GetCapability() *csi.VolumeCapability {
67+
return c.usedCapability
68+
}
69+
5970
// GetSecrets returns secrets used for volume expansion
6071
func (c *MockClient) GetSecrets() map[string]string {
6172
return c.usedSecrets

0 commit comments

Comments
 (0)