Skip to content
Closed
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
15 changes: 15 additions & 0 deletions cmd/csi-snapshotter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
snapshotscheme "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned/scheme"
informers "github.com/kubernetes-csi/external-snapshotter/client/v4/informers/externalversions"
coreinformers "k8s.io/client-go/informers"
csitrans "k8s.io/csi-translation-lib"
)

const (
Expand Down Expand Up @@ -147,6 +148,20 @@ func main() {

klog.V(2).Infof("CSI driver name: %q", driverName)

// Create a new connection with the metrics manager with migrated label if the driver is migrated
translator := csitrans.New()
if translator.IsMigratedCSIDriverByName(driverName) {
metricsManager = metrics.NewCSIMetricsManagerWithOptions("" /* driverName */, metrics.WithMigration())
migratedCsiConn, err := connection.Connect(
*csiAddress,
metricsManager,
connection.OnConnectionLoss(connection.ExitOnConnectionLoss()))
if err == nil {
csiConn.Close()
csiConn = migratedCsiConn
}
}

// Prepare http endpoint for metrics + leader election healthz
mux := http.NewServeMux()
if addr != "" {
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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/kubernetes-csi/csi-test/v4 v4.0.2
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.0.0
github.com/prometheus/client_golang v1.8.0
Expand All @@ -34,6 +34,7 @@ require (
k8s.io/apimachinery v0.20.0
k8s.io/client-go v1.20.0
k8s.io/component-base v0.20.0
k8s.io/csi-translation-lib v0.20.0
k8s.io/klog/v2 v2.4.0
k8s.io/kubernetes v1.20.0
)
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,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/kubernetes-csi/csi-test/v4 v4.0.2 h1:MNj94SFHOGK6lOy+yDgxI+zlFWaPcgByqBH3JZZGyZI=
github.com/kubernetes-csi/csi-test/v4 v4.0.2/go.mod h1:z3FYigjLFAuzmFzKdHQr8gUPm5Xr4Du2twKcxfys0eI=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
Expand Down Expand Up @@ -1143,6 +1143,7 @@ k8s.io/component-base v0.20.0/go.mod h1:wKPj+RHnAr8LW2EIBIK7AxOHPde4gme2lzXwVSoR
k8s.io/component-helpers v0.20.0/go.mod h1:nx6NOtfSfGOxnSZsDJxpGbnsVuUA1UXpwDvZIrtigNk=
k8s.io/controller-manager v0.20.0/go.mod h1:nD4qym/pmCz2v1tpqvlEBVlHW9CAZwedloM8GrJTLpg=
k8s.io/cri-api v0.20.0/go.mod h1:2JRbKt+BFLTjtrILYVqQK5jqhI+XNdF6UiGMgczeBCI=
k8s.io/csi-translation-lib v0.20.0 h1:I4wsA4/nW2low2auCUIq/ZCF58/FlCADr1OddBh0AOQ=
k8s.io/csi-translation-lib v0.20.0/go.mod h1:M4CdD66GxEI6ev8aTtsA2NkK9kIF9K5VZQMcw/SsoLs=
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
Expand Down
17 changes: 17 additions & 0 deletions pkg/snapshotter/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import (

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/protobuf/ptypes"
"github.com/kubernetes-csi/csi-lib-utils/connection"
csirpc "github.com/kubernetes-csi/csi-lib-utils/rpc"

"google.golang.org/grpc"

csitrans "k8s.io/csi-translation-lib"
klog "k8s.io/klog/v2"
)

Expand Down Expand Up @@ -68,6 +70,7 @@ func (s *snapshot) CreateSnapshot(ctx context.Context, snapshotName string, volu
Secrets: snapshotterCredentials,
}

ctx = s.checkAndMarkAsMigrated(ctx)
rsp, err := client.CreateSnapshot(ctx, &req)
if err != nil {
return "", "", time.Time{}, 0, false, err
Expand All @@ -89,6 +92,7 @@ func (s *snapshot) DeleteSnapshot(ctx context.Context, snapshotID string, snapsh
Secrets: snapshotterCredentials,
}

ctx = s.checkAndMarkAsMigrated(ctx)
if _, err := client.DeleteSnapshot(ctx, &req); err != nil {
return err
}
Expand Down Expand Up @@ -129,6 +133,7 @@ func (s *snapshot) GetSnapshotStatus(ctx context.Context, snapshotID string, sna
SnapshotId: snapshotID,
Secrets: snapshotterListCredentials,
}
ctx = s.checkAndMarkAsMigrated(ctx)
rsp, err := client.ListSnapshots(ctx, &req)
if err != nil {
return false, time.Time{}, 0, err
Expand All @@ -144,3 +149,15 @@ func (s *snapshot) GetSnapshotStatus(ctx context.Context, snapshotID string, sna
}
return rsp.Entries[0].Snapshot.ReadyToUse, creationTime, rsp.Entries[0].Snapshot.SizeBytes, nil
}

func (s *snapshot) checkAndMarkAsMigrated(parent context.Context) context.Context {
driverName, err := csirpc.GetDriverName(parent, s.conn)
if err != nil {
return parent
}
translator := csitrans.New()
if translator.IsMigratedCSIDriverByName(driverName) {
return context.WithValue(parent, connection.AdditionalInfoKey, connection.AdditionalInfo{Migrated: "true"})
}
return parent
}

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.

Loading