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
|
||||
if opts.name != "" {
|
||||
config.Metadata.Name = &opts.name
|
||||
config.Metadata.Name = opts.name
|
||||
}
|
||||
|
||||
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{
|
||||
PodSandboxId: &opts.podID,
|
||||
PodSandboxId: opts.podID,
|
||||
Config: config,
|
||||
// TODO(runcom): this is missing PodSandboxConfig!!!
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
fmt.Println(*r.ContainerId)
|
||||
fmt.Println(r.ContainerId)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -346,7 +346,7 @@ func StartContainer(client pb.RuntimeServiceClient, ID string) error {
|
|||
return fmt.Errorf("ID cannot be empty")
|
||||
}
|
||||
_, err := client.StartContainer(context.Background(), &pb.StartContainerRequest{
|
||||
ContainerId: &ID,
|
||||
ContainerId: ID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -362,7 +362,7 @@ func StopContainer(client pb.RuntimeServiceClient, ID string) error {
|
|||
return fmt.Errorf("ID cannot be empty")
|
||||
}
|
||||
_, err := client.StopContainer(context.Background(), &pb.StopContainerRequest{
|
||||
ContainerId: &ID,
|
||||
ContainerId: ID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -378,7 +378,7 @@ func RemoveContainer(client pb.RuntimeServiceClient, ID string) error {
|
|||
return fmt.Errorf("ID cannot be empty")
|
||||
}
|
||||
_, err := client.RemoveContainer(context.Background(), &pb.RemoveContainerRequest{
|
||||
ContainerId: &ID,
|
||||
ContainerId: ID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -394,37 +394,26 @@ func ContainerStatus(client pb.RuntimeServiceClient, ID string) error {
|
|||
return fmt.Errorf("ID cannot be empty")
|
||||
}
|
||||
r, err := client.ContainerStatus(context.Background(), &pb.ContainerStatusRequest{
|
||||
ContainerId: &ID})
|
||||
ContainerId: ID})
|
||||
if err != nil {
|
||||
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.Name != nil {
|
||||
fmt.Printf("Name: %s\n", *r.Status.Metadata.Name)
|
||||
}
|
||||
if r.Status.Metadata.Attempt != nil {
|
||||
fmt.Printf("Attempt: %v\n", *r.Status.Metadata.Attempt)
|
||||
if r.Status.Metadata.Name != "" {
|
||||
fmt.Printf("Name: %s\n", r.Status.Metadata.Name)
|
||||
}
|
||||
fmt.Printf("Attempt: %v\n", r.Status.Metadata.Attempt)
|
||||
}
|
||||
if r.Status.State != nil {
|
||||
fmt.Printf("Status: %s\n", r.Status.State)
|
||||
}
|
||||
if r.Status.CreatedAt != nil {
|
||||
ctm := time.Unix(0, *r.Status.CreatedAt)
|
||||
fmt.Printf("Created: %v\n", ctm)
|
||||
}
|
||||
if r.Status.StartedAt != nil {
|
||||
stm := time.Unix(0, *r.Status.StartedAt)
|
||||
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)
|
||||
}
|
||||
// TODO(mzylowski): print it prettier
|
||||
fmt.Printf("Status: %s\n", r.Status.State)
|
||||
ctm := time.Unix(0, r.Status.CreatedAt)
|
||||
fmt.Printf("Created: %v\n", ctm)
|
||||
stm := time.Unix(0, r.Status.StartedAt)
|
||||
fmt.Printf("Started: %v\n", stm)
|
||||
ftm := time.Unix(0, r.Status.FinishedAt)
|
||||
fmt.Printf("Finished: %v\n", ftm)
|
||||
fmt.Printf("Exit Code: %v\n", r.Status.ExitCode)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -436,9 +425,9 @@ func ExecSync(client pb.RuntimeServiceClient, ID string, cmd []string, timeout i
|
|||
return fmt.Errorf("ID cannot be empty")
|
||||
}
|
||||
r, err := client.ExecSync(context.Background(), &pb.ExecSyncRequest{
|
||||
ContainerId: &ID,
|
||||
ContainerId: ID,
|
||||
Cmd: cmd,
|
||||
Timeout: &timeout,
|
||||
Timeout: timeout,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -447,7 +436,7 @@ func ExecSync(client pb.RuntimeServiceClient, ID string, cmd []string, timeout i
|
|||
fmt.Println(string(r.Stdout))
|
||||
fmt.Println("Stderr:")
|
||||
fmt.Println(string(r.Stderr))
|
||||
fmt.Printf("Exit code: %v\n", *r.ExitCode)
|
||||
fmt.Printf("Exit code: %v\n", r.ExitCode)
|
||||
|
||||
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 {
|
||||
filter := &pb.ContainerFilter{}
|
||||
if opts.id != "" {
|
||||
filter.Id = &opts.id
|
||||
filter.Id = opts.id
|
||||
}
|
||||
if opts.podID != "" {
|
||||
filter.PodSandboxId = &opts.podID
|
||||
filter.PodSandboxId = opts.podID
|
||||
}
|
||||
if opts.state != "" {
|
||||
st := pb.ContainerState_CONTAINER_UNKNOWN
|
||||
st := &pb.ContainerStateValue{}
|
||||
st.State = pb.ContainerState_CONTAINER_UNKNOWN
|
||||
switch opts.state {
|
||||
case "created":
|
||||
st = pb.ContainerState_CONTAINER_CREATED
|
||||
filter.State = &st
|
||||
st.State = pb.ContainerState_CONTAINER_CREATED
|
||||
filter.State = st
|
||||
case "running":
|
||||
st = pb.ContainerState_CONTAINER_RUNNING
|
||||
filter.State = &st
|
||||
st.State = pb.ContainerState_CONTAINER_RUNNING
|
||||
filter.State = st
|
||||
case "stopped":
|
||||
st = pb.ContainerState_CONTAINER_EXITED
|
||||
filter.State = &st
|
||||
st.State = pb.ContainerState_CONTAINER_EXITED
|
||||
filter.State = st
|
||||
default:
|
||||
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() {
|
||||
if opts.quiet {
|
||||
fmt.Println(*c.Id)
|
||||
fmt.Println(c.Id)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("ID: %s\n", *c.Id)
|
||||
fmt.Printf("Pod: %s\n", *c.PodSandboxId)
|
||||
fmt.Printf("ID: %s\n", c.Id)
|
||||
fmt.Printf("Pod: %s\n", c.PodSandboxId)
|
||||
if c.Metadata != nil {
|
||||
if c.Metadata.Name != nil {
|
||||
fmt.Printf("Name: %s\n", *c.Metadata.Name)
|
||||
}
|
||||
if c.Metadata.Attempt != nil {
|
||||
fmt.Printf("Attempt: %v\n", *c.Metadata.Attempt)
|
||||
if c.Metadata.Name != "" {
|
||||
fmt.Printf("Name: %s\n", c.Metadata.Name)
|
||||
}
|
||||
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 {
|
||||
fmt.Printf("Image: %s\n", c.Image.GetImage())
|
||||
}
|
||||
if c.CreatedAt != nil {
|
||||
ctm := time.Unix(0, *c.CreatedAt)
|
||||
fmt.Printf("Created: %v\n", ctm)
|
||||
fmt.Printf("Image: %s\n", c.Image.Image)
|
||||
}
|
||||
ctm := time.Unix(0, c.CreatedAt)
|
||||
fmt.Printf("Created: %v\n", ctm)
|
||||
if c.Labels != nil {
|
||||
fmt.Println("Labels:")
|
||||
for _, k := range getSortedKeys(c.Labels) {
|
||||
|
|
|
@ -63,18 +63,18 @@ var listImageCommand = cli.Command{
|
|||
quiet := context.Bool("quiet")
|
||||
for _, image := range r.Images {
|
||||
if quiet {
|
||||
fmt.Printf("%s\n", *image.Id)
|
||||
fmt.Printf("%s\n", image.Id)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("ID: %s\n", *image.Id)
|
||||
fmt.Printf("ID: %s\n", image.Id)
|
||||
for _, tag := range image.RepoTags {
|
||||
fmt.Printf("Tag: %s\n", tag)
|
||||
}
|
||||
for _, digest := range image.RepoDigests {
|
||||
fmt.Printf("Digest: %s\n", digest)
|
||||
}
|
||||
if image.Size_ != nil {
|
||||
fmt.Printf("Size: %d\n", *image.Size_)
|
||||
if image.Size_ != 0 {
|
||||
fmt.Printf("Size: %d\n", image.Size_)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -107,16 +107,14 @@ var imageStatusCommand = cli.Command{
|
|||
if image == nil {
|
||||
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 {
|
||||
fmt.Printf("Tag: %s\n", tag)
|
||||
}
|
||||
for _, digest := range image.RepoDigests {
|
||||
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
|
||||
},
|
||||
}
|
||||
|
@ -150,19 +148,19 @@ var removeImageCommand = cli.Command{
|
|||
// PullImage sends a PullImageRequest to the server, and parses
|
||||
// the returned PullImageResponse.
|
||||
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
|
||||
// the returned ListImagesResponse.
|
||||
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
|
||||
// the returned ImageStatusResponse.
|
||||
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
|
||||
|
@ -171,5 +169,5 @@ func RemoveImage(client pb.ImageServiceClient, image string) (*pb.RemoveImageRes
|
|||
if image == "" {
|
||||
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
|
||||
if opts.name != "" {
|
||||
config.Metadata.Name = &opts.name
|
||||
config.Metadata.Name = opts.name
|
||||
}
|
||||
|
||||
for k, v := range opts.labels {
|
||||
|
@ -231,7 +231,7 @@ func RunPodSandbox(client pb.RuntimeServiceClient, opts createOptions) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(*r.PodSandboxId)
|
||||
fmt.Println(r.PodSandboxId)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,7 @@ func StopPodSandbox(client pb.RuntimeServiceClient, ID string) error {
|
|||
if ID == "" {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ func RemovePodSandbox(client pb.RuntimeServiceClient, ID string) error {
|
|||
if ID == "" {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
@ -269,37 +269,29 @@ func PodSandboxStatus(client pb.RuntimeServiceClient, ID string) error {
|
|||
if ID == "" {
|
||||
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 {
|
||||
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.Name != nil {
|
||||
fmt.Printf("Name: %s\n", *r.Status.Metadata.Name)
|
||||
if r.Status.Metadata.Name != "" {
|
||||
fmt.Printf("Name: %s\n", r.Status.Metadata.Name)
|
||||
}
|
||||
if r.Status.Metadata.Uid != nil {
|
||||
fmt.Printf("UID: %s\n", *r.Status.Metadata.Uid)
|
||||
if r.Status.Metadata.Uid != "" {
|
||||
fmt.Printf("UID: %s\n", r.Status.Metadata.Uid)
|
||||
}
|
||||
if r.Status.Metadata.Namespace != nil {
|
||||
fmt.Printf("Namespace: %s\n", *r.Status.Metadata.Namespace)
|
||||
}
|
||||
if r.Status.Metadata.Attempt != nil {
|
||||
fmt.Printf("Attempt: %v\n", *r.Status.Metadata.Attempt)
|
||||
if r.Status.Metadata.Namespace != "" {
|
||||
fmt.Printf("Namespace: %s\n", r.Status.Metadata.Namespace)
|
||||
}
|
||||
fmt.Printf("Attempt: %v\n", r.Status.Metadata.Attempt)
|
||||
}
|
||||
if r.Status.State != nil {
|
||||
fmt.Printf("Status: %s\n", r.Status.State)
|
||||
}
|
||||
if r.Status.CreatedAt != nil {
|
||||
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)
|
||||
}
|
||||
fmt.Printf("Status: %s\n", r.Status.State)
|
||||
ctm := time.Unix(0, r.Status.CreatedAt)
|
||||
fmt.Printf("Created: %v\n", ctm)
|
||||
fmt.Printf("Network namespace: %s\n", r.Status.Linux.Namespaces.Network)
|
||||
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 {
|
||||
fmt.Println("Labels:")
|
||||
|
@ -321,17 +313,18 @@ func PodSandboxStatus(client pb.RuntimeServiceClient, ID string) error {
|
|||
func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error {
|
||||
filter := &pb.PodSandboxFilter{}
|
||||
if opts.id != "" {
|
||||
filter.Id = &opts.id
|
||||
filter.Id = opts.id
|
||||
}
|
||||
if opts.state != "" {
|
||||
st := pb.PodSandboxState_SANDBOX_NOTREADY
|
||||
st := &pb.PodSandboxStateValue{}
|
||||
st.State = pb.PodSandboxState_SANDBOX_NOTREADY
|
||||
switch opts.state {
|
||||
case "ready":
|
||||
st = pb.PodSandboxState_SANDBOX_READY
|
||||
filter.State = &st
|
||||
st.State = pb.PodSandboxState_SANDBOX_READY
|
||||
filter.State = st
|
||||
case "notready":
|
||||
st = pb.PodSandboxState_SANDBOX_NOTREADY
|
||||
filter.State = &st
|
||||
st.State = pb.PodSandboxState_SANDBOX_NOTREADY
|
||||
filter.State = st
|
||||
default:
|
||||
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 {
|
||||
if opts.quiet {
|
||||
fmt.Println(*pod.Id)
|
||||
fmt.Println(pod.Id)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("ID: %s\n", *pod.Id)
|
||||
fmt.Printf("ID: %s\n", pod.Id)
|
||||
if pod.Metadata != nil {
|
||||
if pod.Metadata.Name != nil {
|
||||
fmt.Printf("Name: %s\n", *pod.Metadata.Name)
|
||||
if pod.Metadata.Name != "" {
|
||||
fmt.Printf("Name: %s\n", pod.Metadata.Name)
|
||||
}
|
||||
if pod.Metadata.Uid != nil {
|
||||
fmt.Printf("UID: %s\n", *pod.Metadata.Uid)
|
||||
if pod.Metadata.Uid != "" {
|
||||
fmt.Printf("UID: %s\n", pod.Metadata.Uid)
|
||||
}
|
||||
if pod.Metadata.Namespace != nil {
|
||||
fmt.Printf("Namespace: %s\n", *pod.Metadata.Namespace)
|
||||
}
|
||||
if pod.Metadata.Attempt != nil {
|
||||
fmt.Printf("Attempt: %v\n", *pod.Metadata.Attempt)
|
||||
if pod.Metadata.Namespace != "" {
|
||||
fmt.Printf("Namespace: %s\n", pod.Metadata.Namespace)
|
||||
}
|
||||
fmt.Printf("Attempt: %v\n", pod.Metadata.Attempt)
|
||||
}
|
||||
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)
|
||||
if pod.Labels != nil {
|
||||
fmt.Println("Labels:")
|
||||
|
|
|
@ -32,10 +32,10 @@ var runtimeVersionCommand = cli.Command{
|
|||
|
||||
// Version sends a VersionRequest to the server, and parses the returned VersionResponse.
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue