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
b73517d4
Commit
b73517d4
authored
Jun 14, 2017
by
Jan Safranek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix lint errors
Removal of io.go revealed new lint errors in pkg/util/io
parent
c2dc5b5b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
15 deletions
+16
-15
BUILD
pkg/util/io/BUILD
+0
-1
writer.go
pkg/util/io/writer.go
+16
-14
No files found.
pkg/util/io/BUILD
View file @
b73517d4
...
@@ -10,7 +10,6 @@ load(
...
@@ -10,7 +10,6 @@ load(
go_library(
go_library(
name = "go_default_library",
name = "go_default_library",
srcs = ["writer.go"],
srcs = ["writer.go"],
"//vendor/k8s.io/api/core/v1:go_default_library",
tags = ["automanaged"],
tags = ["automanaged"],
deps = ["//vendor/github.com/golang/glog:go_default_library"],
deps = ["//vendor/github.com/golang/glog:go_default_library"],
)
)
...
...
pkg/util/io/writer.go
View file @
b73517d4
...
@@ -28,6 +28,7 @@ import (
...
@@ -28,6 +28,7 @@ import (
// Writer is an interface which allows to write data to a file.
// Writer is an interface which allows to write data to a file.
type
Writer
interface
{
type
Writer
interface
{
// WriteFile mimics ioutil.WriteFile.
WriteFile
(
filename
string
,
data
[]
byte
,
perm
os
.
FileMode
)
error
WriteFile
(
filename
string
,
data
[]
byte
,
perm
os
.
FileMode
)
error
}
}
...
@@ -36,31 +37,32 @@ type Writer interface {
...
@@ -36,31 +37,32 @@ type Writer interface {
type
StdWriter
struct
{
type
StdWriter
struct
{
}
}
// WriteFile directly calls ioutil.WriteFile.
func
(
writer
*
StdWriter
)
WriteFile
(
filename
string
,
data
[]
byte
,
perm
os
.
FileMode
)
error
{
func
(
writer
*
StdWriter
)
WriteFile
(
filename
string
,
data
[]
byte
,
perm
os
.
FileMode
)
error
{
return
ioutil
.
WriteFile
(
filename
,
data
,
perm
)
return
ioutil
.
WriteFile
(
filename
,
data
,
perm
)
}
}
//
Alternative implementation of Writer interface that allows writing data to file
//
NsenterWriter is implementation of Writer interface that allows writing data
// using nsenter command.
//
to file
using nsenter command.
// If a program (e.g. kubelet) runs in a container it may want to write data to
// If a program (e.g. kubelet) runs in a container it may want to write data to
// a mounted device. Since in Docker, mount propagation mode is set to private,
// a mounted device. Since in Docker, mount propagation mode is set to private,
// it will not see the mounted device in its own namespace. To work around this
// it will not see the mounted device in its own namespace. To work around this
// limitaion one has to first enter hosts namespace (by using 'nsenter') and only
// limitation one has to first enter hosts namespace (by using 'nsenter') and
// then write data.
// only then write data.
type
NsenterWriter
struct
{
type
NsenterWriter
struct
{}
}
// TODO: should take a writer, not []byte
// WriteFile calls 'nsenter cat - > <the file>' and 'nsenter chmod' to create a
// file on the host.
func
(
writer
*
NsenterWriter
)
WriteFile
(
filename
string
,
data
[]
byte
,
perm
os
.
FileMode
)
error
{
func
(
writer
*
NsenterWriter
)
WriteFile
(
filename
string
,
data
[]
byte
,
perm
os
.
FileMode
)
error
{
cmd
:=
"nsenter"
cmd
:=
"nsenter"
base
_a
rgs
:=
[]
string
{
base
A
rgs
:=
[]
string
{
"--mount=/rootfs/proc/1/ns/mnt"
,
"--mount=/rootfs/proc/1/ns/mnt"
,
"--"
,
"--"
,
}
}
echo
_args
:=
append
(
base_a
rgs
,
"sh"
,
"-c"
,
fmt
.
Sprintf
(
"cat > %s"
,
filename
))
echo
Args
:=
append
(
baseA
rgs
,
"sh"
,
"-c"
,
fmt
.
Sprintf
(
"cat > %s"
,
filename
))
glog
.
V
(
5
)
.
Infof
(
"Command to write data to file: %v %v"
,
cmd
,
echo
_a
rgs
)
glog
.
V
(
5
)
.
Infof
(
"Command to write data to file: %v %v"
,
cmd
,
echo
A
rgs
)
command
:=
exec
.
Command
(
cmd
,
echo
_a
rgs
...
)
command
:=
exec
.
Command
(
cmd
,
echo
A
rgs
...
)
command
.
Stdin
=
bytes
.
NewBuffer
(
data
)
command
.
Stdin
=
bytes
.
NewBuffer
(
data
)
outputBytes
,
err
:=
command
.
CombinedOutput
()
outputBytes
,
err
:=
command
.
CombinedOutput
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -68,9 +70,9 @@ func (writer *NsenterWriter) WriteFile(filename string, data []byte, perm os.Fil
...
@@ -68,9 +70,9 @@ func (writer *NsenterWriter) WriteFile(filename string, data []byte, perm os.Fil
return
err
return
err
}
}
chmod
_args
:=
append
(
base_a
rgs
,
"chmod"
,
fmt
.
Sprintf
(
"%o"
,
perm
),
filename
)
chmod
Args
:=
append
(
baseA
rgs
,
"chmod"
,
fmt
.
Sprintf
(
"%o"
,
perm
),
filename
)
glog
.
V
(
5
)
.
Infof
(
"Command to change permissions to file: %v %v"
,
cmd
,
chmod
_a
rgs
)
glog
.
V
(
5
)
.
Infof
(
"Command to change permissions to file: %v %v"
,
cmd
,
chmod
A
rgs
)
outputBytes
,
err
=
exec
.
Command
(
cmd
,
chmod
_a
rgs
...
)
.
CombinedOutput
()
outputBytes
,
err
=
exec
.
Command
(
cmd
,
chmod
A
rgs
...
)
.
CombinedOutput
()
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Output from chmod command: %v"
,
string
(
outputBytes
))
glog
.
Errorf
(
"Output from chmod command: %v"
,
string
(
outputBytes
))
return
err
return
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