Replace ID generation function with vendored equivalent
Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
parent
5f74cffd12
commit
12f2dbe2a0
1 changed files with 2 additions and 25 deletions
|
@ -1,12 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/kubernetes-incubator/cri-o/server"
|
"github.com/kubernetes-incubator/cri-o/server"
|
||||||
"github.com/opencontainers/runc/libcontainer/selinux"
|
"github.com/opencontainers/runc/libcontainer/selinux"
|
||||||
"github.com/opencontainers/runc/libcontainer/user"
|
"github.com/opencontainers/runc/libcontainer/user"
|
||||||
|
@ -450,10 +450,7 @@ func parseLaunchCLI(ctx *cli.Context) (*launchConfig, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func makePodSandboxConfig(cliConfig *launchConfig, securityConfig *pb.LinuxSandboxSecurityContext) (*pb.PodSandboxConfig, error) {
|
func makePodSandboxConfig(cliConfig *launchConfig, securityConfig *pb.LinuxSandboxSecurityContext) (*pb.PodSandboxConfig, error) {
|
||||||
sandboxID, err := getRandomID()
|
sandboxID := stringid.GenerateNonCryptoID()
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error generating sandbox id: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
metadata := pb.PodSandboxMetadata{
|
metadata := pb.PodSandboxMetadata{
|
||||||
Name: "kpod_launch_" + sandboxID,
|
Name: "kpod_launch_" + sandboxID,
|
||||||
|
@ -570,23 +567,3 @@ func generateLinuxSecurityConfigs(cliConfig *launchConfig) (*pb.LinuxSandboxSecu
|
||||||
|
|
||||||
return &sandboxConfig, &containerConfig, nil
|
return &sandboxConfig, &containerConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate and hex-encode 128-bit random ID
|
|
||||||
func getRandomID() (string, error) {
|
|
||||||
urandom, err := os.Open("/dev/urandom")
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("could not open /dev/urandom for reading: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer urandom.Close()
|
|
||||||
|
|
||||||
data := make([]byte, 16)
|
|
||||||
count, err := urandom.Read(data)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("error reading from /dev/urandom: %v", err)
|
|
||||||
} else if count != 16 {
|
|
||||||
return "", fmt.Errorf("read too few bytes from /dev/urandom")
|
|
||||||
}
|
|
||||||
|
|
||||||
return hex.EncodeToString(data), nil
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue