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
1d40f471
Commit
1d40f471
authored
May 23, 2016
by
Yifan Gu
Committed by
Yifan Gu
May 30, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rkt: Fix docker auth config save directory to avoid race.
parent
e531a778
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
31 deletions
+38
-31
fake_rkt_interface_test.go
pkg/kubelet/rkt/fake_rkt_interface_test.go
+1
-1
image.go
pkg/kubelet/rkt/image.go
+15
-15
rkt.go
pkg/kubelet/rkt/rkt.go
+22
-15
No files found.
pkg/kubelet/rkt/fake_rkt_interface_test.go
View file @
1d40f471
...
@@ -194,7 +194,7 @@ func newFakeRktCli() *fakeRktCli {
...
@@ -194,7 +194,7 @@ func newFakeRktCli() *fakeRktCli {
}
}
}
}
func
(
f
*
fakeRktCli
)
RunCommand
(
args
...
string
)
(
result
[]
string
,
err
error
)
{
func
(
f
*
fakeRktCli
)
RunCommand
(
config
*
Config
,
args
...
string
)
(
result
[]
string
,
err
error
)
{
f
.
Lock
()
f
.
Lock
()
defer
f
.
Unlock
()
defer
f
.
Unlock
()
cmd
:=
append
([]
string
{
"rkt"
},
args
...
)
cmd
:=
append
([]
string
{
"rkt"
},
args
...
)
...
...
pkg/kubelet/rkt/image.go
View file @
1d40f471
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path"
"path/filepath"
"sort"
"sort"
"strings"
"strings"
...
@@ -62,13 +63,20 @@ func (r *Runtime) PullImage(image kubecontainer.ImageSpec, pullSecrets []api.Sec
...
@@ -62,13 +63,20 @@ func (r *Runtime) PullImage(image kubecontainer.ImageSpec, pullSecrets []api.Sec
glog
.
V
(
1
)
.
Infof
(
"Pulling image %s without credentials"
,
img
)
glog
.
V
(
1
)
.
Infof
(
"Pulling image %s without credentials"
,
img
)
}
}
// Let's update a json.
userConfigDir
,
err
:=
ioutil
.
TempDir
(
""
,
"rktnetes-user-config-dir-"
)
// TODO(yifan): Find a way to feed this to rkt.
if
err
!=
nil
{
if
err
:=
r
.
writeDockerAuthConfig
(
img
,
creds
);
err
!=
nil
{
return
fmt
.
Errorf
(
"rkt: Cannot create a temporary user-config directory: %v"
,
err
)
}
defer
os
.
RemoveAll
(
userConfigDir
)
config
:=
*
r
.
config
config
.
UserConfigDir
=
userConfigDir
if
err
:=
r
.
writeDockerAuthConfig
(
img
,
creds
,
userConfigDir
);
err
!=
nil
{
return
err
return
err
}
}
if
_
,
err
:=
r
.
cli
.
RunCommand
(
"fetch"
,
dockerPrefix
+
img
);
err
!=
nil
{
if
_
,
err
:=
r
.
cli
.
RunCommand
(
&
config
,
"fetch"
,
dockerPrefix
+
img
);
err
!=
nil
{
glog
.
Errorf
(
"Failed to fetch: %v"
,
err
)
glog
.
Errorf
(
"Failed to fetch: %v"
,
err
)
return
err
return
err
}
}
...
@@ -104,7 +112,7 @@ func (r *Runtime) RemoveImage(image kubecontainer.ImageSpec) error {
...
@@ -104,7 +112,7 @@ func (r *Runtime) RemoveImage(image kubecontainer.ImageSpec) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
_
,
err
:=
r
.
cli
.
RunCommand
(
"image"
,
"rm"
,
imageID
);
err
!=
nil
{
if
_
,
err
:=
r
.
cli
.
RunCommand
(
nil
,
"image"
,
"rm"
,
imageID
);
err
!=
nil
{
return
err
return
err
}
}
return
nil
return
nil
...
@@ -186,7 +194,7 @@ func (r *Runtime) getImageManifest(image string) (*appcschema.ImageManifest, err
...
@@ -186,7 +194,7 @@ func (r *Runtime) getImageManifest(image string) (*appcschema.ImageManifest, err
// TODO(yifan): This is very racy, unefficient, and unsafe, we need to provide
// TODO(yifan): This is very racy, unefficient, and unsafe, we need to provide
// different namespaces. See: https://github.com/coreos/rkt/issues/836.
// different namespaces. See: https://github.com/coreos/rkt/issues/836.
func
(
r
*
Runtime
)
writeDockerAuthConfig
(
image
string
,
credsSlice
[]
credentialprovider
.
LazyAuthConfiguration
)
error
{
func
(
r
*
Runtime
)
writeDockerAuthConfig
(
image
string
,
credsSlice
[]
credentialprovider
.
LazyAuthConfiguration
,
userConfigDir
string
)
error
{
if
len
(
credsSlice
)
==
0
{
if
len
(
credsSlice
)
==
0
{
return
nil
return
nil
}
}
...
@@ -204,15 +212,7 @@ func (r *Runtime) writeDockerAuthConfig(image string, credsSlice []credentialpro
...
@@ -204,15 +212,7 @@ func (r *Runtime) writeDockerAuthConfig(image string, credsSlice []credentialpro
registry
=
strings
.
Split
(
image
,
"/"
)[
0
]
registry
=
strings
.
Split
(
image
,
"/"
)[
0
]
}
}
configDir
:=
r
.
config
.
UserConfigDir
authDir
:=
filepath
.
Join
(
userConfigDir
,
"auth.d"
)
if
configDir
==
""
{
configDir
=
r
.
config
.
LocalConfigDir
}
if
configDir
==
""
{
return
fmt
.
Errorf
(
"No user or local config dir is specified"
)
}
authDir
:=
path
.
Join
(
configDir
,
"auth.d"
)
if
_
,
err
:=
os
.
Stat
(
authDir
);
os
.
IsNotExist
(
err
)
{
if
_
,
err
:=
os
.
Stat
(
authDir
);
os
.
IsNotExist
(
err
)
{
if
err
:=
os
.
MkdirAll
(
authDir
,
0600
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
authDir
,
0600
);
err
!=
nil
{
glog
.
Errorf
(
"rkt: Cannot create auth dir: %v"
,
err
)
glog
.
Errorf
(
"rkt: Cannot create auth dir: %v"
,
err
)
...
...
pkg/kubelet/rkt/rkt.go
View file @
1d40f471
...
@@ -167,9 +167,9 @@ type podGetter interface {
...
@@ -167,9 +167,9 @@ type podGetter interface {
// cliInterface wrapps the command line calls for testing purpose.
// cliInterface wrapps the command line calls for testing purpose.
type
cliInterface
interface
{
type
cliInterface
interface
{
//
args are the arguments given to the 'rkt' command,
//
RunCommand creates rkt commands and runs it with the given config.
//
e.g. args can be 'rm ${UUID}'
.
//
If the config is nil, it will use the one inferred from rkt API service
.
RunCommand
(
args
...
string
)
(
result
[]
string
,
err
error
)
RunCommand
(
config
*
Config
,
args
...
string
)
(
result
[]
string
,
err
error
)
}
}
// New creates the rkt container runtime which implements the container runtime interface.
// New creates the rkt container runtime which implements the container runtime interface.
...
@@ -263,9 +263,11 @@ func New(
...
@@ -263,9 +263,11 @@ func New(
return
rkt
,
nil
return
rkt
,
nil
}
}
func
(
r
*
Runtime
)
buildCommand
(
args
...
string
)
*
exec
.
Cmd
{
func
buildCommand
(
config
*
Config
,
args
...
string
)
*
exec
.
Cmd
{
allArgs
:=
append
(
r
.
config
.
buildGlobalOptions
(),
args
...
)
cmd
:=
exec
.
Command
(
config
.
Path
)
return
exec
.
Command
(
r
.
config
.
Path
,
allArgs
...
)
cmd
.
Args
=
append
(
cmd
.
Args
,
config
.
buildGlobalOptions
()
...
)
cmd
.
Args
=
append
(
cmd
.
Args
,
args
...
)
return
cmd
}
}
// convertToACName converts a string into ACName.
// convertToACName converts a string into ACName.
...
@@ -278,13 +280,18 @@ func convertToACName(name string) appctypes.ACName {
...
@@ -278,13 +280,18 @@ func convertToACName(name string) appctypes.ACName {
// RunCommand invokes rkt binary with arguments and returns the result
// RunCommand invokes rkt binary with arguments and returns the result
// from stdout in a list of strings. Each string in the list is a line.
// from stdout in a list of strings. Each string in the list is a line.
func
(
r
*
Runtime
)
RunCommand
(
args
...
string
)
([]
string
,
error
)
{
// If config is non-nil, it will use the given config instead of the config
glog
.
V
(
4
)
.
Info
(
"rkt: Run command:"
,
args
)
// inferred from rkt API service.
func
(
r
*
Runtime
)
RunCommand
(
config
*
Config
,
args
...
string
)
([]
string
,
error
)
{
if
config
==
nil
{
config
=
r
.
config
}
glog
.
V
(
4
)
.
Infof
(
"rkt: Run command: %q with config: %+v"
,
args
,
config
)
var
stdout
,
stderr
bytes
.
Buffer
var
stdout
,
stderr
bytes
.
Buffer
cmd
:=
r
.
buildCommand
(
args
...
)
cmd
.
Stdout
=
&
stdout
cmd
:=
buildCommand
(
config
,
args
...
)
cmd
.
Std
err
=
&
stderr
cmd
.
Std
out
,
cmd
.
Stderr
=
&
stdout
,
&
stderr
if
err
:=
cmd
.
Run
();
err
!=
nil
{
if
err
:=
cmd
.
Run
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to run %v: %v
\n
stdout: %v
\n
stderr: %v"
,
args
,
err
,
stdout
.
String
(),
stderr
.
String
())
return
nil
,
fmt
.
Errorf
(
"failed to run %v: %v
\n
stdout: %v
\n
stderr: %v"
,
args
,
err
,
stdout
.
String
(),
stderr
.
String
())
}
}
...
@@ -895,7 +902,7 @@ func serviceFilePath(serviceName string) string {
...
@@ -895,7 +902,7 @@ func serviceFilePath(serviceName string) string {
// generateRunCommand crafts a 'rkt run-prepared' command with necessary parameters.
// generateRunCommand crafts a 'rkt run-prepared' command with necessary parameters.
func
(
r
*
Runtime
)
generateRunCommand
(
pod
*
api
.
Pod
,
uuid
,
netnsName
string
)
(
string
,
error
)
{
func
(
r
*
Runtime
)
generateRunCommand
(
pod
*
api
.
Pod
,
uuid
,
netnsName
string
)
(
string
,
error
)
{
runPrepared
:=
r
.
buildCommand
(
"run-prepared"
)
.
Args
runPrepared
:=
buildCommand
(
r
.
config
,
"run-prepared"
)
.
Args
// Network namespace set up in kubelet; rkt networking not used
// Network namespace set up in kubelet; rkt networking not used
runPrepared
=
append
(
runPrepared
,
"--net=host"
)
runPrepared
=
append
(
runPrepared
,
"--net=host"
)
...
@@ -1019,7 +1026,7 @@ func (r *Runtime) preparePod(pod *api.Pod, podIP string, pullSecrets []api.Secre
...
@@ -1019,7 +1026,7 @@ func (r *Runtime) preparePod(pod *api.Pod, podIP string, pullSecrets []api.Secre
}
}
prepareCmd
:=
r
.
preparePodArgs
(
manifest
,
manifestFile
.
Name
())
prepareCmd
:=
r
.
preparePodArgs
(
manifest
,
manifestFile
.
Name
())
output
,
err
:=
r
.
RunCommand
(
prepareCmd
...
)
output
,
err
:=
r
.
cli
.
RunCommand
(
nil
,
prepareCmd
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
nil
,
err
return
""
,
nil
,
err
}
}
...
@@ -1826,7 +1833,7 @@ func (r *Runtime) removePod(uuid string) error {
...
@@ -1826,7 +1833,7 @@ func (r *Runtime) removePod(uuid string) error {
// Network may not be around anymore so errors are ignored
// Network may not be around anymore so errors are ignored
r
.
cleanupPodNetworkFromServiceFile
(
serviceFile
)
r
.
cleanupPodNetworkFromServiceFile
(
serviceFile
)
if
_
,
err
:=
r
.
cli
.
RunCommand
(
"rm"
,
uuid
);
err
!=
nil
{
if
_
,
err
:=
r
.
cli
.
RunCommand
(
nil
,
"rm"
,
uuid
);
err
!=
nil
{
errlist
=
append
(
errlist
,
fmt
.
Errorf
(
"rkt: Failed to remove pod %q: %v"
,
uuid
,
err
))
errlist
=
append
(
errlist
,
fmt
.
Errorf
(
"rkt: Failed to remove pod %q: %v"
,
uuid
,
err
))
}
}
...
@@ -1866,7 +1873,7 @@ func (r *Runtime) ExecInContainer(containerID kubecontainer.ContainerID, cmd []s
...
@@ -1866,7 +1873,7 @@ func (r *Runtime) ExecInContainer(containerID kubecontainer.ContainerID, cmd []s
}
}
args
:=
[]
string
{
"enter"
,
fmt
.
Sprintf
(
"--app=%s"
,
id
.
appName
),
id
.
uuid
}
args
:=
[]
string
{
"enter"
,
fmt
.
Sprintf
(
"--app=%s"
,
id
.
appName
),
id
.
uuid
}
args
=
append
(
args
,
cmd
...
)
args
=
append
(
args
,
cmd
...
)
command
:=
r
.
buildCommand
(
args
...
)
command
:=
buildCommand
(
r
.
config
,
args
...
)
if
tty
{
if
tty
{
p
,
err
:=
kubecontainer
.
StartPty
(
command
)
p
,
err
:=
kubecontainer
.
StartPty
(
command
)
...
...
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