From cff96ecf5cee5776e50d0841470e949a104a6135 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 19 Jan 2018 09:15:20 -0800 Subject: [PATCH] server/container_create: Simplify Kube/OCI process merge Handling both the nil ociConfig check and kubeCommands length check on the same line lets us drop one level of nesting. And that initial zero-length check makes the internal kubeCommands nil check redundant, so we can drop that too. Also adjust the buildOCIProcessArgs argument from a *v1.Image to *v1.ImageConfig, because we don't need anything else from Image here. This moves the nil Image check from inside buildOCIProcessArgs to the calling function, but I think that's worth the tighter scoping. Signed-off-by: W. Trevor King --- server/container_create.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/server/container_create.go b/server/container_create.go index a4652cf3..366cb566 100644 --- a/server/container_create.go +++ b/server/container_create.go @@ -376,7 +376,7 @@ func addDevices(sb *sandbox.Sandbox, containerConfig *pb.ContainerConfig, specge } // buildOCIProcessArgs build an OCI compatible process arguments slice. -func buildOCIProcessArgs(containerKubeConfig *pb.ContainerConfig, imageOCIConfig *v1.Image) ([]string, error) { +func buildOCIProcessArgs(containerKubeConfig *pb.ContainerConfig, ociConfig *v1.ImageConfig) ([]string, error) { //# Start the nginx container using the default command, but use custom //arguments (arg1 .. argN) for that command. //kubectl run nginx --image=nginx -- ... @@ -388,15 +388,10 @@ func buildOCIProcessArgs(containerKubeConfig *pb.ContainerConfig, imageOCIConfig kubeArgs := containerKubeConfig.Args // merge image config and kube config - // same as docker does today... - if imageOCIConfig != nil { - if len(kubeCommands) == 0 { - if len(kubeArgs) == 0 { - kubeArgs = imageOCIConfig.Config.Cmd - } - if kubeCommands == nil { - kubeCommands = imageOCIConfig.Config.Entrypoint - } + if ociConfig != nil && len(kubeCommands) == 0 { + kubeCommands = ociConfig.Entrypoint + if len(kubeArgs) == 0 { + kubeArgs = ociConfig.Cmd } } @@ -1179,9 +1174,12 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string, return nil, err } - processArgs, err := buildOCIProcessArgs(containerConfig, containerImageConfig) - if err != nil { - return nil, err + processArgs := []string{} + if containerImageConfig != nil { + processArgs, err := buildOCIProcessArgs(containerConfig, &containerImageConfig.Config) + if err != nil { + return nil, err + } } specgen.SetProcessArgs(processArgs)