Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c8956fa9
Commit
c8956fa9
authored
Feb 24, 2018
by
Serguei Bezverkhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CSI code changes
parent
e3c8ed23
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
23 additions
and
181 deletions
+23
-181
Godeps.json
Godeps/Godeps.json
+2
-2
LICENSES
Godeps/LICENSES
+1
-1
BUILD
pkg/volume/csi/BUILD
+1
-2
csi_client.go
pkg/volume/csi/csi_client.go
+12
-95
csi_client_test.go
pkg/volume/csi/csi_client_test.go
+1
-32
csi_mounter.go
pkg/volume/csi/csi_mounter.go
+4
-21
csi_plugin.go
pkg/volume/csi/csi_plugin.go
+0
-6
BUILD
pkg/volume/csi/fake/BUILD
+1
-1
fake_client.go
pkg/volume/csi/fake/fake_client.go
+1
-21
csi.pb.go
...com/container-storage-interface/spec/lib/go/csi/csi.pb.go
+0
-0
No files found.
Godeps/Godeps.json
View file @
c8956fa9
...
...
@@ -452,9 +452,9 @@
"Rev"
:
"8d75e11374a1928608c906fe745b538483e7aeb2"
},
{
"ImportPath"
:
"github.com/container-storage-interface/spec/lib/go/csi"
,
"ImportPath"
:
"github.com/container-storage-interface/spec/lib/go/csi
/v0
"
,
"Comment"
:
"v0.1.0-5-g7ab01a9"
,
"Rev"
:
"
91c189774c16b0661255943c09ea9d97d5a423e7
"
"Rev"
:
"
31c167062b1a62a9810e4fd94d7c986113b490b8
"
},
{
"ImportPath"
:
"github.com/containerd/console"
,
...
...
Godeps/LICENSES
View file @
c8956fa9
...
...
@@ -12786,7 +12786,7 @@ SOFTWARE.
================================================================================
= vendor/github.com/container-storage-interface/spec/lib/go/csi licensed under: =
= vendor/github.com/container-storage-interface/spec/lib/go/csi
/v0
licensed under: =
Apache License
Version 2.0, January 2004
pkg/volume/csi/BUILD
View file @
c8956fa9
...
...
@@ -16,7 +16,7 @@ go_library(
"//pkg/util/strings:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume/util:go_default_library",
"//vendor/github.com/container-storage-interface/spec/lib/go/csi:go_default_library",
"//vendor/github.com/container-storage-interface/spec/lib/go/csi
/v0
:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/google.golang.org/grpc:go_default_library",
...
...
@@ -43,7 +43,6 @@ go_test(
"//pkg/volume:go_default_library",
"//pkg/volume/csi/fake:go_default_library",
"//pkg/volume/testing:go_default_library",
"//vendor/github.com/container-storage-interface/spec/lib/go/csi:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/google.golang.org/grpc:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
...
...
pkg/volume/csi/csi_client.go
View file @
c8956fa9
...
...
@@ -17,13 +17,11 @@ limitations under the License.
package
csi
import
(
"bytes"
"errors"
"fmt"
"net"
"time"
csipb
"github.com/container-storage-interface/spec/lib/go/csi"
csipb
"github.com/container-storage-interface/spec/lib/go/csi
/v0
"
"github.com/golang/glog"
grpctx
"golang.org/x/net/context"
"google.golang.org/grpc"
...
...
@@ -31,7 +29,6 @@ import (
)
type
csiClient
interface
{
AssertSupportedVersion
(
ctx
grpctx
.
Context
,
ver
*
csipb
.
Version
)
error
NodePublishVolume
(
ctx
grpctx
.
Context
,
volumeid
string
,
...
...
@@ -40,14 +37,13 @@ type csiClient interface {
accessMode
api
.
PersistentVolumeAccessMode
,
volumeInfo
map
[
string
]
string
,
volumeAttribs
map
[
string
]
string
,
nodePublish
Credential
s
map
[
string
]
string
,
nodePublish
Secret
s
map
[
string
]
string
,
fsType
string
,
)
error
NodeUnpublishVolume
(
ctx
grpctx
.
Context
,
volID
string
,
targetPath
string
,
nodeUnpublishCredentials
map
[
string
]
string
,
)
error
}
...
...
@@ -94,63 +90,6 @@ func (c *csiDriverClient) assertConnection() error {
return
nil
}
// AssertSupportedVersion ensures driver supports specified spec version.
// If version is not supported, the assertion fails with an error.
// This test should be done early during the storage operation flow to avoid
// unnecessary calls later.
// `ver` argument holds the expected supported version.
func
(
c
*
csiDriverClient
)
AssertSupportedVersion
(
ctx
grpctx
.
Context
,
ver
*
csipb
.
Version
)
error
{
if
c
.
versionAsserted
{
if
!
c
.
versionSupported
{
return
fmt
.
Errorf
(
"version %s not supported"
,
verToStr
(
ver
))
}
return
nil
}
if
err
:=
c
.
assertConnection
();
err
!=
nil
{
c
.
versionAsserted
=
false
return
err
}
glog
.
V
(
4
)
.
Info
(
log
(
"asserting version supported by driver"
))
rsp
,
err
:=
c
.
idClient
.
GetSupportedVersions
(
ctx
,
&
csipb
.
GetSupportedVersionsRequest
{})
if
err
!=
nil
{
c
.
versionAsserted
=
false
return
err
}
supported
:=
false
vers
:=
rsp
.
GetSupportedVersions
()
glog
.
V
(
4
)
.
Info
(
log
(
"driver reports %d versions supported: %s"
,
len
(
vers
),
versToStr
(
vers
)))
// If our supported version is still at 0.X.X, then check
// also the minor number. If our supported version is >= 1.X.X
// then check only the major number.
for
_
,
v
:=
range
vers
{
if
ver
.
GetMajor
()
==
int32
(
0
)
&&
(
ver
.
GetMajor
()
==
v
.
GetMajor
()
&&
ver
.
GetMinor
()
==
v
.
GetMinor
())
{
supported
=
true
break
}
else
if
ver
.
GetMajor
()
!=
int32
(
0
)
&&
ver
.
GetMajor
()
==
v
.
GetMajor
()
{
supported
=
true
break
}
}
c
.
versionAsserted
=
true
c
.
versionSupported
=
supported
if
!
supported
{
return
fmt
.
Errorf
(
"CSI Driver does not support version %s. Instead it supports versions %s"
,
verToStr
(
ver
),
versToStr
(
vers
))
}
glog
.
V
(
4
)
.
Info
(
log
(
"version %s supported"
,
verToStr
(
ver
)))
return
nil
}
func
(
c
*
csiDriverClient
)
NodePublishVolume
(
ctx
grpctx
.
Context
,
volID
string
,
...
...
@@ -159,7 +98,7 @@ func (c *csiDriverClient) NodePublishVolume(
accessMode
api
.
PersistentVolumeAccessMode
,
volumeInfo
map
[
string
]
string
,
volumeAttribs
map
[
string
]
string
,
nodePublish
Credential
s
map
[
string
]
string
,
nodePublish
Secret
s
map
[
string
]
string
,
fsType
string
,
)
error
{
glog
.
V
(
4
)
.
Info
(
log
(
"calling NodePublishVolume rpc [volid=%s,target_path=%s]"
,
volID
,
targetPath
))
...
...
@@ -175,13 +114,12 @@ func (c *csiDriverClient) NodePublishVolume(
}
req
:=
&
csipb
.
NodePublishVolumeRequest
{
Version
:
csiVersion
,
VolumeId
:
volID
,
TargetPath
:
targetPath
,
Readonly
:
readOnly
,
PublishInfo
:
volumeInfo
,
VolumeAttributes
:
volumeAttribs
,
NodePublishCredentials
:
nodePublishCredentials
,
VolumeId
:
volID
,
TargetPath
:
targetPath
,
Readonly
:
readOnly
,
PublishInfo
:
volumeInfo
,
VolumeAttributes
:
volumeAttribs
,
NodePublishSecrets
:
nodePublishSecrets
,
VolumeCapability
:
&
csipb
.
VolumeCapability
{
AccessMode
:
&
csipb
.
VolumeCapability_AccessMode
{
Mode
:
asCSIAccessMode
(
accessMode
),
...
...
@@ -198,7 +136,7 @@ func (c *csiDriverClient) NodePublishVolume(
return
err
}
func
(
c
*
csiDriverClient
)
NodeUnpublishVolume
(
ctx
grpctx
.
Context
,
volID
string
,
targetPath
string
,
nodeUnpublishCredentials
map
[
string
]
string
)
error
{
func
(
c
*
csiDriverClient
)
NodeUnpublishVolume
(
ctx
grpctx
.
Context
,
volID
string
,
targetPath
string
)
error
{
glog
.
V
(
4
)
.
Info
(
log
(
"calling NodeUnpublishVolume rpc: [volid=%s, target_path=%s"
,
volID
,
targetPath
))
if
volID
==
""
{
return
errors
.
New
(
"missing volume id"
)
...
...
@@ -212,10 +150,8 @@ func (c *csiDriverClient) NodeUnpublishVolume(ctx grpctx.Context, volID string,
}
req
:=
&
csipb
.
NodeUnpublishVolumeRequest
{
Version
:
csiVersion
,
VolumeId
:
volID
,
TargetPath
:
targetPath
,
NodeUnpublishCredentials
:
nodeUnpublishCredentials
,
VolumeId
:
volID
,
TargetPath
:
targetPath
,
}
_
,
err
:=
c
.
nodeClient
.
NodeUnpublishVolume
(
ctx
,
req
)
...
...
@@ -233,22 +169,3 @@ func asCSIAccessMode(am api.PersistentVolumeAccessMode) csipb.VolumeCapability_A
}
return
csipb
.
VolumeCapability_AccessMode_UNKNOWN
}
func
verToStr
(
ver
*
csipb
.
Version
)
string
{
if
ver
==
nil
{
return
""
}
return
fmt
.
Sprintf
(
"%d.%d.%d"
,
ver
.
GetMajor
(),
ver
.
GetMinor
(),
ver
.
GetPatch
())
}
func
versToStr
(
vers
[]
*
csipb
.
Version
)
string
{
if
vers
==
nil
{
return
""
}
str
:=
bytes
.
NewBufferString
(
"["
)
for
_
,
v
:=
range
vers
{
str
.
WriteString
(
fmt
.
Sprintf
(
"{%s};"
,
verToStr
(
v
)))
}
str
.
WriteString
(
"]"
)
return
str
.
String
()
}
pkg/volume/csi/csi_client_test.go
View file @
c8956fa9
...
...
@@ -20,7 +20,6 @@ import (
"errors"
"testing"
csipb
"github.com/container-storage-interface/spec/lib/go/csi"
grpctx
"golang.org/x/net/context"
"google.golang.org/grpc"
api
"k8s.io/api/core/v1"
...
...
@@ -39,35 +38,6 @@ func setupClient(t *testing.T) *csiDriverClient {
return
client
}
func
TestClientAssertSupportedVersion
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testName
string
ver
*
csipb
.
Version
mustFail
bool
err
error
}{
{
testName
:
"supported version"
,
ver
:
&
csipb
.
Version
{
Major
:
0
,
Minor
:
0
,
Patch
:
0
}},
{
testName
:
"supported version"
,
ver
:
&
csipb
.
Version
{
Major
:
0
,
Minor
:
1
,
Patch
:
0
}},
{
testName
:
"supported version"
,
ver
:
&
csipb
.
Version
{
Major
:
0
,
Minor
:
1
,
Patch
:
10
}},
{
testName
:
"supported version"
,
ver
:
&
csipb
.
Version
{
Major
:
0
,
Minor
:
2
,
Patch
:
0
}},
{
testName
:
"supported version"
,
ver
:
&
csipb
.
Version
{
Major
:
1
,
Minor
:
1
,
Patch
:
0
}},
{
testName
:
"supported version"
,
ver
:
&
csipb
.
Version
{
Major
:
1
,
Minor
:
0
,
Patch
:
10
}},
{
testName
:
"unsupported version"
,
ver
:
&
csipb
.
Version
{
Major
:
10
,
Minor
:
0
,
Patch
:
0
},
mustFail
:
true
},
{
testName
:
"unsupported version"
,
ver
:
&
csipb
.
Version
{
Major
:
0
,
Minor
:
10
,
Patch
:
0
},
mustFail
:
true
},
{
testName
:
"grpc error"
,
ver
:
&
csipb
.
Version
{
Major
:
0
,
Minor
:
1
,
Patch
:
0
},
mustFail
:
true
,
err
:
errors
.
New
(
"grpc error"
)},
}
for
_
,
tc
:=
range
testCases
{
t
.
Logf
(
"test case: %s"
,
tc
.
testName
)
client
:=
setupClient
(
t
)
client
.
idClient
.
(
*
fake
.
IdentityClient
)
.
SetNextError
(
tc
.
err
)
err
:=
client
.
AssertSupportedVersion
(
grpctx
.
Background
(),
tc
.
ver
)
if
tc
.
mustFail
&&
err
==
nil
{
t
.
Error
(
"test must fail, but err = nil"
)
}
}
}
func
TestClientNodePublishVolume
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
name
string
...
...
@@ -126,8 +96,7 @@ func TestClientNodeUnpublishVolume(t *testing.T) {
for
_
,
tc
:=
range
testCases
{
t
.
Logf
(
"test case: %s"
,
tc
.
name
)
client
.
nodeClient
.
(
*
fake
.
NodeClient
)
.
SetNextError
(
tc
.
err
)
nodeUnpublishCredentials
:=
map
[
string
]
string
{}
err
:=
client
.
NodeUnpublishVolume
(
grpctx
.
Background
(),
tc
.
volID
,
tc
.
targetPath
,
nodeUnpublishCredentials
)
err
:=
client
.
NodeUnpublishVolume
(
grpctx
.
Background
(),
tc
.
volID
,
tc
.
targetPath
)
if
tc
.
mustFail
&&
err
==
nil
{
t
.
Error
(
"test must fail, but err is nil"
)
}
...
...
pkg/volume/csi/csi_mounter.go
View file @
c8956fa9
...
...
@@ -121,12 +121,6 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
nodeName
:=
string
(
c
.
plugin
.
host
.
GetNodeName
())
attachID
:=
getAttachmentName
(
csiSource
.
VolumeHandle
,
csiSource
.
Driver
,
nodeName
)
// ensure version is supported
if
err
:=
csi
.
AssertSupportedVersion
(
ctx
,
csiVersion
);
err
!=
nil
{
glog
.
Error
(
log
(
"mounter.SetUpAt failed to assert version: %v"
,
err
))
return
err
}
// search for attachment by VolumeAttachment.Spec.Source.PersistentVolumeName
if
c
.
volumeInfo
==
nil
{
attachment
,
err
:=
c
.
k8s
.
StorageV1beta1
()
.
VolumeAttachments
()
.
Get
(
attachID
,
meta
.
GetOptions
{})
...
...
@@ -179,9 +173,9 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
if
len
(
fsType
)
==
0
{
fsType
=
defaultFSType
}
nodePublish
Credential
s
:=
map
[
string
]
string
{}
nodePublish
Secret
s
:=
map
[
string
]
string
{}
if
csiSource
.
NodePublishSecretRef
!=
nil
{
nodePublish
Credential
s
=
getCredentialsFromSecret
(
c
.
k8s
,
csiSource
.
NodePublishSecretRef
)
nodePublish
Secret
s
=
getCredentialsFromSecret
(
c
.
k8s
,
csiSource
.
NodePublishSecretRef
)
}
err
=
csi
.
NodePublishVolume
(
ctx
,
...
...
@@ -191,7 +185,7 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
accessMode
,
c
.
volumeInfo
,
attribs
,
nodePublish
Credential
s
,
nodePublish
Secret
s
,
fsType
,
)
...
...
@@ -239,7 +233,6 @@ func (c *csiMountMgr) TearDownAt(dir string) error {
return
nil
}
csiSource
,
err
:=
getCSISourceFromSpec
(
c
.
spec
)
if
err
!=
nil
{
glog
.
Error
(
log
(
"mounter.TearDownAt failed to get CSI persistent source: %v"
,
err
))
return
err
...
...
@@ -268,17 +261,7 @@ func (c *csiMountMgr) TearDownAt(dir string) error {
csi
:=
c
.
csiClient
// TODO make all assertion calls private within the client itself
if
err
:=
csi
.
AssertSupportedVersion
(
ctx
,
csiVersion
);
err
!=
nil
{
glog
.
Errorf
(
log
(
"mounter.TearDownAt failed to assert version: %v"
,
err
))
return
err
}
nodeUnpublishCredentials
:=
map
[
string
]
string
{}
if
csiSource
.
NodePublishSecretRef
!=
nil
{
nodeUnpublishCredentials
=
getCredentialsFromSecret
(
c
.
k8s
,
csiSource
.
NodePublishSecretRef
)
}
if
err
:=
csi
.
NodeUnpublishVolume
(
ctx
,
volID
,
dir
,
nodeUnpublishCredentials
);
err
!=
nil
{
if
err
:=
csi
.
NodeUnpublishVolume
(
ctx
,
volID
,
dir
);
err
!=
nil
{
glog
.
Errorf
(
log
(
"mounter.TearDownAt failed: %v"
,
err
))
return
err
}
...
...
pkg/volume/csi/csi_plugin.go
View file @
c8956fa9
...
...
@@ -21,7 +21,6 @@ import (
"fmt"
"time"
csipb
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/glog"
api
"k8s.io/api/core/v1"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
...
...
@@ -43,11 +42,6 @@ const (
volDataFileName
=
"vol_data.json"
)
var
(
// csiVersion supported csi version
csiVersion
=
&
csipb
.
Version
{
Major
:
0
,
Minor
:
2
,
Patch
:
0
}
)
type
csiPlugin
struct
{
host
volume
.
VolumeHost
}
...
...
pkg/volume/csi/fake/BUILD
View file @
c8956fa9
...
...
@@ -6,7 +6,7 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/volume/csi/fake",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/container-storage-interface/spec/lib/go/csi:go_default_library",
"//vendor/github.com/container-storage-interface/spec/lib/go/csi
/v0
:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/google.golang.org/grpc:go_default_library",
],
...
...
pkg/volume/csi/fake/fake_client.go
View file @
c8956fa9
...
...
@@ -23,7 +23,7 @@ import (
"google.golang.org/grpc"
csipb
"github.com/container-storage-interface/spec/lib/go/csi"
csipb
"github.com/container-storage-interface/spec/lib/go/csi
/v0
"
grpctx
"golang.org/x/net/context"
)
...
...
@@ -42,26 +42,6 @@ func (f *IdentityClient) SetNextError(err error) {
f
.
nextErr
=
err
}
// GetSupportedVersions returns supported version
func
(
f
*
IdentityClient
)
GetSupportedVersions
(
ctx
grpctx
.
Context
,
req
*
csipb
.
GetSupportedVersionsRequest
,
opts
...
grpc
.
CallOption
)
(
*
csipb
.
GetSupportedVersionsResponse
,
error
)
{
// short circuit with an error
if
f
.
nextErr
!=
nil
{
return
nil
,
f
.
nextErr
}
rsp
:=
&
csipb
.
GetSupportedVersionsResponse
{
SupportedVersions
:
[]
*
csipb
.
Version
{
{
Major
:
0
,
Minor
:
0
,
Patch
:
1
},
{
Major
:
0
,
Minor
:
1
,
Patch
:
0
},
{
Major
:
0
,
Minor
:
2
,
Patch
:
0
},
{
Major
:
1
,
Minor
:
0
,
Patch
:
0
},
{
Major
:
1
,
Minor
:
0
,
Patch
:
1
},
{
Major
:
1
,
Minor
:
1
,
Patch
:
1
},
},
}
return
rsp
,
nil
}
// GetPluginInfo returns plugin info
func
(
f
*
IdentityClient
)
GetPluginInfo
(
ctx
context
.
Context
,
in
*
csipb
.
GetPluginInfoRequest
,
opts
...
grpc
.
CallOption
)
(
*
csipb
.
GetPluginInfoResponse
,
error
)
{
return
nil
,
nil
...
...
vendor/github.com/container-storage-interface/spec/lib/go/csi/csi.pb.go
deleted
100644 → 0
View file @
e3c8ed23
This source diff could not be displayed because it is too large. You can
view the blob
instead.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment