Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmd/csi-resizer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/kubernetes-csi/external-resizer/pkg/controller"
"github.com/kubernetes-csi/external-resizer/pkg/resizer"
"github.com/kubernetes-csi/external-resizer/pkg/util"
csitrans "k8s.io/csi-translation-lib"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/informers"
Expand Down Expand Up @@ -127,6 +128,17 @@ func main() {
}
klog.V(2).Infof("CSI driver name: %q", driverName)

translator := csitrans.New()
if translator.IsMigratedCSIDriverByName(driverName) {
metricsManager = metrics.NewCSIMetricsManagerWithOptions(driverName, metrics.WithMigration())
migratedCsiClient, err := csi.New(*csiAddress, *timeout, metricsManager)
if err != nil {
klog.Fatal(err.Error())
}
csiClient.CloseConnection()
csiClient = migratedCsiClient
}

csiResizer, err := resizer.NewResizerFromClient(
csiClient,
*timeout,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/googleapis/gnostic v0.5.3 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/kubernetes-csi/csi-lib-utils v0.9.0
github.com/kubernetes-csi/csi-lib-utils v0.9.1
github.com/prometheus/client_golang v1.9.0 // indirect
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620 // indirect
golang.org/x/net v0.0.0-20201216054612-986b41b23924 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kubernetes-csi/csi-lib-utils v0.9.0 h1:TbuDmxoVqM+fvVkzG/7sShyX/8jUln0ElLHuETcsQJI=
github.com/kubernetes-csi/csi-lib-utils v0.9.0/go.mod h1:8E2jVUX9j3QgspwHXa6LwyN7IHQDjW9jX3kwoWnSC+M=
github.com/kubernetes-csi/csi-lib-utils v0.9.1 h1:sGq6ifVujfMSkfTsMZip44Ttv8SDXvsBlFk9GdYl/b8=
github.com/kubernetes-csi/csi-lib-utils v0.9.1/go.mod h1:8E2jVUX9j3QgspwHXa6LwyN7IHQDjW9jX3kwoWnSC+M=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
Expand Down
7 changes: 7 additions & 0 deletions pkg/csi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type Client interface {
// Expand expands the volume to a new size at least as big as requestBytes.
// It returns the new size and whether the volume need expand operation on the node.
Expand(ctx context.Context, volumeID string, requestBytes int64, secrets map[string]string, capability *csi.VolumeCapability) (int64, bool, error)

//CloseConnection closes the gRPC connection established by the client
CloseConnection()
}

// New creates a new CSI client.
Expand Down Expand Up @@ -134,3 +137,7 @@ func (c *client) Expand(
}
return resp.CapacityBytes, resp.NodeExpansionRequired, nil
}

func (c *client) CloseConnection() {
c.conn.Close()
}
19 changes: 19 additions & 0 deletions pkg/csi/mock_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-lib-utils/connection"
)

func NewMockClient(
Expand All @@ -28,6 +29,7 @@ type MockClient struct {
supportsPluginControllerService bool
expandCalled int
expansionFailed bool
checkMigratedLabel bool
usedSecrets map[string]string
usedCapability *csi.VolumeCapability
}
Expand All @@ -52,6 +54,10 @@ func (c *MockClient) SetExpansionFailed() {
c.expansionFailed = true
}

func (c *MockClient) SetCheckMigratedLabel() {
c.checkMigratedLabel = true
}

func (c *MockClient) Expand(
ctx context.Context,
volumeID string,
Expand All @@ -63,6 +69,15 @@ func (c *MockClient) Expand(
c.expandCalled++
return requestBytes, c.supportsNodeResize, fmt.Errorf("expansion failed")
}
if c.checkMigratedLabel {
additionalInfo := ctx.Value(connection.AdditionalInfoKey)
additionalInfoVal := additionalInfo.(connection.AdditionalInfo)
migrated := additionalInfoVal.Migrated
if migrated != "true" {
err := fmt.Errorf("Expected value of migrated label: true, Actual value: %s", migrated)
return requestBytes, c.supportsNodeResize, err
}
}
c.expandCalled++
c.usedSecrets = secrets
c.usedCapability = capability
Expand All @@ -81,3 +96,7 @@ func (c *MockClient) GetCapability() *csi.VolumeCapability {
func (c *MockClient) GetSecrets() map[string]string {
return c.usedSecrets
}

func (c *MockClient) CloseConnection() {

}
8 changes: 7 additions & 1 deletion pkg/resizer/csi_resizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (
"context"
"errors"
"fmt"
"strconv"
"time"

csilib "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-lib-utils/connection"
"github.com/kubernetes-csi/external-resizer/pkg/csi"
"github.com/kubernetes-csi/external-resizer/pkg/util"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -125,6 +127,7 @@ func (r *csiResizer) Resize(pv *v1.PersistentVolume, requestSize resource.Quanti
var volumeID string
var source *v1.CSIPersistentVolumeSource
var pvSpec v1.PersistentVolumeSpec
var migrated bool
if pv.Spec.CSI != nil {
// handle CSI volume
source = pv.Spec.CSI
Expand All @@ -138,6 +141,7 @@ func (r *csiResizer) Resize(pv *v1.PersistentVolume, requestSize resource.Quanti
if err != nil {
return oldSize, false, fmt.Errorf("failed to translate persistent volume: %v", err)
}
migrated = true
source = csiPV.Spec.CSI
pvSpec = csiPV.Spec
volumeID = source.VolumeHandle
Expand Down Expand Up @@ -167,8 +171,10 @@ func (r *csiResizer) Resize(pv *v1.PersistentVolume, requestSize resource.Quanti
}

ctx, cancel := timeoutCtx(r.timeout)
resizeCtx := context.WithValue(ctx, connection.AdditionalInfoKey, connection.AdditionalInfo{Migrated: strconv.FormatBool(migrated)})

defer cancel()
newSizeBytes, nodeResizeRequired, err := r.client.Expand(ctx, volumeID, requestSize.Value(), secrets, capability)
newSizeBytes, nodeResizeRequired, err := r.client.Expand(resizeCtx, volumeID, requestSize.Value(), secrets, capability)
if err != nil {
return oldSize, nodeResizeRequired, err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/resizer/csi_resizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func TestResizeMigratedPV(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
driverName := tc.driverName
client := csi.NewMockClient(driverName, true, true, true)
client.SetCheckMigratedLabel()
k8sClient, informerFactory := fakeK8s()
resizer, err := NewResizerFromClient(client, 0, k8sClient, informerFactory, driverName)
if err != nil {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ github.com/hashicorp/golang-lru/simplelru
github.com/imdario/mergo
# github.com/json-iterator/go v1.1.10
github.com/json-iterator/go
# github.com/kubernetes-csi/csi-lib-utils v0.9.0
# github.com/kubernetes-csi/csi-lib-utils v0.9.1
## explicit
github.com/kubernetes-csi/csi-lib-utils/connection
github.com/kubernetes-csi/csi-lib-utils/leaderelection
Expand Down