From c32e7e74bf2699d2f95f427e889acab26bf3554f Mon Sep 17 00:00:00 2001 From: bryanl Date: Sun, 29 Mar 2020 20:11:17 -0400 Subject: [PATCH] Create objects using store This change does the following: * Add Create function to store * Add Create support to plugin api Signed-off-by: bryanl --- changelogs/unreleased/802-bryanl | 1 + go.mod | 5 +- go.sum | 12 +- internal/objectstore/dynamic_cache.go | 46 ++++ pkg/plugin/api/api_test.go | 14 ++ pkg/plugin/api/client.go | 18 ++ pkg/plugin/api/fake/mock_dashboard_client.go | 20 ++ pkg/plugin/api/proto/dashboard.pb.go | 224 +++++++++++++++---- pkg/plugin/api/proto/dashboard.proto | 9 + pkg/plugin/api/proto/generate.sh | 7 +- pkg/plugin/api/server.go | 24 ++ pkg/plugin/dashboard/dashboard.pb.go | 49 +++- pkg/plugin/dashboard/generate.sh | 6 +- pkg/store/fake/mock_store.go | 14 ++ pkg/store/store.go | 1 + 15 files changed, 396 insertions(+), 54 deletions(-) create mode 100644 changelogs/unreleased/802-bryanl diff --git a/changelogs/unreleased/802-bryanl b/changelogs/unreleased/802-bryanl new file mode 100644 index 0000000000..6d61db755b --- /dev/null +++ b/changelogs/unreleased/802-bryanl @@ -0,0 +1 @@ +Add support for creating objects diff --git a/go.mod b/go.mod index 809f0a97ce..aed80b8248 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/fsnotify/fsnotify v1.4.7 github.com/gobwas/glob v0.2.3 github.com/golang/mock v1.3.1 - github.com/golang/protobuf v1.3.1 + github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 github.com/googleapis/gnostic v0.2.0 github.com/gorilla/handlers v1.4.0 @@ -38,8 +38,7 @@ require ( go.opencensus.io v0.22.1 go.uber.org/zap v1.10.0 golang.org/x/sync v0.0.0-20190423024810-112230192c58 - google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 // indirect - google.golang.org/grpc v1.23.0 + google.golang.org/grpc v1.27.0 gopkg.in/inf.v0 v0.9.1 // indirect k8s.io/api v0.0.0-20191016225839-816a9b7df678 k8s.io/apiextensions-apiserver v0.0.0-20181213153335-0fe22c71c476 diff --git a/go.sum b/go.sum index b64d84f7d6..15a9a6d4ad 100644 --- a/go.sum +++ b/go.sum @@ -29,6 +29,7 @@ github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= @@ -61,6 +62,8 @@ github.com/elazarl/goproxy/ext v0.0.0-20190703090003-6125c262ffb0 h1:ht1Fo9uxmem github.com/elazarl/goproxy/ext v0.0.0-20190703090003-6125c262ffb0/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v0.0.0-20190203023257-5858425f7550/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch v4.2.0+incompatible h1:fUDGZCv/7iAN7u0puUVhvKCcsR6vRfwrJatElLBEf0I= github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= @@ -102,6 +105,8 @@ github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20160524151835-7d79101e329e/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= @@ -235,6 +240,7 @@ github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDf github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= @@ -399,8 +405,8 @@ google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19 h1:Lj2SnHtxkRGJDqn google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb h1:i1Ppqkc3WQXikh8bXiwHqAN5Rv3/qDCcRk0/Otx73BY= google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 h1:nfPFGzJkUDX6uBmpN/pSw7MbOAWegH5QDQuoXFHedLg= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0 h1:cfg4PD8YEdSFnm7qLV4++93WcmhH2nIUhMjhdCvl3j8= @@ -410,6 +416,8 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.23.0 h1:AzbTB6ux+okLTzP8Ru1Xs41C303zdcfEht7MQnYJt5A= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/objectstore/dynamic_cache.go b/internal/objectstore/dynamic_cache.go index a0e89630d7..cc585009ed 100644 --- a/internal/objectstore/dynamic_cache.go +++ b/internal/objectstore/dynamic_cache.go @@ -573,3 +573,49 @@ func (dc *DynamicCache) Update(ctx context.Context, key store.Key, updater func( func (dc *DynamicCache) IsLoading(ctx context.Context, key store.Key) bool { return !dc.informerSynced.hasSynced(key) } + +// Create creates an object in the cluster. +// Note: test coverage of DynamicCache is slim. +func (dc *DynamicCache) Create(ctx context.Context, object *unstructured.Unstructured) error { + _, span := trace.StartSpan(ctx, "dynamicCache:create") + defer span.End() + + key, err := store.KeyFromObject(object) + if err != nil { + return fmt.Errorf("key from object: %w", err) + } + + if dc.isBackingOff(ctx, key) { + return nil + } + + if err := dc.access.HasAccess(ctx, key, "create"); err != nil { + if meta.IsNoMatchError(err) { + return nil + } + if !dc.isBackingOff(ctx, key) { + dc.backoff(ctx, key) + } + return fmt.Errorf("check access to create %s: %w", key, err) + } + + dynamicClient, err := dc.client.DynamicClient() + if err != nil { + return err + } + + gvr, err := dc.client.Resource(key.GroupVersionKind().GroupKind()) + if err != nil { + return err + } + + createOptions := metav1.CreateOptions{} + + if key.Namespace == "" { + _, err := dynamicClient.Resource(gvr).Create(object, createOptions) + return err + } + + _, err = dynamicClient.Resource(gvr).Namespace(key.Namespace).Create(object, createOptions) + return err +} diff --git a/pkg/plugin/api/api_test.go b/pkg/plugin/api/api_test.go index 1b27b49fba..9a6871d8f0 100644 --- a/pkg/plugin/api/api_test.go +++ b/pkg/plugin/api/api_test.go @@ -82,6 +82,20 @@ func TestAPI(t *testing.T) { assert.Equal(t, expected, got) }, }, + { + name: "create", + initFunc: func(t *testing.T, mocks *apiMocks) { + mocks.objectStore.EXPECT(). + Create(gomock.Any(), gomock.Eq(object)).Return(nil) + }, + doFunc: func(t *testing.T, client *api.Client) { + clientCtx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() + + err := client.Create(clientCtx, object) + require.NoError(t, err) + }, + }, { name: "get", initFunc: func(t *testing.T, mocks *apiMocks) { diff --git a/pkg/plugin/api/client.go b/pkg/plugin/api/client.go index 787ba14e22..20e94643d9 100644 --- a/pkg/plugin/api/client.go +++ b/pkg/plugin/api/client.go @@ -138,6 +138,24 @@ func (c *Client) Update(ctx context.Context, object *unstructured.Unstructured) return err } +func (c *Client) Create(ctx context.Context, object *unstructured.Unstructured) error { + client := c.DashboardConnection.Client() + + data, err := convertFromObject(object) + if err != nil { + return err + } + + req := &proto.CreateRequest{ + Object: data, + } + + _, err = client.Create(ctx, req) + + return err + +} + // PortForward creates a port forward. func (c *Client) PortForward(ctx context.Context, req PortForwardRequest) (PortForwardResponse, error) { client := c.DashboardConnection.Client() diff --git a/pkg/plugin/api/fake/mock_dashboard_client.go b/pkg/plugin/api/fake/mock_dashboard_client.go index 7d93dd88f2..cdf3cd8484 100644 --- a/pkg/plugin/api/fake/mock_dashboard_client.go +++ b/pkg/plugin/api/fake/mock_dashboard_client.go @@ -55,6 +55,26 @@ func (mr *MockDashboardClientMockRecorder) CancelPortForward(arg0, arg1 interfac return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CancelPortForward", reflect.TypeOf((*MockDashboardClient)(nil).CancelPortForward), varargs...) } +// Create mocks base method +func (m *MockDashboardClient) Create(arg0 context.Context, arg1 *proto.CreateRequest, arg2 ...grpc.CallOption) (*proto.CreateResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Create", varargs...) + ret0, _ := ret[0].(*proto.CreateResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create +func (mr *MockDashboardClientMockRecorder) Create(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockDashboardClient)(nil).Create), varargs...) +} + // ForceFrontendUpdate mocks base method func (m *MockDashboardClient) ForceFrontendUpdate(arg0 context.Context, arg1 *proto.Empty, arg2 ...grpc.CallOption) (*proto.Empty, error) { m.ctrl.T.Helper() diff --git a/pkg/plugin/api/proto/dashboard.pb.go b/pkg/plugin/api/proto/dashboard.pb.go index ff5798c649..a7a74f22bb 100644 --- a/pkg/plugin/api/proto/dashboard.pb.go +++ b/pkg/plugin/api/proto/dashboard.pb.go @@ -9,6 +9,8 @@ import ( proto "github.com/golang/protobuf/proto" wrappers "github.com/golang/protobuf/ptypes/wrappers" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -273,6 +275,76 @@ func (m *UpdateResponse) XXX_DiscardUnknown() { var xxx_messageInfo_UpdateResponse proto.InternalMessageInfo +type CreateRequest struct { + Object []byte `protobuf:"bytes,1,opt,name=object,proto3" json:"object,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateRequest) Reset() { *m = CreateRequest{} } +func (m *CreateRequest) String() string { return proto.CompactTextString(m) } +func (*CreateRequest) ProtoMessage() {} +func (*CreateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9b97678da3a35dfb, []int{6} +} + +func (m *CreateRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateRequest.Unmarshal(m, b) +} +func (m *CreateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateRequest.Marshal(b, m, deterministic) +} +func (m *CreateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateRequest.Merge(m, src) +} +func (m *CreateRequest) XXX_Size() int { + return xxx_messageInfo_CreateRequest.Size(m) +} +func (m *CreateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CreateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateRequest proto.InternalMessageInfo + +func (m *CreateRequest) GetObject() []byte { + if m != nil { + return m.Object + } + return nil +} + +type CreateResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateResponse) Reset() { *m = CreateResponse{} } +func (m *CreateResponse) String() string { return proto.CompactTextString(m) } +func (*CreateResponse) ProtoMessage() {} +func (*CreateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9b97678da3a35dfb, []int{7} +} + +func (m *CreateResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateResponse.Unmarshal(m, b) +} +func (m *CreateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateResponse.Marshal(b, m, deterministic) +} +func (m *CreateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateResponse.Merge(m, src) +} +func (m *CreateResponse) XXX_Size() int { + return xxx_messageInfo_CreateResponse.Size(m) +} +func (m *CreateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CreateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateResponse proto.InternalMessageInfo + type PortForwardRequest struct { Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` PodName string `protobuf:"bytes,2,opt,name=podName,proto3" json:"podName,omitempty"` @@ -287,7 +359,7 @@ func (m *PortForwardRequest) Reset() { *m = PortForwardRequest{} } func (m *PortForwardRequest) String() string { return proto.CompactTextString(m) } func (*PortForwardRequest) ProtoMessage() {} func (*PortForwardRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_9b97678da3a35dfb, []int{6} + return fileDescriptor_9b97678da3a35dfb, []int{8} } func (m *PortForwardRequest) XXX_Unmarshal(b []byte) error { @@ -348,7 +420,7 @@ func (m *PortForwardResponse) Reset() { *m = PortForwardResponse{} } func (m *PortForwardResponse) String() string { return proto.CompactTextString(m) } func (*PortForwardResponse) ProtoMessage() {} func (*PortForwardResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_9b97678da3a35dfb, []int{7} + return fileDescriptor_9b97678da3a35dfb, []int{9} } func (m *PortForwardResponse) XXX_Unmarshal(b []byte) error { @@ -394,7 +466,7 @@ func (m *CancelPortForwardRequest) Reset() { *m = CancelPortForwardReque func (m *CancelPortForwardRequest) String() string { return proto.CompactTextString(m) } func (*CancelPortForwardRequest) ProtoMessage() {} func (*CancelPortForwardRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_9b97678da3a35dfb, []int{8} + return fileDescriptor_9b97678da3a35dfb, []int{10} } func (m *CancelPortForwardRequest) XXX_Unmarshal(b []byte) error { @@ -433,7 +505,7 @@ func (m *NamespacesResponse) Reset() { *m = NamespacesResponse{} } func (m *NamespacesResponse) String() string { return proto.CompactTextString(m) } func (*NamespacesResponse) ProtoMessage() {} func (*NamespacesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_9b97678da3a35dfb, []int{9} + return fileDescriptor_9b97678da3a35dfb, []int{11} } func (m *NamespacesResponse) XXX_Unmarshal(b []byte) error { @@ -468,57 +540,63 @@ func init() { proto.RegisterType((*GetResponse)(nil), "proto.GetResponse") proto.RegisterType((*UpdateRequest)(nil), "proto.UpdateRequest") proto.RegisterType((*UpdateResponse)(nil), "proto.UpdateResponse") + proto.RegisterType((*CreateRequest)(nil), "proto.CreateRequest") + proto.RegisterType((*CreateResponse)(nil), "proto.CreateResponse") proto.RegisterType((*PortForwardRequest)(nil), "proto.PortForwardRequest") proto.RegisterType((*PortForwardResponse)(nil), "proto.PortForwardResponse") proto.RegisterType((*CancelPortForwardRequest)(nil), "proto.CancelPortForwardRequest") proto.RegisterType((*NamespacesResponse)(nil), "proto.NamespacesResponse") } -func init() { proto.RegisterFile("dashboard.proto", fileDescriptor_9b97678da3a35dfb) } +func init() { + proto.RegisterFile("dashboard.proto", fileDescriptor_9b97678da3a35dfb) +} var fileDescriptor_9b97678da3a35dfb = []byte{ - // 510 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0xc7, 0xe5, 0xe6, 0x4b, 0x99, 0x24, 0x85, 0x6e, 0x00, 0x19, 0x83, 0x42, 0x64, 0x15, 0x91, - 0x03, 0x72, 0x45, 0x81, 0x03, 0x37, 0x28, 0x21, 0x15, 0x02, 0x45, 0xc8, 0x88, 0x5e, 0x38, 0xad, - 0xed, 0xa1, 0x18, 0x1c, 0xef, 0xb2, 0xbb, 0x51, 0x95, 0xd7, 0xe0, 0xc4, 0x8b, 0xf0, 0x7e, 0x95, - 0x77, 0xd7, 0xb5, 0xdd, 0xa4, 0x52, 0x4f, 0xd9, 0xf9, 0xcf, 0x47, 0x66, 0x7e, 0x33, 0x86, 0x3b, - 0x09, 0x95, 0x3f, 0x23, 0x46, 0x45, 0x12, 0x70, 0xc1, 0x14, 0x23, 0x1d, 0xfd, 0xe3, 0x4d, 0xce, - 0x19, 0x3b, 0xcf, 0xf0, 0x48, 0x5b, 0xd1, 0xfa, 0xc7, 0xd1, 0x85, 0xa0, 0x9c, 0xa3, 0x90, 0x26, - 0xcc, 0xef, 0x41, 0xe7, 0xc3, 0x8a, 0xab, 0x8d, 0xff, 0xdf, 0x01, 0xf8, 0x84, 0x9b, 0x10, 0xff, - 0xac, 0x51, 0x2a, 0xf2, 0x18, 0xfa, 0x39, 0x5d, 0xa1, 0xe4, 0x34, 0x46, 0xd7, 0x99, 0x3a, 0xb3, - 0x7e, 0x58, 0x09, 0x64, 0x02, 0x40, 0x79, 0x7a, 0x86, 0x42, 0xa6, 0x2c, 0x77, 0xf7, 0xb4, 0xbb, - 0xa6, 0x10, 0x02, 0xed, 0xdf, 0x69, 0x9e, 0xb8, 0x2d, 0xed, 0xd1, 0xef, 0x42, 0x2b, 0x0a, 0xb8, - 0x6d, 0xa3, 0x15, 0x6f, 0xf2, 0x0e, 0x46, 0x19, 0x8d, 0x30, 0xfb, 0x8a, 0x19, 0xc6, 0x8a, 0x09, - 0xb7, 0x33, 0x75, 0x66, 0x83, 0xe3, 0x47, 0x81, 0xe9, 0x3a, 0x28, 0xbb, 0x0e, 0x4e, 0x36, 0x0a, - 0xe5, 0x19, 0xcd, 0xd6, 0x18, 0x36, 0x33, 0xfc, 0x19, 0x0c, 0x3f, 0xa7, 0x52, 0x85, 0x28, 0x39, - 0xcb, 0x25, 0x12, 0x17, 0x7a, 0x2c, 0xfa, 0x85, 0xb1, 0x92, 0xae, 0x33, 0x6d, 0xcd, 0x86, 0x61, - 0x69, 0xfa, 0x4f, 0x61, 0x70, 0x8a, 0x55, 0xe0, 0x03, 0xe8, 0x1a, 0x8f, 0x1e, 0x6f, 0x18, 0x5a, - 0xcb, 0x7f, 0x06, 0xa3, 0x6f, 0x3c, 0xa1, 0x0a, 0x4b, 0x14, 0x37, 0x05, 0xde, 0x85, 0xfd, 0x32, - 0xd0, 0x94, 0xf4, 0xff, 0x3a, 0x40, 0xbe, 0x30, 0xa1, 0x16, 0x4c, 0x5c, 0x50, 0x91, 0xdc, 0x8e, - 0xa5, 0x0b, 0x3d, 0xce, 0x92, 0x65, 0x81, 0xc6, 0x80, 0x2c, 0x4d, 0x72, 0x08, 0xa3, 0x98, 0xe5, - 0x8a, 0xa6, 0x39, 0x0a, 0xed, 0x37, 0x38, 0x9b, 0x62, 0xb1, 0x0b, 0xce, 0x84, 0x5a, 0xae, 0x57, - 0x11, 0x0a, 0x4d, 0x77, 0x14, 0xd6, 0x14, 0xff, 0x3b, 0x8c, 0x1b, 0x3d, 0xd9, 0xf1, 0x0f, 0x61, - 0xc4, 0x2b, 0xf9, 0xe3, 0xdc, 0x36, 0xd6, 0x14, 0xaf, 0x15, 0xdf, 0xdb, 0x2a, 0xfe, 0x16, 0xdc, - 0xf7, 0x34, 0x8f, 0x31, 0xdb, 0x31, 0xf6, 0xad, 0xfe, 0xc1, 0x7f, 0x05, 0x64, 0x59, 0xb2, 0x90, - 0x57, 0xdd, 0x4d, 0x00, 0xae, 0x08, 0x99, 0x45, 0xf6, 0xc3, 0x9a, 0x72, 0xfc, 0xaf, 0x05, 0xfd, - 0x79, 0x79, 0xf1, 0x24, 0x80, 0x76, 0x71, 0x03, 0xe4, 0xc0, 0x1c, 0x4c, 0x50, 0xdd, 0xb1, 0x37, - 0xb6, 0x52, 0xe3, 0x46, 0x9e, 0x43, 0xeb, 0x14, 0x77, 0x86, 0x13, 0x2b, 0xd5, 0x0f, 0xe5, 0x35, - 0x74, 0xcd, 0x9e, 0xc9, 0x3d, 0xeb, 0x6d, 0xdc, 0x87, 0x77, 0xff, 0x9a, 0x6a, 0xd3, 0xe6, 0x30, - 0xa8, 0x41, 0x21, 0x0f, 0x6d, 0xd4, 0x36, 0x28, 0xcf, 0xdb, 0xe5, 0xb2, 0x55, 0x4e, 0xe0, 0x60, - 0x0b, 0x30, 0x79, 0x62, 0x13, 0x6e, 0x42, 0xef, 0x0d, 0x6d, 0x80, 0xfe, 0xb4, 0xc9, 0x1b, 0xd8, - 0x2f, 0xc6, 0xaf, 0x30, 0x93, 0x86, 0xdf, 0x2b, 0x5b, 0xdb, 0xb1, 0x87, 0x17, 0x30, 0x5e, 0x30, - 0x11, 0xe3, 0x42, 0xb0, 0x5c, 0x61, 0x9e, 0x58, 0x10, 0xcd, 0xfc, 0x86, 0x15, 0x75, 0xb5, 0xf1, - 0xf2, 0x32, 0x00, 0x00, 0xff, 0xff, 0x15, 0xd4, 0x9d, 0x8f, 0x92, 0x04, 0x00, 0x00, + // 533 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xdd, 0x6e, 0xd3, 0x30, + 0x14, 0x56, 0xd6, 0x3f, 0xf5, 0xb4, 0x1d, 0xcc, 0x05, 0x14, 0x02, 0x2a, 0x55, 0x34, 0x44, 0x2f, + 0x50, 0x26, 0x06, 0x5c, 0x70, 0x07, 0x5b, 0xe9, 0x84, 0x40, 0x15, 0x0a, 0x62, 0x37, 0x5c, 0x39, + 0xc9, 0x61, 0x14, 0xd2, 0xd8, 0xd8, 0xae, 0xa6, 0xbe, 0x06, 0xef, 0xc2, 0x73, 0xf0, 0x4a, 0x28, + 0xb1, 0xd3, 0xc4, 0x6b, 0x27, 0xf5, 0xaa, 0x39, 0xdf, 0xf9, 0xf1, 0xf1, 0xf7, 0x7d, 0x2e, 0xdc, + 0x49, 0xa8, 0xfc, 0x11, 0x31, 0x2a, 0x92, 0x80, 0x0b, 0xa6, 0x18, 0x69, 0x15, 0x3f, 0xde, 0xe8, + 0x8a, 0xb1, 0xab, 0x14, 0x4f, 0x8a, 0x28, 0x5a, 0x7d, 0x3f, 0xb9, 0x16, 0x94, 0x73, 0x14, 0x52, + 0x97, 0xf9, 0x1d, 0x68, 0xbd, 0x5f, 0x72, 0xb5, 0xf6, 0xff, 0x3a, 0x00, 0x1f, 0x71, 0x1d, 0xe2, + 0xef, 0x15, 0x4a, 0x45, 0x1e, 0x43, 0x37, 0xa3, 0x4b, 0x94, 0x9c, 0xc6, 0xe8, 0x3a, 0x63, 0x67, + 0xd2, 0x0d, 0x2b, 0x80, 0x8c, 0x00, 0x28, 0x5f, 0x5c, 0xa2, 0x90, 0x0b, 0x96, 0xb9, 0x07, 0x45, + 0xba, 0x86, 0x10, 0x02, 0xcd, 0x5f, 0x8b, 0x2c, 0x71, 0x1b, 0x45, 0xa6, 0xf8, 0xce, 0xb1, 0x7c, + 0x80, 0xdb, 0xd4, 0x58, 0xfe, 0x4d, 0xde, 0xc1, 0x20, 0xa5, 0x11, 0xa6, 0x5f, 0x30, 0xc5, 0x58, + 0x31, 0xe1, 0xb6, 0xc6, 0xce, 0xa4, 0x77, 0xfa, 0x28, 0xd0, 0x5b, 0x07, 0xe5, 0xd6, 0xc1, 0xd9, + 0x5a, 0xa1, 0xbc, 0xa4, 0xe9, 0x0a, 0x43, 0xbb, 0xc3, 0x9f, 0x40, 0xff, 0xd3, 0x42, 0xaa, 0x10, + 0x25, 0x67, 0x99, 0x44, 0xe2, 0x42, 0x87, 0x45, 0x3f, 0x31, 0x56, 0xd2, 0x75, 0xc6, 0x8d, 0x49, + 0x3f, 0x2c, 0x43, 0xff, 0x29, 0xf4, 0x2e, 0xb0, 0x2a, 0x7c, 0x00, 0x6d, 0x9d, 0x29, 0xae, 0xd7, + 0x0f, 0x4d, 0xe4, 0x3f, 0x83, 0xc1, 0x57, 0x9e, 0x50, 0x85, 0x25, 0x15, 0xb7, 0x15, 0xde, 0x85, + 0xc3, 0xb2, 0x50, 0x8f, 0xcc, 0x5b, 0xcf, 0x05, 0xee, 0xd7, 0x5a, 0x16, 0x9a, 0xd6, 0x3f, 0x0e, + 0x90, 0xcf, 0x4c, 0xa8, 0x19, 0x13, 0xd7, 0x54, 0x24, 0xfb, 0xc9, 0xe0, 0x42, 0x87, 0xb3, 0x64, + 0x9e, 0xb3, 0xaa, 0x35, 0x28, 0x43, 0x72, 0x0c, 0x83, 0x98, 0x65, 0x8a, 0x2e, 0x32, 0x14, 0x45, + 0x5e, 0x2b, 0x61, 0x83, 0xb9, 0x8c, 0x9c, 0x09, 0x35, 0x5f, 0x2d, 0x23, 0x14, 0x85, 0x30, 0x83, + 0xb0, 0x86, 0xf8, 0xdf, 0x60, 0x68, 0xed, 0x64, 0x98, 0x3b, 0x86, 0x01, 0xaf, 0xe0, 0x0f, 0x53, + 0xb3, 0x98, 0x0d, 0xde, 0x18, 0x7e, 0xb0, 0x35, 0xfc, 0x2d, 0xb8, 0xe7, 0x34, 0x8b, 0x31, 0xdd, + 0x71, 0xed, 0xbd, 0x4e, 0xf0, 0x5f, 0x01, 0x99, 0x97, 0x5c, 0xc8, 0xcd, 0x76, 0x23, 0x80, 0x0d, + 0x43, 0xda, 0x03, 0xdd, 0xb0, 0x86, 0x9c, 0xfe, 0x6b, 0x40, 0x77, 0x5a, 0x3e, 0x16, 0x12, 0x40, + 0x33, 0xb7, 0x0f, 0x39, 0xd2, 0x5e, 0x0b, 0xaa, 0x27, 0xe0, 0x0d, 0x0d, 0x64, 0xd9, 0xeb, 0x39, + 0x34, 0x2e, 0x70, 0x67, 0x39, 0x31, 0x50, 0xdd, 0x63, 0xaf, 0xa1, 0xad, 0x2d, 0x42, 0xee, 0x99, + 0xac, 0x65, 0x2d, 0xef, 0xfe, 0x0d, 0xb4, 0x6a, 0xd3, 0xf6, 0xd8, 0xb4, 0x59, 0xb6, 0xda, 0xb4, + 0xd9, 0x1e, 0x22, 0x53, 0xe8, 0xd5, 0xb8, 0x24, 0x0f, 0x4d, 0xd5, 0x36, 0xbf, 0x9e, 0xb7, 0x2b, + 0x65, 0xa6, 0x9c, 0xc1, 0xd1, 0x96, 0x2e, 0xe4, 0x49, 0x79, 0xe2, 0x2d, 0x8a, 0x79, 0x7d, 0x53, + 0x50, 0xfc, 0x99, 0x90, 0x37, 0x70, 0x98, 0xb3, 0x56, 0xa9, 0x43, 0xac, 0xbc, 0x57, 0xae, 0xb6, + 0x43, 0xbe, 0x17, 0x30, 0x9c, 0x31, 0x11, 0xe3, 0x4c, 0xb0, 0x4c, 0x61, 0x96, 0x18, 0xfe, 0xec, + 0x7e, 0x2b, 0x8a, 0xda, 0x45, 0xf0, 0xf2, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x8f, 0x17, 0xc0, + 0x71, 0x04, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. var _ context.Context -var _ grpc.ClientConn +var _ grpc.ClientConnInterface // 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 +const _ = grpc.SupportPackageIsVersion6 // DashboardClient is the client API for Dashboard service. // @@ -527,6 +605,7 @@ type DashboardClient interface { List(ctx context.Context, in *KeyRequest, opts ...grpc.CallOption) (*ListResponse, error) Get(ctx context.Context, in *KeyRequest, opts ...grpc.CallOption) (*GetResponse, error) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) + Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) PortForward(ctx context.Context, in *PortForwardRequest, opts ...grpc.CallOption) (*PortForwardResponse, error) CancelPortForward(ctx context.Context, in *CancelPortForwardRequest, opts ...grpc.CallOption) (*Empty, error) ListNamespaces(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*NamespacesResponse, error) @@ -534,10 +613,10 @@ type DashboardClient interface { } type dashboardClient struct { - cc *grpc.ClientConn + cc grpc.ClientConnInterface } -func NewDashboardClient(cc *grpc.ClientConn) DashboardClient { +func NewDashboardClient(cc grpc.ClientConnInterface) DashboardClient { return &dashboardClient{cc} } @@ -568,6 +647,15 @@ func (c *dashboardClient) Update(ctx context.Context, in *UpdateRequest, opts .. return out, nil } +func (c *dashboardClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { + out := new(CreateResponse) + err := c.cc.Invoke(ctx, "/proto.Dashboard/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *dashboardClient) PortForward(ctx context.Context, in *PortForwardRequest, opts ...grpc.CallOption) (*PortForwardResponse, error) { out := new(PortForwardResponse) err := c.cc.Invoke(ctx, "/proto.Dashboard/PortForward", in, out, opts...) @@ -609,12 +697,42 @@ type DashboardServer interface { List(context.Context, *KeyRequest) (*ListResponse, error) Get(context.Context, *KeyRequest) (*GetResponse, error) Update(context.Context, *UpdateRequest) (*UpdateResponse, error) + Create(context.Context, *CreateRequest) (*CreateResponse, error) PortForward(context.Context, *PortForwardRequest) (*PortForwardResponse, error) CancelPortForward(context.Context, *CancelPortForwardRequest) (*Empty, error) ListNamespaces(context.Context, *Empty) (*NamespacesResponse, error) ForceFrontendUpdate(context.Context, *Empty) (*Empty, error) } +// UnimplementedDashboardServer can be embedded to have forward compatible implementations. +type UnimplementedDashboardServer struct { +} + +func (*UnimplementedDashboardServer) List(ctx context.Context, req *KeyRequest) (*ListResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method List not implemented") +} +func (*UnimplementedDashboardServer) Get(ctx context.Context, req *KeyRequest) (*GetResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") +} +func (*UnimplementedDashboardServer) Update(ctx context.Context, req *UpdateRequest) (*UpdateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Update not implemented") +} +func (*UnimplementedDashboardServer) Create(ctx context.Context, req *CreateRequest) (*CreateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") +} +func (*UnimplementedDashboardServer) PortForward(ctx context.Context, req *PortForwardRequest) (*PortForwardResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PortForward not implemented") +} +func (*UnimplementedDashboardServer) CancelPortForward(ctx context.Context, req *CancelPortForwardRequest) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method CancelPortForward not implemented") +} +func (*UnimplementedDashboardServer) ListNamespaces(ctx context.Context, req *Empty) (*NamespacesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListNamespaces not implemented") +} +func (*UnimplementedDashboardServer) ForceFrontendUpdate(ctx context.Context, req *Empty) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ForceFrontendUpdate not implemented") +} + func RegisterDashboardServer(s *grpc.Server, srv DashboardServer) { s.RegisterService(&_Dashboard_serviceDesc, srv) } @@ -673,6 +791,24 @@ func _Dashboard_Update_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Dashboard_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DashboardServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Dashboard/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DashboardServer).Create(ctx, req.(*CreateRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _Dashboard_PortForward_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(PortForwardRequest) if err := dec(in); err != nil { @@ -761,6 +897,10 @@ var _Dashboard_serviceDesc = grpc.ServiceDesc{ MethodName: "Update", Handler: _Dashboard_Update_Handler, }, + { + MethodName: "Create", + Handler: _Dashboard_Create_Handler, + }, { MethodName: "PortForward", Handler: _Dashboard_PortForward_Handler, diff --git a/pkg/plugin/api/proto/dashboard.proto b/pkg/plugin/api/proto/dashboard.proto index 7a102c7ef6..73e08da9b1 100644 --- a/pkg/plugin/api/proto/dashboard.proto +++ b/pkg/plugin/api/proto/dashboard.proto @@ -29,6 +29,14 @@ message UpdateResponse { } +message CreateRequest { + bytes object = 1; +} + +message CreateResponse { + +} + message PortForwardRequest { string namespace = 1; string podName = 2; @@ -53,6 +61,7 @@ service Dashboard { rpc List(KeyRequest) returns (ListResponse); rpc Get(KeyRequest) returns (GetResponse); rpc Update(UpdateRequest) returns (UpdateResponse); + rpc Create(CreateRequest) returns (CreateResponse); rpc PortForward(PortForwardRequest) returns (PortForwardResponse); rpc CancelPortForward(CancelPortForwardRequest) returns (Empty); rpc ListNamespaces(Empty) returns (NamespacesResponse); diff --git a/pkg/plugin/api/proto/generate.sh b/pkg/plugin/api/proto/generate.sh index c2fd8b3f60..66f158f0d5 100755 --- a/pkg/plugin/api/proto/generate.sh +++ b/pkg/plugin/api/proto/generate.sh @@ -1,4 +1,9 @@ #!/bin/sh # generate golang for protobuf -protoc -I$GOPATH/src/github.com/vmware-tanzu/octant/vendor -I$GOPATH/src/github.com/vmware-tanzu/octant -I. --go_out=plugins=grpc:. dashboard.proto +# get directory of this script +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +OCTANT_ROOT=${DIR}/../../../.. + +protoc -I${OCTANT_ROOT}/vendor -I${OCTANT_ROOT} -I. --go_out=plugins=grpc:. dashboard.proto + diff --git a/pkg/plugin/api/server.go b/pkg/plugin/api/server.go index c43a0b02c4..80adf5cb2d 100644 --- a/pkg/plugin/api/server.go +++ b/pkg/plugin/api/server.go @@ -7,6 +7,7 @@ package api import ( "context" + "fmt" "github.com/pkg/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -45,6 +46,7 @@ type Service interface { CancelPortForward(ctx context.Context, id string) ListNamespaces(ctx context.Context) (NamespacesResponse, error) Update(ctx context.Context, object *unstructured.Unstructured) error + Create(ctx context.Context, object *unstructured.Unstructured) error ForceFrontendUpdate(ctx context.Context) error } @@ -101,6 +103,10 @@ func (s *GRPCService) Update(ctx context.Context, object *unstructured.Unstructu }) } +func (s *GRPCService) Create(ctx context.Context, object *unstructured.Unstructured) error { + return s.ObjectStore.Create(ctx, object) +} + // PortForward creates a port forward. func (s *GRPCService) PortForward(ctx context.Context, req PortForwardRequest) (PortForwardResponse, error) { pfResponse, err := s.PortForwarder.Create( @@ -221,6 +227,24 @@ func (c *grpcServer) Update(ctx context.Context, in *proto.UpdateRequest) (*prot return &proto.UpdateResponse{}, nil } +// Create creates an object in the cluster. +func (c *grpcServer) Create(ctx context.Context, in *proto.CreateRequest) (*proto.CreateResponse, error) { + object, err := convertToObject(in.Object) + if err != nil { + return nil, err + } + + if object == nil { + return nil, fmt.Errorf("unable to create a nil object") + } + + if err := c.service.Create(ctx, object); err != nil { + return nil, err + } + + return &proto.CreateResponse{}, nil +} + // PortForward creates a port forward. func (c *grpcServer) PortForward(ctx context.Context, in *proto.PortForwardRequest) (*proto.PortForwardResponse, error) { req, err := convertToPortForwardRequest(in) diff --git a/pkg/plugin/dashboard/dashboard.pb.go b/pkg/plugin/dashboard/dashboard.pb.go index eb646477d7..74ff2081f9 100644 --- a/pkg/plugin/dashboard/dashboard.pb.go +++ b/pkg/plugin/dashboard/dashboard.pb.go @@ -8,6 +8,8 @@ import ( fmt "fmt" proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -873,7 +875,9 @@ func init() { proto.RegisterType((*WatchRequest)(nil), "dashboard.WatchRequest") } -func init() { proto.RegisterFile("dashboard.proto", fileDescriptor_9b97678da3a35dfb) } +func init() { + proto.RegisterFile("dashboard.proto", fileDescriptor_9b97678da3a35dfb) +} var fileDescriptor_9b97678da3a35dfb = []byte{ // 871 bytes of a gzipped FileDescriptorProto @@ -936,11 +940,11 @@ var fileDescriptor_9b97678da3a35dfb = []byte{ // Reference imports to suppress errors if they are not otherwise used. var _ context.Context -var _ grpc.ClientConn +var _ grpc.ClientConnInterface // 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 +const _ = grpc.SupportPackageIsVersion6 // PluginClient is the client API for Plugin service. // @@ -959,10 +963,10 @@ type PluginClient interface { } type pluginClient struct { - cc *grpc.ClientConn + cc grpc.ClientConnInterface } -func NewPluginClient(cc *grpc.ClientConn) PluginClient { +func NewPluginClient(cc grpc.ClientConnInterface) PluginClient { return &pluginClient{cc} } @@ -1070,6 +1074,41 @@ type PluginServer interface { WatchDelete(context.Context, *WatchRequest) (*Empty, error) } +// UnimplementedPluginServer can be embedded to have forward compatible implementations. +type UnimplementedPluginServer struct { +} + +func (*UnimplementedPluginServer) Content(ctx context.Context, req *ContentRequest) (*ContentResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Content not implemented") +} +func (*UnimplementedPluginServer) HandleAction(ctx context.Context, req *HandleActionRequest) (*HandleActionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HandleAction not implemented") +} +func (*UnimplementedPluginServer) Navigation(ctx context.Context, req *NavigationRequest) (*NavigationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Navigation not implemented") +} +func (*UnimplementedPluginServer) Register(ctx context.Context, req *RegisterRequest) (*RegisterResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Register not implemented") +} +func (*UnimplementedPluginServer) Print(ctx context.Context, req *ObjectRequest) (*PrintResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Print not implemented") +} +func (*UnimplementedPluginServer) ObjectStatus(ctx context.Context, req *ObjectRequest) (*ObjectStatusResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ObjectStatus not implemented") +} +func (*UnimplementedPluginServer) PrintTab(ctx context.Context, req *ObjectRequest) (*PrintTabResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PrintTab not implemented") +} +func (*UnimplementedPluginServer) WatchAdd(ctx context.Context, req *WatchRequest) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method WatchAdd not implemented") +} +func (*UnimplementedPluginServer) WatchUpdate(ctx context.Context, req *WatchRequest) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method WatchUpdate not implemented") +} +func (*UnimplementedPluginServer) WatchDelete(ctx context.Context, req *WatchRequest) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method WatchDelete not implemented") +} + func RegisterPluginServer(s *grpc.Server, srv PluginServer) { s.RegisterService(&_Plugin_serviceDesc, srv) } diff --git a/pkg/plugin/dashboard/generate.sh b/pkg/plugin/dashboard/generate.sh index c2fd8b3f60..032de75bfb 100755 --- a/pkg/plugin/dashboard/generate.sh +++ b/pkg/plugin/dashboard/generate.sh @@ -1,4 +1,8 @@ #!/bin/sh # generate golang for protobuf -protoc -I$GOPATH/src/github.com/vmware-tanzu/octant/vendor -I$GOPATH/src/github.com/vmware-tanzu/octant -I. --go_out=plugins=grpc:. dashboard.proto +# get directory of this script +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +OCTANT_ROOT=${DIR}/../../.. + +protoc -I${OCTANT_ROOT}/vendor -I${OCTANT_ROOT} -I. --go_out=plugins=grpc:. dashboard.proto diff --git a/pkg/store/fake/mock_store.go b/pkg/store/fake/mock_store.go index 319b56eb25..f696684d3b 100644 --- a/pkg/store/fake/mock_store.go +++ b/pkg/store/fake/mock_store.go @@ -38,6 +38,20 @@ func (m *MockStore) EXPECT() *MockStoreMockRecorder { return m.recorder } +// Create mocks base method +func (m *MockStore) Create(arg0 context.Context, arg1 *unstructured.Unstructured) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Create indicates an expected call of Create +func (mr *MockStoreMockRecorder) Create(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockStore)(nil).Create), arg0, arg1) +} + // Delete mocks base method func (m *MockStore) Delete(arg0 context.Context, arg1 store.Key) error { m.ctrl.T.Helper() diff --git a/pkg/store/store.go b/pkg/store/store.go index 1eb4fa965c..a3a1042e6b 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -37,6 +37,7 @@ type Store interface { RegisterOnUpdate(fn UpdateFn) Update(ctx context.Context, key Key, updater func(*unstructured.Unstructured) error) error IsLoading(ctx context.Context, key Key) bool + Create(ctx context.Context, object *unstructured.Unstructured) error } // Key is a key for the object store.