Merge pull request #400 from sameo/topic/oci-process
server: Fix the OCI process arguments build routine
This commit is contained in:
commit
673b6e4c51
1 changed files with 55 additions and 22 deletions
|
@ -60,6 +60,7 @@ func addOciBindMounts(sb *sandbox, containerConfig *pb.ContainerConfig, specgen
|
||||||
// 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, imageOCIConfig *v1.Image) ([]string, error) {
|
||||||
processArgs := []string{}
|
processArgs := []string{}
|
||||||
|
var processEntryPoint, processCmd []string
|
||||||
|
|
||||||
kubeCommands := containerKubeConfig.Command
|
kubeCommands := containerKubeConfig.Command
|
||||||
kubeArgs := containerKubeConfig.Args
|
kubeArgs := containerKubeConfig.Args
|
||||||
|
@ -86,34 +87,66 @@ func buildOCIProcessArgs(containerKubeConfig *pb.ContainerConfig, imageOCIConfig
|
||||||
|
|
||||||
// We got an OCI Image configuration.
|
// We got an OCI Image configuration.
|
||||||
// We will only use it if the kubelet information is incomplete.
|
// We will only use it if the kubelet information is incomplete.
|
||||||
if kubeCommands == nil {
|
|
||||||
if imageOCIConfig != nil && imageOCIConfig.Config.Entrypoint != nil {
|
// First we set the process entry point.
|
||||||
processArgs = append(processArgs, imageOCIConfig.Config.Entrypoint...)
|
if kubeCommands != nil {
|
||||||
|
// The kubelet command slice is prioritized.
|
||||||
|
processEntryPoint = kubeCommands
|
||||||
|
} else {
|
||||||
|
// Here the kubelet command slice is empty.
|
||||||
|
if imageOCIConfig != nil {
|
||||||
|
// If the OCI image config has an ENTRYPOINT we
|
||||||
|
// use it as our process command.
|
||||||
|
// Otherwise we use the CMD slice if it's not
|
||||||
|
// empty.
|
||||||
|
if imageOCIConfig.Config.Entrypoint != nil {
|
||||||
|
processEntryPoint = imageOCIConfig.Config.Entrypoint
|
||||||
|
} else if imageOCIConfig.Config.Cmd != nil {
|
||||||
|
processEntryPoint = imageOCIConfig.Config.Cmd
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
processArgs = append(processArgs, kubeCommands...)
|
// We neither have a kubelet command not an image OCI config.
|
||||||
|
// Missing an image OCI config will no longer be supported after
|
||||||
|
// https://github.com/kubernetes-incubator/cri-o/issues/395 is fixed.
|
||||||
|
processEntryPoint = []string{"/bin/sh", "-c"}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if kubeArgs == nil {
|
// Then we build the process command arguments
|
||||||
// Our kubelet command arguments slice is empty.
|
if kubeArgs != nil {
|
||||||
// We will use the OCI Image configuration only if we already
|
// The kubelet command arguments slice is prioritized.
|
||||||
// have found a process command, i.e. if processArgs is no
|
processCmd = kubeArgs
|
||||||
// longer empty. No doing so will have us create a process
|
} else {
|
||||||
// arguments slice starting with the OCI Image command arguments
|
if kubeCommands != nil {
|
||||||
// as the entry point.
|
// kubelet gave us a command slice but explicitely
|
||||||
if processArgs != nil &&
|
// left the arguments slice empty. We should keep
|
||||||
imageOCIConfig != nil &&
|
// it that way.
|
||||||
imageOCIConfig.Config.Entrypoint != nil && imageOCIConfig.Config.Cmd != nil {
|
processCmd = []string{}
|
||||||
processArgs = append(processArgs, imageOCIConfig.Config.Cmd...)
|
} else {
|
||||||
|
// Here kubelet kept both the command and arguments
|
||||||
|
// slices empty. We should try building the process
|
||||||
|
// arguments slice from the OCI image config.
|
||||||
|
// If the OCI image config has an ENTRYPOINT slice,
|
||||||
|
// we use the CMD slice as the process arguments.
|
||||||
|
// Otherwise, we already picked CMD as our process
|
||||||
|
// command and we must not add the CMD slice twice.
|
||||||
|
if imageOCIConfig != nil {
|
||||||
|
if imageOCIConfig.Config.Entrypoint != nil {
|
||||||
|
processCmd = imageOCIConfig.Config.Cmd
|
||||||
|
} else {
|
||||||
|
processCmd = []string{}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
processArgs = append(processArgs, kubeArgs...)
|
// Missing an image OCI config will no longer
|
||||||
|
// be supported after https://github.com/kubernetes-incubator/cri-o/issues/395
|
||||||
|
// is fixed.
|
||||||
|
processCmd = []string{}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if processArgs == nil {
|
processArgs = append(processArgs, processEntryPoint...)
|
||||||
// Use a reasonable default if everything failed.
|
processArgs = append(processArgs, processCmd...)
|
||||||
processArgs = []string{"/bin/sh"}
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Debugf("OCI process args %v", processArgs)
|
logrus.Debugf("OCI process args %v", processArgs)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue