Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Add protoc-gen-go-grpc (#2774)
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Foo <[email protected]>
  • Loading branch information
Sam Foo committed Aug 31, 2021
1 parent 3beb33f commit 7a0374a
Show file tree
Hide file tree
Showing 26 changed files with 1,694 additions and 1,365 deletions.
2 changes: 1 addition & 1 deletion HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* [node 10.15.0 or above](https://nodejs.org/en/)
* [npm 6.4.1 or above](https://www.npmjs.com/get-npm)
* [mockgen](https://github.com/golang/mock) - generating go files used for testing
* [protoc](https://github.com/golang/protobuf) - generate go code compatible with gRPC
* [protoc](https://github.com/protocolbuffers/protobuf) - protobuf compiler

## Quick Start

Expand Down
3 changes: 2 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ func goInstall() {
pkgs := []string{
"github.com/golang/mock/gomock",
"github.com/golang/mock/mockgen",
"github.com/golang/protobuf/protoc-gen-go",
"google.golang.org/protobuf/cmd/protoc-gen-go",
"google.golang.org/grpc/cmd/protoc-gen-go-grpc",
"golang.org/x/tools/cmd/goimports",
}
for _, pkg := range pkgs {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/gobwas/glob v0.2.3
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0
github.com/googleapis/gnostic v0.5.5
Expand Down Expand Up @@ -44,6 +43,7 @@ require (
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/tools v0.1.5
google.golang.org/grpc v1.40.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
google.golang.org/protobuf v1.27.1
k8s.io/api v0.21.3
k8s.io/apiextensions-apiserver v0.21.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,8 @@ google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAG
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/grpc v1.40.0 h1:AGJ0Ih4mHjSeibYkFGh1dD9KJ/eOtZ93I6hoHhukQ5Q=
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 h1:M1YKkFIboKNieVO5DLUEVzQfGwJD30Nv2jfUgzb5UcE=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
18 changes: 7 additions & 11 deletions pkg/plugin/api/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ package api
import (
"fmt"

"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/pkg/errors"
"google.golang.org/protobuf/types/known/timestamppb"
"google.golang.org/protobuf/types/known/wrapperspb"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
Expand All @@ -32,7 +32,7 @@ func convertFromKey(in store.Key) (*proto.KeyRequest, error) {
}

if in.Selector != nil {
keyRequest.LabelSelector = &wrappers.BytesValue{Value: []byte(in.Selector.String())}
keyRequest.LabelSelector = &wrapperspb.BytesValue{Value: []byte(in.Selector.String())}
}

return &keyRequest, nil
Expand Down Expand Up @@ -68,15 +68,14 @@ func convertToKey(in *proto.KeyRequest) (store.Key, error) {
}

func convertFromAlert(alert action.Alert) (*proto.AlertRequest, error) {
expiration, err := ptypes.TimestampProto(*alert.Expiration)
if err != nil {
return &proto.AlertRequest{}, err
if alert.Expiration == nil {
return &proto.AlertRequest{}, errors.New("expiration is nil")
}

alertRequest := proto.AlertRequest{
Type: string(alert.Type),
Message: alert.Message,
Expiration: expiration,
Expiration: timestamppb.New(*alert.Expiration),
}

return &alertRequest, nil
Expand All @@ -87,10 +86,7 @@ func convertToAlert(in *proto.AlertRequest) (action.Alert, error) {
return action.Alert{}, errors.New("alert request is nil")
}

expiration, err := ptypes.Timestamp(in.Expiration)
if err != nil {
return action.Alert{}, err
}
expiration := in.Expiration.AsTime()

alert := action.Alert{
Type: action.AlertType(in.Type),
Expand Down
Loading

0 comments on commit 7a0374a

Please sign in to comment.