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
2767f10b
Commit
2767f10b
authored
Dec 31, 2015
by
Yifan Gu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rkt: refactoring on constructing the app section of rkt pods.
parent
7743a4ca
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
72 deletions
+78
-72
rkt.go
pkg/kubelet/rkt/rkt.go
+78
-72
No files found.
pkg/kubelet/rkt/rkt.go
View file @
2767f10b
...
@@ -196,6 +196,14 @@ func (r *Runtime) buildCommand(args ...string) *exec.Cmd {
...
@@ -196,6 +196,14 @@ func (r *Runtime) buildCommand(args ...string) *exec.Cmd {
return
cmd
return
cmd
}
}
// convertToACName converts a string into ACName.
func
convertToACName
(
name
string
)
appctypes
.
ACName
{
// Note that as the 'name' already matches 'DNS_LABEL'
// defined in pkg/api/types.go, there shouldn't be error or panic.
acname
,
_
:=
appctypes
.
SanitizeACName
(
name
)
return
*
appctypes
.
MustACName
(
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
)
{
func
(
r
*
Runtime
)
runCommand
(
args
...
string
)
([]
string
,
error
)
{
...
@@ -320,14 +328,68 @@ func setIsolators(app *appctypes.App, c *api.Container) error {
...
@@ -320,14 +328,68 @@ func setIsolators(app *appctypes.App, c *api.Container) error {
return
nil
return
nil
}
}
// findEnvInList returns the index of environment variable in the environment whose Name equals env.Name.
// mergeEnv merges the optEnv with the image's environments.
func
findEnvInList
(
envs
appctypes
.
Environment
,
env
kubecontainer
.
EnvVar
)
int
{
// The environments defined in the image will be overridden by
for
i
,
e
:=
range
envs
{
// the ones with the same name in optEnv.
if
e
.
Name
==
env
.
Name
{
func
mergeEnv
(
app
*
appctypes
.
App
,
optEnv
[]
kubecontainer
.
EnvVar
)
{
return
i
envMap
:=
make
(
map
[
string
]
string
)
for
_
,
e
:=
range
app
.
Environment
{
envMap
[
e
.
Name
]
=
e
.
Value
}
for
_
,
e
:=
range
optEnv
{
envMap
[
e
.
Name
]
=
e
.
Value
}
app
.
Environment
=
nil
for
name
,
value
:=
range
envMap
{
app
.
Environment
=
append
(
app
.
Environment
,
appctypes
.
EnvironmentVariable
{
Name
:
name
,
Value
:
value
,
})
}
}
// mergeMounts merges the optMounts with the image's mount points.
// The mount points defined in the image will be overridden by the ones
// with the same name in optMounts.
func
mergeMounts
(
app
*
appctypes
.
App
,
optMounts
[]
kubecontainer
.
Mount
)
{
mountMap
:=
make
(
map
[
appctypes
.
ACName
]
appctypes
.
MountPoint
)
for
_
,
m
:=
range
app
.
MountPoints
{
mountMap
[
m
.
Name
]
=
m
}
for
_
,
m
:=
range
optMounts
{
mpName
:=
convertToACName
(
m
.
Name
)
mountMap
[
mpName
]
=
appctypes
.
MountPoint
{
Name
:
mpName
,
Path
:
m
.
ContainerPath
,
ReadOnly
:
m
.
ReadOnly
,
}
}
app
.
MountPoints
=
nil
for
_
,
mount
:=
range
mountMap
{
app
.
MountPoints
=
append
(
app
.
MountPoints
,
mount
)
}
}
// mergePortMappings merges the optPortMappings with the image's port mappings.
// The port mappings defined in the image will be overridden by the ones
// with the same name in optPortMappings.
func
mergePortMappings
(
app
*
appctypes
.
App
,
optPortMappings
[]
kubecontainer
.
PortMapping
)
{
portMap
:=
make
(
map
[
appctypes
.
ACName
]
appctypes
.
Port
)
for
_
,
p
:=
range
app
.
Ports
{
portMap
[
p
.
Name
]
=
p
}
for
_
,
p
:=
range
optPortMappings
{
pName
:=
convertToACName
(
p
.
Name
)
portMap
[
pName
]
=
appctypes
.
Port
{
Name
:
pName
,
Protocol
:
string
(
p
.
Protocol
),
Port
:
uint
(
p
.
ContainerPort
),
}
}
}
}
return
-
1
app
.
Ports
=
nil
for
_
,
port
:=
range
portMap
{
app
.
Ports
=
append
(
app
.
Ports
,
port
)
}
}
}
// setApp overrides the app's fields if any of them are specified in the
// setApp overrides the app's fields if any of them are specified in the
...
@@ -351,50 +413,11 @@ func setApp(app *appctypes.App, c *api.Container, opts *kubecontainer.RunContain
...
@@ -351,50 +413,11 @@ func setApp(app *appctypes.App, c *api.Container, opts *kubecontainer.RunContain
app
.
WorkingDirectory
=
c
.
WorkingDir
app
.
WorkingDirectory
=
c
.
WorkingDir
}
}
// Merge the environment. Override the image with the ones defined in the spec if necessary.
// Notes that we don't create Mounts section in the pod manifest here,
for
_
,
env
:=
range
opts
.
Envs
{
// as Mounts will be automatically generated by rkt.
if
ix
:=
findEnvInList
(
app
.
Environment
,
env
);
ix
>=
0
{
mergeMounts
(
app
,
opts
.
Mounts
)
app
.
Environment
[
ix
]
.
Value
=
env
.
Value
mergeEnv
(
app
,
opts
.
Envs
)
continue
mergePortMappings
(
app
,
opts
.
PortMappings
)
}
app
.
Environment
=
append
(
app
.
Environment
,
appctypes
.
EnvironmentVariable
{
Name
:
env
.
Name
,
Value
:
env
.
Value
,
})
}
// Override the mount points.
if
len
(
opts
.
Mounts
)
>
0
{
app
.
MountPoints
=
[]
appctypes
.
MountPoint
{}
}
for
_
,
m
:=
range
opts
.
Mounts
{
mountPointName
,
err
:=
appctypes
.
NewACName
(
m
.
Name
)
if
err
!=
nil
{
return
err
}
app
.
MountPoints
=
append
(
app
.
MountPoints
,
appctypes
.
MountPoint
{
Name
:
*
mountPointName
,
Path
:
m
.
ContainerPath
,
ReadOnly
:
m
.
ReadOnly
,
})
}
// Override the ports.
if
len
(
opts
.
PortMappings
)
>
0
{
app
.
Ports
=
[]
appctypes
.
Port
{}
}
for
_
,
p
:=
range
opts
.
PortMappings
{
name
,
err
:=
appctypes
.
SanitizeACName
(
p
.
Name
)
if
err
!=
nil
{
return
err
}
portName
:=
appctypes
.
MustACName
(
name
)
app
.
Ports
=
append
(
app
.
Ports
,
appctypes
.
Port
{
Name
:
*
portName
,
Protocol
:
string
(
p
.
Protocol
),
Port
:
uint
(
p
.
ContainerPort
),
})
}
// Override isolators.
// Override isolators.
return
setIsolators
(
app
,
c
)
return
setIsolators
(
app
,
c
)
...
@@ -456,13 +479,9 @@ func (r *Runtime) makePodManifest(pod *api.Pod, pullSecrets []api.Secret) (*appc
...
@@ -456,13 +479,9 @@ func (r *Runtime) makePodManifest(pod *api.Pod, pullSecrets []api.Secret) (*appc
}
}
// Set global volumes.
// Set global volumes.
for
name
,
volume
:=
range
volumeMap
{
for
vname
,
volume
:=
range
volumeMap
{
volName
,
err
:=
appctypes
.
NewACName
(
name
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot use the volume's name %q as ACName: %v"
,
name
,
err
)
}
manifest
.
Volumes
=
append
(
manifest
.
Volumes
,
appctypes
.
Volume
{
manifest
.
Volumes
=
append
(
manifest
.
Volumes
,
appctypes
.
Volume
{
Name
:
*
volName
,
Name
:
convertToACName
(
vname
)
,
Kind
:
"host"
,
Kind
:
"host"
,
Source
:
volume
.
Builder
.
GetPath
(),
Source
:
volume
.
Builder
.
GetPath
(),
})
})
...
@@ -470,13 +489,8 @@ func (r *Runtime) makePodManifest(pod *api.Pod, pullSecrets []api.Secret) (*appc
...
@@ -470,13 +489,8 @@ func (r *Runtime) makePodManifest(pod *api.Pod, pullSecrets []api.Secret) (*appc
// Set global ports.
// Set global ports.
for
_
,
port
:=
range
globalPortMappings
{
for
_
,
port
:=
range
globalPortMappings
{
name
,
err
:=
appctypes
.
SanitizeACName
(
port
.
Name
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot use the port's name %q as ACName: %v"
,
port
.
Name
,
err
)
}
portName
:=
appctypes
.
MustACName
(
name
)
manifest
.
Ports
=
append
(
manifest
.
Ports
,
appctypes
.
ExposedPort
{
manifest
.
Ports
=
append
(
manifest
.
Ports
,
appctypes
.
ExposedPort
{
Name
:
*
portName
,
Name
:
convertToACName
(
port
.
Name
)
,
HostPort
:
uint
(
port
.
HostPort
),
HostPort
:
uint
(
port
.
HostPort
),
})
})
}
}
...
@@ -515,22 +529,14 @@ func (r *Runtime) newAppcRuntimeApp(pod *api.Pod, c api.Container, pullSecrets [
...
@@ -515,22 +529,14 @@ func (r *Runtime) newAppcRuntimeApp(pod *api.Pod, c api.Container, pullSecrets [
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
name
,
err
:=
appctypes
.
SanitizeACName
(
c
.
Name
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
appName
:=
appctypes
.
MustACName
(
name
)
kubehash
:=
kubecontainer
.
HashContainer
(
&
c
)
return
&
appcschema
.
RuntimeApp
{
return
&
appcschema
.
RuntimeApp
{
Name
:
*
appName
,
Name
:
convertToACName
(
c
.
Name
)
,
Image
:
appcschema
.
RuntimeImage
{
ID
:
*
hash
},
Image
:
appcschema
.
RuntimeImage
{
ID
:
*
hash
},
App
:
imgManifest
.
App
,
App
:
imgManifest
.
App
,
Annotations
:
[]
appctypes
.
Annotation
{
Annotations
:
[]
appctypes
.
Annotation
{
{
{
Name
:
*
appctypes
.
MustACIdentifier
(
k8sRktContainerHashAnno
),
Name
:
*
appctypes
.
MustACIdentifier
(
k8sRktContainerHashAnno
),
Value
:
strconv
.
FormatUint
(
kube
hash
,
10
),
Value
:
strconv
.
FormatUint
(
kube
container
.
HashContainer
(
&
c
)
,
10
),
},
},
},
},
},
opts
.
PortMappings
,
nil
},
opts
.
PortMappings
,
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