Fix lint errors
Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
parent
dffe302f55
commit
154e18b9b9
1 changed files with 22 additions and 23 deletions
|
@ -150,7 +150,7 @@ var launchCommand = cli.Command{
|
||||||
|
|
||||||
logrus.Debugf("Going to create container named %v with image %v", cliConfig.containerName, cliConfig.image)
|
logrus.Debugf("Going to create container named %v with image %v", cliConfig.containerName, cliConfig.image)
|
||||||
|
|
||||||
var sandboxId string
|
var sandboxID string
|
||||||
var sandboxConfig *pb.PodSandboxConfig
|
var sandboxConfig *pb.PodSandboxConfig
|
||||||
|
|
||||||
sandboxSecurityConfig, containerSecurityConfig, err := generateLinuxSecurityConfigs(cliConfig)
|
sandboxSecurityConfig, containerSecurityConfig, err := generateLinuxSecurityConfigs(cliConfig)
|
||||||
|
@ -161,21 +161,21 @@ var launchCommand = cli.Command{
|
||||||
if cliConfig.pod != "" {
|
if cliConfig.pod != "" {
|
||||||
// We were passed a pod to join
|
// We were passed a pod to join
|
||||||
// Don't create our own
|
// Don't create our own
|
||||||
sandboxId = cliConfig.pod
|
sandboxID = cliConfig.pod
|
||||||
|
|
||||||
logrus.Debugf("Joining existing sandbox with ID %v", sandboxId)
|
logrus.Debugf("Joining existing sandbox with ID %v", sandboxID)
|
||||||
|
|
||||||
// Get status of pod - verify it exists
|
// Get status of pod - verify it exists
|
||||||
sandboxStatusRequest := pb.PodSandboxStatusRequest{
|
sandboxStatusRequest := pb.PodSandboxStatusRequest{
|
||||||
PodSandboxId: sandboxId,
|
PodSandboxId: sandboxID,
|
||||||
}
|
}
|
||||||
sandboxStatusResp, err := server.PodSandboxStatus(context.Background(), &sandboxStatusRequest)
|
sandboxStatusResp, err := server.PodSandboxStatus(context.Background(), &sandboxStatusRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting status of sandbox %v: %v", sandboxId, err)
|
return fmt.Errorf("error getting status of sandbox %v: %v", sandboxID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if sandboxStatusResp.Status.State != pb.PodSandboxState_SANDBOX_READY {
|
if sandboxStatusResp.Status.State != pb.PodSandboxState_SANDBOX_READY {
|
||||||
return fmt.Errorf("cannot attach to sandbox %v as it is not ready", sandboxId)
|
return fmt.Errorf("cannot attach to sandbox %v as it is not ready", sandboxID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - Before this can work, we need a way of getting the PodSandboxConfig from the server
|
// TODO - Before this can work, we need a way of getting the PodSandboxConfig from the server
|
||||||
|
@ -199,12 +199,12 @@ var launchCommand = cli.Command{
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating sandbox: %v", err)
|
return fmt.Errorf("error creating sandbox: %v", err)
|
||||||
}
|
}
|
||||||
sandboxId = sandboxResp.PodSandboxId
|
sandboxID = sandboxResp.PodSandboxId
|
||||||
|
|
||||||
logrus.Infof("Successfully created sandbox with ID %v", sandboxId)
|
logrus.Infof("Successfully created sandbox with ID %v", sandboxID)
|
||||||
}
|
}
|
||||||
|
|
||||||
createRequest, err := makeContainerCreateRequest(cliConfig, containerSecurityConfig, sandboxId, sandboxConfig)
|
createRequest, err := makeContainerCreateRequest(cliConfig, containerSecurityConfig, sandboxID, sandboxConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating ContainerCreateRequest: %v", err)
|
return fmt.Errorf("error creating ContainerCreateRequest: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -215,11 +215,11 @@ var launchCommand = cli.Command{
|
||||||
// If we did not join an existing pod, clean up the sandbox we made
|
// If we did not join an existing pod, clean up the sandbox we made
|
||||||
defer func() {
|
defer func() {
|
||||||
removeRequest := pb.RemovePodSandboxRequest{
|
removeRequest := pb.RemovePodSandboxRequest{
|
||||||
PodSandboxId: sandboxId,
|
PodSandboxId: sandboxID,
|
||||||
}
|
}
|
||||||
_, err = server.RemovePodSandbox(context.Background(), &removeRequest)
|
_, err = server.RemovePodSandbox(context.Background(), &removeRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatalf("Failed to remove sandbox %v: %v", sandboxId, err)
|
logrus.Fatalf("Failed to remove sandbox %v: %v", sandboxID, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -227,12 +227,12 @@ var launchCommand = cli.Command{
|
||||||
return fmt.Errorf("error creating container: %v", err)
|
return fmt.Errorf("error creating container: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
containerId := containerResp.ContainerId
|
containerID := containerResp.ContainerId
|
||||||
|
|
||||||
logrus.Debugf("Successfully created container with ID %v in sandbox %v", sandboxId, containerId)
|
logrus.Debugf("Successfully created container with ID %v in sandbox %v", sandboxID, containerID)
|
||||||
|
|
||||||
startRequest := pb.StartContainerRequest{
|
startRequest := pb.StartContainerRequest{
|
||||||
ContainerId: containerId,
|
ContainerId: containerID,
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartContainerResponse is an empty struct, just ignore it
|
// StartContainerResponse is an empty struct, just ignore it
|
||||||
|
@ -241,7 +241,7 @@ var launchCommand = cli.Command{
|
||||||
return fmt.Errorf("error starting container: %v", err)
|
return fmt.Errorf("error starting container: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("Successfully started container with ID %v", containerId)
|
logrus.Infof("Successfully started container with ID %v", containerID)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -348,9 +348,8 @@ func parseLaunchCLI(ctx *cli.Context) (*launchConfig, error) {
|
||||||
if ctx.IsSet("labels") {
|
if ctx.IsSet("labels") {
|
||||||
// TODO label parsing code
|
// TODO label parsing code
|
||||||
return nil, fmt.Errorf("label parsing is not yet implemented")
|
return nil, fmt.Errorf("label parsing is not yet implemented")
|
||||||
} else {
|
|
||||||
config.labels = new(map[string]string)
|
|
||||||
}
|
}
|
||||||
|
config.labels = new(map[string]string)
|
||||||
// TODO should set some default label values - indicate we were launched by kpod, maybe?
|
// TODO should set some default label values - indicate we were launched by kpod, maybe?
|
||||||
|
|
||||||
if ctx.IsSet("limits") {
|
if ctx.IsSet("limits") {
|
||||||
|
@ -413,13 +412,13 @@ 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, err := getRandomID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error generating sandbox id: %v", err)
|
return nil, fmt.Errorf("error generating sandbox id: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata := pb.PodSandboxMetadata{
|
metadata := pb.PodSandboxMetadata{
|
||||||
Name: "kpod_launch_" + sandboxId,
|
Name: "kpod_launch_" + sandboxID,
|
||||||
Uid: "kpod_default",
|
Uid: "kpod_default",
|
||||||
Namespace: "kpod_default",
|
Namespace: "kpod_default",
|
||||||
Attempt: 0,
|
Attempt: 0,
|
||||||
|
@ -433,7 +432,7 @@ func makePodSandboxConfig(cliConfig *launchConfig, securityConfig *pb.LinuxSandb
|
||||||
|
|
||||||
config := pb.PodSandboxConfig{
|
config := pb.PodSandboxConfig{
|
||||||
Metadata: &metadata,
|
Metadata: &metadata,
|
||||||
Hostname: "kpod_launch_" + sandboxId,
|
Hostname: "kpod_launch_" + sandboxID,
|
||||||
// TODO Logging
|
// TODO Logging
|
||||||
LogDirectory: "",
|
LogDirectory: "",
|
||||||
DnsConfig: cliConfig.dns,
|
DnsConfig: cliConfig.dns,
|
||||||
|
@ -448,7 +447,7 @@ func makePodSandboxConfig(cliConfig *launchConfig, securityConfig *pb.LinuxSandb
|
||||||
return &config, nil
|
return &config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeContainerCreateRequest(cliConfig *launchConfig, securityConfig *pb.LinuxContainerSecurityContext, sandboxId string, sandboxConfig *pb.PodSandboxConfig) (*pb.CreateContainerRequest, error) {
|
func makeContainerCreateRequest(cliConfig *launchConfig, securityConfig *pb.LinuxContainerSecurityContext, sandboxID string, sandboxConfig *pb.PodSandboxConfig) (*pb.CreateContainerRequest, error) {
|
||||||
metadata := pb.ContainerMetadata{
|
metadata := pb.ContainerMetadata{
|
||||||
Name: cliConfig.containerName,
|
Name: cliConfig.containerName,
|
||||||
Attempt: 0,
|
Attempt: 0,
|
||||||
|
@ -489,7 +488,7 @@ func makeContainerCreateRequest(cliConfig *launchConfig, securityConfig *pb.Linu
|
||||||
}
|
}
|
||||||
|
|
||||||
req := pb.CreateContainerRequest{
|
req := pb.CreateContainerRequest{
|
||||||
PodSandboxId: sandboxId,
|
PodSandboxId: sandboxID,
|
||||||
Config: &config,
|
Config: &config,
|
||||||
SandboxConfig: sandboxConfig,
|
SandboxConfig: sandboxConfig,
|
||||||
}
|
}
|
||||||
|
@ -534,7 +533,7 @@ func generateLinuxSecurityConfigs(cliConfig *launchConfig) (*pb.LinuxSandboxSecu
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate and hex-encode 128-bit random ID
|
// Generate and hex-encode 128-bit random ID
|
||||||
func getRandomId() (string, error) {
|
func getRandomID() (string, error) {
|
||||||
urandom, err := os.Open("/dev/urandom")
|
urandom, err := os.Open("/dev/urandom")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("could not open urandom for reading: %v", err)
|
return "", fmt.Errorf("could not open urandom for reading: %v", err)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue