mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
kubelet/rkt: merge environments instead of overriding.
Merge the environments in container spec and in the image manifest. Also allow empty app in image manifest.
This commit is contained in:
parent
5dfc904c18
commit
763ffdb1fe
@ -301,13 +301,26 @@ 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.
|
||||||
|
func findEnvInList(envs appctypes.Environment, env kubecontainer.EnvVar) int {
|
||||||
|
for i, e := range envs {
|
||||||
|
if e.Name == env.Name {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
// container's spec.
|
// container's spec.
|
||||||
func setApp(app *appctypes.App, c *api.Container, opts *kubecontainer.RunContainerOptions) error {
|
func setApp(app *appctypes.App, c *api.Container, opts *kubecontainer.RunContainerOptions) error {
|
||||||
// Override the exec.
|
// Override the exec.
|
||||||
// TOOD(yifan): Revisit this for the overriding rule.
|
|
||||||
if len(c.Command) > 0 || len(c.Args) > 0 {
|
if len(c.Command) > 0 {
|
||||||
app.Exec = append(c.Command, c.Args...)
|
app.Exec = c.Command
|
||||||
|
}
|
||||||
|
if len(c.Args) > 0 {
|
||||||
|
app.Exec = append(app.Exec, c.Args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(yifan): Use non-root user in the future, see:
|
// TODO(yifan): Use non-root user in the future, see:
|
||||||
@ -319,11 +332,12 @@ func setApp(app *appctypes.App, c *api.Container, opts *kubecontainer.RunContain
|
|||||||
app.WorkingDirectory = c.WorkingDir
|
app.WorkingDirectory = c.WorkingDir
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override the environment.
|
// Merge the environment. Override the image with the ones defined in the spec if necessary.
|
||||||
if len(opts.Envs) > 0 {
|
for _, env := range opts.Envs {
|
||||||
app.Environment = []appctypes.EnvironmentVariable{}
|
if ix := findEnvInList(app.Environment, env); ix >= 0 {
|
||||||
}
|
app.Environment[ix].Value = env.Value
|
||||||
for _, env := range c.Env {
|
continue
|
||||||
|
}
|
||||||
app.Environment = append(app.Environment, appctypes.EnvironmentVariable{
|
app.Environment = append(app.Environment, appctypes.EnvironmentVariable{
|
||||||
Name: env.Name,
|
Name: env.Name,
|
||||||
Value: env.Value,
|
Value: env.Value,
|
||||||
@ -413,7 +427,7 @@ func (r *runtime) makePodManifest(pod *api.Pod, pullSecrets []api.Secret) (*appc
|
|||||||
}
|
}
|
||||||
|
|
||||||
if imgManifest.App == nil {
|
if imgManifest.App == nil {
|
||||||
return nil, fmt.Errorf("no app section in image manifest for image: %q", c.Image)
|
imgManifest.App = new(appctypes.App)
|
||||||
}
|
}
|
||||||
|
|
||||||
img, err := r.getImageByName(c.Image)
|
img, err := r.getImageByName(c.Image)
|
||||||
|
Loading…
Reference in New Issue
Block a user