From 9d3d55d0fb6cb6c34161cd418a580d4fb266fa4d Mon Sep 17 00:00:00 2001 From: Yifan Gu Date: Fri, 18 Mar 2016 16:58:55 -0700 Subject: [PATCH] rkt: Unmarshal the ENTRYPOINT/CMD from jsons instead of strings. Using json makes this robust to ENTRYPOINT/CMD that contains space. Also removed 'RemainAfterExit' option, originally this option is useful when we implement GetPods() by 'systemctl list-units'. However since we are using rkt API service now, it's no longer needed. --- pkg/kubelet/rkt/rkt.go | 12 ++++++++---- pkg/kubelet/rkt/rkt_test.go | 12 ++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pkg/kubelet/rkt/rkt.go b/pkg/kubelet/rkt/rkt.go index ce8dea71dec..c05bb269c80 100644 --- a/pkg/kubelet/rkt/rkt.go +++ b/pkg/kubelet/rkt/rkt.go @@ -426,11 +426,17 @@ func setApp(imgManifest *appcschema.ImageManifest, c *api.Container, opts *kubec var command, args []string cmd, ok := imgManifest.Annotations.Get(appcDockerEntrypoint) if ok { - command = strings.Fields(cmd) + err := json.Unmarshal([]byte(cmd), &command) + if err != nil { + return fmt.Errorf("cannot unmarshal ENTRYPOINT %q: %v", cmd, err) + } } ag, ok := imgManifest.Annotations.Get(appcDockerCmd) if ok { - args = strings.Fields(ag) + err := json.Unmarshal([]byte(ag), &args) + if err != nil { + return fmt.Errorf("cannot unmarshal CMD %q: %v", ag, err) + } } userCommand, userArgs := kubecontainer.ExpandContainerCommandAndArgs(c, opts.Envs) @@ -814,8 +820,6 @@ func (r *Runtime) preparePod(pod *api.Pod, pullSecrets []api.Secret) (string, *k // TODO handle pod.Spec.HostIPC units := []*unit.UnitOption{ - // This makes the service show up for 'systemctl list-units' even if it exits successfully. - newUnitOption("Service", "RemainAfterExit", "true"), newUnitOption("Service", "ExecStart", runPrepared), // This enables graceful stop. newUnitOption("Service", "KillMode", "mixed"), diff --git a/pkg/kubelet/rkt/rkt_test.go b/pkg/kubelet/rkt/rkt_test.go index 0aaf22084df..0377061e47a 100644 --- a/pkg/kubelet/rkt/rkt_test.go +++ b/pkg/kubelet/rkt/rkt_test.go @@ -766,8 +766,16 @@ func baseApp(t *testing.T) *appctypes.App { func baseImageManifest(t *testing.T) *appcschema.ImageManifest { img := &appcschema.ImageManifest{App: baseApp(t)} - img.Annotations.Set(*appctypes.MustACIdentifier(appcDockerEntrypoint), "/bin/foo") - img.Annotations.Set(*appctypes.MustACIdentifier(appcDockerCmd), "bar") + entrypoint, err := json.Marshal([]string{"/bin/foo"}) + if err != nil { + t.Fatal(err) + } + cmd, err := json.Marshal([]string{"bar"}) + if err != nil { + t.Fatal(err) + } + img.Annotations.Set(*appctypes.MustACIdentifier(appcDockerEntrypoint), string(entrypoint)) + img.Annotations.Set(*appctypes.MustACIdentifier(appcDockerCmd), string(cmd)) return img }