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
c6c74d68
Commit
c6c74d68
authored
Aug 28, 2018
by
Jan Safranek
Committed by
Hemant Kumar
Sep 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Skip attach for non-attachable CSI volumes
parent
7c1311bc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
27 deletions
+81
-27
csi_attacher.go
pkg/volume/csi/csi_attacher.go
+32
-13
csi_mounter.go
pkg/volume/csi/csi_mounter.go
+2
-14
csi_plugin.go
pkg/volume/csi/csi_plugin.go
+47
-0
No files found.
pkg/volume/csi/csi_attacher.go
View file @
c6c74d68
...
@@ -70,6 +70,16 @@ func (c *csiAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string
...
@@ -70,6 +70,16 @@ func (c *csiAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string
return
""
,
err
return
""
,
err
}
}
skip
,
err
:=
c
.
plugin
.
skipAttach
(
csiSource
.
Driver
)
if
err
!=
nil
{
glog
.
Error
(
log
(
"attacher.Attach failed to find if driver is attachable: %v"
,
err
))
return
""
,
err
}
if
skip
{
glog
.
V
(
4
)
.
Infof
(
log
(
"skipping attach for driver %s"
,
csiSource
.
Driver
))
return
""
,
nil
}
node
:=
string
(
nodeName
)
node
:=
string
(
nodeName
)
pvName
:=
spec
.
PersistentVolume
.
GetName
()
pvName
:=
spec
.
PersistentVolume
.
GetName
()
attachID
:=
getAttachmentName
(
csiSource
.
VolumeHandle
,
csiSource
.
Driver
,
node
)
attachID
:=
getAttachmentName
(
csiSource
.
VolumeHandle
,
csiSource
.
Driver
,
node
)
...
@@ -120,6 +130,16 @@ func (c *csiAttacher) WaitForAttach(spec *volume.Spec, attachID string, pod *v1.
...
@@ -120,6 +130,16 @@ func (c *csiAttacher) WaitForAttach(spec *volume.Spec, attachID string, pod *v1.
return
""
,
err
return
""
,
err
}
}
skip
,
err
:=
c
.
plugin
.
skipAttach
(
source
.
Driver
)
if
err
!=
nil
{
glog
.
Error
(
log
(
"attacher.Attach failed to find if driver is attachable: %v"
,
err
))
return
""
,
err
}
if
skip
{
glog
.
V
(
4
)
.
Infof
(
log
(
"Driver is not attachable, skip waiting for attach"
))
return
""
,
nil
}
return
c
.
waitForVolumeAttachment
(
source
.
VolumeHandle
,
attachID
,
timeout
)
return
c
.
waitForVolumeAttachment
(
source
.
VolumeHandle
,
attachID
,
timeout
)
}
}
...
@@ -221,11 +241,22 @@ func (c *csiAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName types.No
...
@@ -221,11 +241,22 @@ func (c *csiAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName types.No
glog
.
Error
(
log
(
"attacher.VolumesAreAttached failed: %v"
,
err
))
glog
.
Error
(
log
(
"attacher.VolumesAreAttached failed: %v"
,
err
))
continue
continue
}
}
skip
,
err
:=
c
.
plugin
.
skipAttach
(
source
.
Driver
)
if
err
!=
nil
{
glog
.
Error
(
log
(
"Failed to check CSIDriver for %s: %s"
,
source
.
Driver
,
err
))
}
else
{
if
skip
{
// This volume is not attachable, pretend it's attached
attached
[
spec
]
=
true
continue
}
}
attachID
:=
getAttachmentName
(
source
.
VolumeHandle
,
source
.
Driver
,
string
(
nodeName
))
attachID
:=
getAttachmentName
(
source
.
VolumeHandle
,
source
.
Driver
,
string
(
nodeName
))
glog
.
V
(
4
)
.
Info
(
log
(
"probing attachment status for VolumeAttachment %v"
,
attachID
))
glog
.
V
(
4
)
.
Info
(
log
(
"probing attachment status for VolumeAttachment %v"
,
attachID
))
attach
,
err
:=
c
.
k8s
.
StorageV1beta1
()
.
VolumeAttachments
()
.
Get
(
attachID
,
meta
.
GetOptions
{})
attach
,
err
:=
c
.
k8s
.
StorageV1beta1
()
.
VolumeAttachments
()
.
Get
(
attachID
,
meta
.
GetOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
attached
[
spec
]
=
false
glog
.
Error
(
log
(
"attacher.VolumesAreAttached failed for attach.ID=%v: %v"
,
attachID
,
err
))
glog
.
Error
(
log
(
"attacher.VolumesAreAttached failed for attach.ID=%v: %v"
,
attachID
,
err
))
continue
continue
}
}
...
@@ -325,19 +356,7 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
...
@@ -325,19 +356,7 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
// Start MountDevice
// Start MountDevice
nodeName
:=
string
(
c
.
plugin
.
host
.
GetNodeName
())
nodeName
:=
string
(
c
.
plugin
.
host
.
GetNodeName
())
attachID
:=
getAttachmentName
(
csiSource
.
VolumeHandle
,
csiSource
.
Driver
,
nodeName
)
publishVolumeInfo
,
err
:=
c
.
plugin
.
getPublishVolumeInfo
(
c
.
k8s
,
csiSource
.
VolumeHandle
,
csiSource
.
Driver
,
nodeName
)
// search for attachment by VolumeAttachment.Spec.Source.PersistentVolumeName
attachment
,
err
:=
c
.
k8s
.
StorageV1beta1
()
.
VolumeAttachments
()
.
Get
(
attachID
,
meta
.
GetOptions
{})
if
err
!=
nil
{
return
err
// This err already has enough context ("VolumeAttachment xyz not found")
}
if
attachment
==
nil
{
err
=
errors
.
New
(
"no existing VolumeAttachment found"
)
return
err
}
publishVolumeInfo
:=
attachment
.
Status
.
AttachmentMetadata
nodeStageSecrets
:=
map
[
string
]
string
{}
nodeStageSecrets
:=
map
[
string
]
string
{}
if
csiSource
.
NodeStageSecretRef
!=
nil
{
if
csiSource
.
NodeStageSecretRef
!=
nil
{
...
...
pkg/volume/csi/csi_mounter.go
View file @
c6c74d68
...
@@ -18,7 +18,6 @@ package csi
...
@@ -18,7 +18,6 @@ package csi
import
(
import
(
"context"
"context"
"errors"
"fmt"
"fmt"
"os"
"os"
"path"
"path"
...
@@ -26,7 +25,6 @@ import (
...
@@ -26,7 +25,6 @@ import (
"github.com/golang/glog"
"github.com/golang/glog"
api
"k8s.io/api/core/v1"
api
"k8s.io/api/core/v1"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes"
kstrings
"k8s.io/kubernetes/pkg/util/strings"
kstrings
"k8s.io/kubernetes/pkg/util/strings"
...
@@ -113,9 +111,6 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -113,9 +111,6 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
}
}
csi
:=
c
.
csiClient
csi
:=
c
.
csiClient
nodeName
:=
string
(
c
.
plugin
.
host
.
GetNodeName
())
attachID
:=
getAttachmentName
(
csiSource
.
VolumeHandle
,
csiSource
.
Driver
,
nodeName
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
csiTimeout
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
csiTimeout
)
defer
cancel
()
defer
cancel
()
...
@@ -134,20 +129,13 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -134,20 +129,13 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
return
err
return
err
}
}
}
}
// search for attachment by VolumeAttachment.Spec.Source.PersistentVolumeName
// search for attachment by VolumeAttachment.Spec.Source.PersistentVolumeName
if
c
.
volumeInfo
==
nil
{
if
c
.
volumeInfo
==
nil
{
attachment
,
err
:=
c
.
k8s
.
StorageV1beta1
()
.
VolumeAttachments
()
.
Get
(
attachID
,
meta
.
GetOptions
{})
nodeName
:=
string
(
c
.
plugin
.
host
.
GetNodeName
())
c
.
volumeInfo
,
err
=
c
.
plugin
.
getPublishVolumeInfo
(
c
.
k8s
,
c
.
volumeID
,
c
.
driverName
,
nodeName
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Error
(
log
(
"mounter.SetupAt failed while getting volume attachment [id=%v]: %v"
,
attachID
,
err
))
return
err
return
err
}
}
if
attachment
==
nil
{
glog
.
Error
(
log
(
"unable to find VolumeAttachment [id=%s]"
,
attachID
))
return
errors
.
New
(
"no existing VolumeAttachment found"
)
}
c
.
volumeInfo
=
attachment
.
Status
.
AttachmentMetadata
}
}
attribs
:=
csiSource
.
VolumeAttributes
attribs
:=
csiSource
.
VolumeAttributes
...
...
pkg/volume/csi/csi_plugin.go
View file @
c6c74d68
...
@@ -29,10 +29,12 @@ import (
...
@@ -29,10 +29,12 @@ import (
"github.com/golang/glog"
"github.com/golang/glog"
api
"k8s.io/api/core/v1"
api
"k8s.io/api/core/v1"
apierrs
"k8s.io/apimachinery/pkg/api/errors"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/wait"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
clientset
"k8s.io/client-go/kubernetes"
csiapiinformer
"k8s.io/csi-api/pkg/client/informers/externalversions"
csiapiinformer
"k8s.io/csi-api/pkg/client/informers/externalversions"
csiinformer
"k8s.io/csi-api/pkg/client/informers/externalversions/csi/v1alpha1"
csiinformer
"k8s.io/csi-api/pkg/client/informers/externalversions/csi/v1alpha1"
csilister
"k8s.io/csi-api/pkg/client/listers/csi/v1alpha1"
csilister
"k8s.io/csi-api/pkg/client/listers/csi/v1alpha1"
...
@@ -490,3 +492,48 @@ func (p *csiPlugin) ConstructBlockVolumeSpec(podUID types.UID, specVolName, mapP
...
@@ -490,3 +492,48 @@ func (p *csiPlugin) ConstructBlockVolumeSpec(podUID types.UID, specVolName, mapP
return
volume
.
NewSpecFromPersistentVolume
(
pv
,
false
),
nil
return
volume
.
NewSpecFromPersistentVolume
(
pv
,
false
),
nil
}
}
func
(
p
*
csiPlugin
)
skipAttach
(
driver
string
)
(
bool
,
error
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
CSISkipAttach
)
{
return
false
,
nil
}
if
p
.
csiDriverLister
==
nil
{
return
false
,
errors
.
New
(
"CSIDriver lister does not exist"
)
}
csiDriver
,
err
:=
p
.
csiDriverLister
.
Get
(
driver
)
if
err
!=
nil
{
if
apierrs
.
IsNotFound
(
err
)
{
// Don't skip attach if CSIDriver does not exist
return
false
,
nil
}
return
false
,
err
}
if
csiDriver
.
Spec
.
AttachRequired
!=
nil
&&
*
csiDriver
.
Spec
.
AttachRequired
==
false
{
return
true
,
nil
}
return
false
,
nil
}
func
(
p
*
csiPlugin
)
getPublishVolumeInfo
(
client
clientset
.
Interface
,
handle
,
driver
,
nodeName
string
)
(
map
[
string
]
string
,
error
)
{
skip
,
err
:=
p
.
skipAttach
(
driver
)
if
err
!=
nil
{
return
nil
,
err
}
if
skip
{
return
nil
,
nil
}
attachID
:=
getAttachmentName
(
handle
,
driver
,
nodeName
)
// search for attachment by VolumeAttachment.Spec.Source.PersistentVolumeName
attachment
,
err
:=
client
.
StorageV1beta1
()
.
VolumeAttachments
()
.
Get
(
attachID
,
meta
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
err
// This err already has enough context ("VolumeAttachment xyz not found")
}
if
attachment
==
nil
{
err
=
errors
.
New
(
"no existing VolumeAttachment found"
)
return
nil
,
err
}
return
attachment
.
Status
.
AttachmentMetadata
,
nil
}
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