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
22d5e481
Commit
22d5e481
authored
Aug 23, 2017
by
Mikaël Cluseau
Committed by
Mikaël Cluseau
Aug 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(flexvolume): simplify capabilities handling
parent
470eb922
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
39 deletions
+55
-39
BUILD
pkg/volume/flexvolume/BUILD
+1
-0
driver-call.go
pkg/volume/flexvolume/driver-call.go
+16
-30
driver-call_test.go
pkg/volume/flexvolume/driver-call_test.go
+32
-0
mounter-defaults.go
pkg/volume/flexvolume/mounter-defaults.go
+1
-1
plugin.go
pkg/volume/flexvolume/plugin.go
+5
-8
No files found.
pkg/volume/flexvolume/BUILD
View file @
22d5e481
...
...
@@ -42,6 +42,7 @@ go_test(
"attacher_test.go",
"common_test.go",
"detacher_test.go",
"driver-call_test.go",
"flexvolume_test.go",
"mounter_test.go",
"plugin_test.go",
...
...
pkg/volume/flexvolume/driver-call.go
View file @
22d5e481
...
...
@@ -58,9 +58,6 @@ const (
optionKeyPodUID
=
"kubernetes.io/pod.uid"
optionKeyServiceAccountName
=
"kubernetes.io/serviceAccount.name"
attachCapability
=
"attach"
selinuxRelabelCapability
=
"selinuxRelabel"
)
const
(
...
...
@@ -83,11 +80,6 @@ type DriverCall struct {
args
[]
string
}
type
driverCapabilities
struct
{
attach
bool
selinuxRelabel
bool
}
func
(
plugin
*
flexVolumePlugin
)
NewDriverCall
(
command
string
)
*
DriverCall
{
return
plugin
.
NewDriverCallWithTimeout
(
command
,
0
)
}
...
...
@@ -210,7 +202,19 @@ type DriverStatus struct {
// Returns capabilities of the driver.
// By default we assume all the capabilities are supported.
// If the plugin does not support a capability, it can return false for that capability.
Capabilities
map
[
string
]
bool
Capabilities
*
DriverCapabilities
`json:",omitempty"`
}
type
DriverCapabilities
struct
{
Attach
bool
`json:"attach"`
SELinuxRelabel
bool
`json:"selinuxRelabel"`
}
func
defaultCapabilities
()
*
DriverCapabilities
{
return
&
DriverCapabilities
{
Attach
:
true
,
SELinuxRelabel
:
true
,
}
}
// isCmdNotSupportedErr checks if the error corresponds to command not supported by
...
...
@@ -226,7 +230,9 @@ func isCmdNotSupportedErr(err error) bool {
// handleCmdResponse processes the command output and returns the appropriate
// error code or message.
func
handleCmdResponse
(
cmd
string
,
output
[]
byte
)
(
*
DriverStatus
,
error
)
{
var
status
DriverStatus
status
:=
DriverStatus
{
Capabilities
:
defaultCapabilities
(),
}
if
err
:=
json
.
Unmarshal
(
output
,
&
status
);
err
!=
nil
{
glog
.
Errorf
(
"Failed to unmarshal output for command: %s, output: %q, error: %s"
,
cmd
,
string
(
output
),
err
.
Error
())
return
nil
,
err
...
...
@@ -241,23 +247,3 @@ func handleCmdResponse(cmd string, output []byte) (*DriverStatus, error) {
return
&
status
,
nil
}
// getDriverCapabilities returns the reported capabilities as returned by driver's init() function
func
(
ds
*
DriverStatus
)
getDriverCapabilities
()
*
driverCapabilities
{
driverCaps
:=
&
driverCapabilities
{
attach
:
true
,
selinuxRelabel
:
true
,
}
// Check if driver supports SELinux Relabeling of mounted volume
if
dcap
,
ok
:=
ds
.
Capabilities
[
selinuxRelabelCapability
];
ok
{
driverCaps
.
selinuxRelabel
=
dcap
}
// Check whether the plugin is attachable.
if
dcap
,
ok
:=
ds
.
Capabilities
[
attachCapability
];
ok
{
driverCaps
.
attach
=
dcap
}
return
driverCaps
}
pkg/volume/flexvolume/driver-call_test.go
0 → 100644
View file @
22d5e481
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
flexvolume
import
(
"testing"
)
func
TestHandleResponseDefaults
(
t
*
testing
.
T
)
{
ds
,
err
:=
handleCmdResponse
(
"test"
,
[]
byte
(
`{"status": "Success"}`
))
if
err
!=
nil
{
t
.
Error
(
"error: "
,
err
)
}
if
*
ds
.
Capabilities
!=
*
defaultCapabilities
()
{
t
.
Error
(
"wrong default capabilities: "
,
*
ds
.
Capabilities
)
}
}
pkg/volume/flexvolume/mounter-defaults.go
View file @
22d5e481
...
...
@@ -47,7 +47,7 @@ func (f *mounterDefaults) GetAttributes() volume.Attributes {
return
volume
.
Attributes
{
ReadOnly
:
f
.
readOnly
,
Managed
:
!
f
.
readOnly
,
SupportsSELinux
:
f
.
flexVolume
.
plugin
.
capabilities
.
sel
inuxRelabel
,
SupportsSELinux
:
f
.
flexVolume
.
plugin
.
capabilities
.
SEL
inuxRelabel
,
}
}
...
...
pkg/volume/flexvolume/plugin.go
View file @
22d5e481
...
...
@@ -42,8 +42,8 @@ type flexVolumePlugin struct {
runner
exec
.
Interface
sync
.
Mutex
capabilities
*
driverCapabilities
unsupportedCommands
[]
string
capabilities
DriverCapabilities
}
type
flexVolumeAttachablePlugin
struct
{
...
...
@@ -65,19 +65,16 @@ func NewFlexVolumePlugin(pluginDir, name string) (volume.VolumePlugin, error) {
unsupportedCommands
:
[]
string
{},
}
//
Retrieve driver reported
capabilities
//
Initialize the plugin and probe the
capabilities
call
:=
flexPlugin
.
NewDriverCall
(
initCmd
)
ds
,
err
:=
call
.
Run
()
if
err
!=
nil
{
return
nil
,
err
}
flexPlugin
.
capabilities
=
*
ds
.
Capabilities
driverCaps
:=
ds
.
getDriverCapabilities
()
flexPlugin
.
capabilities
=
driverCaps
// Check whether the plugin is attachable.
if
driverCaps
.
attach
{
// Plugin supports attach/detach by default, so return flexVolumeAttachablePlugin
if
flexPlugin
.
capabilities
.
Attach
{
// Plugin supports attach/detach, so return flexVolumeAttachablePlugin
return
&
flexVolumeAttachablePlugin
{
flexVolumePlugin
:
flexPlugin
},
nil
}
else
{
return
flexPlugin
,
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