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
d76b39ad
Commit
d76b39ad
authored
Oct 05, 2018
by
Darren Shepherd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove CSIBlockVolume
parent
cbbcac47
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
255 deletions
+8
-255
kube_features.go
pkg/features/kube_features.go
+0
-7
csi_block.go
pkg/volume/csi/csi_block.go
+3
-107
csi_plugin.go
pkg/volume/csi/csi_plugin.go
+5
-141
No files found.
pkg/features/kube_features.go
View file @
d76b39ad
...
...
@@ -251,12 +251,6 @@ const (
// Enable resource quota scope selectors
ResourceQuotaScopeSelectors
utilfeature
.
Feature
=
"ResourceQuotaScopeSelectors"
// owner: @vladimirvivien
// alpha: v1.11
//
// Enables CSI to use raw block storage volumes
CSIBlockVolume
utilfeature
.
Feature
=
"CSIBlockVolume"
// owner: @tallclair
// alpha: v1.12
//
...
...
@@ -337,7 +331,6 @@ var defaultKubernetesFeatureGates = map[utilfeature.Feature]utilfeature.FeatureS
PodReadinessGates
:
{
Default
:
true
,
PreRelease
:
utilfeature
.
Beta
},
KubeletPluginsWatcher
:
{
Default
:
true
,
PreRelease
:
utilfeature
.
GA
},
ResourceQuotaScopeSelectors
:
{
Default
:
true
,
PreRelease
:
utilfeature
.
Beta
},
CSIBlockVolume
:
{
Default
:
false
,
PreRelease
:
utilfeature
.
Alpha
},
RuntimeClass
:
{
Default
:
false
,
PreRelease
:
utilfeature
.
Alpha
},
SCTPSupport
:
{
Default
:
false
,
PreRelease
:
utilfeature
.
Alpha
},
VolumeSnapshotDataSource
:
{
Default
:
false
,
PreRelease
:
utilfeature
.
Alpha
},
...
...
pkg/volume/csi/csi_block.go
View file @
d76b39ad
...
...
@@ -26,9 +26,8 @@ import (
"k8s.io/klog"
"k8s.io/api/core/v1"
v1
"k8s.io/api/core/v1"
storage
"k8s.io/api/storage/v1beta1"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
kstrings
"k8s.io/kubernetes/pkg/util/strings"
...
...
@@ -207,65 +206,7 @@ func (m *csiBlockMapper) publishVolumeForBlock(
// SetUpDevice ensures the device is attached returns path where the device is located.
func
(
m
*
csiBlockMapper
)
SetUpDevice
()
(
string
,
error
)
{
if
!
m
.
plugin
.
blockEnabled
{
return
""
,
errors
.
New
(
"CSIBlockVolume feature not enabled"
)
}
klog
.
V
(
4
)
.
Infof
(
log
(
"blockMapper.SetUpDevice called"
))
// Get csiSource from spec
if
m
.
spec
==
nil
{
klog
.
Error
(
log
(
"blockMapper.SetUpDevice spec is nil"
))
return
""
,
fmt
.
Errorf
(
"spec is nil"
)
}
csiSource
,
err
:=
getCSISourceFromSpec
(
m
.
spec
)
if
err
!=
nil
{
klog
.
Error
(
log
(
"blockMapper.SetUpDevice failed to get CSI persistent source: %v"
,
err
))
return
""
,
err
}
// Search for attachment by VolumeAttachment.Spec.Source.PersistentVolumeName
nodeName
:=
string
(
m
.
plugin
.
host
.
GetNodeName
())
attachID
:=
getAttachmentName
(
csiSource
.
VolumeHandle
,
csiSource
.
Driver
,
nodeName
)
attachment
,
err
:=
m
.
k8s
.
StorageV1beta1
()
.
VolumeAttachments
()
.
Get
(
attachID
,
meta
.
GetOptions
{})
if
err
!=
nil
{
klog
.
Error
(
log
(
"blockMapper.SetupDevice failed to get volume attachment [id=%v]: %v"
,
attachID
,
err
))
return
""
,
err
}
if
attachment
==
nil
{
klog
.
Error
(
log
(
"blockMapper.SetupDevice unable to find VolumeAttachment [id=%s]"
,
attachID
))
return
""
,
errors
.
New
(
"no existing VolumeAttachment found"
)
}
//TODO (vladimirvivien) implement better AccessModes mapping between k8s and CSI
accessMode
:=
v1
.
ReadWriteOnce
if
m
.
spec
.
PersistentVolume
.
Spec
.
AccessModes
!=
nil
{
accessMode
=
m
.
spec
.
PersistentVolume
.
Spec
.
AccessModes
[
0
]
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
csiTimeout
)
defer
cancel
()
csiClient
,
err
:=
m
.
csiClientGetter
.
Get
()
if
err
!=
nil
{
klog
.
Error
(
log
(
"blockMapper.SetUpDevice failed to get CSI client: %v"
,
err
))
return
""
,
err
}
// Call NodeStageVolume
stagingPath
,
err
:=
m
.
stageVolumeForBlock
(
ctx
,
csiClient
,
accessMode
,
csiSource
,
attachment
)
if
err
!=
nil
{
return
""
,
err
}
// Call NodePublishVolume
publishPath
,
err
:=
m
.
publishVolumeForBlock
(
ctx
,
csiClient
,
accessMode
,
csiSource
,
attachment
,
stagingPath
)
if
err
!=
nil
{
return
""
,
err
}
return
publishPath
,
nil
return
""
,
errors
.
New
(
"CSIBlockVolume feature not enabled"
)
}
func
(
m
*
csiBlockMapper
)
MapDevice
(
devicePath
,
globalMapPath
,
volumeMapPath
,
volumeMapName
string
,
podUID
types
.
UID
)
error
{
...
...
@@ -323,50 +264,5 @@ func (m *csiBlockMapper) unstageVolumeForBlock(ctx context.Context, csi csiClien
// TearDownDevice removes traces of the SetUpDevice.
func
(
m
*
csiBlockMapper
)
TearDownDevice
(
globalMapPath
,
devicePath
string
)
error
{
if
!
m
.
plugin
.
blockEnabled
{
return
errors
.
New
(
"CSIBlockVolume feature not enabled"
)
}
klog
.
V
(
4
)
.
Infof
(
log
(
"unmapper.TearDownDevice(globalMapPath=%s; devicePath=%s)"
,
globalMapPath
,
devicePath
))
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
csiTimeout
)
defer
cancel
()
csiClient
,
err
:=
m
.
csiClientGetter
.
Get
()
if
err
!=
nil
{
klog
.
Error
(
log
(
"blockMapper.TearDownDevice failed to get CSI client: %v"
,
err
))
return
err
}
// Call NodeUnpublishVolume
publishPath
:=
m
.
getPublishPath
()
if
_
,
err
:=
os
.
Stat
(
publishPath
);
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
klog
.
V
(
4
)
.
Infof
(
log
(
"blockMapper.TearDownDevice publishPath(%s) has already been deleted, skip calling NodeUnpublishVolume"
,
publishPath
))
}
else
{
return
err
}
}
else
{
err
:=
m
.
unpublishVolumeForBlock
(
ctx
,
csiClient
,
publishPath
)
if
err
!=
nil
{
return
err
}
}
// Call NodeUnstageVolume
stagingPath
:=
m
.
getStagingPath
()
if
_
,
err
:=
os
.
Stat
(
stagingPath
);
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
klog
.
V
(
4
)
.
Infof
(
log
(
"blockMapper.TearDownDevice stagingPath(%s) has already been deleted, skip calling NodeUnstageVolume"
,
stagingPath
))
}
else
{
return
err
}
}
else
{
err
:=
m
.
unstageVolumeForBlock
(
ctx
,
csiClient
,
stagingPath
)
if
err
!=
nil
{
return
err
}
}
return
nil
return
errors
.
New
(
"CSIBlockVolume feature not enabled"
)
}
pkg/volume/csi/csi_plugin.go
View file @
d76b39ad
...
...
@@ -34,9 +34,7 @@ import (
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
utilversion
"k8s.io/apimachinery/pkg/util/version"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
clientset
"k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/csi/nodeinfomanager"
)
...
...
@@ -53,23 +51,16 @@ const (
volNameSep
=
"^"
volDataFileName
=
"vol_data.json"
fsTypeBlockName
=
"block"
// TODO: increase to something useful
csiResyncPeriod
=
time
.
Minute
)
var
deprecatedSocketDirVersions
=
[]
string
{
"0.1.0"
,
"0.2.0"
,
"0.3.0"
,
"0.4.0"
}
type
csiPlugin
struct
{
host
volume
.
VolumeHost
blockEnabled
bool
host
volume
.
VolumeHost
}
// ProbeVolumePlugins returns implemented plugins
func
ProbeVolumePlugins
()
[]
volume
.
VolumePlugin
{
p
:=
&
csiPlugin
{
host
:
nil
,
blockEnabled
:
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
CSIBlockVolume
),
host
:
nil
,
}
return
[]
volume
.
VolumePlugin
{
p
}
}
...
...
@@ -447,133 +438,15 @@ func (p *csiPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error)
var
_
volume
.
BlockVolumePlugin
=
&
csiPlugin
{}
func
(
p
*
csiPlugin
)
NewBlockVolumeMapper
(
spec
*
volume
.
Spec
,
podRef
*
api
.
Pod
,
opts
volume
.
VolumeOptions
)
(
volume
.
BlockVolumeMapper
,
error
)
{
if
!
p
.
blockEnabled
{
return
nil
,
errors
.
New
(
"CSIBlockVolume feature not enabled"
)
}
pvSource
,
err
:=
getCSISourceFromSpec
(
spec
)
if
err
!=
nil
{
return
nil
,
err
}
readOnly
,
err
:=
getReadOnlyFromSpec
(
spec
)
if
err
!=
nil
{
return
nil
,
err
}
klog
.
V
(
4
)
.
Info
(
log
(
"setting up block mapper for [volume=%v,driver=%v]"
,
pvSource
.
VolumeHandle
,
pvSource
.
Driver
))
k8s
:=
p
.
host
.
GetKubeClient
()
if
k8s
==
nil
{
klog
.
Error
(
log
(
"failed to get a kubernetes client"
))
return
nil
,
errors
.
New
(
"failed to get a Kubernetes client"
)
}
mapper
:=
&
csiBlockMapper
{
k8s
:
k8s
,
plugin
:
p
,
volumeID
:
pvSource
.
VolumeHandle
,
driverName
:
csiDriverName
(
pvSource
.
Driver
),
readOnly
:
readOnly
,
spec
:
spec
,
specName
:
spec
.
Name
(),
podUID
:
podRef
.
UID
,
}
mapper
.
csiClientGetter
.
driverName
=
csiDriverName
(
pvSource
.
Driver
)
// Save volume info in pod dir
dataDir
:=
getVolumeDeviceDataDir
(
spec
.
Name
(),
p
.
host
)
if
err
:=
os
.
MkdirAll
(
dataDir
,
0750
);
err
!=
nil
{
klog
.
Error
(
log
(
"failed to create data dir %s: %v"
,
dataDir
,
err
))
return
nil
,
err
}
klog
.
V
(
4
)
.
Info
(
log
(
"created path successfully [%s]"
,
dataDir
))
// persist volume info data for teardown
node
:=
string
(
p
.
host
.
GetNodeName
())
attachID
:=
getAttachmentName
(
pvSource
.
VolumeHandle
,
pvSource
.
Driver
,
node
)
volData
:=
map
[
string
]
string
{
volDataKey
.
specVolID
:
spec
.
Name
(),
volDataKey
.
volHandle
:
pvSource
.
VolumeHandle
,
volDataKey
.
driverName
:
pvSource
.
Driver
,
volDataKey
.
nodeName
:
node
,
volDataKey
.
attachmentID
:
attachID
,
}
if
err
:=
saveVolumeData
(
dataDir
,
volDataFileName
,
volData
);
err
!=
nil
{
klog
.
Error
(
log
(
"failed to save volume info data: %v"
,
err
))
if
err
:=
os
.
RemoveAll
(
dataDir
);
err
!=
nil
{
klog
.
Error
(
log
(
"failed to remove dir after error [%s]: %v"
,
dataDir
,
err
))
return
nil
,
err
}
return
nil
,
err
}
return
mapper
,
nil
return
nil
,
errors
.
New
(
"CSIBlockVolume feature not enabled"
)
}
func
(
p
*
csiPlugin
)
NewBlockVolumeUnmapper
(
volName
string
,
podUID
types
.
UID
)
(
volume
.
BlockVolumeUnmapper
,
error
)
{
if
!
p
.
blockEnabled
{
return
nil
,
errors
.
New
(
"CSIBlockVolume feature not enabled"
)
}
klog
.
V
(
4
)
.
Infof
(
log
(
"setting up block unmapper for [Spec=%v, podUID=%v]"
,
volName
,
podUID
))
unmapper
:=
&
csiBlockMapper
{
plugin
:
p
,
podUID
:
podUID
,
specName
:
volName
,
}
// load volume info from file
dataDir
:=
getVolumeDeviceDataDir
(
unmapper
.
specName
,
p
.
host
)
data
,
err
:=
loadVolumeData
(
dataDir
,
volDataFileName
)
if
err
!=
nil
{
klog
.
Error
(
log
(
"unmapper failed to load volume data file [%s]: %v"
,
dataDir
,
err
))
return
nil
,
err
}
unmapper
.
driverName
=
csiDriverName
(
data
[
volDataKey
.
driverName
])
unmapper
.
volumeID
=
data
[
volDataKey
.
volHandle
]
unmapper
.
csiClientGetter
.
driverName
=
unmapper
.
driverName
if
err
!=
nil
{
return
nil
,
err
}
return
unmapper
,
nil
return
nil
,
errors
.
New
(
"CSIBlockVolume feature not enabled"
)
}
func
(
p
*
csiPlugin
)
ConstructBlockVolumeSpec
(
podUID
types
.
UID
,
specVolName
,
mapPath
string
)
(
*
volume
.
Spec
,
error
)
{
if
!
p
.
blockEnabled
{
return
nil
,
errors
.
New
(
"CSIBlockVolume feature not enabled"
)
}
klog
.
V
(
4
)
.
Infof
(
"plugin.ConstructBlockVolumeSpec [podUID=%s, specVolName=%s, path=%s]"
,
string
(
podUID
),
specVolName
,
mapPath
)
dataDir
:=
getVolumeDeviceDataDir
(
specVolName
,
p
.
host
)
volData
,
err
:=
loadVolumeData
(
dataDir
,
volDataFileName
)
if
err
!=
nil
{
klog
.
Error
(
log
(
"plugin.ConstructBlockVolumeSpec failed loading volume data using [%s]: %v"
,
mapPath
,
err
))
return
nil
,
err
}
klog
.
V
(
4
)
.
Info
(
log
(
"plugin.ConstructBlockVolumeSpec extracted [%#v]"
,
volData
))
blockMode
:=
api
.
PersistentVolumeBlock
pv
:=
&
api
.
PersistentVolume
{
ObjectMeta
:
meta
.
ObjectMeta
{
Name
:
volData
[
volDataKey
.
specVolID
],
},
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
CSI
:
&
api
.
CSIPersistentVolumeSource
{
Driver
:
volData
[
volDataKey
.
driverName
],
VolumeHandle
:
volData
[
volDataKey
.
volHandle
],
},
},
VolumeMode
:
&
blockMode
,
},
}
return
volume
.
NewSpecFromPersistentVolume
(
pv
,
false
),
nil
return
nil
,
errors
.
New
(
"CSIBlockVolume feature not enabled"
)
}
func
(
p
*
csiPlugin
)
skipAttach
(
driver
string
)
(
bool
,
error
)
{
...
...
@@ -675,12 +548,3 @@ func isV0Version(version string) bool {
return
parsedVersion
.
Major
()
==
0
}
func
isV1Version
(
version
string
)
bool
{
parsedVersion
,
err
:=
utilversion
.
ParseGeneric
(
version
)
if
err
!=
nil
{
return
false
}
return
parsedVersion
.
Major
()
==
1
}
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