Skip to content

Commit cff96ec

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 54e76af commit cff96ec

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

@@ -1179,9 +1174,12 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
11791174
return nil, err
11801175
}
11811176

1182-
processArgs, err := buildOCIProcessArgs(containerConfig, containerImageConfig)
1183-
if err != nil {
1184-
return nil, err
1177+
processArgs := []string{}
1178+
if containerImageConfig != nil {
1179+
processArgs, err := buildOCIProcessArgs(containerConfig, &containerImageConfig.Config)
1180+
if err != nil {
1181+
return nil, err
1182+
}
11851183
}
11861184
specgen.SetProcessArgs(processArgs)
11871185

0 commit comments

Comments
 (0)