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 <wking@tremily.us>
This commit is contained in:
parent
54e76afc03
commit
cff96ecf5c
1 changed files with 11 additions and 13 deletions
|
@ -376,7 +376,7 @@ func addDevices(sb *sandbox.Sandbox, containerConfig *pb.ContainerConfig, specge
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildOCIProcessArgs build an OCI compatible process arguments slice.
|
// 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
|
//# Start the nginx container using the default command, but use custom
|
||||||
//arguments (arg1 .. argN) for that command.
|
//arguments (arg1 .. argN) for that command.
|
||||||
//kubectl run nginx --image=nginx -- <arg1> <arg2> ... <argN>
|
//kubectl run nginx --image=nginx -- <arg1> <arg2> ... <argN>
|
||||||
|
@ -388,15 +388,10 @@ func buildOCIProcessArgs(containerKubeConfig *pb.ContainerConfig, imageOCIConfig
|
||||||
kubeArgs := containerKubeConfig.Args
|
kubeArgs := containerKubeConfig.Args
|
||||||
|
|
||||||
// merge image config and kube config
|
// merge image config and kube config
|
||||||
// same as docker does today...
|
if ociConfig != nil && len(kubeCommands) == 0 {
|
||||||
if imageOCIConfig != nil {
|
kubeCommands = ociConfig.Entrypoint
|
||||||
if len(kubeCommands) == 0 {
|
if len(kubeArgs) == 0 {
|
||||||
if len(kubeArgs) == 0 {
|
kubeArgs = ociConfig.Cmd
|
||||||
kubeArgs = imageOCIConfig.Config.Cmd
|
|
||||||
}
|
|
||||||
if kubeCommands == nil {
|
|
||||||
kubeCommands = imageOCIConfig.Config.Entrypoint
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1179,9 +1174,12 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
processArgs, err := buildOCIProcessArgs(containerConfig, containerImageConfig)
|
processArgs := []string{}
|
||||||
if err != nil {
|
if containerImageConfig != nil {
|
||||||
return nil, err
|
processArgs, err := buildOCIProcessArgs(containerConfig, &containerImageConfig.Config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
specgen.SetProcessArgs(processArgs)
|
specgen.SetProcessArgs(processArgs)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue