From 07c81ccac44005528cbf2ab15be3b2b4dce44332 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Wed, 25 Jan 2017 13:27:48 -0800 Subject: [PATCH] Add events api to shim Signed-off-by: Michael Crosby --- api/shim/shim.pb.go | 595 ++++++++++++++++++++++++++++++------ api/shim/shim.proto | 97 +++--- cmd/containerd-shim/main.go | 77 +++-- cmd/ctr/shim.go | 35 ++- cmd/ctr/utils.go | 1 - shim/exec.go | 8 - shim/init.go | 2 +- shim/io.go | 1 - shim/process.go | 10 +- shim/service.go | 48 +-- 10 files changed, 663 insertions(+), 211 deletions(-) diff --git a/api/shim/shim.pb.go b/api/shim/shim.pb.go index ed4c014..aba37bf 100644 --- a/api/shim/shim.pb.go +++ b/api/shim/shim.pb.go @@ -19,6 +19,8 @@ Rlimit ExecResponse PtyRequest + EventsRequest + Event */ package shim @@ -52,6 +54,27 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package +type EventType int32 + +const ( + EventType_EXIT EventType = 0 + EventType_OOM EventType = 1 +) + +var EventType_name = map[int32]string{ + 0: "EXIT", + 1: "OOM", +} +var EventType_value = map[string]int32{ + "EXIT": 0, + "OOM": 1, +} + +func (x EventType) String() string { + return proto.EnumName(EventType_name, int32(x)) +} +func (EventType) EnumDescriptor() ([]byte, []int) { return fileDescriptorShim, []int{0} } + type CreateRequest struct { ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Bundle string `protobuf:"bytes,2,opt,name=bundle,proto3" json:"bundle,omitempty"` @@ -83,7 +106,6 @@ func (*StartRequest) ProtoMessage() {} func (*StartRequest) Descriptor() ([]byte, []int) { return fileDescriptorShim, []int{2} } type DeleteRequest struct { - Pid uint32 `protobuf:"varint,1,opt,name=pid,proto3" json:"pid,omitempty"` } func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } @@ -157,17 +179,38 @@ func (m *PtyRequest) Reset() { *m = PtyRequest{} } func (*PtyRequest) ProtoMessage() {} func (*PtyRequest) Descriptor() ([]byte, []int) { return fileDescriptorShim, []int{9} } +type EventsRequest struct { +} + +func (m *EventsRequest) Reset() { *m = EventsRequest{} } +func (*EventsRequest) ProtoMessage() {} +func (*EventsRequest) Descriptor() ([]byte, []int) { return fileDescriptorShim, []int{10} } + +type Event struct { + ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Type EventType `protobuf:"varint,2,opt,name=type,proto3,enum=containerd.shim.v1.EventType" json:"type,omitempty"` + Pid uint32 `protobuf:"varint,3,opt,name=pid,proto3" json:"pid,omitempty"` + ExitStatus uint32 `protobuf:"varint,4,opt,name=exit_status,json=exitStatus,proto3" json:"exit_status,omitempty"` +} + +func (m *Event) Reset() { *m = Event{} } +func (*Event) ProtoMessage() {} +func (*Event) Descriptor() ([]byte, []int) { return fileDescriptorShim, []int{11} } + func init() { - proto.RegisterType((*CreateRequest)(nil), "containerd.v1.CreateRequest") - proto.RegisterType((*CreateResponse)(nil), "containerd.v1.CreateResponse") - proto.RegisterType((*StartRequest)(nil), "containerd.v1.StartRequest") - proto.RegisterType((*DeleteRequest)(nil), "containerd.v1.DeleteRequest") - proto.RegisterType((*DeleteResponse)(nil), "containerd.v1.DeleteResponse") - proto.RegisterType((*ExecRequest)(nil), "containerd.v1.ExecRequest") - proto.RegisterType((*User)(nil), "containerd.v1.User") - proto.RegisterType((*Rlimit)(nil), "containerd.v1.Rlimit") - proto.RegisterType((*ExecResponse)(nil), "containerd.v1.ExecResponse") - proto.RegisterType((*PtyRequest)(nil), "containerd.v1.PtyRequest") + proto.RegisterType((*CreateRequest)(nil), "containerd.shim.v1.CreateRequest") + proto.RegisterType((*CreateResponse)(nil), "containerd.shim.v1.CreateResponse") + proto.RegisterType((*StartRequest)(nil), "containerd.shim.v1.StartRequest") + proto.RegisterType((*DeleteRequest)(nil), "containerd.shim.v1.DeleteRequest") + proto.RegisterType((*DeleteResponse)(nil), "containerd.shim.v1.DeleteResponse") + proto.RegisterType((*ExecRequest)(nil), "containerd.shim.v1.ExecRequest") + proto.RegisterType((*User)(nil), "containerd.shim.v1.User") + proto.RegisterType((*Rlimit)(nil), "containerd.shim.v1.Rlimit") + proto.RegisterType((*ExecResponse)(nil), "containerd.shim.v1.ExecResponse") + proto.RegisterType((*PtyRequest)(nil), "containerd.shim.v1.PtyRequest") + proto.RegisterType((*EventsRequest)(nil), "containerd.shim.v1.EventsRequest") + proto.RegisterType((*Event)(nil), "containerd.shim.v1.Event") + proto.RegisterEnum("containerd.shim.v1.EventType", EventType_name, EventType_value) } func (this *CreateRequest) GoString() string { if this == nil { @@ -209,9 +252,8 @@ func (this *DeleteRequest) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 5) + s := make([]string, 0, 4) s = append(s, "&shim.DeleteRequest{") - s = append(s, "Pid: "+fmt.Sprintf("%#v", this.Pid)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -298,6 +340,28 @@ func (this *PtyRequest) GoString() string { s = append(s, "}") return strings.Join(s, "") } +func (this *EventsRequest) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 4) + s = append(s, "&shim.EventsRequest{") + s = append(s, "}") + return strings.Join(s, "") +} +func (this *Event) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 8) + s = append(s, "&shim.Event{") + s = append(s, "ID: "+fmt.Sprintf("%#v", this.ID)+",\n") + s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") + s = append(s, "Pid: "+fmt.Sprintf("%#v", this.Pid)+",\n") + s = append(s, "ExitStatus: "+fmt.Sprintf("%#v", this.ExitStatus)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} func valueToGoStringShim(v interface{}, typ string) string { rv := reflect.ValueOf(v) if rv.IsNil() { @@ -341,6 +405,7 @@ type ShimClient interface { Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) Exec(ctx context.Context, in *ExecRequest, opts ...grpc.CallOption) (*ExecResponse, error) Pty(ctx context.Context, in *PtyRequest, opts ...grpc.CallOption) (*google_protobuf.Empty, error) + Events(ctx context.Context, in *EventsRequest, opts ...grpc.CallOption) (Shim_EventsClient, error) } type shimClient struct { @@ -353,7 +418,7 @@ func NewShimClient(cc *grpc.ClientConn) ShimClient { func (c *shimClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { out := new(CreateResponse) - err := grpc.Invoke(ctx, "/containerd.v1.Shim/Create", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/containerd.shim.v1.Shim/Create", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -362,7 +427,7 @@ func (c *shimClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc func (c *shimClient) Start(ctx context.Context, in *StartRequest, opts ...grpc.CallOption) (*google_protobuf.Empty, error) { out := new(google_protobuf.Empty) - err := grpc.Invoke(ctx, "/containerd.v1.Shim/Start", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/containerd.shim.v1.Shim/Start", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -371,7 +436,7 @@ func (c *shimClient) Start(ctx context.Context, in *StartRequest, opts ...grpc.C func (c *shimClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { out := new(DeleteResponse) - err := grpc.Invoke(ctx, "/containerd.v1.Shim/Delete", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/containerd.shim.v1.Shim/Delete", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -380,7 +445,7 @@ func (c *shimClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc func (c *shimClient) Exec(ctx context.Context, in *ExecRequest, opts ...grpc.CallOption) (*ExecResponse, error) { out := new(ExecResponse) - err := grpc.Invoke(ctx, "/containerd.v1.Shim/Exec", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/containerd.shim.v1.Shim/Exec", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -389,13 +454,45 @@ func (c *shimClient) Exec(ctx context.Context, in *ExecRequest, opts ...grpc.Cal func (c *shimClient) Pty(ctx context.Context, in *PtyRequest, opts ...grpc.CallOption) (*google_protobuf.Empty, error) { out := new(google_protobuf.Empty) - err := grpc.Invoke(ctx, "/containerd.v1.Shim/Pty", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/containerd.shim.v1.Shim/Pty", in, out, c.cc, opts...) if err != nil { return nil, err } return out, nil } +func (c *shimClient) Events(ctx context.Context, in *EventsRequest, opts ...grpc.CallOption) (Shim_EventsClient, error) { + stream, err := grpc.NewClientStream(ctx, &_Shim_serviceDesc.Streams[0], c.cc, "/containerd.shim.v1.Shim/Events", opts...) + if err != nil { + return nil, err + } + x := &shimEventsClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Shim_EventsClient interface { + Recv() (*Event, error) + grpc.ClientStream +} + +type shimEventsClient struct { + grpc.ClientStream +} + +func (x *shimEventsClient) Recv() (*Event, error) { + m := new(Event) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + // Server API for Shim service type ShimServer interface { @@ -404,6 +501,7 @@ type ShimServer interface { Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) Exec(context.Context, *ExecRequest) (*ExecResponse, error) Pty(context.Context, *PtyRequest) (*google_protobuf.Empty, error) + Events(*EventsRequest, Shim_EventsServer) error } func RegisterShimServer(s *grpc.Server, srv ShimServer) { @@ -420,7 +518,7 @@ func _Shim_Create_Handler(srv interface{}, ctx context.Context, dec func(interfa } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/containerd.v1.Shim/Create", + FullMethod: "/containerd.shim.v1.Shim/Create", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ShimServer).Create(ctx, req.(*CreateRequest)) @@ -438,7 +536,7 @@ func _Shim_Start_Handler(srv interface{}, ctx context.Context, dec func(interfac } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/containerd.v1.Shim/Start", + FullMethod: "/containerd.shim.v1.Shim/Start", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ShimServer).Start(ctx, req.(*StartRequest)) @@ -456,7 +554,7 @@ func _Shim_Delete_Handler(srv interface{}, ctx context.Context, dec func(interfa } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/containerd.v1.Shim/Delete", + FullMethod: "/containerd.shim.v1.Shim/Delete", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ShimServer).Delete(ctx, req.(*DeleteRequest)) @@ -474,7 +572,7 @@ func _Shim_Exec_Handler(srv interface{}, ctx context.Context, dec func(interface } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/containerd.v1.Shim/Exec", + FullMethod: "/containerd.shim.v1.Shim/Exec", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ShimServer).Exec(ctx, req.(*ExecRequest)) @@ -492,7 +590,7 @@ func _Shim_Pty_Handler(srv interface{}, ctx context.Context, dec func(interface{ } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/containerd.v1.Shim/Pty", + FullMethod: "/containerd.shim.v1.Shim/Pty", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ShimServer).Pty(ctx, req.(*PtyRequest)) @@ -500,8 +598,29 @@ func _Shim_Pty_Handler(srv interface{}, ctx context.Context, dec func(interface{ return interceptor(ctx, in, info, handler) } +func _Shim_Events_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(EventsRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(ShimServer).Events(m, &shimEventsServer{stream}) +} + +type Shim_EventsServer interface { + Send(*Event) error + grpc.ServerStream +} + +type shimEventsServer struct { + grpc.ServerStream +} + +func (x *shimEventsServer) Send(m *Event) error { + return x.ServerStream.SendMsg(m) +} + var _Shim_serviceDesc = grpc.ServiceDesc{ - ServiceName: "containerd.v1.Shim", + ServiceName: "containerd.shim.v1.Shim", HandlerType: (*ShimServer)(nil), Methods: []grpc.MethodDesc{ { @@ -525,7 +644,13 @@ var _Shim_serviceDesc = grpc.ServiceDesc{ Handler: _Shim_Pty_Handler, }, }, - Streams: []grpc.StreamDesc{}, + Streams: []grpc.StreamDesc{ + { + StreamName: "Events", + Handler: _Shim_Events_Handler, + ServerStreams: true, + }, + }, Metadata: "shim.proto", } @@ -659,11 +784,6 @@ func (m *DeleteRequest) MarshalTo(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Pid != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintShim(dAtA, i, uint64(m.Pid)) - } return i, nil } @@ -972,6 +1092,63 @@ func (m *PtyRequest) MarshalTo(dAtA []byte) (int, error) { return i, nil } +func (m *EventsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EventsRequest) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + return i, nil +} + +func (m *Event) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Event) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.ID) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintShim(dAtA, i, uint64(len(m.ID))) + i += copy(dAtA[i:], m.ID) + } + if m.Type != 0 { + dAtA[i] = 0x10 + i++ + i = encodeVarintShim(dAtA, i, uint64(m.Type)) + } + if m.Pid != 0 { + dAtA[i] = 0x18 + i++ + i = encodeVarintShim(dAtA, i, uint64(m.Pid)) + } + if m.ExitStatus != 0 { + dAtA[i] = 0x20 + i++ + i = encodeVarintShim(dAtA, i, uint64(m.ExitStatus)) + } + return i, nil +} + func encodeFixed64Shim(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) dAtA[offset+1] = uint8(v >> 8) @@ -1053,9 +1230,6 @@ func (m *StartRequest) Size() (n int) { func (m *DeleteRequest) Size() (n int) { var l int _ = l - if m.Pid != 0 { - n += 1 + sovShim(uint64(m.Pid)) - } return n } @@ -1195,6 +1369,31 @@ func (m *PtyRequest) Size() (n int) { return n } +func (m *EventsRequest) Size() (n int) { + var l int + _ = l + return n +} + +func (m *Event) Size() (n int) { + var l int + _ = l + l = len(m.ID) + if l > 0 { + n += 1 + l + sovShim(uint64(l)) + } + if m.Type != 0 { + n += 1 + sovShim(uint64(m.Type)) + } + if m.Pid != 0 { + n += 1 + sovShim(uint64(m.Pid)) + } + if m.ExitStatus != 0 { + n += 1 + sovShim(uint64(m.ExitStatus)) + } + return n +} + func sovShim(x uint64) (n int) { for { n++ @@ -1249,7 +1448,6 @@ func (this *DeleteRequest) String() string { return "nil" } s := strings.Join([]string{`&DeleteRequest{`, - `Pid:` + fmt.Sprintf("%v", this.Pid) + `,`, `}`, }, "") return s @@ -1333,6 +1531,28 @@ func (this *PtyRequest) String() string { }, "") return s } +func (this *EventsRequest) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&EventsRequest{`, + `}`, + }, "") + return s +} +func (this *Event) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Event{`, + `ID:` + fmt.Sprintf("%v", this.ID) + `,`, + `Type:` + fmt.Sprintf("%v", this.Type) + `,`, + `Pid:` + fmt.Sprintf("%v", this.Pid) + `,`, + `ExitStatus:` + fmt.Sprintf("%v", this.ExitStatus) + `,`, + `}`, + }, "") + return s +} func valueToStringShim(v interface{}) string { rv := reflect.ValueOf(v) if rv.IsNil() { @@ -1753,25 +1973,6 @@ func (m *DeleteRequest) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: DeleteRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Pid", wireType) - } - m.Pid = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowShim - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Pid |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } default: iNdEx = preIndex skippy, err := skipShim(dAtA[iNdEx:]) @@ -2749,6 +2950,192 @@ func (m *PtyRequest) Unmarshal(dAtA []byte) error { } return nil } +func (m *EventsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowShim + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EventsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipShim(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthShim + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Event) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowShim + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Event: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Event: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowShim + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthShim + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowShim + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= (EventType(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Pid", wireType) + } + m.Pid = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowShim + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Pid |= (uint32(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExitStatus", wireType) + } + m.ExitStatus = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowShim + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExitStatus |= (uint32(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipShim(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthShim + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipShim(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 @@ -2857,52 +3244,58 @@ var ( func init() { proto.RegisterFile("shim.proto", fileDescriptorShim) } var fileDescriptorShim = []byte{ - // 747 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x54, 0xcd, 0x6e, 0xd3, 0x4c, - 0x14, 0xad, 0x63, 0xe7, 0xa7, 0x37, 0x71, 0xda, 0x6f, 0xbe, 0x52, 0x4d, 0xd3, 0x92, 0x06, 0xb3, - 0x68, 0x60, 0x91, 0xa8, 0x65, 0xc3, 0x02, 0x09, 0xa9, 0xb4, 0x42, 0x48, 0x15, 0x8a, 0x1c, 0xb1, - 0x8e, 0x9c, 0x78, 0xea, 0x8c, 0xe4, 0x78, 0xcc, 0xcc, 0x38, 0x69, 0x76, 0xbc, 0x16, 0x6f, 0xd0, - 0x0d, 0x12, 0x2b, 0xc4, 0x0a, 0xd1, 0x3c, 0x01, 0x8f, 0x80, 0x66, 0xec, 0x34, 0x3f, 0x6d, 0xc4, - 0xee, 0xdc, 0x73, 0x8f, 0x67, 0xee, 0x3d, 0xbe, 0x77, 0x00, 0xc4, 0x90, 0x8e, 0x5a, 0x31, 0x67, - 0x92, 0x21, 0x7b, 0xc0, 0x22, 0xe9, 0xd1, 0x88, 0x70, 0xbf, 0x35, 0x3e, 0xad, 0x1d, 0x06, 0x8c, - 0x05, 0x21, 0x69, 0xeb, 0x64, 0x3f, 0xb9, 0x6e, 0x93, 0x51, 0x2c, 0xa7, 0xa9, 0xb6, 0xb6, 0x17, - 0xb0, 0x80, 0x69, 0xd8, 0x56, 0x28, 0x65, 0x9d, 0x1f, 0x06, 0xd8, 0xef, 0x38, 0xf1, 0x24, 0x71, - 0xc9, 0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 0x4f, 0xcc, 0xc7, 0x3d, 0xb1, 0x36, 0x78, - 0x92, 0x5f, 0xf6, 0x04, 0x9d, 0x80, 0x95, 0x08, 0xc2, 0xb5, 0xb1, 0xe5, 0xb3, 0xff, 0x5b, 0x2b, - 0xd3, 0xd3, 0xfa, 0x24, 0x08, 0x77, 0xb5, 0x00, 0x21, 0xb0, 0x3c, 0x1e, 0x08, 0x5c, 0x6c, 0x98, - 0xcd, 0x6d, 0x57, 0x63, 0xe5, 0x05, 0x89, 0xc6, 0xb8, 0xa4, 0x29, 0x05, 0x15, 0x33, 0x98, 0xf8, - 0x78, 0x5b, 0xdf, 0xa1, 0x20, 0x72, 0xa0, 0x32, 0xf0, 0x62, 0xaf, 0x4f, 0x43, 0x2a, 0x29, 0x11, - 0x18, 0xb4, 0x78, 0x85, 0x43, 0x6d, 0x28, 0xf2, 0x90, 0x8e, 0xa8, 0x14, 0xb8, 0xdc, 0x30, 0x9b, - 0xe5, 0xb3, 0x27, 0x6b, 0x75, 0xb8, 0x3a, 0xeb, 0xce, 0x55, 0xe8, 0x25, 0xfc, 0x17, 0xb1, 0x5e, - 0x44, 0x26, 0xbd, 0x98, 0xd3, 0x31, 0x0d, 0x49, 0x40, 0x04, 0xae, 0x68, 0x83, 0x76, 0x22, 0xf6, - 0x91, 0x4c, 0x3a, 0xf7, 0x34, 0x7a, 0x01, 0xbb, 0x5e, 0x1c, 0x7b, 0x7c, 0xc4, 0x78, 0x2f, 0xe6, - 0xec, 0x9a, 0x86, 0x04, 0xdb, 0xba, 0xbe, 0x9d, 0x39, 0xdf, 0x49, 0x69, 0xf4, 0x1c, 0x6c, 0x41, - 0x42, 0x1a, 0x25, 0x37, 0xbd, 0xd0, 0xeb, 0x93, 0x10, 0x57, 0xb5, 0xae, 0x92, 0x91, 0x57, 0x8a, - 0x73, 0xba, 0x60, 0x29, 0x5b, 0x54, 0xab, 0xc9, 0x62, 0x10, 0x12, 0xea, 0x2b, 0x26, 0xa0, 0xbe, - 0xfe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6, 0x34, 0x0b, 0xdf, 0x37, 0x75, 0x70, 0x7e, 0x74, 0x7b, - 0x57, 0xdf, 0xfa, 0x79, 0x57, 0xdf, 0xfa, 0x73, 0x57, 0x37, 0xbe, 0xcc, 0xea, 0xc6, 0xed, 0xac, - 0x6e, 0x7c, 0x9f, 0xd5, 0x8d, 0xdf, 0xb3, 0xba, 0xd1, 0x2f, 0x68, 0xf5, 0xab, 0xbf, 0x01, 0x00, - 0x00, 0xff, 0xff, 0x73, 0x2c, 0x79, 0x5f, 0xee, 0x05, 0x00, 0x00, + // 835 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x54, 0xcf, 0x6f, 0xe3, 0x44, + 0x14, 0xae, 0x63, 0xe7, 0x47, 0x5f, 0x7e, 0xb4, 0x8c, 0x56, 0xd5, 0x6c, 0x00, 0x37, 0x98, 0x03, + 0x61, 0x85, 0x52, 0x5a, 0xb8, 0x72, 0x60, 0x69, 0x05, 0x95, 0x16, 0x1a, 0xb9, 0x8b, 0xc4, 0x2d, + 0x72, 0xea, 0x57, 0x67, 0x24, 0xc7, 0x63, 0x66, 0xc6, 0x69, 0x73, 0xe3, 0xc2, 0xdf, 0xc5, 0x81, + 0xcb, 0x1e, 0x39, 0x21, 0x4e, 0x88, 0xe6, 0x2f, 0xe0, 0x4f, 0x40, 0x33, 0xb6, 0x93, 0xa6, 0xeb, + 0xb0, 0xb7, 0xf7, 0xbe, 0x79, 0x7e, 0xf3, 0xde, 0xe7, 0x6f, 0x3e, 0x00, 0x39, 0x63, 0xf3, 0x51, + 0x2a, 0xb8, 0xe2, 0x84, 0xdc, 0xf0, 0x44, 0x05, 0x2c, 0x41, 0x11, 0x8e, 0x0c, 0xbc, 0x38, 0xed, + 0xbf, 0x1f, 0x71, 0x1e, 0xc5, 0x78, 0x62, 0x2a, 0xa6, 0xd9, 0xed, 0x09, 0xce, 0x53, 0xb5, 0xcc,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0x60, 0x5f, 0x5d, 0x7d, 0x7f, 0x68, 0x9d, 0xfd, 0x66, 0x83, 0x73, 0x3d, 0x63, 0x73, + 0x72, 0x05, 0x8d, 0xdc, 0x0a, 0xc8, 0x47, 0x55, 0xa3, 0x6c, 0xd9, 0x5f, 0xdf, 0xfb, 0xbf, 0x92, + 0x82, 0xf2, 0xaf, 0xa1, 0x6e, 0x7c, 0x83, 0x0c, 0xaa, 0x8a, 0x1f, 0x5b, 0x4a, 0xff, 0x68, 0x94, + 0x7b, 0xf2, 0xa8, 0xf4, 0xe4, 0xd1, 0x85, 0xf6, 0x64, 0x3d, 0x53, 0xee, 0x2c, 0xd5, 0x33, 0x6d, + 0xd9, 0x50, 0xf5, 0x4c, 0x4f, 0x8c, 0xe9, 0x12, 0x1c, 0x2d, 0x0b, 0x72, 0x5c, 0xc9, 0xf6, 0xc6, + 0x90, 0xfa, 0x83, 0xdd, 0x05, 0x45, 0xab, 0xaf, 0xc0, 0x1e, 0xab, 0x25, 0x71, 0xab, 0x0a, 0x37, + 0xc2, 0xda, 0xb9, 0xda, 0x77, 0xd0, 0xc8, 0x05, 0x53, 0xbd, 0xda, 0x96, 0x98, 0xfa, 0xcf, 0x77, + 0x96, 0x7c, 0x6e, 0xbd, 0xfc, 0xe0, 0xcd, 0x83, 0xbb, 0xf7, 0xd7, 0x83, 0xbb, 0xf7, 0xef, 0x83, + 0x6b, 0xfd, 0xb2, 0x72, 0xad, 0x37, 0x2b, 0xd7, 0xfa, 0x63, 0xe5, 0x5a, 0xff, 0xac, 0x5c, 0x6b, + 0xda, 0x30, 0xf7, 0x7e, 0xf1, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x8e, 0xcb, 0x80, 0x34, 0x16, + 0x07, 0x00, 0x00, } diff --git a/api/shim/shim.proto b/api/shim/shim.proto index e9e830d..9afaeb0 100644 --- a/api/shim/shim.proto +++ b/api/shim/shim.proto @@ -1,79 +1,94 @@ syntax = "proto3"; -package containerd.v1; +package containerd.shim.v1; import "google/protobuf/empty.proto"; import "gogoproto/gogo.proto"; service Shim { - rpc Create(CreateRequest) returns (CreateResponse); - rpc Start(StartRequest) returns (google.protobuf.Empty); - rpc Delete(DeleteRequest) returns (DeleteResponse); - rpc Exec(ExecRequest) returns (ExecResponse); - rpc Pty(PtyRequest) returns (google.protobuf.Empty); + rpc Create(CreateRequest) returns (CreateResponse); + rpc Start(StartRequest) returns (google.protobuf.Empty); + rpc Delete(DeleteRequest) returns (DeleteResponse); + rpc Exec(ExecRequest) returns (ExecResponse); + rpc Pty(PtyRequest) returns (google.protobuf.Empty); + rpc Events(EventsRequest) returns (stream Event); } message CreateRequest { - string id = 1 [(gogoproto.customname) = "ID"]; - string bundle = 2; - string runtime = 3; - bool no_pivot = 4; - bool terminal = 5; - string stdin = 6; - string stdout = 7; - string stderr = 8; + string id = 1 [(gogoproto.customname) = "ID"]; + string bundle = 2; + string runtime = 3; + bool no_pivot = 4; + bool terminal = 5; + string stdin = 6; + string stdout = 7; + string stderr = 8; } message CreateResponse { - uint32 pid = 1; + uint32 pid = 1; } message StartRequest { } message DeleteRequest { - uint32 pid = 1; } message DeleteResponse { - uint32 exit_status = 1; + uint32 exit_status = 1; } message ExecRequest { - string id = 1 [(gogoproto.customname) = "ID"]; - bool terminal = 2; - string stdin = 3; - string stdout = 4; - string stderr = 5; - User user = 6; - repeated string args = 7; - repeated string env = 8; - string cwd = 9; - repeated string capabilities = 10; - repeated Rlimit rlimits = 11; - bool no_new_privileges = 12; - string apparmor_profile = 13; - string selinux_label = 14; + string id = 1 [(gogoproto.customname) = "ID"]; + bool terminal = 2; + string stdin = 3; + string stdout = 4; + string stderr = 5; + User user = 6; + repeated string args = 7; + repeated string env = 8; + string cwd = 9; + repeated string capabilities = 10; + repeated Rlimit rlimits = 11; + bool no_new_privileges = 12; + string apparmor_profile = 13; + string selinux_label = 14; } message User { - uint32 uid = 1; - uint32 gid = 2; - repeated uint32 additional_gids = 3; + uint32 uid = 1; + uint32 gid = 2; + repeated uint32 additional_gids = 3; } message Rlimit { - string type = 1; - uint64 hard = 2; - uint64 soft = 3; + string type = 1; + uint64 hard = 2; + uint64 soft = 3; } message ExecResponse { - uint32 pid = 1; + uint32 pid = 1; } message PtyRequest { - uint32 pid = 1; - uint32 width = 2; - uint32 height = 3; + uint32 pid = 1; + uint32 width = 2; + uint32 height = 3; +} + +message EventsRequest { +} + +enum EventType { + EXIT = 0; + OOM = 1; +} + +message Event { + string id = 1 [(gogoproto.customname) = "ID"]; + EventType type = 2; + uint32 pid = 3; + uint32 exit_status = 4; } diff --git a/cmd/containerd-shim/main.go b/cmd/containerd-shim/main.go index e61c2e3..d3dc429 100644 --- a/cmd/containerd-shim/main.go +++ b/cmd/containerd-shim/main.go @@ -55,37 +55,12 @@ func main() { server = grpc.NewServer() sv = shim.NewService() ) + logrus.Debug("registering grpc server") apishim.RegisterShimServer(server, sv) - l, err := utils.CreateUnixSocket("shim.sock") - if err != nil { + if err := serve(server, "shim.sock"); err != nil { return err } - go func() { - defer l.Close() - if err := server.Serve(l); err != nil { - l.Close() - logrus.WithError(err).Fatal("containerd-shim: GRPC server failure") - } - }() - for s := range signals { - logrus.WithField("signal", s).Debug("received signal") - switch s { - case syscall.SIGCHLD: - exits, err := utils.Reap(false) - if err != nil { - logrus.WithError(err).Error("reap exit status") - } - for _, e := range exits { - if err := sv.ProcessExit(e); err != nil { - return err - } - } - case syscall.SIGTERM, syscall.SIGINT: - server.GracefulStop() - return nil - } - } - return nil + return handleSignals(signals, server, sv) } if err := app.Run(os.Args); err != nil { fmt.Fprintf(os.Stderr, "containerd-shim: %s\n", err) @@ -104,3 +79,49 @@ func setupSignals() (chan os.Signal, error) { } return signals, nil } + +// serve serves the grpc API over a unix socket at the provided path +// this function does not block +func serve(server *grpc.Server, path string) error { + l, err := utils.CreateUnixSocket(path) + if err != nil { + return err + } + logrus.WithField("socket", path).Debug("serving api on unix socket") + go func() { + defer l.Close() + if err := server.Serve(l); err != nil { + l.Close() + logrus.WithError(err).Fatal("containerd-shim: GRPC server failure") + } + }() + return nil +} + +func handleSignals(signals chan os.Signal, server *grpc.Server, service *shim.Service) error { + for s := range signals { + logrus.WithField("signal", s).Debug("received signal") + switch s { + case syscall.SIGCHLD: + exits, err := utils.Reap(false) + if err != nil { + logrus.WithError(err).Error("reap exit status") + } + for _, e := range exits { + logrus.WithFields(logrus.Fields{ + "status": e.Status, + "pid": e.Pid, + }).Debug("process exited") + if err := service.ProcessExit(e); err != nil { + return err + } + } + case syscall.SIGTERM, syscall.SIGINT: + // TODO: should we forward signals to the processes if they are still running? + // i.e. machine reboot + server.GracefulStop() + return nil + } + } + return nil +} diff --git a/cmd/ctr/shim.go b/cmd/ctr/shim.go index 956e3b3..334f272 100644 --- a/cmd/ctr/shim.go +++ b/cmd/ctr/shim.go @@ -18,6 +18,21 @@ import ( "github.com/urfave/cli" ) +var fifoFlags = []cli.Flag{ + cli.StringFlag{ + Name: "stdin", + Usage: "specify the path to the stdin fifo", + }, + cli.StringFlag{ + Name: "stdout", + Usage: "specify the path to the stdout fifo", + }, + cli.StringFlag{ + Name: "stderr", + Usage: "specify the path to the stderr fifo", + }, +} + var shimCommand = cli.Command{ Name: "shim", Usage: "interact with a shim directly", @@ -41,7 +56,7 @@ var shimCommand = cli.Command{ var shimCreateCommand = cli.Command{ Name: "create", Usage: "create a container with a shim", - Flags: []cli.Flag{ + Flags: append(fifoFlags, cli.StringFlag{ Name: "bundle", Usage: "bundle path for the container", @@ -51,7 +66,11 @@ var shimCreateCommand = cli.Command{ Value: "runc", Usage: "runtime to use for the container", }, - }, + cli.BoolFlag{ + Name: "attach,a", + Usage: "stay attached to the container and open the fifos", + }, + ), Action: func(context *cli.Context) error { id := context.Args().First() if id == "" { @@ -61,15 +80,25 @@ var shimCreateCommand = cli.Command{ if err != nil { return err } + wg, err := prepareStdio(context.String("stdin"), context.String("stdout"), context.String("stderr"), false) + if err != nil { + return err + } r, err := service.Create(gocontext.Background(), &shim.CreateRequest{ ID: id, Bundle: context.String("bundle"), Runtime: context.String("runtime"), + Stdin: context.String("stdin"), + Stdout: context.String("stdout"), + Stderr: context.String("stderr"), }) if err != nil { return err } fmt.Printf("container created with id %s and pid %d\n", id, r.Pid) + if context.Bool("attach") { + wg.Wait() + } return nil }, } @@ -99,7 +128,7 @@ var shimDeleteCommand = cli.Command{ if err != nil { return err } - fmt.Printf("container deleted and returned exit status %d", r.ExitStatus) + fmt.Printf("container deleted and returned exit status %d\n", r.ExitStatus) return nil }, } diff --git a/cmd/ctr/utils.go b/cmd/ctr/utils.go index ba26ebe..d3e7443 100644 --- a/cmd/ctr/utils.go +++ b/cmd/ctr/utils.go @@ -115,7 +115,6 @@ func getTempDir(id string) (string, error) { if err != nil { return "", err } - tmpDir, err := ioutil.TempDir(filepath.Join(os.TempDir(), "ctr"), fmt.Sprintf("%s-", id)) if err != nil { return "", err diff --git a/shim/exec.go b/shim/exec.go index 2991d13..1579281 100644 --- a/shim/exec.go +++ b/shim/exec.go @@ -107,16 +107,8 @@ func (e *execProcess) Status() int { func (e *execProcess) Exited(status int) { e.status = status -} - -func (e *execProcess) Start(_ context.Context) error { - return nil -} - -func (e *execProcess) Delete(context context.Context) error { e.Wait() e.io.Close() - return nil } func (e *execProcess) Resize(ws runc.WinSize) error { diff --git a/shim/init.go b/shim/init.go index f2d3887..64db96d 100644 --- a/shim/init.go +++ b/shim/init.go @@ -23,7 +23,7 @@ type initProcess struct { pid int } -func newInitProcess(context context.Context, r *apishim.CreateRequest) (process, error) { +func newInitProcess(context context.Context, r *apishim.CreateRequest) (*initProcess, error) { cwd, err := os.Getwd() if err != nil { return nil, err diff --git a/shim/io.go b/shim/io.go index 39f641d..7947efe 100644 --- a/shim/io.go +++ b/shim/io.go @@ -67,7 +67,6 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w } dest(fw, fr) } - f, err := fifo.OpenFifo(ctx, stdin, syscall.O_RDONLY, 0) if err != nil { return fmt.Errorf("containerd-shim: opening %s failed: %s", stdin, err) diff --git a/shim/process.go b/shim/process.go index a476e88..90430ee 100644 --- a/shim/process.go +++ b/shim/process.go @@ -1,18 +1,10 @@ package shim -import ( - "context" - - runc "github.com/crosbymichael/go-runc" -) +import runc "github.com/crosbymichael/go-runc" type process interface { // Pid returns the pid for the process Pid() int - // Start starts the user's defined process inside - Start(context.Context) error - // Delete deletes the process and closes all open pipes - Delete(context.Context) error // Resize resizes the process console Resize(ws runc.WinSize) error // Exited sets the exit status for the process diff --git a/shim/service.go b/shim/service.go index 9458a35..e53a618 100644 --- a/shim/service.go +++ b/shim/service.go @@ -13,16 +13,20 @@ import ( var emptyResponse = &google_protobuf.Empty{} +// NewService returns a new shim service that can be used via GRPC func NewService() *Service { return &Service{ processes: make(map[int]process), + events: make(chan *apishim.Event, 2048), } } type Service struct { - initPid int - mu sync.Mutex - processes map[int]process + initProcess *initProcess + id string + mu sync.Mutex + processes map[int]process + events chan *apishim.Event } func (s *Service) Create(ctx context.Context, r *apishim.CreateRequest) (*apishim.CreateResponse, error) { @@ -31,8 +35,10 @@ func (s *Service) Create(ctx context.Context, r *apishim.CreateRequest) (*apishi return nil, err } s.mu.Lock() + s.initProcess = process pid := process.Pid() - s.initPid, s.processes[pid] = pid, process + s.processes[pid] = process + s.id = r.ID s.mu.Unlock() return &apishim.CreateResponse{ Pid: uint32(pid), @@ -40,37 +46,28 @@ func (s *Service) Create(ctx context.Context, r *apishim.CreateRequest) (*apishi } func (s *Service) Start(ctx context.Context, r *apishim.StartRequest) (*google_protobuf.Empty, error) { - s.mu.Lock() - p := s.processes[s.initPid] - s.mu.Unlock() - if err := p.Start(ctx); err != nil { + if err := s.initProcess.Start(ctx); err != nil { return nil, err } return emptyResponse, nil } func (s *Service) Delete(ctx context.Context, r *apishim.DeleteRequest) (*apishim.DeleteResponse, error) { - s.mu.Lock() - p, ok := s.processes[int(r.Pid)] - s.mu.Unlock() - if !ok { - return nil, fmt.Errorf("process does not exist %d", r.Pid) - } - if err := p.Delete(ctx); err != nil { + if err := s.initProcess.Delete(ctx); err != nil { return nil, err } s.mu.Lock() - delete(s.processes, int(r.Pid)) + delete(s.processes, s.initProcess.pid) s.mu.Unlock() return &apishim.DeleteResponse{ - ExitStatus: uint32(p.Status()), + ExitStatus: uint32(s.initProcess.Status()), }, nil } func (s *Service) Exec(ctx context.Context, r *apishim.ExecRequest) (*apishim.ExecResponse, error) { s.mu.Lock() defer s.mu.Unlock() - process, err := newExecProcess(ctx, r, s.processes[s.initPid].(*initProcess)) + process, err := newExecProcess(ctx, r, s.initProcess) if err != nil { return nil, err } @@ -98,10 +95,25 @@ func (s *Service) Pty(ctx context.Context, r *apishim.PtyRequest) (*google_proto return emptyResponse, nil } +func (s *Service) Events(r *apishim.EventsRequest, stream apishim.Shim_EventsServer) error { + for e := range s.events { + if err := stream.Send(e); err != nil { + return err + } + } + return nil +} + func (s *Service) ProcessExit(e utils.Exit) error { s.mu.Lock() if p, ok := s.processes[e.Pid]; ok { p.Exited(e.Status) + s.events <- &apishim.Event{ + Type: apishim.EventType_EXIT, + ID: s.id, + Pid: uint32(p.Pid()), + ExitStatus: uint32(e.Status), + } } s.mu.Unlock() return nil