From d377288744f293aac527d5e61ce64de66ea677ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Hor=C3=A1=C4=8Dek?= Date: Thu, 21 Jun 2018 22:17:18 +0200 Subject: [PATCH] hooks: add hooks api proto specification --- .gitignore | 2 +- glide.lock | 4 +- glide.yaml | 5 +- hack/docker-builder/Dockerfile | 6 +- hack/generate.sh | 2 + pkg/hooks/{api.go => hooks.go} | 0 pkg/hooks/{api_test.go => hooks_test.go} | 0 pkg/hooks/v1alpha/api.pb.go | 276 +++++++++++++++++++++++ pkg/hooks/v1alpha/api.proto | 36 +++ pkg/hooks/v1alpha/v1alpha.go | 7 + 10 files changed, 333 insertions(+), 5 deletions(-) rename pkg/hooks/{api.go => hooks.go} (100%) rename pkg/hooks/{api_test.go => hooks_test.go} (100%) create mode 100644 pkg/hooks/v1alpha/api.pb.go create mode 100644 pkg/hooks/v1alpha/api.proto create mode 100644 pkg/hooks/v1alpha/v1alpha.go diff --git a/.gitignore b/.gitignore index 78f6a1d30f89..a598aa09a3d9 100644 --- a/.gitignore +++ b/.gitignore @@ -27,5 +27,5 @@ _out vendor/**/*_test.go **/polarion.xml tools/manifest-templator/manifest-templator -tools/vms-generator/vms-generator .coverprofile +tools/vms-generator/vms-generator diff --git a/glide.lock b/glide.lock index 3e50b68fe7ed..77d22b0509fa 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 72f3abe955ef368d170b0201cdb32729b15c0c5bc3e8523dbd6d7dc7d235fbcb -updated: 2018-05-30T17:36:13.225619211-04:00 +hash: ebd1a28c668003c851e1c906d85743b0379a4adebb84894247d9c4817f09946f +updated: 2018-06-22T13:13:30.882266906+02:00 imports: - name: cloud.google.com/go version: 3b1ae45394a234c385be014e9a488f2bb6eef821 diff --git a/glide.yaml b/glide.yaml index 6f03e6de93a5..c1ba42107993 100644 --- a/glide.yaml +++ b/glide.yaml @@ -64,7 +64,10 @@ import: version: eabcf70a1bd73e9296fa0c5f57de604689200a1b - package: kubevirt.io/qe-tools version: v0.1.1 - repo: https://github.com/kubevirt/qe-tools.git + repo: https://github.com/kubevirt/qe-tools.git +- package: github.com/golang/protobuf + subpackages: + - proto testImport: - package: github.com/elazarl/goproxy version: 07b16b6e30fcac0ad8c0435548e743bcf2ca7e92 diff --git a/hack/docker-builder/Dockerfile b/hack/docker-builder/Dockerfile index d298261f9513..fa885ab71e0d 100644 --- a/hack/docker-builder/Dockerfile +++ b/hack/docker-builder/Dockerfile @@ -2,7 +2,7 @@ FROM fedora:27 ENV LIBVIRT_VERSION 3.7.0 -RUN dnf -y install libvirt-devel-${LIBVIRT_VERSION} make git mercurial sudo gcc findutils gradle rsync-daemon rsync qemu-img && \ +RUN dnf -y install libvirt-devel-${LIBVIRT_VERSION} make git mercurial sudo gcc findutils gradle rsync-daemon rsync qemu-img protobuf-compiler && \ dnf -y clean all ENV GIMME_GO_VERSION=1.10 @@ -38,6 +38,10 @@ RUN \ go install && \ cd /go/src/k8s.io/code-generator/cmd/openapi-gen && \ git checkout release-1.9 && \ + go install && \ + go get -u -d github.com/golang/protobuf/protoc-gen-go && \ + cd /go/src/github.com/golang/protobuf/protoc-gen-go && \ + git checkout 1643683e1b54a9e88ad26d98f81400c8c9d9f4f9 && \ go install RUN pip install j2cli diff --git a/hack/generate.sh b/hack/generate.sh index 9f9fb1f899c3..0d559aad8b26 100755 --- a/hack/generate.sh +++ b/hack/generate.sh @@ -24,3 +24,5 @@ ${KUBEVIRT_DIR}/tools/crd-generator/crd-generator --crd-type=vm >${KUBEVIRT_DIR} (cd ${KUBEVIRT_DIR}/tools/vms-generator/ && go build) ${KUBEVIRT_DIR}/tools/vms-generator/vms-generator --generated-vms-dir=${KUBEVIRT_DIR}/cluster/examples + +protoc --proto_path=pkg/hooks/v1alpha --go_out=plugins=grpc,import_path=v1alpha:pkg/hooks/v1alpha pkg/hooks/v1alpha/api.proto diff --git a/pkg/hooks/api.go b/pkg/hooks/hooks.go similarity index 100% rename from pkg/hooks/api.go rename to pkg/hooks/hooks.go diff --git a/pkg/hooks/api_test.go b/pkg/hooks/hooks_test.go similarity index 100% rename from pkg/hooks/api_test.go rename to pkg/hooks/hooks_test.go diff --git a/pkg/hooks/v1alpha/api.pb.go b/pkg/hooks/v1alpha/api.pb.go new file mode 100644 index 000000000000..d90bb8ba9634 --- /dev/null +++ b/pkg/hooks/v1alpha/api.pb.go @@ -0,0 +1,276 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: api.proto + +/* +Package v1alpha is a generated protocol buffer package. + +It is generated from these files: + api.proto + +It has these top-level messages: + InfoParams + InfoResult + OnDefineDomainParams + OnDefineDomainResult +*/ +package v1alpha + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" + +import ( + context "golang.org/x/net/context" + grpc "google.golang.org/grpc" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type InfoParams struct { + // supportedVersions is a list of versions supported by client + SupportedVersions []string `protobuf:"bytes,1,rep,name=supportedVersions" json:"supportedVersions,omitempty"` +} + +func (m *InfoParams) Reset() { *m = InfoParams{} } +func (m *InfoParams) String() string { return proto.CompactTextString(m) } +func (*InfoParams) ProtoMessage() {} +func (*InfoParams) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } + +func (m *InfoParams) GetSupportedVersions() []string { + if m != nil { + return m.SupportedVersions + } + return nil +} + +type InfoResult struct { + // name of the hook used by virt-launcher to compare it with requested hooks + Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + // priority is used to sort hooks prior to their execution (second key is the name) + Priority uint32 `protobuf:"varint,2,opt,name=priority" json:"priority,omitempty"` + // hookPoints is a list of subscribed hook points + HookPoints []string `protobuf:"bytes,3,rep,name=hookPoints" json:"hookPoints,omitempty"` + // version is choosen from passed supportedVersions, this version will be used for communication + Version string `protobuf:"bytes,4,opt,name=version" json:"version,omitempty"` +} + +func (m *InfoResult) Reset() { *m = InfoResult{} } +func (m *InfoResult) String() string { return proto.CompactTextString(m) } +func (*InfoResult) ProtoMessage() {} +func (*InfoResult) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } + +func (m *InfoResult) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *InfoResult) GetPriority() uint32 { + if m != nil { + return m.Priority + } + return 0 +} + +func (m *InfoResult) GetHookPoints() []string { + if m != nil { + return m.HookPoints + } + return nil +} + +func (m *InfoResult) GetVersion() string { + if m != nil { + return m.Version + } + return "" +} + +type OnDefineDomainParams struct { + // domainXML is original libvirt domain specification, it is XML passed as string + DomainXML string `protobuf:"bytes,1,opt,name=domainXML" json:"domainXML,omitempty"` + // vm is VirtualMachine is object of virtual machine currently processed by virt-launcher, it is encoded as JSON and passed as string + Vm string `protobuf:"bytes,2,opt,name=vm" json:"vm,omitempty"` +} + +func (m *OnDefineDomainParams) Reset() { *m = OnDefineDomainParams{} } +func (m *OnDefineDomainParams) String() string { return proto.CompactTextString(m) } +func (*OnDefineDomainParams) ProtoMessage() {} +func (*OnDefineDomainParams) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } + +func (m *OnDefineDomainParams) GetDomainXML() string { + if m != nil { + return m.DomainXML + } + return "" +} + +func (m *OnDefineDomainParams) GetVm() string { + if m != nil { + return m.Vm + } + return "" +} + +type OnDefineDomainResult struct { + // domainXML is processed libvirt domain specification, it is XML passed as string + DomainXML string `protobuf:"bytes,1,opt,name=domainXML" json:"domainXML,omitempty"` +} + +func (m *OnDefineDomainResult) Reset() { *m = OnDefineDomainResult{} } +func (m *OnDefineDomainResult) String() string { return proto.CompactTextString(m) } +func (*OnDefineDomainResult) ProtoMessage() {} +func (*OnDefineDomainResult) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } + +func (m *OnDefineDomainResult) GetDomainXML() string { + if m != nil { + return m.DomainXML + } + return "" +} + +func init() { + proto.RegisterType((*InfoParams)(nil), "kubevirt.hooks.v1alpha.InfoParams") + proto.RegisterType((*InfoResult)(nil), "kubevirt.hooks.v1alpha.InfoResult") + proto.RegisterType((*OnDefineDomainParams)(nil), "kubevirt.hooks.v1alpha.OnDefineDomainParams") + proto.RegisterType((*OnDefineDomainResult)(nil), "kubevirt.hooks.v1alpha.OnDefineDomainResult") +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// Client API for Hook service + +type HookClient interface { + Info(ctx context.Context, in *InfoParams, opts ...grpc.CallOption) (*InfoResult, error) + OnDefineDomain(ctx context.Context, in *OnDefineDomainParams, opts ...grpc.CallOption) (*OnDefineDomainResult, error) +} + +type hookClient struct { + cc *grpc.ClientConn +} + +func NewHookClient(cc *grpc.ClientConn) HookClient { + return &hookClient{cc} +} + +func (c *hookClient) Info(ctx context.Context, in *InfoParams, opts ...grpc.CallOption) (*InfoResult, error) { + out := new(InfoResult) + err := grpc.Invoke(ctx, "/kubevirt.hooks.v1alpha.Hook/Info", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *hookClient) OnDefineDomain(ctx context.Context, in *OnDefineDomainParams, opts ...grpc.CallOption) (*OnDefineDomainResult, error) { + out := new(OnDefineDomainResult) + err := grpc.Invoke(ctx, "/kubevirt.hooks.v1alpha.Hook/OnDefineDomain", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Hook service + +type HookServer interface { + Info(context.Context, *InfoParams) (*InfoResult, error) + OnDefineDomain(context.Context, *OnDefineDomainParams) (*OnDefineDomainResult, error) +} + +func RegisterHookServer(s *grpc.Server, srv HookServer) { + s.RegisterService(&_Hook_serviceDesc, srv) +} + +func _Hook_Info_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(InfoParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(HookServer).Info(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/kubevirt.hooks.v1alpha.Hook/Info", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(HookServer).Info(ctx, req.(*InfoParams)) + } + return interceptor(ctx, in, info, handler) +} + +func _Hook_OnDefineDomain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(OnDefineDomainParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(HookServer).OnDefineDomain(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/kubevirt.hooks.v1alpha.Hook/OnDefineDomain", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(HookServer).OnDefineDomain(ctx, req.(*OnDefineDomainParams)) + } + return interceptor(ctx, in, info, handler) +} + +var _Hook_serviceDesc = grpc.ServiceDesc{ + ServiceName: "kubevirt.hooks.v1alpha.Hook", + HandlerType: (*HookServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Info", + Handler: _Hook_Info_Handler, + }, + { + MethodName: "OnDefineDomain", + Handler: _Hook_OnDefineDomain_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "api.proto", +} + +func init() { proto.RegisterFile("api.proto", fileDescriptor0) } + +var fileDescriptor0 = []byte{ + // 282 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xc9, 0x6a, 0xf3, 0x30, + 0x10, 0xc6, 0x89, 0xf9, 0xff, 0x7a, 0xa0, 0x81, 0x0e, 0xa5, 0x88, 0x50, 0x8a, 0xf1, 0xc9, 0x87, + 0x60, 0xe8, 0x72, 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, 0x2c, 0x43, 0x8e, 0xbd, 0x2c, + 0x17, 0xaf, 0x11, 0xc4, 0x37, 0x44, 0x35, 0x3e, 0x40, 0xbc, 0x09, 0x8f, 0x59, 0xb1, 0x7b, 0xb3, + 0xc5, 0x76, 0xad, 0xd3, 0xbd, 0x3d, 0x83, 0x6c, 0x03, 0x93, 0xaf, 0x76, 0x70, 0xf6, 0xdb, 0xd4, + 0xae, 0xf0, 0xd3, 0x3f, 0x76, 0xf7, 0x6a, 0x8b, 0x7f, 0xe1, 0x2a, 0x2e, 0xdf, 0x02, 0x00, 0x00, + 0xff, 0xff, 0x7b, 0x74, 0xe7, 0x62, 0x22, 0x02, 0x00, 0x00, +} diff --git a/pkg/hooks/v1alpha/api.proto b/pkg/hooks/v1alpha/api.proto new file mode 100644 index 000000000000..af2c0c243cf1 --- /dev/null +++ b/pkg/hooks/v1alpha/api.proto @@ -0,0 +1,36 @@ +syntax = "proto3"; + +package kubevirt.hooks.v1alpha; + +service Hook { + rpc Info (InfoParams) returns (InfoResult); + rpc OnDefineDomain (OnDefineDomainParams) returns (OnDefineDomainResult); +} + +message InfoParams { + // supportedVersions is a list of versions supported by client + repeated string supportedVersions = 1; +} + +message InfoResult { + // name of the hook used by virt-launcher to compare it with requested hooks + string name = 1; + // priority is used to sort hooks prior to their execution (second key is the name) + uint32 priority = 2; + // hookPoints is a list of subscribed hook points + repeated string hookPoints = 3; + // version is choosen from passed supportedVersions, this version will be used for communication + string version = 4; +} + +message OnDefineDomainParams { + // domainXML is original libvirt domain specification, it is XML passed as string + string domainXML = 1; + // vm is VirtualMachine is object of virtual machine currently processed by virt-launcher, it is encoded as JSON and passed as string + string vm = 2; +} + +message OnDefineDomainResult { + // domainXML is processed libvirt domain specification, it is XML passed as string + string domainXML = 1; +} \ No newline at end of file diff --git a/pkg/hooks/v1alpha/v1alpha.go b/pkg/hooks/v1alpha/v1alpha.go new file mode 100644 index 000000000000..224bd3a933ff --- /dev/null +++ b/pkg/hooks/v1alpha/v1alpha.go @@ -0,0 +1,7 @@ +package v1alpha + +const Version = "v1alpha" + +const ( + OnDefineDomainHookPointName = "OnDefineDomain" +)