Merge pull request #110 from mrunalp/pod_meta

Return pod metadata in pod list and status APIs
This commit is contained in:
Antonio Murdaca 2016-10-07 20:44:40 +02:00 committed by GitHub
commit 7c6eb77224
2 changed files with 65 additions and 5 deletions

View file

@ -214,6 +214,20 @@ func PodSandboxStatus(client pb.RuntimeServiceClient, ID string) error {
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.Name != nil {
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.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.State != nil { if r.Status.State != nil {
fmt.Printf("Status: %s\n", r.Status.State) fmt.Printf("Status: %s\n", r.Status.State)
} }
@ -227,6 +241,18 @@ func PodSandboxStatus(client pb.RuntimeServiceClient, ID string) error {
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 {
fmt.Println("Labels:")
for k, v := range r.Status.Labels {
fmt.Printf("\t%s -> %s\n", k, v)
}
}
if r.Status.Annotations != nil {
fmt.Println("Annotations:")
for k, v := range r.Status.Annotations {
fmt.Printf("\t%s -> %s\n", k, v)
}
}
return nil return nil
} }
@ -239,9 +265,35 @@ func ListPodSandboxes(client pb.RuntimeServiceClient) error {
} }
for _, pod := range r.Items { for _, pod := range r.Items {
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.Uid != nil {
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)
}
}
fmt.Printf("Status: %s\n", pod.State) fmt.Printf("Status: %s\n", pod.State)
ctm := time.Unix(*pod.CreatedAt, 0) ctm := time.Unix(*pod.CreatedAt, 0)
fmt.Printf("Created: %v\n", ctm) fmt.Printf("Created: %v\n", ctm)
if pod.Labels != nil {
fmt.Println("Labels:")
for k, v := range pod.Labels {
fmt.Printf("\t%s -> %s\n", k, v)
}
}
if pod.Annotations != nil {
fmt.Println("Annotations:")
for k, v := range pod.Annotations {
fmt.Printf("\t%s -> %s\n", k, v)
}
}
} }
return nil return nil
} }

View file

@ -25,6 +25,7 @@ type sandbox struct {
containers oci.Store containers oci.Store
processLabel string processLabel string
mountLabel string mountLabel string
metadata *pb.PodSandboxMetadata
} }
const ( const (
@ -190,6 +191,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
containers: oci.NewMemoryStore(), containers: oci.NewMemoryStore(),
processLabel: processLabel, processLabel: processLabel,
mountLabel: mountLabel, mountLabel: mountLabel,
metadata: req.GetConfig().GetMetadata(),
}) })
for k, v := range annotations { for k, v := range annotations {
@ -409,8 +411,11 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR
Network: sPtr(netNsPath), Network: sPtr(netNsPath),
}, },
}, },
Network: &pb.PodSandboxNetworkStatus{Ip: &ip}, Network: &pb.PodSandboxNetworkStatus{Ip: &ip},
State: &rStatus, State: &rStatus,
Labels: sb.labels,
Annotations: sb.annotations,
Metadata: sb.metadata,
}, },
}, nil }, nil
} }
@ -437,9 +442,12 @@ func (s *Server) ListPodSandbox(context.Context, *pb.ListPodSandboxRequest) (*pb
} }
pod := &pb.PodSandbox{ pod := &pb.PodSandbox{
Id: &sb.id, Id: &sb.id,
CreatedAt: int64Ptr(created), CreatedAt: int64Ptr(created),
State: &rStatus, State: &rStatus,
Labels: sb.labels,
Annotations: sb.annotations,
Metadata: sb.metadata,
} }
pods = append(pods, pod) pods = append(pods, pod)