Skip to content

Commit a4cd5e3

Browse files
committed
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 <[email protected]>
1 parent 77561e9 commit a4cd5e3

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

server/container_create.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func addDevices(sb *sandbox.Sandbox, containerConfig *pb.ContainerConfig, specge
376376
}
377377

378378
// buildOCIProcessArgs build an OCI compatible process arguments slice.
379-
func buildOCIProcessArgs(containerKubeConfig *pb.ContainerConfig, imageOCIConfig *v1.Image) ([]string, error) {
379+
func buildOCIProcessArgs(containerKubeConfig *pb.ContainerConfig, ociConfig *v1.ImageConfig) ([]string, error) {
380380
//# Start the nginx container using the default command, but use custom
381381
//arguments (arg1 .. argN) for that command.
382382
//kubectl run nginx --image=nginx -- <arg1> <arg2> ... <argN>
@@ -388,15 +388,10 @@ func buildOCIProcessArgs(containerKubeConfig *pb.ContainerConfig, imageOCIConfig
388388
kubeArgs := containerKubeConfig.Args
389389

390390
// merge image config and kube config
391-
// same as docker does today...
392-
if imageOCIConfig != nil {
393-
if len(kubeCommands) == 0 {
394-
if len(kubeArgs) == 0 {
395-
kubeArgs = imageOCIConfig.Config.Cmd
396-
}
397-
if kubeCommands == nil {
398-
kubeCommands = imageOCIConfig.Config.Entrypoint
399-
}
391+
if ociConfig != nil && len(kubeCommands) == 0 {
392+
kubeCommands = ociConfig.Entrypoint
393+
if len(kubeArgs) == 0 {
394+
kubeArgs = ociConfig.Cmd
400395
}
401396
}
402397

@@ -1163,9 +1158,12 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
11631158
return nil, err
11641159
}
11651160

1166-
processArgs, err := buildOCIProcessArgs(containerConfig, containerImageConfig)
1167-
if err != nil {
1168-
return nil, err
1161+
processArgs := []string{}
1162+
if containerImageConfig != nil {
1163+
processArgs, err := buildOCIProcessArgs(containerConfig, &containerImageConfig.Config)
1164+
if err != nil {
1165+
return nil, err
1166+
}
11691167
}
11701168
specgen.SetProcessArgs(processArgs)
11711169

0 commit comments

Comments
 (0)