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
96827de9
Commit
96827de9
authored
Aug 22, 2017
by
Jan Safranek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
azure: Use VolumeHost.GetExec() to execute stuff in volume plugins
This prepares volume plugins to run things in containers instead of running them on the host.
parent
9484d243
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
44 deletions
+12
-44
BUILD
pkg/volume/azure_dd/BUILD
+0
-3
attacher.go
pkg/volume/azure_dd/attacher.go
+2
-5
azure_common.go
pkg/volume/azure_dd/azure_common.go
+9
-13
azure_common_test.go
pkg/volume/azure_dd/azure_common_test.go
+1
-23
No files found.
pkg/volume/azure_dd/BUILD
View file @
96827de9
...
...
@@ -34,7 +34,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
],
)
...
...
@@ -63,7 +62,5 @@ go_test(
"//pkg/volume/testing:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/client-go/util/testing:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
"//vendor/k8s.io/utils/exec/testing:go_default_library",
],
)
pkg/volume/azure_dd/attacher.go
View file @
96827de9
...
...
@@ -36,7 +36,6 @@ import (
"k8s.io/kubernetes/pkg/volume"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
"k8s.io/kubernetes/pkg/volume/util/volumehelper"
"k8s.io/utils/exec"
)
type
azureDiskDetacher
struct
{
...
...
@@ -171,9 +170,7 @@ func (a *azureDiskAttacher) WaitForAttach(spec *volume.Spec, devicePath string,
newDevicePath
:=
""
err
=
wait
.
Poll
(
1
*
time
.
Second
,
timeout
,
func
()
(
bool
,
error
)
{
exe
:=
exec
.
New
()
if
newDevicePath
,
err
=
findDiskByLun
(
lun
,
io
,
exe
);
err
!=
nil
{
if
newDevicePath
,
err
=
findDiskByLun
(
lun
,
io
);
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"azureDisk - WaitForAttach ticker failed node (%s) disk (%s) lun(%v) err(%s)"
,
nodeName
,
diskName
,
lun
,
err
)
}
...
...
@@ -182,7 +179,7 @@ func (a *azureDiskAttacher) WaitForAttach(spec *volume.Spec, devicePath string,
// the curent sequence k8s uses for unformated disk (check-disk, mount, fail, mkfs.extX) hangs on
// Azure Managed disk scsi interface. this is a hack and will be replaced once we identify and solve
// the root case on Azure.
formatIfNotFormatted
(
newDevicePath
,
*
volumeSource
.
FSType
)
formatIfNotFormatted
(
newDevicePath
,
*
volumeSource
.
FSType
,
a
.
plugin
.
host
.
GetExec
(
a
.
plugin
.
GetPluginName
())
)
return
true
,
nil
}
...
...
pkg/volume/azure_dd/azure_common.go
View file @
96827de9
...
...
@@ -34,7 +34,6 @@ import (
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/strings"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/utils/exec"
)
const
(
...
...
@@ -213,13 +212,13 @@ func scsiHostRescan(io ioHandler) {
}
}
func
findDiskByLun
(
lun
int
,
io
ioHandler
,
exe
exec
.
Interface
)
(
string
,
error
)
{
func
findDiskByLun
(
lun
int
,
io
ioHandler
)
(
string
,
error
)
{
azureDisks
:=
listAzureDiskPath
(
io
)
return
findDiskByLunWithConstraint
(
lun
,
io
,
exe
,
azureDisks
)
return
findDiskByLunWithConstraint
(
lun
,
io
,
azureDisks
)
}
// finds a device mounted to "current" node
func
findDiskByLunWithConstraint
(
lun
int
,
io
ioHandler
,
exe
exec
.
Interface
,
azureDisks
[]
string
)
(
string
,
error
)
{
func
findDiskByLunWithConstraint
(
lun
int
,
io
ioHandler
,
azureDisks
[]
string
)
(
string
,
error
)
{
var
err
error
sys_path
:=
"/sys/bus/scsi/devices"
if
dirs
,
err
:=
io
.
ReadDir
(
sys_path
);
err
==
nil
{
...
...
@@ -286,8 +285,8 @@ func findDiskByLunWithConstraint(lun int, io ioHandler, exe exec.Interface, azur
return
""
,
err
}
func
formatIfNotFormatted
(
disk
string
,
fstype
string
)
{
notFormatted
,
err
:=
diskLooksUnformatted
(
disk
)
func
formatIfNotFormatted
(
disk
string
,
fstype
string
,
exec
mount
.
Exec
)
{
notFormatted
,
err
:=
diskLooksUnformatted
(
disk
,
exec
)
if
err
==
nil
&&
notFormatted
{
args
:=
[]
string
{
disk
}
// Disk is unformatted so format it.
...
...
@@ -299,9 +298,8 @@ func formatIfNotFormatted(disk string, fstype string) {
args
=
[]
string
{
"-E"
,
"lazy_itable_init=0,lazy_journal_init=0"
,
"-F"
,
disk
}
}
glog
.
Infof
(
"azureDisk - Disk %q appears to be unformatted, attempting to format as type: %q with options: %v"
,
disk
,
fstype
,
args
)
runner
:=
exec
.
New
()
cmd
:=
runner
.
Command
(
"mkfs."
+
fstype
,
args
...
)
_
,
err
:=
cmd
.
CombinedOutput
()
_
,
err
:=
exec
.
Run
(
"mkfs."
+
fstype
,
args
...
)
if
err
==
nil
{
// the disk has been formatted successfully try to mount it again.
glog
.
Infof
(
"azureDisk - Disk successfully formatted (mkfs): %s - %s %s"
,
fstype
,
disk
,
"tt"
)
...
...
@@ -316,12 +314,10 @@ func formatIfNotFormatted(disk string, fstype string) {
}
}
func
diskLooksUnformatted
(
disk
string
)
(
bool
,
error
)
{
func
diskLooksUnformatted
(
disk
string
,
exec
mount
.
Exec
)
(
bool
,
error
)
{
args
:=
[]
string
{
"-nd"
,
"-o"
,
"FSTYPE"
,
disk
}
runner
:=
exec
.
New
()
cmd
:=
runner
.
Command
(
"lsblk"
,
args
...
)
glog
.
V
(
4
)
.
Infof
(
"Attempting to determine if disk %q is formatted using lsblk with args: (%v)"
,
disk
,
args
)
dataOut
,
err
:=
cmd
.
CombinedOutput
(
)
dataOut
,
err
:=
exec
.
Run
(
"lsblk"
,
args
...
)
if
err
!=
nil
{
glog
.
Errorf
(
"Could not determine if disk %q is formatted (%v)"
,
disk
,
err
)
return
false
,
err
...
...
pkg/volume/azure_dd/azure_common_test.go
View file @
96827de9
...
...
@@ -22,9 +22,6 @@ import (
"strings"
"testing"
"time"
"k8s.io/utils/exec"
fakeexec
"k8s.io/utils/exec/testing"
)
type
fakeFileInfo
struct
{
...
...
@@ -119,26 +116,7 @@ func (handler *fakeIOHandler) ReadFile(filename string) ([]byte, error) {
}
func
TestIoHandler
(
t
*
testing
.
T
)
{
var
fcmd
fakeexec
.
FakeCmd
fcmd
=
fakeexec
.
FakeCmd
{
CombinedOutputScript
:
[]
fakeexec
.
FakeCombinedOutputAction
{
// cat
func
()
([]
byte
,
error
)
{
return
[]
byte
(
"Msft
\n
Virtual Disk
\n
"
),
nil
},
// cat
func
()
([]
byte
,
error
)
{
return
[]
byte
(
"Msft
\n
Virtual Disk
\n
"
),
nil
},
},
}
fake
:=
fakeexec
.
FakeExec
{
CommandScript
:
[]
fakeexec
.
FakeCommandAction
{
func
(
cmd
string
,
args
...
string
)
exec
.
Cmd
{
return
fakeexec
.
InitFakeCmd
(
&
fcmd
,
cmd
,
args
...
)
},
func
(
cmd
string
,
args
...
string
)
exec
.
Cmd
{
return
fakeexec
.
InitFakeCmd
(
&
fcmd
,
cmd
,
args
...
)
},
},
}
disk
,
err
:=
findDiskByLun
(
lun
,
&
fakeIOHandler
{},
&
fake
)
disk
,
err
:=
findDiskByLun
(
lun
,
&
fakeIOHandler
{})
// if no disk matches lun, exit
if
disk
!=
"/dev/"
+
devName
||
err
!=
nil
{
t
.
Errorf
(
"no data disk found: disk %v err %v"
,
disk
,
err
)
...
...
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