Applying k8s.io v3 API for ocic and ocid
Signed-off-by: Michał Żyłowski <michal.zylowski@intel.com>
This commit is contained in:
parent
a48336f981
commit
5c81217e09
26 changed files with 247 additions and 289 deletions
|
@ -319,7 +319,7 @@ func CreateContainer(client pb.RuntimeServiceClient, opts createOptions) error {
|
||||||
|
|
||||||
// Override the name by the one specified through CLI
|
// Override the name by the one specified through CLI
|
||||||
if opts.name != "" {
|
if opts.name != "" {
|
||||||
config.Metadata.Name = &opts.name
|
config.Metadata.Name = opts.name
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range opts.labels {
|
for k, v := range opts.labels {
|
||||||
|
@ -327,7 +327,7 @@ func CreateContainer(client pb.RuntimeServiceClient, opts createOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := client.CreateContainer(context.Background(), &pb.CreateContainerRequest{
|
r, err := client.CreateContainer(context.Background(), &pb.CreateContainerRequest{
|
||||||
PodSandboxId: &opts.podID,
|
PodSandboxId: opts.podID,
|
||||||
Config: config,
|
Config: config,
|
||||||
// TODO(runcom): this is missing PodSandboxConfig!!!
|
// TODO(runcom): this is missing PodSandboxConfig!!!
|
||||||
// we should/could find a way to retrieve it from the fs and set it here
|
// we should/could find a way to retrieve it from the fs and set it here
|
||||||
|
@ -335,7 +335,7 @@ func CreateContainer(client pb.RuntimeServiceClient, opts createOptions) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(*r.ContainerId)
|
fmt.Println(r.ContainerId)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ func StartContainer(client pb.RuntimeServiceClient, ID string) error {
|
||||||
return fmt.Errorf("ID cannot be empty")
|
return fmt.Errorf("ID cannot be empty")
|
||||||
}
|
}
|
||||||
_, err := client.StartContainer(context.Background(), &pb.StartContainerRequest{
|
_, err := client.StartContainer(context.Background(), &pb.StartContainerRequest{
|
||||||
ContainerId: &ID,
|
ContainerId: ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -362,7 +362,7 @@ func StopContainer(client pb.RuntimeServiceClient, ID string) error {
|
||||||
return fmt.Errorf("ID cannot be empty")
|
return fmt.Errorf("ID cannot be empty")
|
||||||
}
|
}
|
||||||
_, err := client.StopContainer(context.Background(), &pb.StopContainerRequest{
|
_, err := client.StopContainer(context.Background(), &pb.StopContainerRequest{
|
||||||
ContainerId: &ID,
|
ContainerId: ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -378,7 +378,7 @@ func RemoveContainer(client pb.RuntimeServiceClient, ID string) error {
|
||||||
return fmt.Errorf("ID cannot be empty")
|
return fmt.Errorf("ID cannot be empty")
|
||||||
}
|
}
|
||||||
_, err := client.RemoveContainer(context.Background(), &pb.RemoveContainerRequest{
|
_, err := client.RemoveContainer(context.Background(), &pb.RemoveContainerRequest{
|
||||||
ContainerId: &ID,
|
ContainerId: ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -394,37 +394,26 @@ func ContainerStatus(client pb.RuntimeServiceClient, ID string) error {
|
||||||
return fmt.Errorf("ID cannot be empty")
|
return fmt.Errorf("ID cannot be empty")
|
||||||
}
|
}
|
||||||
r, err := client.ContainerStatus(context.Background(), &pb.ContainerStatusRequest{
|
r, err := client.ContainerStatus(context.Background(), &pb.ContainerStatusRequest{
|
||||||
ContainerId: &ID})
|
ContainerId: ID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("ID: %s\n", *r.Status.Id)
|
fmt.Printf("ID: %s\n", r.Status.Id)
|
||||||
if r.Status.Metadata != nil {
|
if r.Status.Metadata != nil {
|
||||||
if r.Status.Metadata.Name != nil {
|
if r.Status.Metadata.Name != "" {
|
||||||
fmt.Printf("Name: %s\n", *r.Status.Metadata.Name)
|
fmt.Printf("Name: %s\n", r.Status.Metadata.Name)
|
||||||
}
|
|
||||||
if r.Status.Metadata.Attempt != nil {
|
|
||||||
fmt.Printf("Attempt: %v\n", *r.Status.Metadata.Attempt)
|
|
||||||
}
|
}
|
||||||
|
fmt.Printf("Attempt: %v\n", r.Status.Metadata.Attempt)
|
||||||
}
|
}
|
||||||
if r.Status.State != nil {
|
// TODO(mzylowski): print it prettier
|
||||||
fmt.Printf("Status: %s\n", r.Status.State)
|
fmt.Printf("Status: %s\n", r.Status.State)
|
||||||
}
|
ctm := time.Unix(0, r.Status.CreatedAt)
|
||||||
if r.Status.CreatedAt != nil {
|
fmt.Printf("Created: %v\n", ctm)
|
||||||
ctm := time.Unix(0, *r.Status.CreatedAt)
|
stm := time.Unix(0, r.Status.StartedAt)
|
||||||
fmt.Printf("Created: %v\n", ctm)
|
fmt.Printf("Started: %v\n", stm)
|
||||||
}
|
ftm := time.Unix(0, r.Status.FinishedAt)
|
||||||
if r.Status.StartedAt != nil {
|
fmt.Printf("Finished: %v\n", ftm)
|
||||||
stm := time.Unix(0, *r.Status.StartedAt)
|
fmt.Printf("Exit Code: %v\n", r.Status.ExitCode)
|
||||||
fmt.Printf("Started: %v\n", stm)
|
|
||||||
}
|
|
||||||
if r.Status.FinishedAt != nil {
|
|
||||||
ftm := time.Unix(0, *r.Status.FinishedAt)
|
|
||||||
fmt.Printf("Finished: %v\n", ftm)
|
|
||||||
}
|
|
||||||
if r.Status.ExitCode != nil {
|
|
||||||
fmt.Printf("Exit Code: %v\n", *r.Status.ExitCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -436,9 +425,9 @@ func ExecSync(client pb.RuntimeServiceClient, ID string, cmd []string, timeout i
|
||||||
return fmt.Errorf("ID cannot be empty")
|
return fmt.Errorf("ID cannot be empty")
|
||||||
}
|
}
|
||||||
r, err := client.ExecSync(context.Background(), &pb.ExecSyncRequest{
|
r, err := client.ExecSync(context.Background(), &pb.ExecSyncRequest{
|
||||||
ContainerId: &ID,
|
ContainerId: ID,
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
Timeout: &timeout,
|
Timeout: timeout,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -447,7 +436,7 @@ func ExecSync(client pb.RuntimeServiceClient, ID string, cmd []string, timeout i
|
||||||
fmt.Println(string(r.Stdout))
|
fmt.Println(string(r.Stdout))
|
||||||
fmt.Println("Stderr:")
|
fmt.Println("Stderr:")
|
||||||
fmt.Println(string(r.Stderr))
|
fmt.Println(string(r.Stderr))
|
||||||
fmt.Printf("Exit code: %v\n", *r.ExitCode)
|
fmt.Printf("Exit code: %v\n", r.ExitCode)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -457,23 +446,24 @@ func ExecSync(client pb.RuntimeServiceClient, ID string, cmd []string, timeout i
|
||||||
func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
|
func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
|
||||||
filter := &pb.ContainerFilter{}
|
filter := &pb.ContainerFilter{}
|
||||||
if opts.id != "" {
|
if opts.id != "" {
|
||||||
filter.Id = &opts.id
|
filter.Id = opts.id
|
||||||
}
|
}
|
||||||
if opts.podID != "" {
|
if opts.podID != "" {
|
||||||
filter.PodSandboxId = &opts.podID
|
filter.PodSandboxId = opts.podID
|
||||||
}
|
}
|
||||||
if opts.state != "" {
|
if opts.state != "" {
|
||||||
st := pb.ContainerState_CONTAINER_UNKNOWN
|
st := &pb.ContainerStateValue{}
|
||||||
|
st.State = pb.ContainerState_CONTAINER_UNKNOWN
|
||||||
switch opts.state {
|
switch opts.state {
|
||||||
case "created":
|
case "created":
|
||||||
st = pb.ContainerState_CONTAINER_CREATED
|
st.State = pb.ContainerState_CONTAINER_CREATED
|
||||||
filter.State = &st
|
filter.State = st
|
||||||
case "running":
|
case "running":
|
||||||
st = pb.ContainerState_CONTAINER_RUNNING
|
st.State = pb.ContainerState_CONTAINER_RUNNING
|
||||||
filter.State = &st
|
filter.State = st
|
||||||
case "stopped":
|
case "stopped":
|
||||||
st = pb.ContainerState_CONTAINER_EXITED
|
st.State = pb.ContainerState_CONTAINER_EXITED
|
||||||
filter.State = &st
|
filter.State = st
|
||||||
default:
|
default:
|
||||||
log.Fatalf("--state should be one of created, running or stopped")
|
log.Fatalf("--state should be one of created, running or stopped")
|
||||||
}
|
}
|
||||||
|
@ -489,29 +479,23 @@ func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
|
||||||
}
|
}
|
||||||
for _, c := range r.GetContainers() {
|
for _, c := range r.GetContainers() {
|
||||||
if opts.quiet {
|
if opts.quiet {
|
||||||
fmt.Println(*c.Id)
|
fmt.Println(c.Id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("ID: %s\n", *c.Id)
|
fmt.Printf("ID: %s\n", c.Id)
|
||||||
fmt.Printf("Pod: %s\n", *c.PodSandboxId)
|
fmt.Printf("Pod: %s\n", c.PodSandboxId)
|
||||||
if c.Metadata != nil {
|
if c.Metadata != nil {
|
||||||
if c.Metadata.Name != nil {
|
if c.Metadata.Name != "" {
|
||||||
fmt.Printf("Name: %s\n", *c.Metadata.Name)
|
fmt.Printf("Name: %s\n", c.Metadata.Name)
|
||||||
}
|
|
||||||
if c.Metadata.Attempt != nil {
|
|
||||||
fmt.Printf("Attempt: %v\n", *c.Metadata.Attempt)
|
|
||||||
}
|
}
|
||||||
|
fmt.Printf("Attempt: %v\n", c.Metadata.Attempt)
|
||||||
}
|
}
|
||||||
if c.State != nil {
|
fmt.Printf("Status: %s\n", c.State)
|
||||||
fmt.Printf("Status: %s\n", *c.State)
|
|
||||||
}
|
|
||||||
if c.Image != nil {
|
if c.Image != nil {
|
||||||
fmt.Printf("Image: %s\n", c.Image.GetImage())
|
fmt.Printf("Image: %s\n", c.Image.Image)
|
||||||
}
|
|
||||||
if c.CreatedAt != nil {
|
|
||||||
ctm := time.Unix(0, *c.CreatedAt)
|
|
||||||
fmt.Printf("Created: %v\n", ctm)
|
|
||||||
}
|
}
|
||||||
|
ctm := time.Unix(0, c.CreatedAt)
|
||||||
|
fmt.Printf("Created: %v\n", ctm)
|
||||||
if c.Labels != nil {
|
if c.Labels != nil {
|
||||||
fmt.Println("Labels:")
|
fmt.Println("Labels:")
|
||||||
for _, k := range getSortedKeys(c.Labels) {
|
for _, k := range getSortedKeys(c.Labels) {
|
||||||
|
|
|
@ -63,18 +63,18 @@ var listImageCommand = cli.Command{
|
||||||
quiet := context.Bool("quiet")
|
quiet := context.Bool("quiet")
|
||||||
for _, image := range r.Images {
|
for _, image := range r.Images {
|
||||||
if quiet {
|
if quiet {
|
||||||
fmt.Printf("%s\n", *image.Id)
|
fmt.Printf("%s\n", image.Id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("ID: %s\n", *image.Id)
|
fmt.Printf("ID: %s\n", image.Id)
|
||||||
for _, tag := range image.RepoTags {
|
for _, tag := range image.RepoTags {
|
||||||
fmt.Printf("Tag: %s\n", tag)
|
fmt.Printf("Tag: %s\n", tag)
|
||||||
}
|
}
|
||||||
for _, digest := range image.RepoDigests {
|
for _, digest := range image.RepoDigests {
|
||||||
fmt.Printf("Digest: %s\n", digest)
|
fmt.Printf("Digest: %s\n", digest)
|
||||||
}
|
}
|
||||||
if image.Size_ != nil {
|
if image.Size_ != 0 {
|
||||||
fmt.Printf("Size: %d\n", *image.Size_)
|
fmt.Printf("Size: %d\n", image.Size_)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -107,16 +107,14 @@ var imageStatusCommand = cli.Command{
|
||||||
if image == nil {
|
if image == nil {
|
||||||
return fmt.Errorf("no such image present")
|
return fmt.Errorf("no such image present")
|
||||||
}
|
}
|
||||||
fmt.Printf("ID: %s\n", *image.Id)
|
fmt.Printf("ID: %s\n", image.Id)
|
||||||
for _, tag := range image.RepoTags {
|
for _, tag := range image.RepoTags {
|
||||||
fmt.Printf("Tag: %s\n", tag)
|
fmt.Printf("Tag: %s\n", tag)
|
||||||
}
|
}
|
||||||
for _, digest := range image.RepoDigests {
|
for _, digest := range image.RepoDigests {
|
||||||
fmt.Printf("Digest: %s\n", digest)
|
fmt.Printf("Digest: %s\n", digest)
|
||||||
}
|
}
|
||||||
if image.Size_ != nil {
|
fmt.Printf("Size: %d\n", image.Size_)
|
||||||
fmt.Printf("Size: %d\n", *image.Size_)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -150,19 +148,19 @@ var removeImageCommand = cli.Command{
|
||||||
// PullImage sends a PullImageRequest to the server, and parses
|
// PullImage sends a PullImageRequest to the server, and parses
|
||||||
// the returned PullImageResponse.
|
// the returned PullImageResponse.
|
||||||
func PullImage(client pb.ImageServiceClient, image string) (*pb.PullImageResponse, error) {
|
func PullImage(client pb.ImageServiceClient, image string) (*pb.PullImageResponse, error) {
|
||||||
return client.PullImage(context.Background(), &pb.PullImageRequest{Image: &pb.ImageSpec{Image: &image}})
|
return client.PullImage(context.Background(), &pb.PullImageRequest{Image: &pb.ImageSpec{Image: image}})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListImages sends a ListImagesRequest to the server, and parses
|
// ListImages sends a ListImagesRequest to the server, and parses
|
||||||
// the returned ListImagesResponse.
|
// the returned ListImagesResponse.
|
||||||
func ListImages(client pb.ImageServiceClient, image string) (*pb.ListImagesResponse, error) {
|
func ListImages(client pb.ImageServiceClient, image string) (*pb.ListImagesResponse, error) {
|
||||||
return client.ListImages(context.Background(), &pb.ListImagesRequest{Filter: &pb.ImageFilter{Image: &pb.ImageSpec{Image: &image}}})
|
return client.ListImages(context.Background(), &pb.ListImagesRequest{Filter: &pb.ImageFilter{Image: &pb.ImageSpec{Image: image}}})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImageStatus sends an ImageStatusRequest to the server, and parses
|
// ImageStatus sends an ImageStatusRequest to the server, and parses
|
||||||
// the returned ImageStatusResponse.
|
// the returned ImageStatusResponse.
|
||||||
func ImageStatus(client pb.ImageServiceClient, image string) (*pb.ImageStatusResponse, error) {
|
func ImageStatus(client pb.ImageServiceClient, image string) (*pb.ImageStatusResponse, error) {
|
||||||
return client.ImageStatus(context.Background(), &pb.ImageStatusRequest{Image: &pb.ImageSpec{Image: &image}})
|
return client.ImageStatus(context.Background(), &pb.ImageStatusRequest{Image: &pb.ImageSpec{Image: image}})
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveImage sends a RemoveImageRequest to the server, and parses
|
// RemoveImage sends a RemoveImageRequest to the server, and parses
|
||||||
|
@ -171,5 +169,5 @@ func RemoveImage(client pb.ImageServiceClient, image string) (*pb.RemoveImageRes
|
||||||
if image == "" {
|
if image == "" {
|
||||||
return nil, fmt.Errorf("ID cannot be empty")
|
return nil, fmt.Errorf("ID cannot be empty")
|
||||||
}
|
}
|
||||||
return client.RemoveImage(context.Background(), &pb.RemoveImageRequest{Image: &pb.ImageSpec{Image: &image}})
|
return client.RemoveImage(context.Background(), &pb.RemoveImageRequest{Image: &pb.ImageSpec{Image: image}})
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,7 +220,7 @@ func RunPodSandbox(client pb.RuntimeServiceClient, opts createOptions) error {
|
||||||
|
|
||||||
// Override the name by the one specified through CLI
|
// Override the name by the one specified through CLI
|
||||||
if opts.name != "" {
|
if opts.name != "" {
|
||||||
config.Metadata.Name = &opts.name
|
config.Metadata.Name = opts.name
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range opts.labels {
|
for k, v := range opts.labels {
|
||||||
|
@ -231,7 +231,7 @@ func RunPodSandbox(client pb.RuntimeServiceClient, opts createOptions) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(*r.PodSandboxId)
|
fmt.Println(r.PodSandboxId)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ func StopPodSandbox(client pb.RuntimeServiceClient, ID string) error {
|
||||||
if ID == "" {
|
if ID == "" {
|
||||||
return fmt.Errorf("ID cannot be empty")
|
return fmt.Errorf("ID cannot be empty")
|
||||||
}
|
}
|
||||||
_, err := client.StopPodSandbox(context.Background(), &pb.StopPodSandboxRequest{PodSandboxId: &ID})
|
_, err := client.StopPodSandbox(context.Background(), &pb.StopPodSandboxRequest{PodSandboxId: ID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -255,7 +255,7 @@ func RemovePodSandbox(client pb.RuntimeServiceClient, ID string) error {
|
||||||
if ID == "" {
|
if ID == "" {
|
||||||
return fmt.Errorf("ID cannot be empty")
|
return fmt.Errorf("ID cannot be empty")
|
||||||
}
|
}
|
||||||
_, err := client.RemovePodSandbox(context.Background(), &pb.RemovePodSandboxRequest{PodSandboxId: &ID})
|
_, err := client.RemovePodSandbox(context.Background(), &pb.RemovePodSandboxRequest{PodSandboxId: ID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -269,37 +269,29 @@ func PodSandboxStatus(client pb.RuntimeServiceClient, ID string) error {
|
||||||
if ID == "" {
|
if ID == "" {
|
||||||
return fmt.Errorf("ID cannot be empty")
|
return fmt.Errorf("ID cannot be empty")
|
||||||
}
|
}
|
||||||
r, err := client.PodSandboxStatus(context.Background(), &pb.PodSandboxStatusRequest{PodSandboxId: &ID})
|
r, err := client.PodSandboxStatus(context.Background(), &pb.PodSandboxStatusRequest{PodSandboxId: ID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("ID: %s\n", *r.Status.Id)
|
fmt.Printf("ID: %s\n", r.Status.Id)
|
||||||
if r.Status.Metadata != nil {
|
if r.Status.Metadata != nil {
|
||||||
if r.Status.Metadata.Name != nil {
|
if r.Status.Metadata.Name != "" {
|
||||||
fmt.Printf("Name: %s\n", *r.Status.Metadata.Name)
|
fmt.Printf("Name: %s\n", r.Status.Metadata.Name)
|
||||||
}
|
}
|
||||||
if r.Status.Metadata.Uid != nil {
|
if r.Status.Metadata.Uid != "" {
|
||||||
fmt.Printf("UID: %s\n", *r.Status.Metadata.Uid)
|
fmt.Printf("UID: %s\n", r.Status.Metadata.Uid)
|
||||||
}
|
}
|
||||||
if r.Status.Metadata.Namespace != nil {
|
if r.Status.Metadata.Namespace != "" {
|
||||||
fmt.Printf("Namespace: %s\n", *r.Status.Metadata.Namespace)
|
fmt.Printf("Namespace: %s\n", r.Status.Metadata.Namespace)
|
||||||
}
|
|
||||||
if r.Status.Metadata.Attempt != nil {
|
|
||||||
fmt.Printf("Attempt: %v\n", *r.Status.Metadata.Attempt)
|
|
||||||
}
|
}
|
||||||
|
fmt.Printf("Attempt: %v\n", r.Status.Metadata.Attempt)
|
||||||
}
|
}
|
||||||
if r.Status.State != nil {
|
fmt.Printf("Status: %s\n", r.Status.State)
|
||||||
fmt.Printf("Status: %s\n", r.Status.State)
|
ctm := time.Unix(0, r.Status.CreatedAt)
|
||||||
}
|
fmt.Printf("Created: %v\n", ctm)
|
||||||
if r.Status.CreatedAt != nil {
|
fmt.Printf("Network namespace: %s\n", r.Status.Linux.Namespaces.Network)
|
||||||
ctm := time.Unix(0, *r.Status.CreatedAt)
|
|
||||||
fmt.Printf("Created: %v\n", ctm)
|
|
||||||
}
|
|
||||||
if r.Status.Linux != nil {
|
|
||||||
fmt.Printf("Network namespace: %s\n", *r.Status.Linux.Namespaces.Network)
|
|
||||||
}
|
|
||||||
if r.Status.Network != nil {
|
if r.Status.Network != nil {
|
||||||
fmt.Printf("IP Address: %v\n", *r.Status.Network.Ip)
|
fmt.Printf("IP Address: %v\n", r.Status.Network.Ip)
|
||||||
}
|
}
|
||||||
if r.Status.Labels != nil {
|
if r.Status.Labels != nil {
|
||||||
fmt.Println("Labels:")
|
fmt.Println("Labels:")
|
||||||
|
@ -321,17 +313,18 @@ func PodSandboxStatus(client pb.RuntimeServiceClient, ID string) error {
|
||||||
func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error {
|
func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error {
|
||||||
filter := &pb.PodSandboxFilter{}
|
filter := &pb.PodSandboxFilter{}
|
||||||
if opts.id != "" {
|
if opts.id != "" {
|
||||||
filter.Id = &opts.id
|
filter.Id = opts.id
|
||||||
}
|
}
|
||||||
if opts.state != "" {
|
if opts.state != "" {
|
||||||
st := pb.PodSandboxState_SANDBOX_NOTREADY
|
st := &pb.PodSandboxStateValue{}
|
||||||
|
st.State = pb.PodSandboxState_SANDBOX_NOTREADY
|
||||||
switch opts.state {
|
switch opts.state {
|
||||||
case "ready":
|
case "ready":
|
||||||
st = pb.PodSandboxState_SANDBOX_READY
|
st.State = pb.PodSandboxState_SANDBOX_READY
|
||||||
filter.State = &st
|
filter.State = st
|
||||||
case "notready":
|
case "notready":
|
||||||
st = pb.PodSandboxState_SANDBOX_NOTREADY
|
st.State = pb.PodSandboxState_SANDBOX_NOTREADY
|
||||||
filter.State = &st
|
filter.State = st
|
||||||
default:
|
default:
|
||||||
log.Fatalf("--state should be ready or notready")
|
log.Fatalf("--state should be ready or notready")
|
||||||
}
|
}
|
||||||
|
@ -347,26 +340,24 @@ func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error {
|
||||||
}
|
}
|
||||||
for _, pod := range r.Items {
|
for _, pod := range r.Items {
|
||||||
if opts.quiet {
|
if opts.quiet {
|
||||||
fmt.Println(*pod.Id)
|
fmt.Println(pod.Id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("ID: %s\n", *pod.Id)
|
fmt.Printf("ID: %s\n", pod.Id)
|
||||||
if pod.Metadata != nil {
|
if pod.Metadata != nil {
|
||||||
if pod.Metadata.Name != nil {
|
if pod.Metadata.Name != "" {
|
||||||
fmt.Printf("Name: %s\n", *pod.Metadata.Name)
|
fmt.Printf("Name: %s\n", pod.Metadata.Name)
|
||||||
}
|
}
|
||||||
if pod.Metadata.Uid != nil {
|
if pod.Metadata.Uid != "" {
|
||||||
fmt.Printf("UID: %s\n", *pod.Metadata.Uid)
|
fmt.Printf("UID: %s\n", pod.Metadata.Uid)
|
||||||
}
|
}
|
||||||
if pod.Metadata.Namespace != nil {
|
if pod.Metadata.Namespace != "" {
|
||||||
fmt.Printf("Namespace: %s\n", *pod.Metadata.Namespace)
|
fmt.Printf("Namespace: %s\n", pod.Metadata.Namespace)
|
||||||
}
|
|
||||||
if pod.Metadata.Attempt != nil {
|
|
||||||
fmt.Printf("Attempt: %v\n", *pod.Metadata.Attempt)
|
|
||||||
}
|
}
|
||||||
|
fmt.Printf("Attempt: %v\n", pod.Metadata.Attempt)
|
||||||
}
|
}
|
||||||
fmt.Printf("Status: %s\n", pod.State)
|
fmt.Printf("Status: %s\n", pod.State)
|
||||||
ctm := time.Unix(0, *pod.CreatedAt)
|
ctm := time.Unix(0, pod.CreatedAt)
|
||||||
fmt.Printf("Created: %v\n", ctm)
|
fmt.Printf("Created: %v\n", ctm)
|
||||||
if pod.Labels != nil {
|
if pod.Labels != nil {
|
||||||
fmt.Println("Labels:")
|
fmt.Println("Labels:")
|
||||||
|
|
|
@ -32,10 +32,10 @@ var runtimeVersionCommand = cli.Command{
|
||||||
|
|
||||||
// Version sends a VersionRequest to the server, and parses the returned VersionResponse.
|
// Version sends a VersionRequest to the server, and parses the returned VersionResponse.
|
||||||
func Version(client pb.RuntimeServiceClient, version string) error {
|
func Version(client pb.RuntimeServiceClient, version string) error {
|
||||||
r, err := client.Version(context.Background(), &pb.VersionRequest{Version: &version})
|
r, err := client.Version(context.Background(), &pb.VersionRequest{Version: version})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("VersionResponse: Version: %s, RuntimeName: %s, RuntimeVersion: %s, RuntimeApiVersion: %s\n", *r.Version, *r.RuntimeName, *r.RuntimeVersion, *r.RuntimeApiVersion)
|
fmt.Printf("VersionResponse: Version: %s, RuntimeName: %s, RuntimeVersion: %s, RuntimeApiVersion: %s\n", r.Version, r.RuntimeName, r.RuntimeVersion, r.RuntimeApiVersion)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,19 +13,14 @@ const (
|
||||||
containerTypeContainer = "container"
|
containerTypeContainer = "container"
|
||||||
)
|
)
|
||||||
|
|
||||||
type containerRequest interface {
|
func (s *Server) getContainerFromRequest(containerID string) (*oci.Container, error) {
|
||||||
GetContainerId() string
|
if containerID == "" {
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) getContainerFromRequest(req containerRequest) (*oci.Container, error) {
|
|
||||||
ctrID := req.GetContainerId()
|
|
||||||
if ctrID == "" {
|
|
||||||
return nil, fmt.Errorf("container ID should not be empty")
|
return nil, fmt.Errorf("container ID should not be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
containerID, err := s.ctrIDIndex.Get(ctrID)
|
containerID, err := s.ctrIDIndex.Get(containerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("container with ID starting with %s not found: %v", ctrID, err)
|
return nil, fmt.Errorf("container with ID starting with %s not found: %v", containerID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c := s.state.containers.Get(containerID)
|
c := s.state.containers.Get(containerID)
|
||||||
|
|
|
@ -29,7 +29,7 @@ const (
|
||||||
func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (res *pb.CreateContainerResponse, err error) {
|
func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (res *pb.CreateContainerResponse, err error) {
|
||||||
logrus.Debugf("CreateContainerRequest %+v", req)
|
logrus.Debugf("CreateContainerRequest %+v", req)
|
||||||
s.Update()
|
s.Update()
|
||||||
sbID := req.GetPodSandboxId()
|
sbID := req.PodSandboxId
|
||||||
if sbID == "" {
|
if sbID == "" {
|
||||||
return nil, fmt.Errorf("PodSandboxId should not be empty")
|
return nil, fmt.Errorf("PodSandboxId should not be empty")
|
||||||
}
|
}
|
||||||
|
@ -50,12 +50,12 @@ func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerReq
|
||||||
return nil, fmt.Errorf("CreateContainerRequest.ContainerConfig is nil")
|
return nil, fmt.Errorf("CreateContainerRequest.ContainerConfig is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
name := containerConfig.GetMetadata().GetName()
|
name := containerConfig.GetMetadata().Name
|
||||||
if name == "" {
|
if name == "" {
|
||||||
return nil, fmt.Errorf("CreateContainerRequest.ContainerConfig.Name is empty")
|
return nil, fmt.Errorf("CreateContainerRequest.ContainerConfig.Name is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
attempt := containerConfig.GetMetadata().GetAttempt()
|
attempt := containerConfig.GetMetadata().Attempt
|
||||||
containerID, containerName, err := s.generateContainerIDandName(sb.name, name, attempt)
|
containerID, containerName, err := s.generateContainerIDandName(sb.name, name, attempt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -96,7 +96,7 @@ func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerReq
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := &pb.CreateContainerResponse{
|
resp := &pb.CreateContainerResponse{
|
||||||
ContainerId: &containerID,
|
ContainerId: containerID,
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf("CreateContainerResponse: %+v", resp)
|
logrus.Debugf("CreateContainerResponse: %+v", resp)
|
||||||
|
@ -108,14 +108,15 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
return nil, errors.New("createSandboxContainer needs a sandbox")
|
return nil, errors.New("createSandboxContainer needs a sandbox")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: simplify this function (cyclomatic complexity here is high)
|
||||||
// TODO: factor generating/updating the spec into something other projects can vendor
|
// TODO: factor generating/updating the spec into something other projects can vendor
|
||||||
|
|
||||||
// creates a spec Generator with the default spec.
|
// creates a spec Generator with the default spec.
|
||||||
specgen := generate.New()
|
specgen := generate.New()
|
||||||
|
|
||||||
processArgs := []string{}
|
processArgs := []string{}
|
||||||
commands := containerConfig.GetCommand()
|
commands := containerConfig.Command
|
||||||
args := containerConfig.GetArgs()
|
args := containerConfig.Args
|
||||||
if commands == nil && args == nil {
|
if commands == nil && args == nil {
|
||||||
processArgs = nil
|
processArgs = nil
|
||||||
}
|
}
|
||||||
|
@ -126,7 +127,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
processArgs = append(processArgs, args...)
|
processArgs = append(processArgs, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
cwd := containerConfig.GetWorkingDir()
|
cwd := containerConfig.WorkingDir
|
||||||
if cwd == "" {
|
if cwd == "" {
|
||||||
cwd = "/"
|
cwd = "/"
|
||||||
}
|
}
|
||||||
|
@ -135,8 +136,8 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
envs := containerConfig.GetEnvs()
|
envs := containerConfig.GetEnvs()
|
||||||
if envs != nil {
|
if envs != nil {
|
||||||
for _, item := range envs {
|
for _, item := range envs {
|
||||||
key := item.GetKey()
|
key := item.Key
|
||||||
value := item.GetValue()
|
value := item.Value
|
||||||
if key == "" {
|
if key == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -146,22 +147,22 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
|
|
||||||
mounts := containerConfig.GetMounts()
|
mounts := containerConfig.GetMounts()
|
||||||
for _, mount := range mounts {
|
for _, mount := range mounts {
|
||||||
dest := mount.GetContainerPath()
|
dest := mount.ContainerPath
|
||||||
if dest == "" {
|
if dest == "" {
|
||||||
return nil, fmt.Errorf("Mount.ContainerPath is empty")
|
return nil, fmt.Errorf("Mount.ContainerPath is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
src := mount.GetHostPath()
|
src := mount.HostPath
|
||||||
if src == "" {
|
if src == "" {
|
||||||
return nil, fmt.Errorf("Mount.HostPath is empty")
|
return nil, fmt.Errorf("Mount.HostPath is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
options := []string{"rw"}
|
options := []string{"rw"}
|
||||||
if mount.GetReadonly() {
|
if mount.Readonly {
|
||||||
options = []string{"ro"}
|
options = []string{"ro"}
|
||||||
}
|
}
|
||||||
|
|
||||||
if mount.GetSelinuxRelabel() {
|
if mount.SelinuxRelabel {
|
||||||
// Need a way in kubernetes to determine if the volume is shared or private
|
// Need a way in kubernetes to determine if the volume is shared or private
|
||||||
if err := label.Relabel(src, sb.mountLabel, true); err != nil && err != syscall.ENOTSUP {
|
if err := label.Relabel(src, sb.mountLabel, true); err != nil && err != syscall.ENOTSUP {
|
||||||
return nil, fmt.Errorf("relabel failed %s: %v", src, err)
|
return nil, fmt.Errorf("relabel failed %s: %v", src, err)
|
||||||
|
@ -184,7 +185,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
|
|
||||||
// set this container's apparmor profile if it is set by sandbox
|
// set this container's apparmor profile if it is set by sandbox
|
||||||
if s.appArmorEnabled {
|
if s.appArmorEnabled {
|
||||||
appArmorProfileName := s.getAppArmorProfileName(sb.annotations, metadata.GetName())
|
appArmorProfileName := s.getAppArmorProfileName(sb.annotations, metadata.Name)
|
||||||
if appArmorProfileName != "" {
|
if appArmorProfileName != "" {
|
||||||
// reload default apparmor profile if it is unloaded.
|
// reload default apparmor profile if it is unloaded.
|
||||||
if s.appArmorProfile == apparmor.DefaultApparmorProfile {
|
if s.appArmorProfile == apparmor.DefaultApparmorProfile {
|
||||||
|
@ -196,46 +197,44 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
specgen.SetProcessApparmorProfile(appArmorProfileName)
|
specgen.SetProcessApparmorProfile(appArmorProfileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if containerConfig.GetLinux().GetSecurityContext() != nil {
|
||||||
|
if containerConfig.GetLinux().GetSecurityContext().Privileged {
|
||||||
|
specgen.SetupPrivileged(true)
|
||||||
|
}
|
||||||
|
|
||||||
if containerConfig.GetLinux().GetSecurityContext().GetPrivileged() {
|
if containerConfig.GetLinux().GetSecurityContext().ReadonlyRootfs {
|
||||||
specgen.SetupPrivileged(true)
|
specgen.SetRootReadonly(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if containerConfig.GetLinux().GetSecurityContext().GetReadonlyRootfs() {
|
logPath := containerConfig.LogPath
|
||||||
specgen.SetRootReadonly(true)
|
specgen.SetProcessTerminal(containerConfig.Tty)
|
||||||
}
|
|
||||||
|
|
||||||
logPath := containerConfig.GetLogPath()
|
|
||||||
|
|
||||||
if containerConfig.GetTty() {
|
|
||||||
specgen.SetProcessTerminal(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
linux := containerConfig.GetLinux()
|
linux := containerConfig.GetLinux()
|
||||||
if linux != nil {
|
if linux != nil {
|
||||||
resources := linux.GetResources()
|
resources := linux.GetResources()
|
||||||
if resources != nil {
|
if resources != nil {
|
||||||
cpuPeriod := resources.GetCpuPeriod()
|
cpuPeriod := resources.CpuPeriod
|
||||||
if cpuPeriod != 0 {
|
if cpuPeriod != 0 {
|
||||||
specgen.SetLinuxResourcesCPUPeriod(uint64(cpuPeriod))
|
specgen.SetLinuxResourcesCPUPeriod(uint64(cpuPeriod))
|
||||||
}
|
}
|
||||||
|
|
||||||
cpuQuota := resources.GetCpuQuota()
|
cpuQuota := resources.CpuQuota
|
||||||
if cpuQuota != 0 {
|
if cpuQuota != 0 {
|
||||||
specgen.SetLinuxResourcesCPUQuota(uint64(cpuQuota))
|
specgen.SetLinuxResourcesCPUQuota(uint64(cpuQuota))
|
||||||
}
|
}
|
||||||
|
|
||||||
cpuShares := resources.GetCpuShares()
|
cpuShares := resources.CpuShares
|
||||||
if cpuShares != 0 {
|
if cpuShares != 0 {
|
||||||
specgen.SetLinuxResourcesCPUShares(uint64(cpuShares))
|
specgen.SetLinuxResourcesCPUShares(uint64(cpuShares))
|
||||||
}
|
}
|
||||||
|
|
||||||
memoryLimit := resources.GetMemoryLimitInBytes()
|
memoryLimit := resources.MemoryLimitInBytes
|
||||||
if memoryLimit != 0 {
|
if memoryLimit != 0 {
|
||||||
specgen.SetLinuxResourcesMemoryLimit(uint64(memoryLimit))
|
specgen.SetLinuxResourcesMemoryLimit(uint64(memoryLimit))
|
||||||
}
|
}
|
||||||
|
|
||||||
oomScoreAdj := resources.GetOomScoreAdj()
|
oomScoreAdj := resources.OomScoreAdj
|
||||||
specgen.SetLinuxResourcesOOMScoreAdj(int(oomScoreAdj))
|
specgen.SetLinuxResourcesOOMScoreAdj(int(oomScoreAdj))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +249,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
|
|
||||||
capabilities := linux.GetSecurityContext().GetCapabilities()
|
capabilities := linux.GetSecurityContext().GetCapabilities()
|
||||||
if capabilities != nil {
|
if capabilities != nil {
|
||||||
addCaps := capabilities.GetAddCapabilities()
|
addCaps := capabilities.AddCapabilities
|
||||||
if addCaps != nil {
|
if addCaps != nil {
|
||||||
for _, cap := range addCaps {
|
for _, cap := range addCaps {
|
||||||
if err := specgen.AddProcessCapability(cap); err != nil {
|
if err := specgen.AddProcessCapability(cap); err != nil {
|
||||||
|
@ -259,7 +258,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dropCaps := capabilities.GetDropCapabilities()
|
dropCaps := capabilities.DropCapabilities
|
||||||
if dropCaps != nil {
|
if dropCaps != nil {
|
||||||
for _, cap := range dropCaps {
|
for _, cap := range dropCaps {
|
||||||
if err := specgen.DropProcessCapability(cap); err != nil {
|
if err := specgen.DropProcessCapability(cap); err != nil {
|
||||||
|
@ -272,14 +271,14 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
specgen.SetProcessSelinuxLabel(sb.processLabel)
|
specgen.SetProcessSelinuxLabel(sb.processLabel)
|
||||||
specgen.SetLinuxMountLabel(sb.mountLabel)
|
specgen.SetLinuxMountLabel(sb.mountLabel)
|
||||||
|
|
||||||
user := linux.GetSecurityContext().GetRunAsUser()
|
if linux.GetSecurityContext() != nil {
|
||||||
specgen.SetProcessUID(uint32(user))
|
user := linux.GetSecurityContext().GetRunAsUser()
|
||||||
|
specgen.SetProcessUID(uint32(user.Value))
|
||||||
specgen.SetProcessGID(uint32(user))
|
specgen.SetProcessGID(uint32(user.Value))
|
||||||
|
groups := linux.GetSecurityContext().SupplementalGroups
|
||||||
groups := linux.GetSecurityContext().GetSupplementalGroups()
|
for _, group := range groups {
|
||||||
for _, group := range groups {
|
specgen.AddProcessAdditionalGid(uint32(group))
|
||||||
specgen.AddProcessAdditionalGid(uint32(group))
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Join the namespace paths for the pod sandbox container.
|
// Join the namespace paths for the pod sandbox container.
|
||||||
|
@ -308,7 +307,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
return nil, fmt.Errorf("CreateContainerRequest.ContainerConfig.Image is nil")
|
return nil, fmt.Errorf("CreateContainerRequest.ContainerConfig.Image is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
image := imageSpec.GetImage()
|
image := imageSpec.Image
|
||||||
if image == "" {
|
if image == "" {
|
||||||
return nil, fmt.Errorf("CreateContainerRequest.ContainerConfig.Image.Image is empty")
|
return nil, fmt.Errorf("CreateContainerRequest.ContainerConfig.Image.Image is empty")
|
||||||
}
|
}
|
||||||
|
@ -321,7 +320,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
specgen.AddAnnotation("ocid/sandbox_name", sb.infraContainer.Name())
|
specgen.AddAnnotation("ocid/sandbox_name", sb.infraContainer.Name())
|
||||||
specgen.AddAnnotation("ocid/container_type", containerTypeContainer)
|
specgen.AddAnnotation("ocid/container_type", containerTypeContainer)
|
||||||
specgen.AddAnnotation("ocid/log_path", logPath)
|
specgen.AddAnnotation("ocid/log_path", logPath)
|
||||||
specgen.AddAnnotation("ocid/tty", fmt.Sprintf("%v", containerConfig.GetTty()))
|
specgen.AddAnnotation("ocid/tty", fmt.Sprintf("%v", containerConfig.Tty))
|
||||||
specgen.AddAnnotation("ocid/image", image)
|
specgen.AddAnnotation("ocid/image", image)
|
||||||
|
|
||||||
metadataJSON, err := json.Marshal(metadata)
|
metadataJSON, err := json.Marshal(metadata)
|
||||||
|
@ -346,8 +345,8 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
metaname := metadata.GetName()
|
metaname := metadata.Name
|
||||||
attempt := metadata.GetAttempt()
|
attempt := metadata.Attempt
|
||||||
containerInfo, err := s.storage.CreateContainer(s.imageContext,
|
containerInfo, err := s.storage.CreateContainer(s.imageContext,
|
||||||
sb.name, sb.id,
|
sb.name, sb.id,
|
||||||
image, image,
|
image, image,
|
||||||
|
@ -385,7 +384,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := oci.NewContainer(containerID, containerName, containerInfo.RunDir, logPath, sb.netNs(), labels, annotations, imageSpec, metadata, sb.id, containerConfig.GetTty())
|
container, err := oci.NewContainer(containerID, containerName, containerInfo.RunDir, logPath, sb.netNs(), labels, annotations, imageSpec, metadata, sb.id, containerConfig.Tty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
// ExecSync runs a command in a container synchronously.
|
// ExecSync runs a command in a container synchronously.
|
||||||
func (s *Server) ExecSync(ctx context.Context, req *pb.ExecSyncRequest) (*pb.ExecSyncResponse, error) {
|
func (s *Server) ExecSync(ctx context.Context, req *pb.ExecSyncRequest) (*pb.ExecSyncResponse, error) {
|
||||||
logrus.Debugf("ExecSyncRequest %+v", req)
|
logrus.Debugf("ExecSyncRequest %+v", req)
|
||||||
c, err := s.getContainerFromRequest(req)
|
c, err := s.getContainerFromRequest(req.ContainerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -26,19 +26,19 @@ func (s *Server) ExecSync(ctx context.Context, req *pb.ExecSyncRequest) (*pb.Exe
|
||||||
return nil, fmt.Errorf("container is not created or running")
|
return nil, fmt.Errorf("container is not created or running")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := req.GetCmd()
|
cmd := req.Cmd
|
||||||
if cmd == nil {
|
if cmd == nil {
|
||||||
return nil, fmt.Errorf("exec command cannot be empty")
|
return nil, fmt.Errorf("exec command cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
execResp, err := s.runtime.ExecSync(c, cmd, req.GetTimeout())
|
execResp, err := s.runtime.ExecSync(c, cmd, req.Timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp := &pb.ExecSyncResponse{
|
resp := &pb.ExecSyncResponse{
|
||||||
Stdout: execResp.Stdout,
|
Stdout: execResp.Stdout,
|
||||||
Stderr: execResp.Stderr,
|
Stderr: execResp.Stderr,
|
||||||
ExitCode: &execResp.ExitCode,
|
ExitCode: execResp.ExitCode,
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf("ExecSyncResponse: %+v", resp)
|
logrus.Debugf("ExecSyncResponse: %+v", resp)
|
||||||
|
|
|
@ -4,15 +4,15 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/kubernetes-incubator/cri-o/oci"
|
"github.com/kubernetes-incubator/cri-o/oci"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/fields"
|
|
||||||
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
||||||
|
"k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/fields"
|
||||||
)
|
)
|
||||||
|
|
||||||
// filterContainer returns whether passed container matches filtering criteria
|
// filterContainer returns whether passed container matches filtering criteria
|
||||||
func filterContainer(c *pb.Container, filter *pb.ContainerFilter) bool {
|
func filterContainer(c *pb.Container, filter *pb.ContainerFilter) bool {
|
||||||
if filter != nil {
|
if filter != nil {
|
||||||
if filter.State != nil {
|
if filter.State != nil {
|
||||||
if *c.State != *filter.State {
|
if c.State != filter.State.State {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,15 +36,15 @@ func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersReque
|
||||||
|
|
||||||
// Filter using container id and pod id first.
|
// Filter using container id and pod id first.
|
||||||
if filter != nil {
|
if filter != nil {
|
||||||
if filter.Id != nil {
|
if filter.Id != "" {
|
||||||
id, err := s.ctrIDIndex.Get(*filter.Id)
|
id, err := s.ctrIDIndex.Get(filter.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c := s.state.containers.Get(id)
|
c := s.state.containers.Get(id)
|
||||||
if c != nil {
|
if c != nil {
|
||||||
if filter.PodSandboxId != nil {
|
if filter.PodSandboxId != "" {
|
||||||
if c.Sandbox() == *filter.PodSandboxId {
|
if c.Sandbox() == filter.PodSandboxId {
|
||||||
ctrList = []*oci.Container{c}
|
ctrList = []*oci.Container{c}
|
||||||
} else {
|
} else {
|
||||||
ctrList = []*oci.Container{}
|
ctrList = []*oci.Container{}
|
||||||
|
@ -55,8 +55,8 @@ func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersReque
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if filter.PodSandboxId != nil {
|
if filter.PodSandboxId != "" {
|
||||||
pod := s.state.sandboxes[*filter.PodSandboxId]
|
pod := s.state.sandboxes[filter.PodSandboxId]
|
||||||
if pod == nil {
|
if pod == nil {
|
||||||
ctrList = []*oci.Container{}
|
ctrList = []*oci.Container{}
|
||||||
} else {
|
} else {
|
||||||
|
@ -78,9 +78,9 @@ func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersReque
|
||||||
cID := ctr.ID()
|
cID := ctr.ID()
|
||||||
|
|
||||||
c := &pb.Container{
|
c := &pb.Container{
|
||||||
Id: &cID,
|
Id: cID,
|
||||||
PodSandboxId: &podSandboxID,
|
PodSandboxId: podSandboxID,
|
||||||
CreatedAt: int64Ptr(created),
|
CreatedAt: int64(created),
|
||||||
Labels: ctr.Labels(),
|
Labels: ctr.Labels(),
|
||||||
Metadata: ctr.Metadata(),
|
Metadata: ctr.Metadata(),
|
||||||
Annotations: ctr.Annotations(),
|
Annotations: ctr.Annotations(),
|
||||||
|
@ -95,7 +95,7 @@ func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersReque
|
||||||
case oci.ContainerStateStopped:
|
case oci.ContainerStateStopped:
|
||||||
rState = pb.ContainerState_CONTAINER_EXITED
|
rState = pb.ContainerState_CONTAINER_EXITED
|
||||||
}
|
}
|
||||||
c.State = &rState
|
c.State = rState
|
||||||
|
|
||||||
// Filter by other criteria such as state and labels.
|
// Filter by other criteria such as state and labels.
|
||||||
if filterContainer(c, req.Filter) {
|
if filterContainer(c, req.Filter) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerRequest) (*pb.RemoveContainerResponse, error) {
|
func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerRequest) (*pb.RemoveContainerResponse, error) {
|
||||||
logrus.Debugf("RemoveContainerRequest %+v", req)
|
logrus.Debugf("RemoveContainerRequest %+v", req)
|
||||||
s.Update()
|
s.Update()
|
||||||
c, err := s.getContainerFromRequest(req)
|
c, err := s.getContainerFromRequest(req.ContainerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerRequest) (*pb.StartContainerResponse, error) {
|
func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerRequest) (*pb.StartContainerResponse, error) {
|
||||||
logrus.Debugf("StartContainerRequest %+v", req)
|
logrus.Debugf("StartContainerRequest %+v", req)
|
||||||
s.Update()
|
s.Update()
|
||||||
c, err := s.getContainerFromRequest(req)
|
c, err := s.getContainerFromRequest(req.ContainerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusRequest) (*pb.ContainerStatusResponse, error) {
|
func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusRequest) (*pb.ContainerStatusResponse, error) {
|
||||||
logrus.Debugf("ContainerStatusRequest %+v", req)
|
logrus.Debugf("ContainerStatusRequest %+v", req)
|
||||||
s.Update()
|
s.Update()
|
||||||
c, err := s.getContainerFromRequest(req)
|
c, err := s.getContainerFromRequest(req.ContainerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
|
||||||
containerID := c.ID()
|
containerID := c.ID()
|
||||||
resp := &pb.ContainerStatusResponse{
|
resp := &pb.ContainerStatusResponse{
|
||||||
Status: &pb.ContainerStatus{
|
Status: &pb.ContainerStatus{
|
||||||
Id: &containerID,
|
Id: containerID,
|
||||||
Metadata: c.Metadata(),
|
Metadata: c.Metadata(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -35,25 +35,25 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
|
||||||
case oci.ContainerStateCreated:
|
case oci.ContainerStateCreated:
|
||||||
rStatus = pb.ContainerState_CONTAINER_CREATED
|
rStatus = pb.ContainerState_CONTAINER_CREATED
|
||||||
created := cState.Created.UnixNano()
|
created := cState.Created.UnixNano()
|
||||||
resp.Status.CreatedAt = int64Ptr(created)
|
resp.Status.CreatedAt = int64(created)
|
||||||
case oci.ContainerStateRunning:
|
case oci.ContainerStateRunning:
|
||||||
rStatus = pb.ContainerState_CONTAINER_RUNNING
|
rStatus = pb.ContainerState_CONTAINER_RUNNING
|
||||||
created := cState.Created.UnixNano()
|
created := cState.Created.UnixNano()
|
||||||
resp.Status.CreatedAt = int64Ptr(created)
|
resp.Status.CreatedAt = int64(created)
|
||||||
started := cState.Started.UnixNano()
|
started := cState.Started.UnixNano()
|
||||||
resp.Status.StartedAt = int64Ptr(started)
|
resp.Status.StartedAt = int64(started)
|
||||||
case oci.ContainerStateStopped:
|
case oci.ContainerStateStopped:
|
||||||
rStatus = pb.ContainerState_CONTAINER_EXITED
|
rStatus = pb.ContainerState_CONTAINER_EXITED
|
||||||
created := cState.Created.UnixNano()
|
created := cState.Created.UnixNano()
|
||||||
resp.Status.CreatedAt = int64Ptr(created)
|
resp.Status.CreatedAt = int64(created)
|
||||||
started := cState.Started.UnixNano()
|
started := cState.Started.UnixNano()
|
||||||
resp.Status.StartedAt = int64Ptr(started)
|
resp.Status.StartedAt = int64(started)
|
||||||
finished := cState.Finished.UnixNano()
|
finished := cState.Finished.UnixNano()
|
||||||
resp.Status.FinishedAt = int64Ptr(finished)
|
resp.Status.FinishedAt = int64(finished)
|
||||||
resp.Status.ExitCode = int32Ptr(cState.ExitCode)
|
resp.Status.ExitCode = int32(cState.ExitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Status.State = &rStatus
|
resp.Status.State = rStatus
|
||||||
|
|
||||||
logrus.Debugf("ContainerStatusResponse: %+v", resp)
|
logrus.Debugf("ContainerStatusResponse: %+v", resp)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest) (*pb.StopContainerResponse, error) {
|
func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest) (*pb.StopContainerResponse, error) {
|
||||||
logrus.Debugf("StopContainerRequest %+v", req)
|
logrus.Debugf("StopContainerRequest %+v", req)
|
||||||
s.Update()
|
s.Update()
|
||||||
c, err := s.getContainerFromRequest(req)
|
c, err := s.getContainerFromRequest(req.ContainerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ func (s *Server) ListImages(ctx context.Context, req *pb.ListImagesRequest) (*pb
|
||||||
if reqFilter != nil {
|
if reqFilter != nil {
|
||||||
filterImage := reqFilter.GetImage()
|
filterImage := reqFilter.GetImage()
|
||||||
if filterImage != nil {
|
if filterImage != nil {
|
||||||
filter = filterImage.GetImage()
|
filter = filterImage.Image
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
results, err := s.images.ListImages(filter)
|
results, err := s.images.ListImages(filter)
|
||||||
|
@ -23,11 +23,18 @@ func (s *Server) ListImages(ctx context.Context, req *pb.ListImagesRequest) (*pb
|
||||||
}
|
}
|
||||||
response := pb.ListImagesResponse{}
|
response := pb.ListImagesResponse{}
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
response.Images = append(response.Images, &pb.Image{
|
if result.Size != nil {
|
||||||
Id: sPtr(result.ID),
|
response.Images = append(response.Images, &pb.Image{
|
||||||
RepoTags: result.Names,
|
Id: result.ID,
|
||||||
Size_: result.Size,
|
RepoTags: result.Names,
|
||||||
})
|
Size_: *result.Size,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
response.Images = append(response.Images, &pb.Image{
|
||||||
|
Id: result.ID,
|
||||||
|
RepoTags: result.Names,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logrus.Debugf("ListImagesResponse: %+v", response)
|
logrus.Debugf("ListImagesResponse: %+v", response)
|
||||||
return &response, nil
|
return &response, nil
|
||||||
|
|
|
@ -15,7 +15,7 @@ func (s *Server) PullImage(ctx context.Context, req *pb.PullImageRequest) (*pb.P
|
||||||
image := ""
|
image := ""
|
||||||
img := req.GetImage()
|
img := req.GetImage()
|
||||||
if img != nil {
|
if img != nil {
|
||||||
image = img.GetImage()
|
image = img.Image
|
||||||
}
|
}
|
||||||
options := ©.Options{}
|
options := ©.Options{}
|
||||||
_, err := s.images.PullImage(s.imageContext, image, options)
|
_, err := s.images.PullImage(s.imageContext, image, options)
|
||||||
|
@ -23,7 +23,7 @@ func (s *Server) PullImage(ctx context.Context, req *pb.PullImageRequest) (*pb.P
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp := &pb.PullImageResponse{
|
resp := &pb.PullImageResponse{
|
||||||
ImageRef: &image,
|
ImageRef: image,
|
||||||
}
|
}
|
||||||
logrus.Debugf("PullImageResponse: %+v", resp)
|
logrus.Debugf("PullImageResponse: %+v", resp)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
|
|
@ -14,7 +14,7 @@ func (s *Server) RemoveImage(ctx context.Context, req *pb.RemoveImageRequest) (*
|
||||||
image := ""
|
image := ""
|
||||||
img := req.GetImage()
|
img := req.GetImage()
|
||||||
if img != nil {
|
if img != nil {
|
||||||
image = img.GetImage()
|
image = img.Image
|
||||||
}
|
}
|
||||||
if image == "" {
|
if image == "" {
|
||||||
return nil, fmt.Errorf("no image specified")
|
return nil, fmt.Errorf("no image specified")
|
||||||
|
|
|
@ -15,7 +15,7 @@ func (s *Server) ImageStatus(ctx context.Context, req *pb.ImageStatusRequest) (*
|
||||||
image := ""
|
image := ""
|
||||||
img := req.GetImage()
|
img := req.GetImage()
|
||||||
if img != nil {
|
if img != nil {
|
||||||
image = img.GetImage()
|
image = img.Image
|
||||||
}
|
}
|
||||||
if image == "" {
|
if image == "" {
|
||||||
return nil, fmt.Errorf("no image specified")
|
return nil, fmt.Errorf("no image specified")
|
||||||
|
@ -29,9 +29,9 @@ func (s *Server) ImageStatus(ctx context.Context, req *pb.ImageStatusRequest) (*
|
||||||
}
|
}
|
||||||
resp := &pb.ImageStatusResponse{
|
resp := &pb.ImageStatusResponse{
|
||||||
Image: &pb.Image{
|
Image: &pb.Image{
|
||||||
Id: &status.ID,
|
Id: status.ID,
|
||||||
RepoTags: status.Names,
|
RepoTags: status.Names,
|
||||||
Size_: status.Size,
|
Size_: *status.Size,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
logrus.Debugf("ImageStatusResponse: %+v", resp)
|
logrus.Debugf("ImageStatusResponse: %+v", resp)
|
||||||
|
|
|
@ -26,12 +26,12 @@ func (s *Server) Status(ctx context.Context, req *pb.StatusRequest) (*pb.StatusR
|
||||||
Status: &pb.RuntimeStatus{
|
Status: &pb.RuntimeStatus{
|
||||||
Conditions: []*pb.RuntimeCondition{
|
Conditions: []*pb.RuntimeCondition{
|
||||||
{
|
{
|
||||||
Type: &runtimeReadyConditionString,
|
Type: runtimeReadyConditionString,
|
||||||
Status: &runtimeReady,
|
Status: runtimeReady,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: &networkReadyConditionString,
|
Type: networkReadyConditionString,
|
||||||
Status: &networkReady,
|
Status: networkReady,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -261,19 +261,14 @@ func (s *Server) generatePodIDandName(name string, namespace string, attempt uin
|
||||||
return id, name, err
|
return id, name, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type podSandboxRequest interface {
|
func (s *Server) getPodSandboxFromRequest(podSandboxID string) (*sandbox, error) {
|
||||||
GetPodSandboxId() string
|
if podSandboxID == "" {
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) getPodSandboxFromRequest(req podSandboxRequest) (*sandbox, error) {
|
|
||||||
sbID := req.GetPodSandboxId()
|
|
||||||
if sbID == "" {
|
|
||||||
return nil, errSandboxIDEmpty
|
return nil, errSandboxIDEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
sandboxID, err := s.podIDIndex.Get(sbID)
|
sandboxID, err := s.podIDIndex.Get(podSandboxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("PodSandbox with ID starting with %s not found: %v", sbID, err)
|
return nil, fmt.Errorf("PodSandbox with ID starting with %s not found: %v", podSandboxID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sb := s.getSandbox(sandboxID)
|
sb := s.getSandbox(sandboxID)
|
||||||
|
|
|
@ -4,15 +4,15 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/kubernetes-incubator/cri-o/oci"
|
"github.com/kubernetes-incubator/cri-o/oci"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/fields"
|
|
||||||
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
||||||
|
"k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/fields"
|
||||||
)
|
)
|
||||||
|
|
||||||
// filterSandbox returns whether passed container matches filtering criteria
|
// filterSandbox returns whether passed container matches filtering criteria
|
||||||
func filterSandbox(p *pb.PodSandbox, filter *pb.PodSandboxFilter) bool {
|
func filterSandbox(p *pb.PodSandbox, filter *pb.PodSandboxFilter) bool {
|
||||||
if filter != nil {
|
if filter != nil {
|
||||||
if filter.State != nil {
|
if filter.State != nil {
|
||||||
if *p.State != *filter.State {
|
if p.State != filter.State.State {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ func (s *Server) ListPodSandbox(ctx context.Context, req *pb.ListPodSandboxReque
|
||||||
filter := req.Filter
|
filter := req.Filter
|
||||||
// Filter by pod id first.
|
// Filter by pod id first.
|
||||||
if filter != nil {
|
if filter != nil {
|
||||||
if filter.Id != nil {
|
if filter.Id != "" {
|
||||||
id, err := s.podIDIndex.Get(*filter.Id)
|
id, err := s.podIDIndex.Get(filter.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -71,9 +71,9 @@ func (s *Server) ListPodSandbox(ctx context.Context, req *pb.ListPodSandboxReque
|
||||||
}
|
}
|
||||||
|
|
||||||
pod := &pb.PodSandbox{
|
pod := &pb.PodSandbox{
|
||||||
Id: &sb.id,
|
Id: sb.id,
|
||||||
CreatedAt: int64Ptr(created),
|
CreatedAt: int64(created),
|
||||||
State: &rStatus,
|
State: rStatus,
|
||||||
Labels: sb.labels,
|
Labels: sb.labels,
|
||||||
Annotations: sb.annotations,
|
Annotations: sb.annotations,
|
||||||
Metadata: sb.metadata,
|
Metadata: sb.metadata,
|
||||||
|
|
|
@ -16,14 +16,14 @@ import (
|
||||||
func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxRequest) (*pb.RemovePodSandboxResponse, error) {
|
func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxRequest) (*pb.RemovePodSandboxResponse, error) {
|
||||||
logrus.Debugf("RemovePodSandboxRequest %+v", req)
|
logrus.Debugf("RemovePodSandboxRequest %+v", req)
|
||||||
s.Update()
|
s.Update()
|
||||||
sb, err := s.getPodSandboxFromRequest(req)
|
sb, err := s.getPodSandboxFromRequest(req.PodSandboxId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == errSandboxIDEmpty {
|
if err == errSandboxIDEmpty {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := &pb.RemovePodSandboxResponse{}
|
resp := &pb.RemovePodSandboxResponse{}
|
||||||
logrus.Warnf("could not get sandbox %s, it's probably been removed already: %v", req.GetPodSandboxId(), err)
|
logrus.Warnf("could not get sandbox %s, it's probably been removed already: %v", req.PodSandboxId, err)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,13 +42,13 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
logrus.Debugf("RunPodSandboxRequest %+v", req)
|
logrus.Debugf("RunPodSandboxRequest %+v", req)
|
||||||
var processLabel, mountLabel, netNsPath string
|
var processLabel, mountLabel, netNsPath string
|
||||||
// process req.Name
|
// process req.Name
|
||||||
name := req.GetConfig().GetMetadata().GetName()
|
name := req.GetConfig().GetMetadata().Name
|
||||||
if name == "" {
|
if name == "" {
|
||||||
return nil, fmt.Errorf("PodSandboxConfig.Name should not be empty")
|
return nil, fmt.Errorf("PodSandboxConfig.Name should not be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace := req.GetConfig().GetMetadata().GetNamespace()
|
namespace := req.GetConfig().GetMetadata().Namespace
|
||||||
attempt := req.GetConfig().GetMetadata().GetAttempt()
|
attempt := req.GetConfig().GetMetadata().Attempt
|
||||||
|
|
||||||
id, name, err := s.generatePodIDandName(name, namespace, attempt)
|
id, name, err := s.generatePodIDandName(name, namespace, attempt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -81,8 +81,8 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
name, id,
|
name, id,
|
||||||
s.config.PauseImage, "",
|
s.config.PauseImage, "",
|
||||||
containerName,
|
containerName,
|
||||||
req.GetConfig().GetMetadata().GetName(),
|
req.GetConfig().GetMetadata().Name,
|
||||||
req.GetConfig().GetMetadata().GetUid(),
|
req.GetConfig().GetMetadata().Uid,
|
||||||
namespace,
|
namespace,
|
||||||
attempt,
|
attempt,
|
||||||
nil)
|
nil)
|
||||||
|
@ -118,34 +118,35 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
// set hostname
|
// set hostname
|
||||||
hostname := req.GetConfig().GetHostname()
|
hostname := req.GetConfig().Hostname
|
||||||
if hostname != "" {
|
if hostname != "" {
|
||||||
g.SetHostname(hostname)
|
g.SetHostname(hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set log directory
|
// set log directory
|
||||||
logDir := req.GetConfig().GetLogDirectory()
|
logDir := req.GetConfig().LogDirectory
|
||||||
if logDir == "" {
|
if logDir == "" {
|
||||||
logDir = filepath.Join(s.config.LogDir, id)
|
logDir = filepath.Join(s.config.LogDir, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set DNS options
|
// set DNS options
|
||||||
dnsServers := req.GetConfig().GetDnsConfig().GetServers()
|
if req.GetConfig().GetDnsConfig() != nil {
|
||||||
dnsSearches := req.GetConfig().GetDnsConfig().GetSearches()
|
dnsServers := req.GetConfig().GetDnsConfig().Servers
|
||||||
dnsOptions := req.GetConfig().GetDnsConfig().GetOptions()
|
dnsSearches := req.GetConfig().GetDnsConfig().Searches
|
||||||
resolvPath := fmt.Sprintf("%s/resolv.conf", podContainer.RunDir)
|
dnsOptions := req.GetConfig().GetDnsConfig().Options
|
||||||
err = parseDNSOptions(dnsServers, dnsSearches, dnsOptions, resolvPath)
|
resolvPath := fmt.Sprintf("%s/resolv.conf", podContainer.RunDir)
|
||||||
if err != nil {
|
err = parseDNSOptions(dnsServers, dnsSearches, dnsOptions, resolvPath)
|
||||||
err1 := removeFile(resolvPath)
|
if err != nil {
|
||||||
if err1 != nil {
|
err1 := removeFile(resolvPath)
|
||||||
err = err1
|
if err1 != nil {
|
||||||
return nil, fmt.Errorf("%v; failed to remove %s: %v", err, resolvPath, err1)
|
err = err1
|
||||||
|
return nil, fmt.Errorf("%v; failed to remove %s: %v", err, resolvPath, err1)
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil, err
|
g.AddBindMount(resolvPath, "/etc/resolv.conf", []string{"ro"})
|
||||||
}
|
}
|
||||||
|
|
||||||
g.AddBindMount(resolvPath, "/etc/resolv.conf", []string{"ro"})
|
|
||||||
|
|
||||||
// add metadata
|
// add metadata
|
||||||
metadata := req.GetConfig().GetMetadata()
|
metadata := req.GetConfig().GetMetadata()
|
||||||
metadataJSON, err := json.Marshal(metadata)
|
metadataJSON, err := json.Marshal(metadata)
|
||||||
|
@ -168,7 +169,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't use SELinux separation with Host Pid or IPC Namespace,
|
// Don't use SELinux separation with Host Pid or IPC Namespace,
|
||||||
if !req.GetConfig().GetLinux().GetSecurityContext().GetNamespaceOptions().GetHostPid() && !req.GetConfig().GetLinux().GetSecurityContext().GetNamespaceOptions().GetHostIpc() {
|
if !req.GetConfig().GetLinux().GetSecurityContext().GetNamespaceOptions().HostPid && !req.GetConfig().GetLinux().GetSecurityContext().GetNamespaceOptions().HostIpc {
|
||||||
processLabel, mountLabel, err = getSELinuxLabels(nil)
|
processLabel, mountLabel, err = getSELinuxLabels(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -178,7 +179,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
|
|
||||||
// create shm mount for the pod containers.
|
// create shm mount for the pod containers.
|
||||||
var shmPath string
|
var shmPath string
|
||||||
if req.GetConfig().GetLinux().GetSecurityContext().GetNamespaceOptions().GetHostIpc() {
|
if req.GetConfig().GetLinux().GetSecurityContext().GetNamespaceOptions().HostIpc {
|
||||||
shmPath = "/dev/shm"
|
shmPath = "/dev/shm"
|
||||||
} else {
|
} else {
|
||||||
shmPath, err = setupShm(podContainer.RunDir, mountLabel)
|
shmPath, err = setupShm(podContainer.RunDir, mountLabel)
|
||||||
|
@ -260,7 +261,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup cgroup settings
|
// setup cgroup settings
|
||||||
cgroupParent := req.GetConfig().GetLinux().GetCgroupParent()
|
cgroupParent := req.GetConfig().GetLinux().CgroupParent
|
||||||
if cgroupParent != "" {
|
if cgroupParent != "" {
|
||||||
if s.config.CgroupManager == "systemd" {
|
if s.config.CgroupManager == "systemd" {
|
||||||
cgPath := sb.cgroupParent + ":" + "ocid" + ":" + id
|
cgPath := sb.cgroupParent + ":" + "ocid" + ":" + id
|
||||||
|
@ -273,7 +274,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
sb.cgroupParent = cgroupParent
|
sb.cgroupParent = cgroupParent
|
||||||
}
|
}
|
||||||
|
|
||||||
hostNetwork := req.GetConfig().GetLinux().GetSecurityContext().GetNamespaceOptions().GetHostNetwork()
|
hostNetwork := req.GetConfig().GetLinux().GetSecurityContext().GetNamespaceOptions().HostNetwork
|
||||||
|
|
||||||
// set up namespaces
|
// set up namespaces
|
||||||
if hostNetwork {
|
if hostNetwork {
|
||||||
|
@ -311,14 +312,14 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
netNsPath = sb.netNsPath()
|
netNsPath = sb.netNsPath()
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.GetConfig().GetLinux().GetSecurityContext().GetNamespaceOptions().GetHostPid() {
|
if req.GetConfig().GetLinux().GetSecurityContext().GetNamespaceOptions().HostPid {
|
||||||
err = g.RemoveLinuxNamespace("pid")
|
err = g.RemoveLinuxNamespace("pid")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.GetConfig().GetLinux().GetSecurityContext().GetNamespaceOptions().GetHostIpc() {
|
if req.GetConfig().GetLinux().GetSecurityContext().GetNamespaceOptions().HostIpc {
|
||||||
err = g.RemoveLinuxNamespace("ipc")
|
err = g.RemoveLinuxNamespace("ipc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -358,7 +359,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = &pb.RunPodSandboxResponse{PodSandboxId: &id}
|
resp = &pb.RunPodSandboxResponse{PodSandboxId: id}
|
||||||
logrus.Debugf("RunPodSandboxResponse: %+v", resp)
|
logrus.Debugf("RunPodSandboxResponse: %+v", resp)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
@ -379,22 +380,22 @@ func (s *Server) setPodSandboxMountLabel(id, mountLabel string) error {
|
||||||
func getSELinuxLabels(selinuxOptions *pb.SELinuxOption) (processLabel string, mountLabel string, err error) {
|
func getSELinuxLabels(selinuxOptions *pb.SELinuxOption) (processLabel string, mountLabel string, err error) {
|
||||||
processLabel = ""
|
processLabel = ""
|
||||||
if selinuxOptions != nil {
|
if selinuxOptions != nil {
|
||||||
user := selinuxOptions.GetUser()
|
user := selinuxOptions.User
|
||||||
if user == "" {
|
if user == "" {
|
||||||
return "", "", fmt.Errorf("SELinuxOption.User is empty")
|
return "", "", fmt.Errorf("SELinuxOption.User is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
role := selinuxOptions.GetRole()
|
role := selinuxOptions.Role
|
||||||
if role == "" {
|
if role == "" {
|
||||||
return "", "", fmt.Errorf("SELinuxOption.Role is empty")
|
return "", "", fmt.Errorf("SELinuxOption.Role is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
t := selinuxOptions.GetType()
|
t := selinuxOptions.Type
|
||||||
if t == "" {
|
if t == "" {
|
||||||
return "", "", fmt.Errorf("SELinuxOption.Type is empty")
|
return "", "", fmt.Errorf("SELinuxOption.Type is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
level := selinuxOptions.GetLevel()
|
level := selinuxOptions.Level
|
||||||
if level == "" {
|
if level == "" {
|
||||||
return "", "", fmt.Errorf("SELinuxOption.Level is empty")
|
return "", "", fmt.Errorf("SELinuxOption.Level is empty")
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusRequest) (*pb.PodSandboxStatusResponse, error) {
|
func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusRequest) (*pb.PodSandboxStatusResponse, error) {
|
||||||
logrus.Debugf("PodSandboxStatusRequest %+v", req)
|
logrus.Debugf("PodSandboxStatusRequest %+v", req)
|
||||||
s.Update()
|
s.Update()
|
||||||
sb, err := s.getPodSandboxFromRequest(req)
|
sb, err := s.getPodSandboxFromRequest(req.PodSandboxId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -43,15 +43,15 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR
|
||||||
sandboxID := sb.id
|
sandboxID := sb.id
|
||||||
resp := &pb.PodSandboxStatusResponse{
|
resp := &pb.PodSandboxStatusResponse{
|
||||||
Status: &pb.PodSandboxStatus{
|
Status: &pb.PodSandboxStatus{
|
||||||
Id: &sandboxID,
|
Id: sandboxID,
|
||||||
CreatedAt: int64Ptr(created),
|
CreatedAt: int64(created),
|
||||||
Linux: &pb.LinuxPodSandboxStatus{
|
Linux: &pb.LinuxPodSandboxStatus{
|
||||||
Namespaces: &pb.Namespace{
|
Namespaces: &pb.Namespace{
|
||||||
Network: sPtr(netNsPath),
|
Network: netNsPath,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Network: &pb.PodSandboxNetworkStatus{Ip: &ip},
|
Network: &pb.PodSandboxNetworkStatus{Ip: ip},
|
||||||
State: &rStatus,
|
State: rStatus,
|
||||||
Labels: sb.labels,
|
Labels: sb.labels,
|
||||||
Annotations: sb.annotations,
|
Annotations: sb.annotations,
|
||||||
Metadata: sb.metadata,
|
Metadata: sb.metadata,
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxRequest) (*pb.StopPodSandboxResponse, error) {
|
func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxRequest) (*pb.StopPodSandboxResponse, error) {
|
||||||
logrus.Debugf("StopPodSandboxRequest %+v", req)
|
logrus.Debugf("StopPodSandboxRequest %+v", req)
|
||||||
s.Update()
|
s.Update()
|
||||||
sb, err := s.getPodSandboxFromRequest(req)
|
sb, err := s.getPodSandboxFromRequest(req.PodSandboxId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ func (s *Server) loadContainer(id string) error {
|
||||||
image, ok := m.Annotations["ocid/image"]
|
image, ok := m.Annotations["ocid/image"]
|
||||||
if ok {
|
if ok {
|
||||||
img = &pb.ImageSpec{
|
img = &pb.ImageSpec{
|
||||||
Image: &image,
|
Image: image,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,18 +13,6 @@ const (
|
||||||
maxDNSSearches = 6
|
maxDNSSearches = 6
|
||||||
)
|
)
|
||||||
|
|
||||||
func int64Ptr(i int64) *int64 {
|
|
||||||
return &i
|
|
||||||
}
|
|
||||||
|
|
||||||
func int32Ptr(i int32) *int32 {
|
|
||||||
return &i
|
|
||||||
}
|
|
||||||
|
|
||||||
func sPtr(s string) *string {
|
|
||||||
return &s
|
|
||||||
}
|
|
||||||
|
|
||||||
func copyFile(src, dest string) error {
|
func copyFile(src, dest string) error {
|
||||||
in, err := os.Open(src)
|
in, err := os.Open(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -21,9 +21,9 @@ func (s *Server) Version(ctx context.Context, req *pb.VersionRequest) (*pb.Versi
|
||||||
runtimeName := s.runtime.Name()
|
runtimeName := s.runtime.Name()
|
||||||
|
|
||||||
return &pb.VersionResponse{
|
return &pb.VersionResponse{
|
||||||
Version: &version,
|
Version: version,
|
||||||
RuntimeName: &runtimeName,
|
RuntimeName: runtimeName,
|
||||||
RuntimeVersion: &runtimeVersion,
|
RuntimeVersion: runtimeVersion,
|
||||||
RuntimeApiVersion: &rav,
|
RuntimeApiVersion: rav,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue