Merge pull request #12603 from hashicorp/remove-gogo-pbservice

Remove gogo from pbservice
This commit is contained in:
Eric Haberkorn 2022-03-23 15:35:05 -04:00 committed by GitHub
commit d5c8284d18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 2059 additions and 11130 deletions

View File

@ -16,7 +16,7 @@ type registry struct {
byAuthority map[string]*ServerResolverBuilder byAuthority map[string]*ServerResolverBuilder
} }
func (r *registry) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOption) (resolver.Resolver, error) { func (r *registry) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) {
r.lock.RLock() r.lock.RLock()
defer r.lock.RUnlock() defer r.lock.RUnlock()
res, ok := r.byAuthority[target.Authority] res, ok := r.byAuthority[target.Authority]

View File

@ -85,7 +85,7 @@ func (s *ServerResolverBuilder) ServerForGlobalAddr(globalAddr string) (*metadat
// Build returns a new serverResolver for the given ClientConn. The resolver // Build returns a new serverResolver for the given ClientConn. The resolver
// will keep the ClientConn's state updated based on updates from Serf. // will keep the ClientConn's state updated based on updates from Serf.
func (s *ServerResolverBuilder) Build(target resolver.Target, cc resolver.ClientConn, _ resolver.BuildOption) (resolver.Resolver, error) { func (s *ServerResolverBuilder) Build(target resolver.Target, cc resolver.ClientConn, _ resolver.BuildOptions) (resolver.Resolver, error) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
@ -221,7 +221,6 @@ func (s *ServerResolverBuilder) getDCAddrs(dc string) []resolver.Address {
addrs = append(addrs, resolver.Address{ addrs = append(addrs, resolver.Address{
// NOTE: the address persisted here is only dialable using our custom dialer // NOTE: the address persisted here is only dialable using our custom dialer
Addr: DCPrefix(server.Datacenter, server.Addr.String()), Addr: DCPrefix(server.Datacenter, server.Addr.String()),
Type: resolver.Backend,
ServerName: server.Name, ServerName: server.Name,
}) })
} }
@ -294,14 +293,14 @@ func (r *serverResolver) Close() {
} }
// ResolveNow is not used // ResolveNow is not used
func (*serverResolver) ResolveNow(resolver.ResolveNowOption) {} func (*serverResolver) ResolveNow(options resolver.ResolveNowOptions) {}
type leaderResolver struct { type leaderResolver struct {
globalAddr string globalAddr string
clientConn resolver.ClientConn clientConn resolver.ClientConn
} }
func (l leaderResolver) ResolveNow(resolver.ResolveNowOption) {} func (l leaderResolver) ResolveNow(resolver.ResolveNowOptions) {}
func (l leaderResolver) Close() {} func (l leaderResolver) Close() {}
@ -313,7 +312,6 @@ func (l leaderResolver) updateClientConn() {
{ {
// NOTE: the address persisted here is only dialable using our custom dialer // NOTE: the address persisted here is only dialable using our custom dialer
Addr: l.globalAddr, Addr: l.globalAddr,
Type: resolver.Backend,
ServerName: "leader", ServerName: "leader",
}, },
} }

View File

@ -3,6 +3,8 @@ package subscribe
import ( import (
"context" "context"
"errors" "errors"
"github.com/golang/protobuf/ptypes/duration"
"github.com/hashicorp/consul/proto/pbcommon"
"io" "io"
"net" "net"
"testing" "testing"
@ -154,12 +156,14 @@ func TestServer_Subscribe_IntegrationWithBackend(t *testing.T) {
Port: 8080, Port: 8080,
Weights: &pbservice.Weights{Passing: 1, Warning: 1}, Weights: &pbservice.Weights{Passing: 1, Warning: 1},
// Sad empty state // Sad empty state
Proxy: pbservice.ConnectProxyConfig{ Proxy: &pbservice.ConnectProxyConfig{
MeshGateway: pbservice.MeshGatewayConfig{}, MeshGateway: &pbservice.MeshGatewayConfig{},
Expose: pbservice.ExposeConfig{}, Expose: &pbservice.ExposeConfig{},
TransparentProxy: &pbservice.TransparentProxyConfig{},
}, },
Connect: &pbservice.ServiceConnect{},
RaftIndex: raftIndex(ids, "reg2", "reg2"), RaftIndex: raftIndex(ids, "reg2", "reg2"),
EnterpriseMeta: pbcommongogo.DefaultEnterpriseMeta, EnterpriseMeta: pbcommon.DefaultEnterpriseMeta,
}, },
}, },
}, },
@ -185,12 +189,14 @@ func TestServer_Subscribe_IntegrationWithBackend(t *testing.T) {
Port: 8080, Port: 8080,
Weights: &pbservice.Weights{Passing: 1, Warning: 1}, Weights: &pbservice.Weights{Passing: 1, Warning: 1},
// Sad empty state // Sad empty state
Proxy: pbservice.ConnectProxyConfig{ Proxy: &pbservice.ConnectProxyConfig{
MeshGateway: pbservice.MeshGatewayConfig{}, MeshGateway: &pbservice.MeshGatewayConfig{},
Expose: pbservice.ExposeConfig{}, Expose: &pbservice.ExposeConfig{},
TransparentProxy: &pbservice.TransparentProxyConfig{},
}, },
Connect: &pbservice.ServiceConnect{},
RaftIndex: raftIndex(ids, "reg3", "reg3"), RaftIndex: raftIndex(ids, "reg3", "reg3"),
EnterpriseMeta: pbcommongogo.DefaultEnterpriseMeta, EnterpriseMeta: pbcommon.DefaultEnterpriseMeta,
}, },
}, },
}, },
@ -235,12 +241,14 @@ func TestServer_Subscribe_IntegrationWithBackend(t *testing.T) {
Port: 8080, Port: 8080,
Weights: &pbservice.Weights{Passing: 1, Warning: 1}, Weights: &pbservice.Weights{Passing: 1, Warning: 1},
// Sad empty state // Sad empty state
Proxy: pbservice.ConnectProxyConfig{ Proxy: &pbservice.ConnectProxyConfig{
MeshGateway: pbservice.MeshGatewayConfig{}, MeshGateway: &pbservice.MeshGatewayConfig{},
Expose: pbservice.ExposeConfig{}, Expose: &pbservice.ExposeConfig{},
TransparentProxy: &pbservice.TransparentProxyConfig{},
}, },
Connect: &pbservice.ServiceConnect{},
RaftIndex: raftIndex(ids, "reg3", "reg3"), RaftIndex: raftIndex(ids, "reg3", "reg3"),
EnterpriseMeta: pbcommongogo.DefaultEnterpriseMeta, EnterpriseMeta: pbcommon.DefaultEnterpriseMeta,
}, },
Checks: []*pbservice.HealthCheck{ Checks: []*pbservice.HealthCheck{
{ {
@ -251,7 +259,13 @@ func TestServer_Subscribe_IntegrationWithBackend(t *testing.T) {
ServiceID: "redis1", ServiceID: "redis1",
ServiceName: "redis", ServiceName: "redis",
RaftIndex: raftIndex(ids, "update", "update"), RaftIndex: raftIndex(ids, "update", "update"),
EnterpriseMeta: pbcommongogo.DefaultEnterpriseMeta, EnterpriseMeta: pbcommon.DefaultEnterpriseMeta,
Definition: &pbservice.HealthCheckDefinition{
Interval: &duration.Duration{},
Timeout: &duration.Duration{},
DeregisterCriticalServiceAfter: &duration.Duration{},
TTL: &duration.Duration{},
},
}, },
}, },
}, },
@ -395,8 +409,8 @@ func newCounter() *counter {
return &counter{labels: make(map[string]uint64)} return &counter{labels: make(map[string]uint64)}
} }
func raftIndex(ids *counter, created, modified string) pbcommongogo.RaftIndex { func raftIndex(ids *counter, created, modified string) *pbcommon.RaftIndex {
return pbcommongogo.RaftIndex{ return &pbcommon.RaftIndex{
CreateIndex: ids.For(created), CreateIndex: ids.For(created),
ModifyIndex: ids.For(modified), ModifyIndex: ids.For(modified),
} }
@ -507,11 +521,13 @@ func TestServer_Subscribe_IntegrationWithBackend_ForwardToDC(t *testing.T) {
Port: 8080, Port: 8080,
Weights: &pbservice.Weights{Passing: 1, Warning: 1}, Weights: &pbservice.Weights{Passing: 1, Warning: 1},
// Sad empty state // Sad empty state
Proxy: pbservice.ConnectProxyConfig{ Proxy: &pbservice.ConnectProxyConfig{
MeshGateway: pbservice.MeshGatewayConfig{}, MeshGateway: &pbservice.MeshGatewayConfig{},
Expose: pbservice.ExposeConfig{}, Expose: &pbservice.ExposeConfig{},
TransparentProxy: &pbservice.TransparentProxyConfig{},
}, },
EnterpriseMeta: pbcommongogo.DefaultEnterpriseMeta, Connect: &pbservice.ServiceConnect{},
EnterpriseMeta: pbcommon.DefaultEnterpriseMeta,
RaftIndex: raftIndex(ids, "reg2", "reg2"), RaftIndex: raftIndex(ids, "reg2", "reg2"),
}, },
}, },
@ -538,11 +554,13 @@ func TestServer_Subscribe_IntegrationWithBackend_ForwardToDC(t *testing.T) {
Port: 8080, Port: 8080,
Weights: &pbservice.Weights{Passing: 1, Warning: 1}, Weights: &pbservice.Weights{Passing: 1, Warning: 1},
// Sad empty state // Sad empty state
Proxy: pbservice.ConnectProxyConfig{ Proxy: &pbservice.ConnectProxyConfig{
MeshGateway: pbservice.MeshGatewayConfig{}, MeshGateway: &pbservice.MeshGatewayConfig{},
Expose: pbservice.ExposeConfig{}, Expose: &pbservice.ExposeConfig{},
TransparentProxy: &pbservice.TransparentProxyConfig{},
}, },
EnterpriseMeta: pbcommongogo.DefaultEnterpriseMeta, Connect: &pbservice.ServiceConnect{},
EnterpriseMeta: pbcommon.DefaultEnterpriseMeta,
RaftIndex: raftIndex(ids, "reg3", "reg3"), RaftIndex: raftIndex(ids, "reg3", "reg3"),
}, },
}, },
@ -589,11 +607,13 @@ func TestServer_Subscribe_IntegrationWithBackend_ForwardToDC(t *testing.T) {
RaftIndex: raftIndex(ids, "reg3", "reg3"), RaftIndex: raftIndex(ids, "reg3", "reg3"),
Weights: &pbservice.Weights{Passing: 1, Warning: 1}, Weights: &pbservice.Weights{Passing: 1, Warning: 1},
// Sad empty state // Sad empty state
Proxy: pbservice.ConnectProxyConfig{ Proxy: &pbservice.ConnectProxyConfig{
MeshGateway: pbservice.MeshGatewayConfig{}, MeshGateway: &pbservice.MeshGatewayConfig{},
Expose: pbservice.ExposeConfig{}, Expose: &pbservice.ExposeConfig{},
TransparentProxy: &pbservice.TransparentProxyConfig{},
}, },
EnterpriseMeta: pbcommongogo.DefaultEnterpriseMeta, Connect: &pbservice.ServiceConnect{},
EnterpriseMeta: pbcommon.DefaultEnterpriseMeta,
}, },
Checks: []*pbservice.HealthCheck{ Checks: []*pbservice.HealthCheck{
{ {
@ -604,7 +624,13 @@ func TestServer_Subscribe_IntegrationWithBackend_ForwardToDC(t *testing.T) {
ServiceID: "redis1", ServiceID: "redis1",
ServiceName: "redis", ServiceName: "redis",
RaftIndex: raftIndex(ids, "update", "update"), RaftIndex: raftIndex(ids, "update", "update"),
EnterpriseMeta: pbcommongogo.DefaultEnterpriseMeta, EnterpriseMeta: pbcommon.DefaultEnterpriseMeta,
Definition: &pbservice.HealthCheckDefinition{
Interval: &duration.Duration{},
Timeout: &duration.Duration{},
DeregisterCriticalServiceAfter: &duration.Duration{},
TTL: &duration.Duration{},
},
}, },
}, },
}, },
@ -986,8 +1012,18 @@ func TestNewEventFromSteamEvent(t *testing.T) {
ServiceHealth: &pbsubscribe.ServiceHealthUpdate{ ServiceHealth: &pbsubscribe.ServiceHealthUpdate{
Op: pbsubscribe.CatalogOp_Register, Op: pbsubscribe.CatalogOp_Register,
CheckServiceNode: &pbservice.CheckServiceNode{ CheckServiceNode: &pbservice.CheckServiceNode{
Node: &pbservice.Node{Node: "node1"}, Node: &pbservice.Node{Node: "node1", RaftIndex: &pbcommon.RaftIndex{}},
Service: &pbservice.NodeService{Service: "web1"}, Service: &pbservice.NodeService{
Service: "web1",
Proxy: &pbservice.ConnectProxyConfig{
MeshGateway: &pbservice.MeshGatewayConfig{},
Expose: &pbservice.ExposeConfig{},
TransparentProxy: &pbservice.TransparentProxyConfig{},
},
Connect: &pbservice.ServiceConnect{},
EnterpriseMeta: &pbcommon.EnterpriseMeta{},
RaftIndex: &pbcommon.RaftIndex{},
},
}, },
}, },
}, },
@ -998,8 +1034,18 @@ func TestNewEventFromSteamEvent(t *testing.T) {
ServiceHealth: &pbsubscribe.ServiceHealthUpdate{ ServiceHealth: &pbsubscribe.ServiceHealthUpdate{
Op: pbsubscribe.CatalogOp_Deregister, Op: pbsubscribe.CatalogOp_Deregister,
CheckServiceNode: &pbservice.CheckServiceNode{ CheckServiceNode: &pbservice.CheckServiceNode{
Node: &pbservice.Node{Node: "node2"}, Node: &pbservice.Node{Node: "node2", RaftIndex: &pbcommon.RaftIndex{}},
Service: &pbservice.NodeService{Service: "web1"}, Service: &pbservice.NodeService{
Service: "web1",
Proxy: &pbservice.ConnectProxyConfig{
MeshGateway: &pbservice.MeshGatewayConfig{},
Expose: &pbservice.ExposeConfig{},
TransparentProxy: &pbservice.TransparentProxyConfig{},
},
Connect: &pbservice.ServiceConnect{},
EnterpriseMeta: &pbcommon.EnterpriseMeta{},
RaftIndex: &pbcommon.RaftIndex{},
},
}, },
}, },
}, },
@ -1027,8 +1073,18 @@ func TestNewEventFromSteamEvent(t *testing.T) {
ServiceHealth: &pbsubscribe.ServiceHealthUpdate{ ServiceHealth: &pbsubscribe.ServiceHealthUpdate{
Op: pbsubscribe.CatalogOp_Register, Op: pbsubscribe.CatalogOp_Register,
CheckServiceNode: &pbservice.CheckServiceNode{ CheckServiceNode: &pbservice.CheckServiceNode{
Node: &pbservice.Node{Node: "node1"}, Node: &pbservice.Node{Node: "node1", RaftIndex: &pbcommon.RaftIndex{}},
Service: &pbservice.NodeService{Service: "web1"}, Service: &pbservice.NodeService{
Service: "web1",
Proxy: &pbservice.ConnectProxyConfig{
MeshGateway: &pbservice.MeshGatewayConfig{},
Expose: &pbservice.ExposeConfig{},
TransparentProxy: &pbservice.TransparentProxyConfig{},
},
Connect: &pbservice.ServiceConnect{},
EnterpriseMeta: &pbcommon.EnterpriseMeta{},
RaftIndex: &pbcommon.RaftIndex{},
},
}, },
}, },
}, },

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/hashicorp/consul/proto/pbcommon"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -568,11 +569,11 @@ func newEventServiceHealthRegister(index uint64, nodeNum int, svc string) *pbsub
Op: pbsubscribe.CatalogOp_Register, Op: pbsubscribe.CatalogOp_Register,
CheckServiceNode: &pbservice.CheckServiceNode{ CheckServiceNode: &pbservice.CheckServiceNode{
Node: &pbservice.Node{ Node: &pbservice.Node{
ID: nodeID, ID: string(nodeID),
Node: node, Node: node,
Address: addr, Address: addr,
Datacenter: "dc1", Datacenter: "dc1",
RaftIndex: pbcommongogo.RaftIndex{ RaftIndex: &pbcommon.RaftIndex{
CreateIndex: index, CreateIndex: index,
ModifyIndex: index, ModifyIndex: index,
}, },
@ -581,7 +582,7 @@ func newEventServiceHealthRegister(index uint64, nodeNum int, svc string) *pbsub
ID: svc, ID: svc,
Service: svc, Service: svc,
Port: 8080, Port: 8080,
RaftIndex: pbcommongogo.RaftIndex{ RaftIndex: &pbcommon.RaftIndex{
CreateIndex: index, CreateIndex: index,
ModifyIndex: index, ModifyIndex: index,
}, },
@ -612,7 +613,7 @@ func newEventServiceHealthDeregister(index uint64, nodeNum int, svc string) *pbs
Passing: 1, Passing: 1,
Warning: 1, Warning: 1,
}, },
RaftIndex: pbcommongogo.RaftIndex{ RaftIndex: &pbcommon.RaftIndex{
// The original insertion index since a delete doesn't update // The original insertion index since a delete doesn't update
// this. This magic value came from state store tests where we // this. This magic value came from state store tests where we
// setup at index 10 and then mutate at index 100. It can be // setup at index 10 and then mutate at index 100. It can be

View File

@ -3,11 +3,11 @@ package submatview
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/hashicorp/consul/proto/pbcommon"
"sync" "sync"
"google.golang.org/grpc" "google.golang.org/grpc"
"github.com/hashicorp/consul/proto/pbcommongogo"
"github.com/hashicorp/consul/proto/pbservice" "github.com/hashicorp/consul/proto/pbservice"
"github.com/hashicorp/consul/proto/pbsubscribe" "github.com/hashicorp/consul/proto/pbsubscribe"
"github.com/hashicorp/consul/types" "github.com/hashicorp/consul/types"
@ -116,11 +116,11 @@ func newEventServiceHealthRegister(index uint64, nodeNum int, svc string) *pbsub
Op: pbsubscribe.CatalogOp_Register, Op: pbsubscribe.CatalogOp_Register,
CheckServiceNode: &pbservice.CheckServiceNode{ CheckServiceNode: &pbservice.CheckServiceNode{
Node: &pbservice.Node{ Node: &pbservice.Node{
ID: nodeID, ID: string(nodeID),
Node: node, Node: node,
Address: addr, Address: addr,
Datacenter: "dc1", Datacenter: "dc1",
RaftIndex: pbcommongogo.RaftIndex{ RaftIndex: &pbcommon.RaftIndex{
CreateIndex: index, CreateIndex: index,
ModifyIndex: index, ModifyIndex: index,
}, },
@ -129,7 +129,7 @@ func newEventServiceHealthRegister(index uint64, nodeNum int, svc string) *pbsub
ID: svc, ID: svc,
Service: svc, Service: svc,
Port: 8080, Port: 8080,
RaftIndex: pbcommongogo.RaftIndex{ RaftIndex: &pbcommon.RaftIndex{
CreateIndex: index, CreateIndex: index,
ModifyIndex: index, ModifyIndex: index,
}, },
@ -160,7 +160,7 @@ func newEventServiceHealthDeregister(index uint64, nodeNum int, svc string) *pbs
Passing: 1, Passing: 1,
Warning: 1, Warning: 1,
}, },
RaftIndex: pbcommongogo.RaftIndex{ RaftIndex: &pbcommon.RaftIndex{
// The original insertion index since a delete doesn't update // The original insertion index since a delete doesn't update
// this. This magic value came from state store tests where we // this. This magic value came from state store tests where we
// setup at index 10 and then mutate at index 100. It can be // setup at index 10 and then mutate at index 100. It can be

View File

@ -14,6 +14,12 @@ elif [[ "$FILENAME" =~ .*pbconfig/.* ]]; then
elif [[ "$FILENAME" =~ .*pbautoconf/.* ]]; then elif [[ "$FILENAME" =~ .*pbautoconf/.* ]]; then
echo "$FILENAME no gogo" echo "$FILENAME no gogo"
./build-support/scripts/proto-gen-no-gogo.sh $1 $2 $3 ./build-support/scripts/proto-gen-no-gogo.sh $1 $2 $3
elif [[ "$FILENAME" =~ .*pbservice/.* ]]; then
echo "$FILENAME no gogo"
./build-support/scripts/proto-gen-no-gogo.sh $1 $2 $3
elif [[ "$FILENAME" =~ .*pbsubscribe/.* ]]; then
echo "$FILENAME no gogo"
./build-support/scripts/proto-gen-no-gogo.sh $1 $2 $3
else else
echo "$FILENAME gogo" echo "$FILENAME gogo"
./build-support/scripts/proto-gen.sh $1 $2 $3 ./build-support/scripts/proto-gen.sh $1 $2 $3

2
go.mod
View File

@ -94,7 +94,7 @@ require (
google.golang.org/api v0.9.0 // indirect google.golang.org/api v0.9.0 // indirect
google.golang.org/appengine v1.6.0 // indirect google.golang.org/appengine v1.6.0 // indirect
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55
google.golang.org/grpc v1.25.1 google.golang.org/grpc v1.27.1
gopkg.in/square/go-jose.v2 v2.5.1 gopkg.in/square/go-jose.v2 v2.5.1
gotest.tools/v3 v3.0.3 gotest.tools/v3 v3.0.3
k8s.io/api v0.18.2 k8s.io/api v0.18.2

4
go.sum
View File

@ -130,6 +130,7 @@ github.com/elazarl/go-bindata-assetfs v0.0.0-20160803192304-e1a2a7ec64b0/go.mod
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.5 h1:lRJIqDD8yjV1YyPRqecMdytjDLs2fTXq363aCib5xPU= github.com/envoyproxy/go-control-plane v0.9.5 h1:lRJIqDD8yjV1YyPRqecMdytjDLs2fTXq363aCib5xPU=
github.com/envoyproxy/go-control-plane v0.9.5/go.mod h1:OXl5to++W0ctG+EHWTFUjiypVxC/Y4VLc/KFU+al13s= github.com/envoyproxy/go-control-plane v0.9.5/go.mod h1:OXl5to++W0ctG+EHWTFUjiypVxC/Y4VLc/KFU+al13s=
github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A= github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A=
@ -714,8 +715,9 @@ 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.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1 h1:wdKvqQk7IttEw92GoRyKG2IDrUIpgpj6H6m81yfeMW0=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk=
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -7,7 +7,7 @@ import (
"github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/structs"
) )
var DefaultEnterpriseMeta = EnterpriseMeta{} var DefaultEnterpriseMeta = &EnterpriseMeta{}
func NewEnterpriseMetaFromStructs(_ structs.EnterpriseMeta) *EnterpriseMeta { func NewEnterpriseMetaFromStructs(_ structs.EnterpriseMeta) *EnterpriseMeta {
return &EnterpriseMeta{} return &EnterpriseMeta{}

View File

@ -2,24 +2,28 @@ package pbservice
import ( import (
"github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/proto/pbcommongogo" "github.com/hashicorp/consul/proto/pbcommon"
"github.com/hashicorp/consul/types"
) )
func RaftIndexToStructs(s pbcommongogo.RaftIndex) structs.RaftIndex { type CheckIDType = types.CheckID
type NodeIDType = types.NodeID
func RaftIndexToStructs(s *pbcommon.RaftIndex) structs.RaftIndex {
return structs.RaftIndex{ return structs.RaftIndex{
CreateIndex: s.CreateIndex, CreateIndex: s.CreateIndex,
ModifyIndex: s.ModifyIndex, ModifyIndex: s.ModifyIndex,
} }
} }
func NewRaftIndexFromStructs(s structs.RaftIndex) pbcommongogo.RaftIndex { func NewRaftIndexFromStructs(s structs.RaftIndex) *pbcommon.RaftIndex {
return pbcommongogo.RaftIndex{ return &pbcommon.RaftIndex{
CreateIndex: s.CreateIndex, CreateIndex: s.CreateIndex,
ModifyIndex: s.ModifyIndex, ModifyIndex: s.ModifyIndex,
} }
} }
func MapHeadersToStructs(s map[string]HeaderValue) map[string][]string { func MapHeadersToStructs(s map[string]*HeaderValue) map[string][]string {
t := make(map[string][]string, len(s)) t := make(map[string][]string, len(s))
for k, v := range s { for k, v := range s {
t[k] = v.Value t[k] = v.Value
@ -27,10 +31,10 @@ func MapHeadersToStructs(s map[string]HeaderValue) map[string][]string {
return t return t
} }
func NewMapHeadersFromStructs(t map[string][]string) map[string]HeaderValue { func NewMapHeadersFromStructs(t map[string][]string) map[string]*HeaderValue {
s := make(map[string]HeaderValue, len(t)) s := make(map[string]*HeaderValue, len(t))
for k, v := range t { for k, v := range t {
s[k] = HeaderValue{Value: v} s[k] = &HeaderValue{Value: v}
} }
return s return s
} }
@ -42,23 +46,23 @@ func CheckServiceNodeToStructs(s *CheckServiceNode) (*structs.CheckServiceNode,
} }
var t structs.CheckServiceNode var t structs.CheckServiceNode
if s.Node != nil { if s.Node != nil {
n := NodeToStructs(*s.Node) n := new(structs.Node)
t.Node = &n NodeToStructs(s.Node, n)
t.Node = n
} }
if s.Service != nil { if s.Service != nil {
r := NodeServiceToStructs(*s.Service) r := new(structs.NodeService)
t.Service = &r NodeServiceToStructs(s.Service, r)
t.Service = r
} }
t.Checks = make(structs.HealthChecks, len(s.Checks)) t.Checks = make(structs.HealthChecks, len(s.Checks))
for i, c := range s.Checks { for i, c := range s.Checks {
if c == nil { if c == nil {
continue continue
} }
h, err := HealthCheckToStructs(*c) h := new(structs.HealthCheck)
if err != nil { HealthCheckToStructs(c, h)
return &t, err t.Checks[i] = h
}
t.Checks[i] = &h
} }
return &t, nil return &t, nil
} }
@ -70,20 +74,23 @@ func NewCheckServiceNodeFromStructs(t *structs.CheckServiceNode) *CheckServiceNo
} }
var s CheckServiceNode var s CheckServiceNode
if t.Node != nil { if t.Node != nil {
n := NewNodeFromStructs(*t.Node) n := new(Node)
s.Node = &n NodeFromStructs(t.Node, n)
s.Node = n
} }
if t.Service != nil { if t.Service != nil {
r := NewNodeServiceFromStructs(*t.Service) r := new(NodeService)
s.Service = &r NodeServiceFromStructs(t.Service, r)
s.Service = r
} }
s.Checks = make([]*HealthCheck, len(t.Checks)) s.Checks = make([]*HealthCheck, len(t.Checks))
for i, c := range t.Checks { for i, c := range t.Checks {
if c == nil { if c == nil {
continue continue
} }
h := NewHealthCheckFromStructs(*c) h := new(HealthCheck)
s.Checks[i] = &h HealthCheckFromStructs(c, h)
s.Checks[i] = h
} }
return &s return &s
} }
@ -111,7 +118,7 @@ func NewWeightsPtrFromStructs(t *structs.Weights) *Weights {
} }
// TODO: handle this with mog // TODO: handle this with mog
func MapStringServiceAddressToStructs(s map[string]ServiceAddress) map[string]structs.ServiceAddress { func MapStringServiceAddressToStructs(s map[string]*ServiceAddress) map[string]structs.ServiceAddress {
t := make(map[string]structs.ServiceAddress, len(s)) t := make(map[string]structs.ServiceAddress, len(s))
for k, v := range s { for k, v := range s {
t[k] = structs.ServiceAddress{Address: v.Address, Port: int(v.Port)} t[k] = structs.ServiceAddress{Address: v.Address, Port: int(v.Port)}
@ -120,64 +127,70 @@ func MapStringServiceAddressToStructs(s map[string]ServiceAddress) map[string]st
} }
// TODO: handle this with mog // TODO: handle this with mog
func NewMapStringServiceAddressFromStructs(t map[string]structs.ServiceAddress) map[string]ServiceAddress { func NewMapStringServiceAddressFromStructs(t map[string]structs.ServiceAddress) map[string]*ServiceAddress {
s := make(map[string]ServiceAddress, len(t)) s := make(map[string]*ServiceAddress, len(t))
for k, v := range t { for k, v := range t {
s[k] = ServiceAddress{Address: v.Address, Port: int32(v.Port)} s[k] = &ServiceAddress{Address: v.Address, Port: int32(v.Port)}
} }
return s return s
} }
// TODO: handle this with mog // TODO: handle this with mog
func ExposePathSliceToStructs(s []ExposePath) []structs.ExposePath { func ExposePathSliceToStructs(s []*ExposePath) []structs.ExposePath {
t := make([]structs.ExposePath, len(s)) t := make([]structs.ExposePath, len(s))
for i, v := range s { for i, v := range s {
t[i] = ExposePathToStructs(v) e := new(structs.ExposePath)
ExposePathToStructs(v, e)
t[i] = *e
} }
return t return t
} }
// TODO: handle this with mog // TODO: handle this with mog
func NewExposePathSliceFromStructs(t []structs.ExposePath) []ExposePath { func NewExposePathSliceFromStructs(t []structs.ExposePath) []*ExposePath {
s := make([]ExposePath, len(t)) s := make([]*ExposePath, len(t))
for i, v := range t { for i, v := range t {
s[i] = NewExposePathFromStructs(v) ep := new(ExposePath)
ExposePathFromStructs(&v, ep)
s[i] = ep
} }
return s return s
} }
// TODO: handle this with mog // TODO: handle this with mog
func UpstreamsToStructs(s []Upstream) structs.Upstreams { func UpstreamsToStructs(s []*Upstream) structs.Upstreams {
t := make(structs.Upstreams, len(s)) t := make(structs.Upstreams, len(s))
for i, v := range s { for i, v := range s {
t[i] = UpstreamToStructs(v) u := new(structs.Upstream)
UpstreamToStructs(v, u)
t[i] = *u
} }
return t return t
} }
// TODO: handle this with mog // TODO: handle this with mog
func NewUpstreamsFromStructs(t structs.Upstreams) []Upstream { func NewUpstreamsFromStructs(t structs.Upstreams) []*Upstream {
s := make([]Upstream, len(t)) s := make([]*Upstream, len(t))
for i, v := range t { for i, v := range t {
s[i] = NewUpstreamFromStructs(v) u := new(Upstream)
UpstreamFromStructs(&v, u)
s[i] = u
} }
return s return s
} }
// TODO: handle this with mog // TODO: handle this with mog
func CheckTypesToStructs(s []*CheckType) (structs.CheckTypes, error) { func CheckTypesToStructs(s []*CheckType) structs.CheckTypes {
t := make(structs.CheckTypes, len(s)) t := make(structs.CheckTypes, len(s))
for i, v := range s { for i, v := range s {
if v == nil { if v == nil {
continue continue
} }
newV, err := CheckTypeToStructs(*v) c := new(structs.CheckType)
if err != nil { CheckTypeToStructs(v, c)
return t, err t[i] = c
} }
t[i] = &newV return t
}
return t, nil
} }
// TODO: handle this with mog // TODO: handle this with mog
@ -187,8 +200,9 @@ func NewCheckTypesFromStructs(t structs.CheckTypes) []*CheckType {
if v == nil { if v == nil {
continue continue
} }
newV := NewCheckTypeFromStructs(*v) newV := new(CheckType)
s[i] = &newV CheckTypeFromStructs(v, newV)
s[i] = newV
} }
return s return s
} }
@ -198,8 +212,9 @@ func ConnectProxyConfigPtrToStructs(s *ConnectProxyConfig) *structs.ConnectProxy
if s == nil { if s == nil {
return nil return nil
} }
t := ConnectProxyConfigToStructs(*s) c := new(structs.ConnectProxyConfig)
return &t ConnectProxyConfigToStructs(s, c)
return c
} }
// TODO: handle this with mog // TODO: handle this with mog
@ -207,8 +222,9 @@ func NewConnectProxyConfigPtrFromStructs(t *structs.ConnectProxyConfig) *Connect
if t == nil { if t == nil {
return nil return nil
} }
s := NewConnectProxyConfigFromStructs(*t) cp := new(ConnectProxyConfig)
return &s ConnectProxyConfigFromStructs(t, cp)
return cp
} }
// TODO: handle this with mog // TODO: handle this with mog
@ -216,8 +232,9 @@ func ServiceConnectPtrToStructs(s *ServiceConnect) *structs.ServiceConnect {
if s == nil { if s == nil {
return nil return nil
} }
t := ServiceConnectToStructs(*s) sc := new(structs.ServiceConnect)
return &t ServiceConnectToStructs(s, sc)
return sc
} }
// TODO: handle this with mog // TODO: handle this with mog
@ -225,8 +242,9 @@ func NewServiceConnectPtrFromStructs(t *structs.ServiceConnect) *ServiceConnect
if t == nil { if t == nil {
return nil return nil
} }
s := NewServiceConnectFromStructs(*t) sc := new(ServiceConnect)
return &s ServiceConnectFromStructs(t, sc)
return sc
} }
// TODO: handle this with mog // TODO: handle this with mog
@ -234,11 +252,9 @@ func ServiceDefinitionPtrToStructs(s *ServiceDefinition) *structs.ServiceDefinit
if s == nil { if s == nil {
return nil return nil
} }
t, err := ServiceDefinitionToStructs(*s) sd := new(structs.ServiceDefinition)
if err != nil { ServiceDefinitionToStructs(s, sd)
return nil return sd
}
return &t
} }
// TODO: handle this with mog // TODO: handle this with mog
@ -246,6 +262,7 @@ func NewServiceDefinitionPtrFromStructs(t *structs.ServiceDefinition) *ServiceDe
if t == nil { if t == nil {
return nil return nil
} }
s := NewServiceDefinitionFromStructs(*t) sd := new(ServiceDefinition)
return &s ServiceDefinitionFromStructs(t, sd)
return sd
} }

View File

@ -5,13 +5,13 @@ package pbservice
import ( import (
"github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/proto/pbcommongogo" "github.com/hashicorp/consul/proto/pbcommon"
) )
func EnterpriseMetaToStructs(_ pbcommongogo.EnterpriseMeta) structs.EnterpriseMeta { func EnterpriseMetaToStructs(_ *pbcommon.EnterpriseMeta) structs.EnterpriseMeta {
return structs.EnterpriseMeta{} return structs.EnterpriseMeta{}
} }
func NewEnterpriseMetaFromStructs(_ structs.EnterpriseMeta) pbcommongogo.EnterpriseMeta { func NewEnterpriseMetaFromStructs(_ structs.EnterpriseMeta) *pbcommon.EnterpriseMeta {
return pbcommongogo.EnterpriseMeta{} return &pbcommon.EnterpriseMeta{}
} }

View File

@ -4,7 +4,8 @@ import (
fmt "fmt" fmt "fmt"
"reflect" "reflect"
types "github.com/gogo/protobuf/types" //TODO(gogo-remove): remove the types alias
types "github.com/golang/protobuf/ptypes/struct"
) )
// ProtobufTypesStructToMapStringInterface converts a protobuf/types.Struct into a // ProtobufTypesStructToMapStringInterface converts a protobuf/types.Struct into a

View File

@ -2,14 +2,13 @@
package pbservice package pbservice
import ( import "github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/proto/pbutil"
)
func CheckTypeToStructs(s CheckType) (structs.CheckType, error) { func CheckTypeToStructs(s *CheckType, t *structs.CheckType) {
var t structs.CheckType if s == nil {
t.CheckID = s.CheckID return
}
t.CheckID = CheckIDType(s.CheckID)
t.Name = s.Name t.Name = s.Name
t.Status = s.Status t.Status = s.Status
t.Notes = s.Notes t.Notes = s.Notes
@ -21,12 +20,7 @@ func CheckTypeToStructs(s CheckType) (structs.CheckType, error) {
t.Method = s.Method t.Method = s.Method
t.Body = s.Body t.Body = s.Body
t.TCP = s.TCP t.TCP = s.TCP
interval, err := pbutil.DurationFromProto(&s.Interval) t.Interval = structs.DurationFromProto(s.Interval)
if err != nil {
return t, err
}
t.Interval = interval
t.AliasNode = s.AliasNode t.AliasNode = s.AliasNode
t.AliasService = s.AliasService t.AliasService = s.AliasService
t.DockerContainerID = s.DockerContainerID t.DockerContainerID = s.DockerContainerID
@ -35,32 +29,21 @@ func CheckTypeToStructs(s CheckType) (structs.CheckType, error) {
t.GRPCUseTLS = s.GRPCUseTLS t.GRPCUseTLS = s.GRPCUseTLS
t.TLSServerName = s.TLSServerName t.TLSServerName = s.TLSServerName
t.TLSSkipVerify = s.TLSSkipVerify t.TLSSkipVerify = s.TLSSkipVerify
timeout, err := pbutil.DurationFromProto(&s.Timeout) t.Timeout = structs.DurationFromProto(s.Timeout)
if err != nil { t.TTL = structs.DurationFromProto(s.TTL)
return t, err
}
t.Timeout = timeout
ttl, err := pbutil.DurationFromProto(&s.TTL)
if err != nil {
return t, err
}
t.TTL = ttl
t.SuccessBeforePassing = int(s.SuccessBeforePassing) t.SuccessBeforePassing = int(s.SuccessBeforePassing)
t.FailuresBeforeCritical = int(s.FailuresBeforeCritical)
t.FailuresBeforeWarning = int(s.FailuresBeforeWarning) t.FailuresBeforeWarning = int(s.FailuresBeforeWarning)
t.FailuresBeforeCritical = int(s.FailuresBeforeCritical)
t.ProxyHTTP = s.ProxyHTTP t.ProxyHTTP = s.ProxyHTTP
t.ProxyGRPC = s.ProxyGRPC t.ProxyGRPC = s.ProxyGRPC
deregisterCriticalServiceAfter, err := pbutil.DurationFromProto(&s.DeregisterCriticalServiceAfter) t.DeregisterCriticalServiceAfter = structs.DurationFromProto(s.DeregisterCriticalServiceAfter)
if err != nil {
return t, err
}
t.DeregisterCriticalServiceAfter = deregisterCriticalServiceAfter
t.OutputMaxSize = int(s.OutputMaxSize) t.OutputMaxSize = int(s.OutputMaxSize)
return t, nil
} }
func NewCheckTypeFromStructs(t structs.CheckType) CheckType { func CheckTypeFromStructs(t *structs.CheckType, s *CheckType) {
var s CheckType if s == nil {
s.CheckID = t.CheckID return
}
s.CheckID = string(t.CheckID)
s.Name = t.Name s.Name = t.Name
s.Status = t.Status s.Status = t.Status
s.Notes = t.Notes s.Notes = t.Notes
@ -72,7 +55,7 @@ func NewCheckTypeFromStructs(t structs.CheckType) CheckType {
s.Method = t.Method s.Method = t.Method
s.Body = t.Body s.Body = t.Body
s.TCP = t.TCP s.TCP = t.TCP
s.Interval = *pbutil.DurationToProto(t.Interval) s.Interval = structs.DurationToProto(t.Interval)
s.AliasNode = t.AliasNode s.AliasNode = t.AliasNode
s.AliasService = t.AliasService s.AliasService = t.AliasService
s.DockerContainerID = t.DockerContainerID s.DockerContainerID = t.DockerContainerID
@ -81,21 +64,22 @@ func NewCheckTypeFromStructs(t structs.CheckType) CheckType {
s.GRPCUseTLS = t.GRPCUseTLS s.GRPCUseTLS = t.GRPCUseTLS
s.TLSServerName = t.TLSServerName s.TLSServerName = t.TLSServerName
s.TLSSkipVerify = t.TLSSkipVerify s.TLSSkipVerify = t.TLSSkipVerify
s.Timeout = *pbutil.DurationToProto(t.Timeout) s.Timeout = structs.DurationToProto(t.Timeout)
s.TTL = *pbutil.DurationToProto(t.TTL) s.TTL = structs.DurationToProto(t.TTL)
s.SuccessBeforePassing = int32(t.SuccessBeforePassing) s.SuccessBeforePassing = int32(t.SuccessBeforePassing)
s.FailuresBeforeCritical = int32(t.FailuresBeforeCritical)
s.FailuresBeforeWarning = int32(t.FailuresBeforeWarning) s.FailuresBeforeWarning = int32(t.FailuresBeforeWarning)
s.FailuresBeforeCritical = int32(t.FailuresBeforeCritical)
s.ProxyHTTP = t.ProxyHTTP s.ProxyHTTP = t.ProxyHTTP
s.ProxyGRPC = t.ProxyGRPC s.ProxyGRPC = t.ProxyGRPC
s.DeregisterCriticalServiceAfter = *pbutil.DurationToProto(t.DeregisterCriticalServiceAfter) s.DeregisterCriticalServiceAfter = structs.DurationToProto(t.DeregisterCriticalServiceAfter)
s.OutputMaxSize = int32(t.OutputMaxSize) s.OutputMaxSize = int32(t.OutputMaxSize)
return s
} }
func HealthCheckToStructs(s HealthCheck) (structs.HealthCheck, error) { func HealthCheckToStructs(s *HealthCheck, t *structs.HealthCheck) {
var t structs.HealthCheck if s == nil {
return
}
t.Node = s.Node t.Node = s.Node
t.CheckID = s.CheckID t.CheckID = CheckIDType(s.CheckID)
t.Name = s.Name t.Name = s.Name
t.Status = s.Status t.Status = s.Status
t.Notes = s.Notes t.Notes = s.Notes
@ -104,22 +88,21 @@ func HealthCheckToStructs(s HealthCheck) (structs.HealthCheck, error) {
t.ServiceName = s.ServiceName t.ServiceName = s.ServiceName
t.ServiceTags = s.ServiceTags t.ServiceTags = s.ServiceTags
t.Type = s.Type t.Type = s.Type
t.ExposedPort = int(s.ExposedPort)
definition, err := HealthCheckDefinitionToStructs(s.Definition)
if err != nil {
return t, err
}
t.Definition = definition
t.EnterpriseMeta = EnterpriseMetaToStructs(s.EnterpriseMeta)
t.RaftIndex = RaftIndexToStructs(s.RaftIndex)
t.Interval = s.Interval t.Interval = s.Interval
t.Timeout = s.Timeout t.Timeout = s.Timeout
return t, nil t.ExposedPort = int(s.ExposedPort)
if s.Definition != nil {
HealthCheckDefinitionToStructs(s.Definition, &t.Definition)
}
t.EnterpriseMeta = EnterpriseMetaToStructs(s.EnterpriseMeta)
t.RaftIndex = RaftIndexToStructs(s.RaftIndex)
}
func HealthCheckFromStructs(t *structs.HealthCheck, s *HealthCheck) {
if s == nil {
return
} }
func NewHealthCheckFromStructs(t structs.HealthCheck) HealthCheck {
var s HealthCheck
s.Node = t.Node s.Node = t.Node
s.CheckID = t.CheckID s.CheckID = string(t.CheckID)
s.Name = t.Name s.Name = t.Name
s.Status = t.Status s.Status = t.Status
s.Notes = t.Notes s.Notes = t.Notes
@ -128,16 +111,21 @@ func NewHealthCheckFromStructs(t structs.HealthCheck) HealthCheck {
s.ServiceName = t.ServiceName s.ServiceName = t.ServiceName
s.ServiceTags = t.ServiceTags s.ServiceTags = t.ServiceTags
s.Type = t.Type s.Type = t.Type
s.ExposedPort = int32(t.ExposedPort)
s.Definition = NewHealthCheckDefinitionFromStructs(t.Definition)
s.EnterpriseMeta = NewEnterpriseMetaFromStructs(t.EnterpriseMeta)
s.RaftIndex = NewRaftIndexFromStructs(t.RaftIndex)
s.Interval = t.Interval s.Interval = t.Interval
s.Timeout = t.Timeout s.Timeout = t.Timeout
return s s.ExposedPort = int32(t.ExposedPort)
{
var x HealthCheckDefinition
HealthCheckDefinitionFromStructs(&t.Definition, &x)
s.Definition = &x
}
s.EnterpriseMeta = NewEnterpriseMetaFromStructs(t.EnterpriseMeta)
s.RaftIndex = NewRaftIndexFromStructs(t.RaftIndex)
}
func HealthCheckDefinitionToStructs(s *HealthCheckDefinition, t *structs.HealthCheckDefinition) {
if s == nil {
return
} }
func HealthCheckDefinitionToStructs(s HealthCheckDefinition) (structs.HealthCheckDefinition, error) {
var t structs.HealthCheckDefinition
t.HTTP = s.HTTP t.HTTP = s.HTTP
t.TLSServerName = s.TLSServerName t.TLSServerName = s.TLSServerName
t.TLSSkipVerify = s.TLSSkipVerify t.TLSSkipVerify = s.TLSSkipVerify
@ -147,22 +135,10 @@ func HealthCheckDefinitionToStructs(s HealthCheckDefinition) (structs.HealthChec
t.TCP = s.TCP t.TCP = s.TCP
t.H2PING = s.H2PING t.H2PING = s.H2PING
t.H2PingUseTLS = s.H2PingUseTLS t.H2PingUseTLS = s.H2PingUseTLS
interval, err := pbutil.DurationFromProto(&s.Interval) t.Interval = structs.DurationFromProto(s.Interval)
if err != nil {
return t, err
}
t.Interval = interval
t.OutputMaxSize = uint(s.OutputMaxSize) t.OutputMaxSize = uint(s.OutputMaxSize)
timeout, err := pbutil.DurationFromProto(&s.Timeout) t.Timeout = structs.DurationFromProto(s.Timeout)
if err != nil { t.DeregisterCriticalServiceAfter = structs.DurationFromProto(s.DeregisterCriticalServiceAfter)
return t, err
}
t.Timeout = timeout
deregisterCriticalServiceAfter, err := pbutil.DurationFromProto(&s.DeregisterCriticalServiceAfter)
if err != nil {
return t, err
}
t.DeregisterCriticalServiceAfter = deregisterCriticalServiceAfter
t.ScriptArgs = s.ScriptArgs t.ScriptArgs = s.ScriptArgs
t.DockerContainerID = s.DockerContainerID t.DockerContainerID = s.DockerContainerID
t.Shell = s.Shell t.Shell = s.Shell
@ -170,15 +146,12 @@ func HealthCheckDefinitionToStructs(s HealthCheckDefinition) (structs.HealthChec
t.GRPCUseTLS = s.GRPCUseTLS t.GRPCUseTLS = s.GRPCUseTLS
t.AliasNode = s.AliasNode t.AliasNode = s.AliasNode
t.AliasService = s.AliasService t.AliasService = s.AliasService
ttl, err := pbutil.DurationFromProto(&s.TTL) t.TTL = structs.DurationFromProto(s.TTL)
if err != nil {
return t, err
} }
t.TTL = ttl func HealthCheckDefinitionFromStructs(t *structs.HealthCheckDefinition, s *HealthCheckDefinition) {
return t, nil if s == nil {
return
} }
func NewHealthCheckDefinitionFromStructs(t structs.HealthCheckDefinition) HealthCheckDefinition {
var s HealthCheckDefinition
s.HTTP = t.HTTP s.HTTP = t.HTTP
s.TLSServerName = t.TLSServerName s.TLSServerName = t.TLSServerName
s.TLSSkipVerify = t.TLSSkipVerify s.TLSSkipVerify = t.TLSSkipVerify
@ -188,10 +161,10 @@ func NewHealthCheckDefinitionFromStructs(t structs.HealthCheckDefinition) Health
s.TCP = t.TCP s.TCP = t.TCP
s.H2PING = t.H2PING s.H2PING = t.H2PING
s.H2PingUseTLS = t.H2PingUseTLS s.H2PingUseTLS = t.H2PingUseTLS
s.Interval = *pbutil.DurationToProto(t.Interval) s.Interval = structs.DurationToProto(t.Interval)
s.OutputMaxSize = uint32(t.OutputMaxSize) s.OutputMaxSize = uint32(t.OutputMaxSize)
s.Timeout = *pbutil.DurationToProto(t.Timeout) s.Timeout = structs.DurationToProto(t.Timeout)
s.DeregisterCriticalServiceAfter = *pbutil.DurationToProto(t.DeregisterCriticalServiceAfter) s.DeregisterCriticalServiceAfter = structs.DurationToProto(t.DeregisterCriticalServiceAfter)
s.ScriptArgs = t.ScriptArgs s.ScriptArgs = t.ScriptArgs
s.DockerContainerID = t.DockerContainerID s.DockerContainerID = t.DockerContainerID
s.Shell = t.Shell s.Shell = t.Shell
@ -199,6 +172,5 @@ func NewHealthCheckDefinitionFromStructs(t structs.HealthCheckDefinition) Health
s.GRPCUseTLS = t.GRPCUseTLS s.GRPCUseTLS = t.GRPCUseTLS
s.AliasNode = t.AliasNode s.AliasNode = t.AliasNode
s.AliasService = t.AliasService s.AliasService = t.AliasService
s.TTL = *pbutil.DurationToProto(t.TTL) s.TTL = structs.DurationToProto(t.TTL)
return s
} }

File diff suppressed because it is too large Load Diff

View File

@ -5,15 +5,7 @@ package pbservice;
option go_package = "github.com/hashicorp/consul/proto/pbservice"; option go_package = "github.com/hashicorp/consul/proto/pbservice";
import "google/protobuf/duration.proto"; import "google/protobuf/duration.proto";
import "proto/pbcommongogo/common.proto"; import "proto/pbcommon/common.proto";
// This fake import path is replaced by the build script with a versioned path
import "gogoproto/gogo.proto";
option (gogoproto.goproto_unkeyed_all) = false;
option (gogoproto.goproto_unrecognized_all) = false;
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.goproto_sizecache_all) = false;
// HealthCheck represents a single check on a given node // HealthCheck represents a single check on a given node
// //
@ -24,7 +16,8 @@ option (gogoproto.goproto_sizecache_all) = false;
// name=Structs // name=Structs
message HealthCheck { message HealthCheck {
string Node = 1; string Node = 1;
string CheckID = 2 [(gogoproto.casttype) = "github.com/hashicorp/consul/types.CheckID"]; // mog: func-to=CheckIDType func-from=string
string CheckID = 2;
string Name = 3; string Name = 3;
string Status = 4; // The current check status string Status = 4; // The current check status
string Notes = 5; // Additional notes with the status string Notes = 5; // Additional notes with the status
@ -34,13 +27,13 @@ message HealthCheck {
repeated string ServiceTags = 9; // optional service tags repeated string ServiceTags = 9; // optional service tags
string Type = 12; // Check type: http/ttl/tcp/etc string Type = 12; // Check type: http/ttl/tcp/etc
HealthCheckDefinition Definition = 10 [(gogoproto.nullable) = false]; HealthCheckDefinition Definition = 10;
// mog: func-to=RaftIndexToStructs func-from=NewRaftIndexFromStructs // mog: func-to=RaftIndexToStructs func-from=NewRaftIndexFromStructs
commongogo.RaftIndex RaftIndex = 11 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; common.RaftIndex RaftIndex = 11;
// mog: func-to=EnterpriseMetaToStructs func-from=NewEnterpriseMetaFromStructs // mog: func-to=EnterpriseMetaToStructs func-from=NewEnterpriseMetaFromStructs
commongogo.EnterpriseMeta EnterpriseMeta = 13 [(gogoproto.nullable) = false]; common.EnterpriseMeta EnterpriseMeta = 13;
// mog: func-to=int func-from=int32 // mog: func-to=int func-from=int32
int32 ExposedPort = 14; int32 ExposedPort = 14;
@ -66,19 +59,19 @@ message HealthCheckDefinition {
bool TLSSkipVerify = 2; bool TLSSkipVerify = 2;
// mog: func-to=MapHeadersToStructs func-from=NewMapHeadersFromStructs // mog: func-to=MapHeadersToStructs func-from=NewMapHeadersFromStructs
map<string, HeaderValue> Header = 3 [(gogoproto.nullable) = false]; map<string, HeaderValue> Header = 3;
string Method = 4; string Method = 4;
string Body = 18; string Body = 18;
string TCP = 5; string TCP = 5;
google.protobuf.Duration Interval = 6 // mog: func-to=structs.DurationFromProto func-from=structs.DurationToProto
[(gogoproto.nullable) = false]; google.protobuf.Duration Interval = 6;
// mog: func-to=uint func-from=uint32 // mog: func-to=uint func-from=uint32
uint32 OutputMaxSize = 9; uint32 OutputMaxSize = 9;
google.protobuf.Duration Timeout = 7 // mog: func-to=structs.DurationFromProto func-from=structs.DurationToProto
[(gogoproto.nullable) = false]; google.protobuf.Duration Timeout = 7;
google.protobuf.Duration DeregisterCriticalServiceAfter = 8 // mog: func-to=structs.DurationFromProto func-from=structs.DurationToProto
[(gogoproto.nullable) = false]; google.protobuf.Duration DeregisterCriticalServiceAfter = 8;
repeated string ScriptArgs = 10; repeated string ScriptArgs = 10;
string DockerContainerID = 11; string DockerContainerID = 11;
string Shell = 12; string Shell = 12;
@ -88,8 +81,8 @@ message HealthCheckDefinition {
bool GRPCUseTLS = 14; bool GRPCUseTLS = 14;
string AliasNode = 15; string AliasNode = 15;
string AliasService = 16; string AliasService = 16;
google.protobuf.Duration TTL = 17 // mog: func-to=structs.DurationFromProto func-from=structs.DurationToProto
[(gogoproto.nullable) = false]; google.protobuf.Duration TTL = 17;
} }
// CheckType is used to create either the CheckMonitor or the CheckTTL. // CheckType is used to create either the CheckMonitor or the CheckTTL.
@ -105,7 +98,8 @@ message HealthCheckDefinition {
// output=healthcheck.gen.go // output=healthcheck.gen.go
// name=Structs // name=Structs
message CheckType { message CheckType {
string CheckID = 1 [(gogoproto.casttype) = "github.com/hashicorp/consul/types.CheckID"]; // mog: func-to=CheckIDType func-from=string
string CheckID = 1;
string Name = 2; string Name = 2;
string Status = 3; string Status = 3;
string Notes = 4; string Notes = 4;
@ -113,12 +107,12 @@ message CheckType {
repeated string ScriptArgs = 5; repeated string ScriptArgs = 5;
string HTTP = 6; string HTTP = 6;
// mog: func-to=MapHeadersToStructs func-from=NewMapHeadersFromStructs // mog: func-to=MapHeadersToStructs func-from=NewMapHeadersFromStructs
map<string, HeaderValue> Header = 20 [(gogoproto.nullable) = false]; map<string, HeaderValue> Header = 20;
string Method = 7; string Method = 7;
string Body = 26; string Body = 26;
string TCP = 8; string TCP = 8;
google.protobuf.Duration Interval = 9 // mog: func-to=structs.DurationFromProto func-from=structs.DurationToProto
[(gogoproto.nullable) = false]; google.protobuf.Duration Interval = 9;
string AliasNode = 10; string AliasNode = 10;
string AliasService = 11; string AliasService = 11;
@ -130,10 +124,10 @@ message CheckType {
bool GRPCUseTLS = 15; bool GRPCUseTLS = 15;
string TLSServerName = 27; string TLSServerName = 27;
bool TLSSkipVerify = 16; bool TLSSkipVerify = 16;
google.protobuf.Duration Timeout = 17 // mog: func-to=structs.DurationFromProto func-from=structs.DurationToProto
[(gogoproto.nullable) = false]; google.protobuf.Duration Timeout = 17;
google.protobuf.Duration TTL = 18 // mog: func-to=structs.DurationFromProto func-from=structs.DurationToProto
[(gogoproto.nullable) = false]; google.protobuf.Duration TTL = 18;
// mog: func-to=int func-from=int32 // mog: func-to=int func-from=int32
int32 SuccessBeforePassing = 21; int32 SuccessBeforePassing = 21;
@ -149,8 +143,8 @@ message CheckType {
// DeregisterCriticalServiceAfter, if >0, will cause the associated // DeregisterCriticalServiceAfter, if >0, will cause the associated
// service, if any, to be deregistered if this check is critical for // service, if any, to be deregistered if this check is critical for
// longer than this duration. // longer than this duration.
google.protobuf.Duration DeregisterCriticalServiceAfter = 19 // mog: func-to=structs.DurationFromProto func-from=structs.DurationToProto
[(gogoproto.nullable) = false]; google.protobuf.Duration DeregisterCriticalServiceAfter = 19;
// mog: func-to=int func-from=int32 // mog: func-to=int func-from=int32
int32 OutputMaxSize = 25; int32 OutputMaxSize = 25;

View File

@ -23,14 +23,22 @@ func (m *CheckServiceNode) UniqueID() string {
case m.Node != nil: case m.Node != nil:
builder.WriteString(m.Node.Partition + "/") builder.WriteString(m.Node.Partition + "/")
case m.Service != nil: case m.Service != nil:
builder.WriteString(m.Service.EnterpriseMeta.Partition + "/") partition := ""
if m.Service.EnterpriseMeta != nil {
partition = m.Service.EnterpriseMeta.Partition
}
builder.WriteString(partition + "/")
} }
if m.Node != nil { if m.Node != nil {
builder.WriteString(m.Node.Node + "/") builder.WriteString(m.Node.Node + "/")
} }
if m.Service != nil { if m.Service != nil {
builder.WriteString(m.Service.EnterpriseMeta.Namespace + "/") namespace := ""
if m.Service.EnterpriseMeta != nil {
namespace = m.Service.EnterpriseMeta.Namespace
}
builder.WriteString(namespace + "/")
builder.WriteString(m.Service.ID) builder.WriteString(m.Service.ID)
} }
return builder.String() return builder.String()

View File

@ -5,7 +5,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/hashicorp/consul/proto/pbcommongogo" "github.com/hashicorp/consul/proto/pbcommon"
) )
func TestCheckServiceNode_UniqueID(t *testing.T) { func TestCheckServiceNode_UniqueID(t *testing.T) {
@ -25,7 +25,7 @@ func TestCheckServiceNode_UniqueID(t *testing.T) {
Node: &Node{Node: "the-node-name"}, Node: &Node{Node: "the-node-name"},
Service: &NodeService{ Service: &NodeService{
ID: "the-service-id", ID: "the-service-id",
EnterpriseMeta: pbcommongogo.EnterpriseMeta{Namespace: "the-namespace"}, EnterpriseMeta: &pbcommon.EnterpriseMeta{Namespace: "the-namespace"},
}, },
}, },
expected: "/the-node-name/the-namespace/the-service-id", expected: "/the-node-name/the-namespace/the-service-id",
@ -35,7 +35,7 @@ func TestCheckServiceNode_UniqueID(t *testing.T) {
csn: CheckServiceNode{ csn: CheckServiceNode{
Service: &NodeService{ Service: &NodeService{
ID: "the-service-id", ID: "the-service-id",
EnterpriseMeta: pbcommongogo.EnterpriseMeta{Namespace: "the-namespace"}, EnterpriseMeta: &pbcommon.EnterpriseMeta{Namespace: "the-namespace"},
}, },
}, },
expected: "/the-namespace/the-service-id", expected: "/the-namespace/the-service-id",

View File

@ -2,11 +2,13 @@
package pbservice package pbservice
import structs "github.com/hashicorp/consul/agent/structs" import "github.com/hashicorp/consul/agent/structs"
func NodeToStructs(s Node) structs.Node { func NodeToStructs(s *Node, t *structs.Node) {
var t structs.Node if s == nil {
t.ID = s.ID return
}
t.ID = NodeIDType(s.ID)
t.Node = s.Node t.Node = s.Node
t.Address = s.Address t.Address = s.Address
t.Datacenter = s.Datacenter t.Datacenter = s.Datacenter
@ -14,11 +16,12 @@ func NodeToStructs(s Node) structs.Node {
t.TaggedAddresses = s.TaggedAddresses t.TaggedAddresses = s.TaggedAddresses
t.Meta = s.Meta t.Meta = s.Meta
t.RaftIndex = RaftIndexToStructs(s.RaftIndex) t.RaftIndex = RaftIndexToStructs(s.RaftIndex)
return t
} }
func NewNodeFromStructs(t structs.Node) Node { func NodeFromStructs(t *structs.Node, s *Node) {
var s Node if s == nil {
s.ID = t.ID return
}
s.ID = string(t.ID)
s.Node = t.Node s.Node = t.Node
s.Address = t.Address s.Address = t.Address
s.Datacenter = t.Datacenter s.Datacenter = t.Datacenter
@ -26,11 +29,12 @@ func NewNodeFromStructs(t structs.Node) Node {
s.TaggedAddresses = t.TaggedAddresses s.TaggedAddresses = t.TaggedAddresses
s.Meta = t.Meta s.Meta = t.Meta
s.RaftIndex = NewRaftIndexFromStructs(t.RaftIndex) s.RaftIndex = NewRaftIndexFromStructs(t.RaftIndex)
return s
} }
func NodeServiceToStructs(s NodeService) structs.NodeService { func NodeServiceToStructs(s *NodeService, t *structs.NodeService) {
var t structs.NodeService if s == nil {
t.Kind = s.Kind return
}
t.Kind = structs.ServiceKind(s.Kind)
t.ID = s.ID t.ID = s.ID
t.Service = s.Service t.Service = s.Service
t.Tags = s.Tags t.Tags = s.Tags
@ -41,16 +45,21 @@ func NodeServiceToStructs(s NodeService) structs.NodeService {
t.SocketPath = s.SocketPath t.SocketPath = s.SocketPath
t.Weights = WeightsPtrToStructs(s.Weights) t.Weights = WeightsPtrToStructs(s.Weights)
t.EnableTagOverride = s.EnableTagOverride t.EnableTagOverride = s.EnableTagOverride
t.Proxy = ConnectProxyConfigToStructs(s.Proxy) if s.Proxy != nil {
t.Connect = ServiceConnectToStructs(s.Connect) ConnectProxyConfigToStructs(s.Proxy, &t.Proxy)
}
if s.Connect != nil {
ServiceConnectToStructs(s.Connect, &t.Connect)
}
t.LocallyRegisteredAsSidecar = s.LocallyRegisteredAsSidecar t.LocallyRegisteredAsSidecar = s.LocallyRegisteredAsSidecar
t.EnterpriseMeta = EnterpriseMetaToStructs(s.EnterpriseMeta) t.EnterpriseMeta = EnterpriseMetaToStructs(s.EnterpriseMeta)
t.RaftIndex = RaftIndexToStructs(s.RaftIndex) t.RaftIndex = RaftIndexToStructs(s.RaftIndex)
return t
} }
func NewNodeServiceFromStructs(t structs.NodeService) NodeService { func NodeServiceFromStructs(t *structs.NodeService, s *NodeService) {
var s NodeService if s == nil {
s.Kind = t.Kind return
}
s.Kind = string(t.Kind)
s.ID = t.ID s.ID = t.ID
s.Service = t.Service s.Service = t.Service
s.Tags = t.Tags s.Tags = t.Tags
@ -61,10 +70,17 @@ func NewNodeServiceFromStructs(t structs.NodeService) NodeService {
s.SocketPath = t.SocketPath s.SocketPath = t.SocketPath
s.Weights = NewWeightsPtrFromStructs(t.Weights) s.Weights = NewWeightsPtrFromStructs(t.Weights)
s.EnableTagOverride = t.EnableTagOverride s.EnableTagOverride = t.EnableTagOverride
s.Proxy = NewConnectProxyConfigFromStructs(t.Proxy) {
s.Connect = NewServiceConnectFromStructs(t.Connect) var x ConnectProxyConfig
ConnectProxyConfigFromStructs(&t.Proxy, &x)
s.Proxy = &x
}
{
var x ServiceConnect
ServiceConnectFromStructs(&t.Connect, &x)
s.Connect = &x
}
s.LocallyRegisteredAsSidecar = t.LocallyRegisteredAsSidecar s.LocallyRegisteredAsSidecar = t.LocallyRegisteredAsSidecar
s.EnterpriseMeta = NewEnterpriseMetaFromStructs(t.EnterpriseMeta) s.EnterpriseMeta = NewEnterpriseMetaFromStructs(t.EnterpriseMeta)
s.RaftIndex = NewRaftIndexFromStructs(t.RaftIndex) s.RaftIndex = NewRaftIndexFromStructs(t.RaftIndex)
return s
} }

File diff suppressed because it is too large Load Diff

View File

@ -4,18 +4,10 @@ package pbservice;
option go_package = "github.com/hashicorp/consul/proto/pbservice"; option go_package = "github.com/hashicorp/consul/proto/pbservice";
import "proto/pbcommongogo/common.proto"; import "proto/pbcommon/common.proto";
import "proto/pbservice/healthcheck.proto"; import "proto/pbservice/healthcheck.proto";
import "proto/pbservice/service.proto"; import "proto/pbservice/service.proto";
// This fake import path is replaced by the build script with a versioned path
import "gogoproto/gogo.proto";
option (gogoproto.goproto_unkeyed_all) = false;
option (gogoproto.goproto_unrecognized_all) = false;
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.goproto_sizecache_all) = false;
// CheckServiceNode is used to provide the node, its service // CheckServiceNode is used to provide the node, its service
// definition, as well as a HealthCheck that is associated. // definition, as well as a HealthCheck that is associated.
message CheckServiceNode { message CheckServiceNode {
@ -32,7 +24,8 @@ message CheckServiceNode {
// output=node.gen.go // output=node.gen.go
// name=Structs // name=Structs
message Node { message Node {
string ID = 1 [(gogoproto.casttype) = "github.com/hashicorp/consul/types.NodeID"]; // mog: func-to=NodeIDType func-from=string
string ID = 1;
string Node = 2; string Node = 2;
string Partition = 8; string Partition = 8;
@ -42,7 +35,7 @@ message Node {
map<string, string> Meta = 6; map<string, string> Meta = 6;
// mog: func-to=RaftIndexToStructs func-from=NewRaftIndexFromStructs // mog: func-to=RaftIndexToStructs func-from=NewRaftIndexFromStructs
commongogo.RaftIndex RaftIndex = 7 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; common.RaftIndex RaftIndex = 7;
} }
// NodeService is a service provided by a node // NodeService is a service provided by a node
@ -56,14 +49,15 @@ message NodeService {
// Kind is the kind of service this is. Different kinds of services may // Kind is the kind of service this is. Different kinds of services may
// have differing validation, DNS behavior, etc. An empty kind will default // have differing validation, DNS behavior, etc. An empty kind will default
// to the Default kind. See ServiceKind for the full list of kinds. // to the Default kind. See ServiceKind for the full list of kinds.
string Kind = 1 [(gogoproto.casttype) = "github.com/hashicorp/consul/agent/structs.ServiceKind"]; // mog: func-to=structs.ServiceKind func-from=string
string Kind = 1;
string ID = 2; string ID = 2;
string Service = 3; string Service = 3;
repeated string Tags = 4; repeated string Tags = 4;
string Address = 5; string Address = 5;
// mog: func-to=MapStringServiceAddressToStructs func-from=NewMapStringServiceAddressFromStructs // mog: func-to=MapStringServiceAddressToStructs func-from=NewMapStringServiceAddressFromStructs
map<string, ServiceAddress> TaggedAddresses = 15 [(gogoproto.nullable) = false]; map<string, ServiceAddress> TaggedAddresses = 15;
map<string, string> Meta = 6; map<string, string> Meta = 6;
// mog: func-to=int func-from=int32 // mog: func-to=int func-from=int32
int32 Port = 7; int32 Port = 7;
@ -83,11 +77,11 @@ message NodeService {
// in the other case. ProxyConfig may be a more natural name here, but it's // in the other case. ProxyConfig may be a more natural name here, but it's
// confusing for the UX because one of the fields in ConnectProxyConfig is // confusing for the UX because one of the fields in ConnectProxyConfig is
// also called just "Config" // also called just "Config"
ConnectProxyConfig Proxy = 11 [(gogoproto.nullable) = false]; ConnectProxyConfig Proxy = 11;
// Connect are the Connect settings for a service. This is purposely NOT // Connect are the Connect settings for a service. This is purposely NOT
// a pointer so that we never have to nil-check this. // a pointer so that we never have to nil-check this.
ServiceConnect Connect = 12 [(gogoproto.nullable) = false]; ServiceConnect Connect = 12;
// LocallyRegisteredAsSidecar is private as it is only used by a local agent // LocallyRegisteredAsSidecar is private as it is only used by a local agent
// state to track if the service was registered from a nested sidecar_service // state to track if the service was registered from a nested sidecar_service
@ -109,8 +103,8 @@ message NodeService {
bool LocallyRegisteredAsSidecar = 13; bool LocallyRegisteredAsSidecar = 13;
// mog: func-to=EnterpriseMetaToStructs func-from=NewEnterpriseMetaFromStructs // mog: func-to=EnterpriseMetaToStructs func-from=NewEnterpriseMetaFromStructs
commongogo.EnterpriseMeta EnterpriseMeta = 16 [(gogoproto.nullable) = false]; common.EnterpriseMeta EnterpriseMeta = 16;
// mog: func-to=RaftIndexToStructs func-from=NewRaftIndexFromStructs // mog: func-to=RaftIndexToStructs func-from=NewRaftIndexFromStructs
commongogo.RaftIndex RaftIndex = 14 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; common.RaftIndex RaftIndex = 14;
} }

View File

@ -2,93 +2,123 @@
package pbservice package pbservice
import structs "github.com/hashicorp/consul/agent/structs" import "github.com/hashicorp/consul/agent/structs"
func ConnectProxyConfigToStructs(s ConnectProxyConfig) structs.ConnectProxyConfig { func ConnectProxyConfigToStructs(s *ConnectProxyConfig, t *structs.ConnectProxyConfig) {
var t structs.ConnectProxyConfig if s == nil {
return
}
t.DestinationServiceName = s.DestinationServiceName t.DestinationServiceName = s.DestinationServiceName
t.DestinationServiceID = s.DestinationServiceID t.DestinationServiceID = s.DestinationServiceID
t.LocalServiceAddress = s.LocalServiceAddress t.LocalServiceAddress = s.LocalServiceAddress
t.LocalServicePort = int(s.LocalServicePort) t.LocalServicePort = int(s.LocalServicePort)
t.LocalServiceSocketPath = s.LocalServiceSocketPath t.LocalServiceSocketPath = s.LocalServiceSocketPath
t.Mode = s.Mode t.Mode = structs.ProxyMode(s.Mode)
t.Config = ProtobufTypesStructToMapStringInterface(s.Config) t.Config = ProtobufTypesStructToMapStringInterface(s.Config)
t.Upstreams = UpstreamsToStructs(s.Upstreams) t.Upstreams = UpstreamsToStructs(s.Upstreams)
t.MeshGateway = MeshGatewayConfigToStructs(s.MeshGateway) if s.MeshGateway != nil {
t.Expose = ExposeConfigToStructs(s.Expose) MeshGatewayConfigToStructs(s.MeshGateway, &t.MeshGateway)
t.TransparentProxy = TransparentProxyConfigToStructs(s.TransparentProxy) }
return t if s.Expose != nil {
ExposeConfigToStructs(s.Expose, &t.Expose)
}
if s.TransparentProxy != nil {
TransparentProxyConfigToStructs(s.TransparentProxy, &t.TransparentProxy)
}
}
func ConnectProxyConfigFromStructs(t *structs.ConnectProxyConfig, s *ConnectProxyConfig) {
if s == nil {
return
} }
func NewConnectProxyConfigFromStructs(t structs.ConnectProxyConfig) ConnectProxyConfig {
var s ConnectProxyConfig
s.DestinationServiceName = t.DestinationServiceName s.DestinationServiceName = t.DestinationServiceName
s.DestinationServiceID = t.DestinationServiceID s.DestinationServiceID = t.DestinationServiceID
s.LocalServiceAddress = t.LocalServiceAddress s.LocalServiceAddress = t.LocalServiceAddress
s.LocalServicePort = int32(t.LocalServicePort) s.LocalServicePort = int32(t.LocalServicePort)
s.LocalServiceSocketPath = t.LocalServiceSocketPath s.LocalServiceSocketPath = t.LocalServiceSocketPath
s.Mode = t.Mode s.Mode = string(t.Mode)
s.Config = MapStringInterfaceToProtobufTypesStruct(t.Config) s.Config = MapStringInterfaceToProtobufTypesStruct(t.Config)
s.Upstreams = NewUpstreamsFromStructs(t.Upstreams) s.Upstreams = NewUpstreamsFromStructs(t.Upstreams)
s.MeshGateway = NewMeshGatewayConfigFromStructs(t.MeshGateway) {
s.Expose = NewExposeConfigFromStructs(t.Expose) var x MeshGatewayConfig
s.TransparentProxy = NewTransparentProxyConfigFromStructs(t.TransparentProxy) MeshGatewayConfigFromStructs(&t.MeshGateway, &x)
return s s.MeshGateway = &x
}
{
var x ExposeConfig
ExposeConfigFromStructs(&t.Expose, &x)
s.Expose = &x
}
{
var x TransparentProxyConfig
TransparentProxyConfigFromStructs(&t.TransparentProxy, &x)
s.TransparentProxy = &x
}
}
func ExposeConfigToStructs(s *ExposeConfig, t *structs.ExposeConfig) {
if s == nil {
return
} }
func ExposeConfigToStructs(s ExposeConfig) structs.ExposeConfig {
var t structs.ExposeConfig
t.Checks = s.Checks t.Checks = s.Checks
t.Paths = ExposePathSliceToStructs(s.Paths) t.Paths = ExposePathSliceToStructs(s.Paths)
return t
} }
func NewExposeConfigFromStructs(t structs.ExposeConfig) ExposeConfig { func ExposeConfigFromStructs(t *structs.ExposeConfig, s *ExposeConfig) {
var s ExposeConfig if s == nil {
return
}
s.Checks = t.Checks s.Checks = t.Checks
s.Paths = NewExposePathSliceFromStructs(t.Paths) s.Paths = NewExposePathSliceFromStructs(t.Paths)
return s
} }
func ExposePathToStructs(s ExposePath) structs.ExposePath { func ExposePathToStructs(s *ExposePath, t *structs.ExposePath) {
var t structs.ExposePath if s == nil {
return
}
t.ListenerPort = int(s.ListenerPort) t.ListenerPort = int(s.ListenerPort)
t.Path = s.Path t.Path = s.Path
t.LocalPathPort = int(s.LocalPathPort) t.LocalPathPort = int(s.LocalPathPort)
t.Protocol = s.Protocol t.Protocol = s.Protocol
t.ParsedFromCheck = s.ParsedFromCheck t.ParsedFromCheck = s.ParsedFromCheck
return t
} }
func NewExposePathFromStructs(t structs.ExposePath) ExposePath { func ExposePathFromStructs(t *structs.ExposePath, s *ExposePath) {
var s ExposePath if s == nil {
return
}
s.ListenerPort = int32(t.ListenerPort) s.ListenerPort = int32(t.ListenerPort)
s.Path = t.Path s.Path = t.Path
s.LocalPathPort = int32(t.LocalPathPort) s.LocalPathPort = int32(t.LocalPathPort)
s.Protocol = t.Protocol s.Protocol = t.Protocol
s.ParsedFromCheck = t.ParsedFromCheck s.ParsedFromCheck = t.ParsedFromCheck
return s
} }
func MeshGatewayConfigToStructs(s MeshGatewayConfig) structs.MeshGatewayConfig { func MeshGatewayConfigToStructs(s *MeshGatewayConfig, t *structs.MeshGatewayConfig) {
var t structs.MeshGatewayConfig if s == nil {
t.Mode = s.Mode return
return t
} }
func NewMeshGatewayConfigFromStructs(t structs.MeshGatewayConfig) MeshGatewayConfig { t.Mode = structs.MeshGatewayMode(s.Mode)
var s MeshGatewayConfig }
s.Mode = t.Mode func MeshGatewayConfigFromStructs(t *structs.MeshGatewayConfig, s *MeshGatewayConfig) {
return s if s == nil {
return
}
s.Mode = string(t.Mode)
}
func ServiceConnectToStructs(s *ServiceConnect, t *structs.ServiceConnect) {
if s == nil {
return
} }
func ServiceConnectToStructs(s ServiceConnect) structs.ServiceConnect {
var t structs.ServiceConnect
t.Native = s.Native t.Native = s.Native
t.SidecarService = ServiceDefinitionPtrToStructs(s.SidecarService) t.SidecarService = ServiceDefinitionPtrToStructs(s.SidecarService)
return t
} }
func NewServiceConnectFromStructs(t structs.ServiceConnect) ServiceConnect { func ServiceConnectFromStructs(t *structs.ServiceConnect, s *ServiceConnect) {
var s ServiceConnect if s == nil {
return
}
s.Native = t.Native s.Native = t.Native
s.SidecarService = NewServiceDefinitionPtrFromStructs(t.SidecarService) s.SidecarService = NewServiceDefinitionPtrFromStructs(t.SidecarService)
return s
} }
func ServiceDefinitionToStructs(s ServiceDefinition) (structs.ServiceDefinition, error) { func ServiceDefinitionToStructs(s *ServiceDefinition, t *structs.ServiceDefinition) {
var t structs.ServiceDefinition if s == nil {
t.Kind = s.Kind return
}
t.Kind = structs.ServiceKind(s.Kind)
t.ID = s.ID t.ID = s.ID
t.Name = s.Name t.Name = s.Name
t.Tags = s.Tags t.Tags = s.Tags
@ -97,27 +127,22 @@ func ServiceDefinitionToStructs(s ServiceDefinition) (structs.ServiceDefinition,
t.Meta = s.Meta t.Meta = s.Meta
t.Port = int(s.Port) t.Port = int(s.Port)
t.SocketPath = s.SocketPath t.SocketPath = s.SocketPath
check, err := CheckTypeToStructs(s.Check) if s.Check != nil {
if err != nil { CheckTypeToStructs(s.Check, &t.Check)
return t, err
} }
t.Check = check t.Checks = CheckTypesToStructs(s.Checks)
checks, err := CheckTypesToStructs(s.Checks)
if err != nil {
return t, err
}
t.Checks = checks
t.Weights = WeightsPtrToStructs(s.Weights) t.Weights = WeightsPtrToStructs(s.Weights)
t.Token = s.Token t.Token = s.Token
t.EnableTagOverride = s.EnableTagOverride t.EnableTagOverride = s.EnableTagOverride
t.Proxy = ConnectProxyConfigPtrToStructs(s.Proxy) t.Proxy = ConnectProxyConfigPtrToStructs(s.Proxy)
t.EnterpriseMeta = EnterpriseMetaToStructs(s.EnterpriseMeta) t.EnterpriseMeta = EnterpriseMetaToStructs(s.EnterpriseMeta)
t.Connect = ServiceConnectPtrToStructs(s.Connect) t.Connect = ServiceConnectPtrToStructs(s.Connect)
return t, nil
} }
func NewServiceDefinitionFromStructs(t structs.ServiceDefinition) ServiceDefinition { func ServiceDefinitionFromStructs(t *structs.ServiceDefinition, s *ServiceDefinition) {
var s ServiceDefinition if s == nil {
s.Kind = t.Kind return
}
s.Kind = string(t.Kind)
s.ID = t.ID s.ID = t.ID
s.Name = t.Name s.Name = t.Name
s.Tags = t.Tags s.Tags = t.Tags
@ -126,7 +151,11 @@ func NewServiceDefinitionFromStructs(t structs.ServiceDefinition) ServiceDefinit
s.Meta = t.Meta s.Meta = t.Meta
s.Port = int32(t.Port) s.Port = int32(t.Port)
s.SocketPath = t.SocketPath s.SocketPath = t.SocketPath
s.Check = NewCheckTypeFromStructs(t.Check) {
var x CheckType
CheckTypeFromStructs(&t.Check, &x)
s.Check = &x
}
s.Checks = NewCheckTypesFromStructs(t.Checks) s.Checks = NewCheckTypesFromStructs(t.Checks)
s.Weights = NewWeightsPtrFromStructs(t.Weights) s.Weights = NewWeightsPtrFromStructs(t.Weights)
s.Token = t.Token s.Token = t.Token
@ -134,22 +163,25 @@ func NewServiceDefinitionFromStructs(t structs.ServiceDefinition) ServiceDefinit
s.Proxy = NewConnectProxyConfigPtrFromStructs(t.Proxy) s.Proxy = NewConnectProxyConfigPtrFromStructs(t.Proxy)
s.EnterpriseMeta = NewEnterpriseMetaFromStructs(t.EnterpriseMeta) s.EnterpriseMeta = NewEnterpriseMetaFromStructs(t.EnterpriseMeta)
s.Connect = NewServiceConnectPtrFromStructs(t.Connect) s.Connect = NewServiceConnectPtrFromStructs(t.Connect)
return s
} }
func TransparentProxyConfigToStructs(s TransparentProxyConfig) structs.TransparentProxyConfig { func TransparentProxyConfigToStructs(s *TransparentProxyConfig, t *structs.TransparentProxyConfig) {
var t structs.TransparentProxyConfig if s == nil {
return
}
t.OutboundListenerPort = int(s.OutboundListenerPort) t.OutboundListenerPort = int(s.OutboundListenerPort)
t.DialedDirectly = s.DialedDirectly t.DialedDirectly = s.DialedDirectly
return t
} }
func NewTransparentProxyConfigFromStructs(t structs.TransparentProxyConfig) TransparentProxyConfig { func TransparentProxyConfigFromStructs(t *structs.TransparentProxyConfig, s *TransparentProxyConfig) {
var s TransparentProxyConfig if s == nil {
return
}
s.OutboundListenerPort = int32(t.OutboundListenerPort) s.OutboundListenerPort = int32(t.OutboundListenerPort)
s.DialedDirectly = t.DialedDirectly s.DialedDirectly = t.DialedDirectly
return s
} }
func UpstreamToStructs(s Upstream) structs.Upstream { func UpstreamToStructs(s *Upstream, t *structs.Upstream) {
var t structs.Upstream if s == nil {
return
}
t.DestinationType = s.DestinationType t.DestinationType = s.DestinationType
t.DestinationNamespace = s.DestinationNamespace t.DestinationNamespace = s.DestinationNamespace
t.DestinationPartition = s.DestinationPartition t.DestinationPartition = s.DestinationPartition
@ -160,12 +192,15 @@ func UpstreamToStructs(s Upstream) structs.Upstream {
t.LocalBindSocketPath = s.LocalBindSocketPath t.LocalBindSocketPath = s.LocalBindSocketPath
t.LocalBindSocketMode = s.LocalBindSocketMode t.LocalBindSocketMode = s.LocalBindSocketMode
t.Config = ProtobufTypesStructToMapStringInterface(s.Config) t.Config = ProtobufTypesStructToMapStringInterface(s.Config)
t.MeshGateway = MeshGatewayConfigToStructs(s.MeshGateway) if s.MeshGateway != nil {
t.CentrallyConfigured = s.CentrallyConfigured MeshGatewayConfigToStructs(s.MeshGateway, &t.MeshGateway)
return t }
t.CentrallyConfigured = s.CentrallyConfigured
}
func UpstreamFromStructs(t *structs.Upstream, s *Upstream) {
if s == nil {
return
} }
func NewUpstreamFromStructs(t structs.Upstream) Upstream {
var s Upstream
s.DestinationType = t.DestinationType s.DestinationType = t.DestinationType
s.DestinationNamespace = t.DestinationNamespace s.DestinationNamespace = t.DestinationNamespace
s.DestinationPartition = t.DestinationPartition s.DestinationPartition = t.DestinationPartition
@ -176,7 +211,10 @@ func NewUpstreamFromStructs(t structs.Upstream) Upstream {
s.LocalBindSocketPath = t.LocalBindSocketPath s.LocalBindSocketPath = t.LocalBindSocketPath
s.LocalBindSocketMode = t.LocalBindSocketMode s.LocalBindSocketMode = t.LocalBindSocketMode
s.Config = MapStringInterfaceToProtobufTypesStruct(t.Config) s.Config = MapStringInterfaceToProtobufTypesStruct(t.Config)
s.MeshGateway = NewMeshGatewayConfigFromStructs(t.MeshGateway) {
s.CentrallyConfigured = t.CentrallyConfigured var x MeshGatewayConfig
return s MeshGatewayConfigFromStructs(&t.MeshGateway, &x)
s.MeshGateway = &x
}
s.CentrallyConfigured = t.CentrallyConfigured
} }

File diff suppressed because it is too large Load Diff

View File

@ -5,17 +5,9 @@ package pbservice;
option go_package = "github.com/hashicorp/consul/proto/pbservice"; option go_package = "github.com/hashicorp/consul/proto/pbservice";
import "google/protobuf/struct.proto"; import "google/protobuf/struct.proto";
import "proto/pbcommongogo/common.proto"; import "proto/pbcommon/common.proto";
import "proto/pbservice/healthcheck.proto"; import "proto/pbservice/healthcheck.proto";
// This fake import path is replaced by the build script with a versioned path
import "gogoproto/gogo.proto";
option (gogoproto.goproto_unkeyed_all) = false;
option (gogoproto.goproto_unrecognized_all) = false;
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.goproto_sizecache_all) = false;
// ConnectProxyConfig describes the configuration needed for any proxy managed // ConnectProxyConfig describes the configuration needed for any proxy managed
// or unmanaged. It describes a single logical service's listener and optionally // or unmanaged. It describes a single logical service's listener and optionally
@ -57,25 +49,26 @@ message ConnectProxyConfig {
// Config is the arbitrary configuration data provided with the proxy // Config is the arbitrary configuration data provided with the proxy
// registration. // registration.
// mog: func-to=ProtobufTypesStructToMapStringInterface func-from=MapStringInterfaceToProtobufTypesStruct // mog: func-to=ProtobufTypesStructToMapStringInterface func-from=MapStringInterfaceToProtobufTypesStruct
google.protobuf.Struct Config = 5 [(gogoproto.nullable) = true]; google.protobuf.Struct Config = 5;
// Upstreams describes any upstream dependencies the proxy instance should // Upstreams describes any upstream dependencies the proxy instance should
// setup. // setup.
// mog: func-to=UpstreamsToStructs func-from=NewUpstreamsFromStructs // mog: func-to=UpstreamsToStructs func-from=NewUpstreamsFromStructs
repeated Upstream Upstreams = 6 [(gogoproto.nullable) = false]; repeated Upstream Upstreams = 6;
// MeshGateway defines the mesh gateway configuration for upstreams // MeshGateway defines the mesh gateway configuration for upstreams
MeshGatewayConfig MeshGateway = 7 [(gogoproto.nullable) = false]; MeshGatewayConfig MeshGateway = 7;
// Expose defines whether checks or paths are exposed through the proxy // Expose defines whether checks or paths are exposed through the proxy
ExposeConfig Expose = 8 [(gogoproto.nullable) = false]; ExposeConfig Expose = 8;
// Mode represents how the proxy's inbound and upstream listeners are dialed. // Mode represents how the proxy's inbound and upstream listeners are dialed.
string Mode = 9 [(gogoproto.casttype) = "github.com/hashicorp/consul/agent/structs.ProxyMode"]; // mog: func-to=structs.ProxyMode func-from=string
string Mode = 9;
// TransparentProxy defines configuration for when the proxy is in // TransparentProxy defines configuration for when the proxy is in
// transparent mode. // transparent mode.
TransparentProxyConfig TransparentProxy = 10 [(gogoproto.nullable) = false]; TransparentProxyConfig TransparentProxy = 10;
// LocalServiceSocketPath is the path to the unix domain socket for the local service instance // LocalServiceSocketPath is the path to the unix domain socket for the local service instance
string LocalServiceSocketPath = 11; string LocalServiceSocketPath = 11;
@ -122,10 +115,10 @@ message Upstream {
// It can be used to pass arbitrary configuration for this specific upstream // It can be used to pass arbitrary configuration for this specific upstream
// to the proxy. // to the proxy.
// mog: func-to=ProtobufTypesStructToMapStringInterface func-from=MapStringInterfaceToProtobufTypesStruct // mog: func-to=ProtobufTypesStructToMapStringInterface func-from=MapStringInterfaceToProtobufTypesStruct
google.protobuf.Struct Config = 7 [(gogoproto.nullable) = true]; google.protobuf.Struct Config = 7;
// MeshGateway is the configuration for mesh gateway usage of this upstream // MeshGateway is the configuration for mesh gateway usage of this upstream
MeshGatewayConfig MeshGateway = 8 [(gogoproto.nullable) = false]; MeshGatewayConfig MeshGateway = 8;
// CentrallyConfigured indicates whether the upstream was defined in a proxy // CentrallyConfigured indicates whether the upstream was defined in a proxy
// instance registration or whether it was generated from a config entry. // instance registration or whether it was generated from a config entry.
@ -174,7 +167,7 @@ message ExposeConfig {
// Paths is the list of paths exposed through the proxy. // Paths is the list of paths exposed through the proxy.
// mog: func-to=ExposePathSliceToStructs func-from=NewExposePathSliceFromStructs // mog: func-to=ExposePathSliceToStructs func-from=NewExposePathSliceFromStructs
repeated ExposePath Paths = 2 [(gogoproto.nullable) = false]; repeated ExposePath Paths = 2;
} }
// mog annotation: // mog annotation:
@ -208,7 +201,8 @@ message ExposePath {
// output=service.gen.go // output=service.gen.go
// name=Structs // name=Structs
message MeshGatewayConfig { message MeshGatewayConfig {
string Mode = 1 [(gogoproto.casttype) = "github.com/hashicorp/consul/agent/structs.MeshGatewayMode"]; // mog: func-to=structs.MeshGatewayMode func-from=string
string Mode = 1;
} }
// mog annotation: // mog annotation:
@ -235,19 +229,20 @@ message TransparentProxyConfig {
// output=service.gen.go // output=service.gen.go
// name=Structs // name=Structs
message ServiceDefinition { message ServiceDefinition {
string Kind = 1 [(gogoproto.casttype) = "github.com/hashicorp/consul/agent/structs.ServiceKind"]; // mog: func-to=structs.ServiceKind func-from=string
string Kind = 1;
string ID = 2; string ID = 2;
string Name = 3; string Name = 3;
repeated string Tags = 4; repeated string Tags = 4;
string Address = 5; string Address = 5;
// mog: func-to=MapStringServiceAddressToStructs func-from=NewMapStringServiceAddressFromStructs // mog: func-to=MapStringServiceAddressToStructs func-from=NewMapStringServiceAddressFromStructs
map<string, ServiceAddress> TaggedAddresses = 16 [(gogoproto.nullable) = false]; map<string, ServiceAddress> TaggedAddresses = 16;
map<string, string> Meta = 6; map<string, string> Meta = 6;
// mog: func-to=int func-from=int32 // mog: func-to=int func-from=int32
int32 Port = 7; int32 Port = 7;
// Path for socket // Path for socket
string SocketPath = 18; string SocketPath = 18;
CheckType Check = 8 [(gogoproto.nullable) = false]; CheckType Check = 8;
// mog: func-to=CheckTypesToStructs func-from=NewCheckTypesFromStructs // mog: func-to=CheckTypesToStructs func-from=NewCheckTypesFromStructs
repeated CheckType Checks = 9; repeated CheckType Checks = 9;
// mog: func-to=WeightsPtrToStructs func-from=NewWeightsPtrFromStructs // mog: func-to=WeightsPtrToStructs func-from=NewWeightsPtrFromStructs
@ -269,7 +264,7 @@ message ServiceDefinition {
ConnectProxyConfig Proxy = 14; ConnectProxyConfig Proxy = 14;
// mog: func-to=EnterpriseMetaToStructs func-from=NewEnterpriseMetaFromStructs // mog: func-to=EnterpriseMetaToStructs func-from=NewEnterpriseMetaFromStructs
commongogo.EnterpriseMeta EnterpriseMeta = 17 [(gogoproto.nullable) = false]; common.EnterpriseMeta EnterpriseMeta = 17;
// mog: func-to=ServiceConnectPtrToStructs func-from=NewServiceConnectPtrFromStructs // mog: func-to=ServiceConnectPtrToStructs func-from=NewServiceConnectPtrFromStructs
ServiceConnect Connect = 15; ServiceConnect Connect = 15;

File diff suppressed because it is too large Load Diff