Skip to content

Commit

Permalink
Add svc discoverer for readreplica svc (#2263)
Browse files Browse the repository at this point in the history
* Add svc discoverer for readreplica svc

* Build with buf

* Rename

* Update configmap

* Removed unnecessary indexing

* Lint

* Remove memo

* Allow apimachinery errors since it is currently used in internal/k8s

* Fix copy of large value inside loop

* Skip unavoidable warning

* fix nits

* Validate option

* Gen tests

* Make read replica svc reconciler more generic

* Make it possible to disable readreplica discoverer

* Fix config test

* rename svcs to rrsvcs

* Update discoverer decoupled from readreplica

* Add extractAPIPorts test

* Add t.Parallel on the top level

* style: format code with Gofumpt and Prettier

This commit fixes the style issues introduced in f0e2e00 according to the output
from Gofumpt and Prettier.

Details: #2263

* rename rrsvcs to services

* style: format code with Gofumpt and Prettier

This commit fixes the style issues introduced in a16b1e5 according to the output
from Gofumpt and Prettier.

Details: #2263

* Add Labels and Annotations field in payload

* Use map type as Labels and Annotations payload

* Add godoc comments

* Disable service controller for now

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
ykadowak and deepsource-autofix[bot] authored Dec 18, 2023
1 parent f0a4be0 commit 9b6217b
Show file tree
Hide file tree
Showing 39 changed files with 5,537 additions and 242 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ linters-settings:
desc: "golang.org/x/sync/semaphore is allowed only by internal/sync/semaphore"
- pkg: "errors"
desc: "errors is allowed only by internal/errors"
- pkg: "k8s.io/apimachinery/pkg/api/errors"
desc: "errors is allowed only by internal/errors"
- pkg: "github.com/cockroachdb/errors"
desc: "errors is allowed only by internal/errors"
- pkg: "github.com/pkg/errors"
Expand Down
90 changes: 86 additions & 4 deletions apis/docs/v1/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,25 @@
- [Filter.Config](#payload-v1-Filter-Config)
- [Filter.Target](#payload-v1-Filter-Target)
- [Info](#payload-v1-Info)
- [Info.Annotations](#payload-v1-Info-Annotations)
- [Info.Annotations.AnnotationsEntry](#payload-v1-Info-Annotations-AnnotationsEntry)
- [Info.CPU](#payload-v1-Info-CPU)
- [Info.IPs](#payload-v1-Info-IPs)
- [Info.Index](#payload-v1-Info-Index)
- [Info.Index.Count](#payload-v1-Info-Index-Count)
- [Info.Index.UUID](#payload-v1-Info-Index-UUID)
- [Info.Index.UUID.Committed](#payload-v1-Info-Index-UUID-Committed)
- [Info.Index.UUID.Uncommitted](#payload-v1-Info-Index-UUID-Uncommitted)
- [Info.Labels](#payload-v1-Info-Labels)
- [Info.Labels.LabelsEntry](#payload-v1-Info-Labels-LabelsEntry)
- [Info.Memory](#payload-v1-Info-Memory)
- [Info.Node](#payload-v1-Info-Node)
- [Info.Nodes](#payload-v1-Info-Nodes)
- [Info.Pod](#payload-v1-Info-Pod)
- [Info.Pods](#payload-v1-Info-Pods)
- [Info.Service](#payload-v1-Info-Service)
- [Info.ServicePort](#payload-v1-Info-ServicePort)
- [Info.Services](#payload-v1-Info-Services)
- [Insert](#payload-v1-Insert)
- [Insert.Config](#payload-v1-Insert-Config)
- [Insert.MultiObjectRequest](#payload-v1-Insert-MultiObjectRequest)
Expand Down Expand Up @@ -208,6 +215,25 @@ Represent the target filter server.

Info related messages.

<a name="payload-v1-Info-Annotations"></a>

### Info.Annotations

Represent the kubernetes annotations.

| Field | Type | Label | Description |
| ----------- | ---------------------------------------------------------------------------------- | -------- | ----------- |
| annotations | [Info.Annotations.AnnotationsEntry](#payload-v1-Info-Annotations-AnnotationsEntry) | repeated | |

<a name="payload-v1-Info-Annotations-AnnotationsEntry"></a>

### Info.Annotations.AnnotationsEntry

| Field | Type | Label | Description |
| ----- | ----------------- | ----- | ----------- |
| key | [string](#string) | | |
| value | [string](#string) | | |

<a name="payload-v1-Info-CPU"></a>

### Info.CPU
Expand Down Expand Up @@ -275,6 +301,25 @@ The uncommitted UUID.
| ----- | ----------------- | ----- | ----------- |
| uuid | [string](#string) | | |

<a name="payload-v1-Info-Labels"></a>

### Info.Labels

Represent the kubernetes labels.

| Field | Type | Label | Description |
| ------ | -------------------------------------------------------------- | -------- | ----------- |
| labels | [Info.Labels.LabelsEntry](#payload-v1-Info-Labels-LabelsEntry) | repeated | |

<a name="payload-v1-Info-Labels-LabelsEntry"></a>

### Info.Labels.LabelsEntry

| Field | Type | Label | Description |
| ----- | ----------------- | ----- | ----------- |
| key | [string](#string) | | |
| value | [string](#string) | | |

<a name="payload-v1-Info-Memory"></a>

### Info.Memory
Expand Down Expand Up @@ -338,6 +383,42 @@ Represent the multiple pod information message.
| ----- | -------------------------------- | -------- | ----------------------------- |
| pods | [Info.Pod](#payload-v1-Info-Pod) | repeated | The multiple pod information. |

<a name="payload-v1-Info-Service"></a>

### Info.Service

Represent the service information message.

| Field | Type | Label | Description |
| ----------- | ------------------------------------------------ | -------- | ------------------------------- |
| name | [string](#string) | | The name of the svc. |
| cluster_ip | [string](#string) | | The cluster ip of the svc. |
| cluster_ips | [string](#string) | repeated | The cluster ips of the svc. |
| ports | [Info.ServicePort](#payload-v1-Info-ServicePort) | repeated | The port of the svc. |
| labels | [Info.Labels](#payload-v1-Info-Labels) | | The labels of the service. |
| annotations | [Info.Annotations](#payload-v1-Info-Annotations) | | The annotations of the service. |

<a name="payload-v1-Info-ServicePort"></a>

### Info.ServicePort

Represets the service port information message.

| Field | Type | Label | Description |
| ----- | ----------------- | ----- | --------------------- |
| name | [string](#string) | | The name of the port. |
| port | [int32](#int32) | | The port number |

<a name="payload-v1-Info-Services"></a>

### Info.Services

Represent the multiple service information message.

| Field | Type | Label | Description |
| -------- | ---------------------------------------- | -------- | --------------------------------- |
| services | [Info.Service](#payload-v1-Info-Service) | repeated | The multiple service information. |

<a name="payload-v1-Insert"></a>

### Insert
Expand Down Expand Up @@ -976,10 +1057,11 @@ Represent the agent sidecar service.

Represent the discoverer service.

| Method Name | Request Type | Response Type | Description |
| ----------- | ---------------------------------------------------------------- | ------------------------------------------------ | ---------------------------------------------------- |
| Pods | [.payload.v1.Discoverer.Request](#payload-v1-Discoverer-Request) | [.payload.v1.Info.Pods](#payload-v1-Info-Pods) | Represent the RPC to get the agent pods information. |
| Nodes | [.payload.v1.Discoverer.Request](#payload-v1-Discoverer-Request) | [.payload.v1.Info.Nodes](#payload-v1-Info-Nodes) | Represent the RPC to get the node information. |
| Method Name | Request Type | Response Type | Description |
| ----------- | ---------------------------------------------------------------- | ------------------------------------------------------ | --------------------------------------------------------- |
| Pods | [.payload.v1.Discoverer.Request](#payload-v1-Discoverer-Request) | [.payload.v1.Info.Pods](#payload-v1-Info-Pods) | Represent the RPC to get the agent pods information. |
| Nodes | [.payload.v1.Discoverer.Request](#payload-v1-Discoverer-Request) | [.payload.v1.Info.Nodes](#payload-v1-Info-Nodes) | Represent the RPC to get the node information. |
| Services | [.payload.v1.Discoverer.Request](#payload-v1-Discoverer-Request) | [.payload.v1.Info.Services](#payload-v1-Info-Services) | Represent the RPC to get the readreplica svc information. |

<a name="v1_filter_egress_egress_filter-proto"></a>

Expand Down
35 changes: 22 additions & 13 deletions apis/grpc/v1/discoverer/discoverer.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions apis/grpc/v1/discoverer/discoverer_vtproto.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type DiscovererClient interface {
Pods(ctx context.Context, in *payload.Discoverer_Request, opts ...grpc.CallOption) (*payload.Info_Pods, error)
// Represent the RPC to get the node information.
Nodes(ctx context.Context, in *payload.Discoverer_Request, opts ...grpc.CallOption) (*payload.Info_Nodes, error)
// Represent the RPC to get the readreplica svc information.
Services(ctx context.Context, in *payload.Discoverer_Request, opts ...grpc.CallOption) (*payload.Info_Services, error)
}

type discovererClient struct {
Expand Down Expand Up @@ -74,6 +76,15 @@ func (c *discovererClient) Nodes(ctx context.Context, in *payload.Discoverer_Req
return out, nil
}

func (c *discovererClient) Services(ctx context.Context, in *payload.Discoverer_Request, opts ...grpc.CallOption) (*payload.Info_Services, error) {
out := new(payload.Info_Services)
err := c.cc.Invoke(ctx, "/discoverer.v1.Discoverer/Services", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}

// DiscovererServer is the server API for Discoverer service.
// All implementations must embed UnimplementedDiscovererServer
// for forward compatibility
Expand All @@ -82,6 +93,8 @@ type DiscovererServer interface {
Pods(context.Context, *payload.Discoverer_Request) (*payload.Info_Pods, error)
// Represent the RPC to get the node information.
Nodes(context.Context, *payload.Discoverer_Request) (*payload.Info_Nodes, error)
// Represent the RPC to get the readreplica svc information.
Services(context.Context, *payload.Discoverer_Request) (*payload.Info_Services, error)
mustEmbedUnimplementedDiscovererServer()
}

Expand All @@ -95,6 +108,9 @@ func (UnimplementedDiscovererServer) Pods(context.Context, *payload.Discoverer_R
func (UnimplementedDiscovererServer) Nodes(context.Context, *payload.Discoverer_Request) (*payload.Info_Nodes, error) {
return nil, status.Errorf(codes.Unimplemented, "method Nodes not implemented")
}
func (UnimplementedDiscovererServer) Services(context.Context, *payload.Discoverer_Request) (*payload.Info_Services, error) {
return nil, status.Errorf(codes.Unimplemented, "method Services not implemented")
}
func (UnimplementedDiscovererServer) mustEmbedUnimplementedDiscovererServer() {}

// UnsafeDiscovererServer may be embedded to opt out of forward compatibility for this service.
Expand Down Expand Up @@ -144,6 +160,24 @@ func _Discoverer_Nodes_Handler(srv interface{}, ctx context.Context, dec func(in
return interceptor(ctx, in, info, handler)
}

func _Discoverer_Services_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(payload.Discoverer_Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DiscovererServer).Services(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/discoverer.v1.Discoverer/Services",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DiscovererServer).Services(ctx, req.(*payload.Discoverer_Request))
}
return interceptor(ctx, in, info, handler)
}

// Discoverer_ServiceDesc is the grpc.ServiceDesc for Discoverer service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
Expand All @@ -159,6 +193,10 @@ var Discoverer_ServiceDesc = grpc.ServiceDesc{
MethodName: "Nodes",
Handler: _Discoverer_Nodes_Handler,
},
{
MethodName: "Services",
Handler: _Discoverer_Services_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "v1/discoverer/discoverer.proto",
Expand Down
Loading

0 comments on commit 9b6217b

Please sign in to comment.