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
53d340f0
Commit
53d340f0
authored
Sep 18, 2017
by
Di Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor NsenterWriter to utilize pkg/util/nsenter
parent
7fb445c9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
15 deletions
+14
-15
BUILD
pkg/util/io/BUILD
+4
-1
writer.go
pkg/util/io/writer.go
+10
-14
No files found.
pkg/util/io/BUILD
View file @
53d340f0
...
@@ -12,7 +12,10 @@ go_library(
...
@@ -12,7 +12,10 @@ go_library(
"writer.go",
"writer.go",
],
],
importpath = "k8s.io/kubernetes/pkg/util/io",
importpath = "k8s.io/kubernetes/pkg/util/io",
deps = ["//vendor/github.com/golang/glog:go_default_library"],
deps = [
"//pkg/util/nsenter:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
],
)
)
filegroup(
filegroup(
...
...
pkg/util/io/writer.go
View file @
53d340f0
...
@@ -21,7 +21,8 @@ import (
...
@@ -21,7 +21,8 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"os/exec"
"k8s.io/kubernetes/pkg/util/nsenter"
"github.com/golang/glog"
"github.com/golang/glog"
)
)
...
@@ -54,25 +55,20 @@ type NsenterWriter struct{}
...
@@ -54,25 +55,20 @@ type NsenterWriter struct{}
// WriteFile calls 'nsenter cat - > <the file>' and 'nsenter chmod' to create a
// WriteFile calls 'nsenter cat - > <the file>' and 'nsenter chmod' to create a
// file on the host.
// 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"
ne
:=
nsenter
.
NewNsenter
()
baseArgs
:=
[]
string
{
echoArgs
:=
[]
string
{
"-c"
,
fmt
.
Sprintf
(
"cat > %s"
,
filename
)}
"--mount=/rootfs/proc/1/ns/mnt"
,
glog
.
V
(
5
)
.
Infof
(
"nsenter: write data to file %s by nsenter"
,
filename
)
"--"
,
command
:=
ne
.
Exec
(
"sh"
,
echoArgs
)
}
command
.
SetStdin
(
bytes
.
NewBuffer
(
data
))
echoArgs
:=
append
(
baseArgs
,
"sh"
,
"-c"
,
fmt
.
Sprintf
(
"cat > %s"
,
filename
))
glog
.
V
(
5
)
.
Infof
(
"Command to write data to file: %v %v"
,
cmd
,
echoArgs
)
command
:=
exec
.
Command
(
cmd
,
echoArgs
...
)
command
.
Stdin
=
bytes
.
NewBuffer
(
data
)
outputBytes
,
err
:=
command
.
CombinedOutput
()
outputBytes
,
err
:=
command
.
CombinedOutput
()
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Output from writing to %q: %v"
,
filename
,
string
(
outputBytes
))
glog
.
Errorf
(
"Output from writing to %q: %v"
,
filename
,
string
(
outputBytes
))
return
err
return
err
}
}
chmodArgs
:=
append
(
baseArgs
,
"chmod"
,
fmt
.
Sprintf
(
"%o"
,
perm
),
filename
)
chmodArgs
:=
[]
string
{
fmt
.
Sprintf
(
"%o"
,
perm
),
filename
}
glog
.
V
(
5
)
.
Infof
(
"
Command to change permissions to file: %v %v"
,
cmd
,
chmodArgs
)
glog
.
V
(
5
)
.
Infof
(
"
nsenter: change permissions of file %s to %s"
,
filename
,
chmodArgs
[
0
]
)
outputBytes
,
err
=
exec
.
Command
(
cmd
,
chmodArgs
...
)
.
CombinedOutput
()
outputBytes
,
err
=
ne
.
Exec
(
"chmod"
,
chmodArgs
)
.
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