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
5ff35681
Commit
5ff35681
authored
Jan 24, 2018
by
Felipe Musse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make CSI volume attributes first class
parent
c153aff9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
10 additions
and
80 deletions
+10
-80
types.go
pkg/apis/core/types.go
+4
-0
csi_mounter.go
pkg/volume/csi/csi_mounter.go
+1
-31
csi_mounter_test.go
pkg/volume/csi/csi_mounter_test.go
+0
-47
csi_plugin.go
pkg/volume/csi/csi_plugin.go
+1
-2
types.go
staging/src/k8s.io/api/core/v1/types.go
+4
-0
No files found.
pkg/apis/core/types.go
View file @
5ff35681
...
@@ -1634,6 +1634,10 @@ type CSIPersistentVolumeSource struct {
...
@@ -1634,6 +1634,10 @@ type CSIPersistentVolumeSource struct {
// Ex. "ext4", "xfs", "ntfs". Implicitly inferred to be "ext4" if unspecified.
// Ex. "ext4", "xfs", "ntfs". Implicitly inferred to be "ext4" if unspecified.
// +optional
// +optional
FSType
string
FSType
string
// Attributes of the volume to publish.
// +optional
VolumeAttributes
map
[
string
]
string
}
}
// ContainerPort represents a network port in a single container
// ContainerPort represents a network port in a single container
...
...
pkg/volume/csi/csi_mounter.go
View file @
5ff35681
...
@@ -151,14 +151,7 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -151,14 +151,7 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
c
.
volumeInfo
=
attachment
.
Status
.
AttachmentMetadata
c
.
volumeInfo
=
attachment
.
Status
.
AttachmentMetadata
}
}
// get volume attributes
attribs
:=
csiSource
.
VolumeAttributes
// TODO: for alpha vol attributes are passed via PV.Annotations
// Beta will fix that
attribs
,
err
:=
getVolAttribsFromSpec
(
c
.
spec
)
if
err
!=
nil
{
glog
.
Error
(
log
(
"mounter.SetUpAt failed to extract volume attributes from PV annotations: %v"
,
err
))
return
err
}
// create target_dir before call to NodePublish
// create target_dir before call to NodePublish
if
err
:=
os
.
MkdirAll
(
dir
,
0750
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
dir
,
0750
);
err
!=
nil
{
...
@@ -295,29 +288,6 @@ func (c *csiMountMgr) TearDownAt(dir string) error {
...
@@ -295,29 +288,6 @@ func (c *csiMountMgr) TearDownAt(dir string) error {
return
nil
return
nil
}
}
// getVolAttribsFromSpec extracts CSI VolumeAttributes information from PV.Annotations
// using key csi.kubernetes.io/volume-attributes. The annotation value is expected
// to be a JSON-encoded object of form {"key0":"val0",...,"keyN":"valN"}
func
getVolAttribsFromSpec
(
spec
*
volume
.
Spec
)
(
map
[
string
]
string
,
error
)
{
if
spec
==
nil
{
return
nil
,
errors
.
New
(
"missing volume spec"
)
}
annotations
:=
spec
.
PersistentVolume
.
GetAnnotations
()
if
annotations
==
nil
{
return
nil
,
nil
// no annotations found
}
jsonAttribs
:=
annotations
[
csiVolAttribsAnnotationKey
]
if
jsonAttribs
==
""
{
return
nil
,
nil
// csi annotation not found
}
attribs
:=
map
[
string
]
string
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
jsonAttribs
),
&
attribs
);
err
!=
nil
{
glog
.
Error
(
log
(
"error parsing csi PV.Annotation [%s]=%s: %v"
,
csiVolAttribsAnnotationKey
,
jsonAttribs
,
err
))
return
nil
,
err
}
return
attribs
,
nil
}
// saveVolumeData persists parameter data as json file using the location
// saveVolumeData persists parameter data as json file using the location
// generated by /var/lib/kubelet/pods/<podID>/volumes/kubernetes.io~csi/<specVolId>/volume_data.json
// generated by /var/lib/kubelet/pods/<podID>/volumes/kubernetes.io~csi/<specVolId>/volume_data.json
func
saveVolumeData
(
p
*
csiPlugin
,
podUID
types
.
UID
,
specVolID
string
,
data
map
[
string
]
string
)
error
{
func
saveVolumeData
(
p
*
csiPlugin
,
podUID
types
.
UID
,
specVolID
string
,
data
map
[
string
]
string
)
error
{
...
...
pkg/volume/csi/csi_mounter_test.go
View file @
5ff35681
...
@@ -202,53 +202,6 @@ func TestUnmounterTeardown(t *testing.T) {
...
@@ -202,53 +202,6 @@ func TestUnmounterTeardown(t *testing.T) {
}
}
func
TestGetVolAttribsFromSpec
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
name
string
annotations
map
[
string
]
string
attribs
map
[
string
]
string
shouldFail
bool
}{
{
name
:
"attribs ok"
,
annotations
:
map
[
string
]
string
{
"key0"
:
"val0"
,
csiVolAttribsAnnotationKey
:
`{"k0":"attr0","k1":"attr1","k2":"attr2"}`
,
"keyN"
:
"valN"
},
attribs
:
map
[
string
]
string
{
"k0"
:
"attr0"
,
"k1"
:
"attr1"
,
"k2"
:
"attr2"
},
},
{
name
:
"missing attribs"
,
annotations
:
map
[
string
]
string
{
"key0"
:
"val0"
,
"keyN"
:
"valN"
},
},
{
name
:
"missing annotations"
,
},
{
name
:
"bad json"
,
annotations
:
map
[
string
]
string
{
"key0"
:
"val0"
,
csiVolAttribsAnnotationKey
:
`{"k0""attr0","k1":"attr1,"k2":"attr2"`
,
"keyN"
:
"valN"
},
attribs
:
map
[
string
]
string
{
"k0"
:
"attr0"
,
"k1"
:
"attr1"
,
"k2"
:
"attr2"
},
shouldFail
:
true
,
},
}
spec
:=
volume
.
NewSpecFromPersistentVolume
(
makeTestPV
(
"test-pv"
,
10
,
testDriver
,
testVol
),
false
)
for
_
,
tc
:=
range
testCases
{
t
.
Logf
(
"test case: %s"
,
tc
.
name
)
spec
.
PersistentVolume
.
Annotations
=
tc
.
annotations
attribs
,
err
:=
getVolAttribsFromSpec
(
spec
)
if
!
tc
.
shouldFail
&&
err
!=
nil
{
t
.
Errorf
(
"test case should not fail, but err != nil: %v"
,
err
)
}
eq
:=
true
for
k
,
v
:=
range
attribs
{
if
tc
.
attribs
[
k
]
!=
v
{
eq
=
false
}
}
if
!
eq
{
t
.
Errorf
(
"expecting attribs %#v, but got %#v"
,
tc
.
attribs
,
attribs
)
}
}
}
func
TestSaveVolumeData
(
t
*
testing
.
T
)
{
func
TestSaveVolumeData
(
t
*
testing
.
T
)
{
plug
,
tmpDir
:=
newTestPlugin
(
t
)
plug
,
tmpDir
:=
newTestPlugin
(
t
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
...
pkg/volume/csi/csi_plugin.go
View file @
5ff35681
...
@@ -31,8 +31,7 @@ import (
...
@@ -31,8 +31,7 @@ import (
)
)
const
(
const
(
csiPluginName
=
"kubernetes.io/csi"
csiPluginName
=
"kubernetes.io/csi"
csiVolAttribsAnnotationKey
=
"csi.volume.kubernetes.io/volume-attributes"
// TODO (vladimirvivien) implement a more dynamic way to discover
// TODO (vladimirvivien) implement a more dynamic way to discover
// the unix domain socket path for each installed csi driver.
// the unix domain socket path for each installed csi driver.
...
...
staging/src/k8s.io/api/core/v1/types.go
View file @
5ff35681
...
@@ -1748,6 +1748,10 @@ type CSIPersistentVolumeSource struct {
...
@@ -1748,6 +1748,10 @@ type CSIPersistentVolumeSource struct {
// Ex. "ext4", "xfs", "ntfs". Implicitly inferred to be "ext4" if unspecified.
// Ex. "ext4", "xfs", "ntfs". Implicitly inferred to be "ext4" if unspecified.
// +optional
// +optional
FSType
string
`json:"fsType,omitempty" protobuf:"bytes,4,opt,name=fsType"`
FSType
string
`json:"fsType,omitempty" protobuf:"bytes,4,opt,name=fsType"`
// Attributes of the volume to publish.
// +optional
VolumeAttributes
map
[
string
]
string
`json:"volumeAttributes,omitempty" protobuf:"bytes,5,rep,name=volumeAttributes"`
}
}
// ContainerPort represents a network port in a single container.
// ContainerPort represents a network port in a single container.
...
...
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