From 190ec3130d6acfe6b63f62e2eaa34f8391dffdb7 Mon Sep 17 00:00:00 2001 From: Evan Hazlett Date: Mon, 7 Oct 2019 13:52:47 -0400 Subject: [PATCH 1/3] add advertise grpc address option Signed-off-by: Evan Hazlett --- README.md | 2 - api/v1/heimdall.pb.go | 198 ++++++++++++++++++++++++++++-------------- api/v1/heimdall.proto | 8 ++ client/join.go | 12 +-- cmd/heimdall/main.go | 6 ++ cmd/heimdall/run.go | 23 ++--- config.go | 2 + server/join.go | 28 ++++++ server/net.go | 7 +- server/node.go | 194 +++++++++++++++++++++++++++-------------- server/peer.go | 61 +++++++------ server/server.go | 78 +++++++++++++---- 12 files changed, 415 insertions(+), 204 deletions(-) diff --git a/README.md b/README.md index 2cfd306..609acdb 100644 --- a/README.md +++ b/README.md @@ -5,5 +5,3 @@ auto-elects in the event of a current master failure. Non-node peers are also s can only access the network but do not provide routing capabilities. ![Heimdall](docs/overview.png) - -# diff --git a/api/v1/heimdall.pb.go b/api/v1/heimdall.pb.go index c1530ab..90e875d 100644 --- a/api/v1/heimdall.pb.go +++ b/api/v1/heimdall.pb.go @@ -32,6 +32,7 @@ type Master struct { ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` GRPCAddress string `protobuf:"bytes,2,opt,name=grpc_address,json=grpcAddress,proto3" json:"grpc_address,omitempty"` RedisURL string `protobuf:"bytes,3,opt,name=redis_url,json=redisUrl,proto3" json:"redis_url,omitempty"` + Peers []*Peer `protobuf:"bytes,5,rep,name=peers,proto3" json:"peers,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -82,9 +83,20 @@ func (m *Master) GetRedisURL() string { return "" } +func (m *Master) GetPeers() []*Peer { + if m != nil { + return m.Peers + } + return nil +} + type JoinRequest struct { ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` ClusterKey string `protobuf:"bytes,2,opt,name=cluster_key,json=clusterKey,proto3" json:"cluster_key,omitempty"` + GRPCAddress string `protobuf:"bytes,3,opt,name=grpc_address,json=grpcAddress,proto3" json:"grpc_address,omitempty"` + EndpointIP string `protobuf:"bytes,4,opt,name=endpoint_ip,json=endpointIp,proto3" json:"endpoint_ip,omitempty"` + EndpointPort uint64 `protobuf:"varint,5,opt,name=endpoint_port,json=endpointPort,proto3" json:"endpoint_port,omitempty"` + InterfaceName string `protobuf:"bytes,6,opt,name=interface_name,json=interfaceName,proto3" json:"interface_name,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -128,8 +140,38 @@ func (m *JoinRequest) GetClusterKey() string { return "" } +func (m *JoinRequest) GetGRPCAddress() string { + if m != nil { + return m.GRPCAddress + } + return "" +} + +func (m *JoinRequest) GetEndpointIP() string { + if m != nil { + return m.EndpointIP + } + return "" +} + +func (m *JoinRequest) GetEndpointPort() uint64 { + if m != nil { + return m.EndpointPort + } + return 0 +} + +func (m *JoinRequest) GetInterfaceName() string { + if m != nil { + return m.InterfaceName + } + return "" +} + type JoinResponse struct { Master *Master `protobuf:"bytes,1,opt,name=master,proto3" json:"master,omitempty"` + Node *Node `protobuf:"bytes,2,opt,name=node,proto3" json:"node,omitempty"` + Peers []*Peer `protobuf:"bytes,3,rep,name=peers,proto3" json:"peers,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -166,6 +208,20 @@ func (m *JoinResponse) GetMaster() *Master { return nil } +func (m *JoinResponse) GetNode() *Node { + if m != nil { + return m.Node + } + return nil +} + +func (m *JoinResponse) GetPeers() []*Peer { + if m != nil { + return m.Peers + } + return nil +} + type ConnectRequest struct { ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -464,6 +520,7 @@ type Node struct { EndpointPort uint64 `protobuf:"varint,5,opt,name=endpoint_port,json=endpointPort,proto3" json:"endpoint_port,omitempty"` GatewayIP string `protobuf:"bytes,6,opt,name=gateway_ip,json=gatewayIp,proto3" json:"gateway_ip,omitempty"` Updated time.Time `protobuf:"bytes,7,opt,name=updated,proto3,stdtime" json:"updated"` + InterfaceName string `protobuf:"bytes,8,opt,name=interface_name,json=interfaceName,proto3" json:"interface_name,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -542,6 +599,13 @@ func (m *Node) GetUpdated() time.Time { return time.Time{} } +func (m *Node) GetInterfaceName() string { + if m != nil { + return m.InterfaceName + } + return "" +} + type NodesRequest struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -967,71 +1031,75 @@ func init() { } var fileDescriptor_b6184fc395da86b1 = []byte{ - // 1014 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0x5d, 0x6f, 0xe3, 0x44, - 0x17, 0x7e, 0x9d, 0xef, 0x1c, 0x27, 0x8d, 0x34, 0x5a, 0xf5, 0xf5, 0x06, 0x21, 0x17, 0xef, 0x05, - 0x59, 0xb4, 0xb2, 0x9b, 0x00, 0xe2, 0x4b, 0x8b, 0x68, 0x9a, 0xdd, 0xc5, 0x14, 0xaa, 0xec, 0x2c, - 0x7b, 0x83, 0x56, 0x0a, 0x6e, 0x3c, 0xa4, 0x6e, 0x9d, 0xcc, 0x60, 0x4f, 0x5a, 0x85, 0x1b, 0x6e, - 0xb9, 0xe4, 0xff, 0x20, 0x71, 0x0d, 0xff, 0x80, 0xab, 0x20, 0xe5, 0x97, 0xa0, 0x19, 0x8f, 0x4d, - 0xd2, 0x36, 0xaa, 0xbb, 0xec, 0x5d, 0xe6, 0xcc, 0x79, 0xce, 0x39, 0x7e, 0xce, 0x73, 0x8e, 0x1d, - 0xf8, 0x78, 0x12, 0xf0, 0xd3, 0xf9, 0x89, 0x3d, 0xa6, 0x53, 0x27, 0xe6, 0x24, 0x0c, 0xbd, 0x88, - 0x45, 0xf4, 0x8c, 0x8c, 0xb9, 0x73, 0x4a, 0x82, 0xa9, 0xef, 0x85, 0xa1, 0xe3, 0xb1, 0xc0, 0xb9, - 0xe8, 0x66, 0x67, 0x9b, 0x45, 0x94, 0x53, 0xf4, 0x4e, 0x40, 0xed, 0x4d, 0x84, 0x9d, 0x79, 0x78, - 0x2c, 0xb0, 0x2f, 0xba, 0xed, 0x7b, 0x13, 0x3a, 0xa1, 0xd2, 0xdb, 0x11, 0xbf, 0x12, 0x60, 0xfb, - 0xad, 0x09, 0xa5, 0x93, 0x90, 0x38, 0xf2, 0x74, 0x32, 0xff, 0xc1, 0x21, 0x53, 0xc6, 0x17, 0xea, - 0xd2, 0xbc, 0x7a, 0xc9, 0x83, 0x29, 0x89, 0xb9, 0x37, 0x65, 0x89, 0x83, 0xf5, 0x33, 0x54, 0xbe, - 0xf1, 0x62, 0x4e, 0x22, 0xb4, 0x0b, 0x85, 0xc0, 0x37, 0xb4, 0x3d, 0xad, 0x53, 0xef, 0x57, 0x56, - 0x4b, 0xb3, 0xe0, 0x0e, 0x70, 0x21, 0xf0, 0x51, 0x0f, 0x1a, 0x93, 0x88, 0x8d, 0x47, 0x9e, 0xef, - 0x47, 0x24, 0x8e, 0x8d, 0x82, 0xf4, 0x68, 0xad, 0x96, 0xa6, 0xfe, 0x0c, 0x0f, 0x0f, 0x0f, 0x12, - 0x33, 0xd6, 0x85, 0x93, 0x3a, 0xa0, 0x87, 0x50, 0x8f, 0x88, 0x1f, 0xc4, 0xa3, 0x79, 0x14, 0x1a, - 0x45, 0x09, 0x68, 0xac, 0x96, 0x66, 0x0d, 0x0b, 0xe3, 0x4b, 0xfc, 0x35, 0xae, 0xc9, 0xeb, 0x97, - 0x51, 0x68, 0x3d, 0x05, 0xfd, 0x2b, 0x1a, 0xcc, 0x30, 0xf9, 0x71, 0x4e, 0x62, 0xbe, 0xb5, 0x0a, - 0x13, 0xf4, 0x71, 0x38, 0x17, 0x85, 0x8e, 0xce, 0xc9, 0x22, 0x29, 0x02, 0x83, 0x32, 0x1d, 0x91, - 0x85, 0xf5, 0x1c, 0x1a, 0x49, 0x9c, 0x98, 0xd1, 0x59, 0x4c, 0xd0, 0x01, 0x54, 0xa6, 0xf2, 0xc1, - 0x64, 0x30, 0xbd, 0xf7, 0xd0, 0xbe, 0x95, 0x60, 0x3b, 0x61, 0x02, 0x2b, 0xa0, 0xd5, 0x81, 0x9d, - 0x43, 0x3a, 0x9b, 0x91, 0x31, 0xbf, 0xa5, 0x3a, 0xeb, 0x2f, 0x0d, 0x5a, 0x99, 0xab, 0x2a, 0xe0, - 0x39, 0x54, 0xcf, 0xc9, 0x82, 0x79, 0x41, 0x5a, 0xc1, 0x7b, 0x39, 0x2a, 0x38, 0x22, 0x8b, 0xa1, - 0x17, 0x44, 0x7d, 0x7d, 0xb5, 0x34, 0xab, 0xea, 0x80, 0xd3, 0x38, 0xc8, 0x80, 0xea, 0x46, 0x17, - 0x70, 0x7a, 0x44, 0x8f, 0xa1, 0xcc, 0x08, 0x89, 0x62, 0xa3, 0xb8, 0x57, 0xec, 0xe8, 0xbd, 0x77, - 0x73, 0xa4, 0x1a, 0x12, 0x12, 0xe1, 0x04, 0x85, 0xee, 0x43, 0xd1, 0x9f, 0xc5, 0x46, 0x69, 0xaf, - 0xd8, 0xa9, 0xf7, 0xab, 0xab, 0xa5, 0x59, 0x1c, 0x1c, 0xbf, 0xc0, 0xc2, 0x66, 0xd9, 0x70, 0xef, - 0x60, 0xce, 0x4f, 0x69, 0x14, 0xfc, 0x44, 0x24, 0xe4, 0x16, 0x2a, 0xf6, 0x61, 0x77, 0x40, 0xbc, - 0xbb, 0x20, 0x0c, 0xd8, 0xcd, 0x32, 0xf8, 0x02, 0x10, 0x2b, 0x84, 0xf5, 0x01, 0xfc, 0xff, 0xda, - 0x8d, 0x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x44, 0x0c, 0x00, 0x00, + // 1076 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x5f, 0x6f, 0xe3, 0x44, + 0x10, 0xc7, 0xf9, 0x9f, 0x49, 0xd3, 0x4a, 0xab, 0x53, 0xf1, 0x05, 0x21, 0x97, 0x9c, 0x10, 0x39, + 0x74, 0xb2, 0xdb, 0x02, 0xe2, 0xcf, 0xe9, 0x10, 0x4d, 0x73, 0x1c, 0xa6, 0x50, 0x85, 0x3d, 0xee, + 0x05, 0x9d, 0x14, 0xdc, 0x78, 0x2e, 0x75, 0xeb, 0xd8, 0x8b, 0xbd, 0x69, 0x15, 0x3e, 0x01, 0x8f, + 0x7c, 0x1f, 0x24, 0x9e, 0x79, 0xe1, 0x9d, 0xa7, 0x20, 0xe5, 0x13, 0xf0, 0xc6, 0x2b, 0xda, 0xf5, + 0xda, 0x97, 0xb4, 0x8d, 0xea, 0xf6, 0x8e, 0xb7, 0xee, 0xec, 0xfc, 0x66, 0x32, 0xbf, 0xdf, 0xcc, + 0xac, 0x0b, 0x9f, 0x8c, 0x3c, 0x7e, 0x3c, 0x39, 0x32, 0x87, 0xe1, 0xd8, 0x8a, 0x39, 0xfa, 0xbe, + 0x13, 0xb1, 0x28, 0x3c, 0xc1, 0x21, 0xb7, 0x8e, 0xd1, 0x1b, 0xbb, 0x8e, 0xef, 0x5b, 0x0e, 0xf3, + 0xac, 0xb3, 0x9d, 0xec, 0x6c, 0xb2, 0x28, 0xe4, 0x21, 0x79, 0xc7, 0x0b, 0xcd, 0x65, 0x84, 0x99, + 0x79, 0x38, 0xcc, 0x33, 0xcf, 0x76, 0x5a, 0x77, 0x46, 0xe1, 0x28, 0x94, 0xde, 0x96, 0xf8, 0x2b, + 0x01, 0xb6, 0xde, 0x1a, 0x85, 0xe1, 0xc8, 0x47, 0x4b, 0x9e, 0x8e, 0x26, 0x2f, 0x2c, 0x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x30, 0xf2, 0x7e, 0x46, 0x09, 0xb9, 0x86, + 0x8a, 0x6d, 0xd8, 0xec, 0xa1, 0x73, 0x13, 0x84, 0x0e, 0x9b, 0x59, 0x06, 0x57, 0x00, 0x62, 0x85, + 0x68, 0x7f, 0x08, 0x6f, 0x5e, 0xba, 0x51, 0xec, 0xde, 0x85, 0xa2, 0xe7, 0xc6, 0xba, 0xf6, 0xf2, + 0x17, 0xdb, 0xbd, 0x98, 0x0a, 0x5b, 0xdb, 0x86, 0x94, 0x39, 0x31, 0x63, 0x2c, 0xf2, 0xce, 0x1c, + 0x8e, 0x72, 0xc6, 0xb4, 0x64, 0xc6, 0x94, 0x49, 0xcc, 0xd8, 0xdb, 0x00, 0x6c, 0x72, 0xe4, 0x7b, + 0xc3, 0x85, 0x19, 0xac, 0x27, 0x96, 0x03, 0x9c, 0xb6, 0xff, 0x29, 0x40, 0x49, 0xf4, 0xd3, 0xca, + 0x21, 0x26, 0x50, 0x12, 0x12, 0x28, 0xa4, 0xfc, 0x7b, 0x51, 0xf8, 0xe2, 0x6b, 0x12, 0xfe, 0xff, + 0x19, 0xeb, 0x07, 0x00, 0x23, 0x87, 0xe3, 0xb9, 0x33, 0x15, 0x41, 0xe5, 0x48, 0x77, 0x9b, 0xf3, + 0x99, 0x51, 0x7f, 0x92, 0x58, 0xed, 0x3e, 0xad, 0x2b, 0x07, 0x9b, 0x91, 0xcf, 0xa1, 0x3a, 0x61, + 0xae, 0xc3, 0xd1, 0xd5, 0xab, 0xb2, 0xac, 0x96, 0x99, 0xec, 0x72, 0x33, 0xdd, 0xe5, 0xe6, 0xf7, + 0xe9, 0x2e, 0xef, 0xd6, 0xfe, 0x98, 0x19, 0x6f, 0xfc, 0xfa, 0xb7, 0xa1, 0xd1, 0x14, 0x74, 0xc5, + 0x12, 0xa9, 0x5d, 0xb5, 0x44, 0xd6, 0x61, 0x4d, 0x30, 0x9e, 0xf5, 0xc0, 0x21, 0x34, 0xd5, 0x59, + 0x29, 0xff, 0x08, 0xca, 0x62, 0xb8, 0x13, 0xed, 0x6f, 0xb0, 0x12, 0x12, 0x94, 0x78, 0x5f, 0x4a, + 0xa2, 0x95, 0x56, 0x4a, 0xba, 0x20, 0x5f, 0xe1, 0xf5, 0xc9, 0xe7, 0xf8, 0x7e, 0x78, 0x8e, 0xee, + 0xc0, 0x63, 0xc9, 0x8c, 0x2a, 0xf9, 0xf6, 0x12, 0xb3, 0xdd, 0x8f, 0x29, 0x28, 0x17, 0x9b, 0xc5, + 0xa4, 0x05, 0xb5, 0x54, 0xa9, 0x44, 0x6c, 0x9a, 0x9d, 0x05, 0x41, 0x4b, 0x43, 0x72, 0x08, 0xcd, + 0xe5, 0xd1, 0xc8, 0x76, 0x81, 0x76, 0xab, 0xad, 0xf7, 0x25, 0x94, 0x69, 0x38, 0xe1, 0x48, 0xee, + 0x41, 0x55, 0x50, 0x36, 0xc8, 0x58, 0x82, 0xf9, 0xcc, 0xa8, 0x08, 0x2e, 0xed, 0x1e, 0xad, 0x88, + 0x2b, 0xdb, 0x15, 0x2b, 0x29, 0x40, 0x7e, 0x1e, 0x46, 0xa7, 0xe9, 0x4a, 0x52, 0xc7, 0xf6, 0x53, + 0x20, 0xfb, 0x11, 0x3a, 0x1c, 0x65, 0xb4, 0x74, 0x09, 0xbc, 0x62, 0x50, 0x13, 0x48, 0x0f, 0x7d, + 0xbc, 0x10, 0x74, 0xc1, 0x5f, 0x5b, 0xf6, 0xdf, 0x80, 0xa6, 0xf4, 0xcc, 0xd8, 0xa2, 0xb0, 0x9e, + 0x1a, 0x14, 0x5d, 0x5f, 0x40, 0x25, 0x92, 0x16, 0xc5, 0x57, 0x27, 0x07, 0x5f, 0x49, 0x76, 0x85, + 0xdb, 0xfd, 0xad, 0x06, 0xb5, 0xaf, 0x94, 0x07, 0x61, 0x50, 0x55, 0x2f, 0x01, 0xd9, 0xc9, 0x11, + 0x69, 0xf9, 0x81, 0x69, 0xed, 0xde, 0x04, 0xa2, 0x0a, 0xf8, 0x11, 0x9a, 0x4b, 0x1b, 0x9a, 0x7c, + 0x9c, 0x23, 0xc8, 0x55, 0x3b, 0xbd, 0xb5, 0x79, 0x69, 0xa2, 0x1f, 0x8b, 0x4f, 0x37, 0xe2, 0xc2, + 0xc6, 0x85, 0x9d, 0x4e, 0x3e, 0xcd, 0x91, 0xe3, 0xea, 0x77, 0x60, 0x65, 0x96, 0x5f, 0x34, 0xd8, + 0xb8, 0xb0, 0xee, 0x73, 0xa5, 0xb9, 0xfa, 0xf1, 0x68, 0x7d, 0x76, 0x1b, 0xa8, 0xa2, 0x74, 0x04, + 0x25, 0xf1, 0x21, 0x43, 0xcc, 0x1c, 0x31, 0x16, 0xbe, 0xf5, 0x5a, 0x56, 0x6e, 0x7f, 0x95, 0x68, + 0x0c, 0x95, 0xa4, 0x1d, 0xc9, 0x76, 0xde, 0xb6, 0xcb, 0x0a, 0xdc, 0xb9, 0x01, 0x42, 0xa5, 0x7b, + 0x0e, 0x8d, 0x85, 0x99, 0x24, 0x1f, 0xe5, 0xe9, 0xb6, 0x4b, 0x33, 0xbc, 0x52, 0xc0, 0xe7, 0xd0, + 0x58, 0x18, 0xce, 0x5c, 0xd1, 0x2f, 0x0f, 0xf3, 0xca, 0xe8, 0x27, 0x50, 0x96, 0x0f, 0x01, 0xb1, + 0x72, 0x6e, 0xfc, 0x8c, 0xa8, 0xed, 0xfc, 0x00, 0xc5, 0xd3, 0x09, 0x94, 0x93, 0xfe, 0xb3, 0x72, + 0x2e, 0xcf, 0x1b, 0xe5, 0x5a, 0xea, 0xb5, 0xae, 0xf9, 0xc3, 0x83, 0xdc, 0xff, 0xa3, 0x3d, 0x3c, + 0xdb, 0x39, 0xaa, 0x48, 0x5e, 0x3e, 0xf8, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x58, 0x29, 0xda, 0xfa, + 0xda, 0x0d, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/api/v1/heimdall.proto b/api/v1/heimdall.proto index 50e5a9d..97d0bdf 100644 --- a/api/v1/heimdall.proto +++ b/api/v1/heimdall.proto @@ -25,15 +25,22 @@ message Master { string id = 1 [(gogoproto.customname) = "ID"]; string grpc_address = 2 [(gogoproto.customname) = "GRPCAddress"]; string redis_url = 3 [(gogoproto.customname) = "RedisURL"]; + repeated Peer peers = 5; } message JoinRequest { string id = 1 [(gogoproto.customname) = "ID"]; string cluster_key = 2; + string grpc_address = 3 [(gogoproto.customname) = "GRPCAddress"]; + string endpoint_ip = 4 [(gogoproto.customname) = "EndpointIP"]; + uint64 endpoint_port = 5; + string interface_name = 6; } message JoinResponse { Master master = 1; + Node node = 2; + repeated Peer peers = 3; } message ConnectRequest { @@ -74,6 +81,7 @@ message Node { uint64 endpoint_port = 5; string gateway_ip = 6 [(gogoproto.customname) = "GatewayIP"]; google.protobuf.Timestamp updated = 7 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + string interface_name = 8; } message NodesRequest {} diff --git a/client/join.go b/client/join.go index ad18ce6..39159d6 100644 --- a/client/join.go +++ b/client/join.go @@ -28,15 +28,7 @@ import ( ) // Join attempts to connect to the peer and returns the master info -func (c *Client) Join(key string) (*v1.Master, error) { +func (c *Client) Join(req *v1.JoinRequest) (*v1.JoinResponse, error) { ctx := context.Background() - resp, err := c.heimdallClient.Join(ctx, &v1.JoinRequest{ - ID: c.id, - ClusterKey: key, - }) - if err != nil { - return nil, err - } - - return resp.Master, nil + return c.heimdallClient.Join(ctx, req) } diff --git a/cmd/heimdall/main.go b/cmd/heimdall/main.go index dc4f779..af7f20c 100644 --- a/cmd/heimdall/main.go +++ b/cmd/heimdall/main.go @@ -60,6 +60,12 @@ func main() { Value: fmt.Sprintf("tcp://%s:%d", heimdall.GetIP(), defaultGRPCPort), EnvVar: "HEIMDALL_GRPC_ADDR", }, + cli.StringFlag{ + Name: "advertise-grpc-address", + Usage: "public advertise grpc address", + Value: fmt.Sprintf("tcp://%s:%d", heimdall.GetIP(), defaultGRPCPort), + EnvVar: "HEIMDALL_ADVERTISE_GRPC_ADDR", + }, cli.StringFlag{ Name: "redis-url, r", Usage: "uri for datastore backend", diff --git a/cmd/heimdall/run.go b/cmd/heimdall/run.go index 1eccbdf..8c51e94 100644 --- a/cmd/heimdall/run.go +++ b/cmd/heimdall/run.go @@ -41,17 +41,18 @@ import ( func runServer(cx *cli.Context) error { cfg := &heimdall.Config{ - ID: cx.String("id"), - GRPCAddress: cx.String("addr"), - GRPCPeerAddress: cx.String("peer"), - ClusterKey: cx.String("cluster-key"), - NodeNetwork: cx.String("node-network"), - PeerNetwork: cx.String("peer-network"), - EndpointIP: cx.String("endpoint-ip"), - EndpointPort: cx.Int("endpoint-port"), - InterfaceName: cx.String("interface-name"), - RedisURL: cx.String("redis-url"), - AdvertiseRedisURL: cx.String("advertise-redis-url"), + ID: cx.String("id"), + GRPCAddress: cx.String("addr"), + AdvertiseGRPCAddress: cx.String("advertise-grpc-address"), + GRPCPeerAddress: cx.String("peer"), + ClusterKey: cx.String("cluster-key"), + NodeNetwork: cx.String("node-network"), + PeerNetwork: cx.String("peer-network"), + EndpointIP: cx.String("endpoint-ip"), + EndpointPort: cx.Int("endpoint-port"), + InterfaceName: cx.String("interface-name"), + RedisURL: cx.String("redis-url"), + AdvertiseRedisURL: cx.String("advertise-redis-url"), } errCh := make(chan error, 1) diff --git a/config.go b/config.go index c8915cd..76c1dd5 100644 --- a/config.go +++ b/config.go @@ -29,6 +29,8 @@ type Config struct { ID string // GRPCAddress is the address for the grpc server GRPCAddress string + // AdvertiseGRPCAddress is the public address for the grpc server + AdvertiseGRPCAddress string // GRPCPeerAddress is the peer address to join GRPCPeerAddress string // ClusterKey is a preshared key for cluster peers diff --git a/server/join.go b/server/join.go index 5de5666..8bbfa82 100644 --- a/server/join.go +++ b/server/join.go @@ -60,7 +60,35 @@ func (s *Server) Join(ctx context.Context, req *v1.JoinRequest) (*v1.JoinRespons return nil, err } + peers, err := s.getPeers(ctx) + if err != nil { + return nil, err + } + + if err := s.ensureNetworkSubnet(ctx, req.ID); err != nil { + return nil, err + } + + node, err := s.getNode(ctx, req.ID) + if err != nil { + if err != redis.ErrNil { + return nil, err + } + n, err := s.createNode(ctx, req) + if err != nil { + return nil, err + } + + if err := s.updatePeerInfo(ctx, req.ID); err != nil { + return nil, err + } + + node = n + } + return &v1.JoinResponse{ Master: &master, + Node: node, + Peers: peers, }, nil } diff --git a/server/net.go b/server/net.go index 20449a9..a766069 100644 --- a/server/net.go +++ b/server/net.go @@ -29,6 +29,7 @@ import ( "strings" "github.com/gomodule/redigo/redis" + "github.com/pkg/errors" ) type subnetRange struct { @@ -37,8 +38,8 @@ type subnetRange struct { Subnet *net.IPNet } -func (s *Server) updateNodeNetwork(ctx context.Context, subnet string) error { - if _, err := s.master(ctx, "SET", s.getNodeNetworkKey(s.cfg.ID), subnet); err != nil { +func (s *Server) updateNodeNetwork(ctx context.Context, id string, subnet string) error { + if _, err := s.master(ctx, "SET", s.getNodeNetworkKey(id), subnet); err != nil { return err } return nil @@ -70,7 +71,7 @@ func (s *Server) getOrAllocatePeerIP(ctx context.Context, id string) (net.IP, *n func (s *Server) getNodeIP(ctx context.Context, id string) (net.IP, *net.IPNet, error) { subnet, err := redis.String(s.local(ctx, "GET", s.getNodeNetworkKey(id))) if err != nil { - return nil, nil, err + return nil, nil, errors.Wrap(err, "error getting node ip") } r, err := parseSubnetRange(subnet) if err != nil { diff --git a/server/node.go b/server/node.go index e8ceba4..c624a35 100644 --- a/server/node.go +++ b/server/node.go @@ -23,6 +23,7 @@ package server import ( "context" + "fmt" "net/url" "sort" "strings" @@ -82,24 +83,15 @@ func (s *Server) getNode(ctx context.Context, id string) (*v1.Node, error) { func (s *Server) configureNode() error { ctx := context.Background() - nodeKeys, err := redis.Strings(s.local(ctx, "KEYS", s.getNodeKey("*"))) + nodes, err := s.getNodes(ctx) if err != nil { return err } // attempt to connect to existing - if len(nodeKeys) > 0 { - for _, nodeKey := range nodeKeys { - nodeData, err := redis.Bytes(s.local(ctx, "GET", nodeKey)) - if err != nil { - logrus.Warn(err) - continue - } - var node v1.Node - if err := proto.Unmarshal(nodeData, &node); err != nil { - return err - } + if len(nodes) > 0 { + for _, node := range nodes { // ignore self - if node.Addr == s.cfg.GRPCAddress { + if node.ID == s.cfg.ID { continue } @@ -109,14 +101,28 @@ func (s *Server) configureNode() error { logrus.Warn(err) continue } - m, err := c.Join(s.cfg.ClusterKey) + r, err := c.Join(&v1.JoinRequest{ + ID: s.cfg.ID, + ClusterKey: s.cfg.ClusterKey, + GRPCAddress: s.cfg.GRPCAddress, + EndpointIP: s.cfg.EndpointIP, + EndpointPort: uint64(s.cfg.EndpointPort), + InterfaceName: s.cfg.InterfaceName, + }) if err != nil { c.Close() logrus.Warn(err) continue } - if err := s.joinMaster(m); err != nil { + // TODO: start tunnel + if err := s.updatePeerConfig(ctx, r.Node, r.Peers); err != nil { + return err + } + // TODO: wait for tunnel to come up + time.Sleep(time.Second * 20) + + if err := s.joinMaster(r.Master); err != nil { c.Close() logrus.Warn(err) continue @@ -154,6 +160,8 @@ func (s *Server) configureNode() error { return err } + // TODO: start tunnel + if err := s.joinMaster(&master); err != nil { return err } @@ -163,14 +171,19 @@ func (s *Server) configureNode() error { return nil } -func (s *Server) disableReplica() { - s.wpool = getPool(s.cfg.RedisURL) +func (s *Server) disableReplica() error { + p, err := getPool(s.cfg.RedisURL) + if err != nil { + return err + } + s.wpool = p // signal replica monitor to stop if started as a peer close(s.replicaCh) // unset peer s.cfg.GRPCPeerAddress = "" + return nil } func (s *Server) replicaMonitor() { @@ -187,7 +200,7 @@ func (s *Server) replicaMonitor() { logrus.Error(err) continue } - if n.ID != s.cfg.ID { + if n == nil || n.ID != s.cfg.ID { logrus.Debugf("waiting for new master to initialize: %s", n.ID) continue } @@ -242,12 +255,15 @@ func (s *Server) masterHeartbeat() { func (s *Server) joinMaster(m *v1.Master) error { // configure replica logrus.Infof("configuring node as replica of %+v", m.ID) - conn, err := redis.DialURL(s.cfg.RedisURL) + pool, err := getPool(s.cfg.RedisURL) if err != nil { - return errors.Wrap(err, "unable to connect to redis") + return err } + + conn := pool.Get() defer conn.Close() + logrus.Debugf("configuring redis as slave of %s", m.RedisURL) u, err := url.Parse(m.RedisURL) if err != nil { return errors.Wrap(err, "error parsing master redis url") @@ -258,15 +274,11 @@ func (s *Server) joinMaster(m *v1.Master) error { if _, err := conn.Do("REPLICAOF", host, port); err != nil { return err } - // auth - auth, ok := u.User.Password() - if ok { - if _, err := conn.Do("CONFIG", "SET", "MASTERAUTH", auth); err != nil { - return errors.Wrap(err, "error authenticating to redis") - } - } - s.wpool = getPool(m.RedisURL) + s.wpool, err = getPool(m.RedisURL) + if err != nil { + return err + } return nil } @@ -275,10 +287,21 @@ func (s *Server) updateMasterInfo(ctx context.Context) error { if _, err := s.master(ctx, "SET", clusterKey, s.cfg.ClusterKey); err != nil { return err } + // build redis url with gateway ip + gatewayIP, _, err := s.getNodeIP(ctx, s.cfg.ID) + if err != nil { + return err + } + u, err := url.Parse(s.cfg.RedisURL) + if err != nil { + return err + } + // update master redis url to gateway to serve over wireguard + u.Host = fmt.Sprintf("%s:%s", gatewayIP.String(), u.Port()) m := &v1.Master{ ID: s.cfg.ID, - GRPCAddress: s.cfg.GRPCAddress, - RedisURL: s.cfg.AdvertiseRedisURL, + GRPCAddress: s.cfg.AdvertiseGRPCAddress, + RedisURL: u.String(), } data, err := proto.Marshal(m) if err != nil { @@ -292,48 +315,91 @@ func (s *Server) updateMasterInfo(ctx context.Context) error { if _, err := s.master(ctx, "EXPIRE", masterKey, int(masterHeartbeatInterval.Seconds())); err != nil { return errors.Wrap(err, "error setting expire for master info") } + return nil } -func (s *Server) nodeHeartbeat(ctx context.Context) { +func (s *Server) updateNodeInfo(ctx context.Context) { logrus.Debugf("starting node heartbeat: ttl=%s", nodeHeartbeatInterval) t := time.NewTicker(nodeHeartbeatInterval) - key := s.getNodeKey(s.cfg.ID) for range t.C { - keyPair, err := s.getOrCreateKeyPair(ctx, s.cfg.ID) - if err != nil { - logrus.Error(err) - continue - } - nodeIP, _, err := s.getNodeIP(ctx, s.cfg.ID) - if err != nil { - logrus.Error(err) - continue - } - node := &v1.Node{ - Updated: time.Now(), - ID: s.cfg.ID, - Addr: s.cfg.GRPCAddress, - KeyPair: keyPair, - EndpointIP: s.cfg.EndpointIP, - EndpointPort: uint64(s.cfg.EndpointPort), - GatewayIP: nodeIP.String(), - } - - data, err := proto.Marshal(node) - if err != nil { - logrus.Error(err) - continue - } - - if _, err := s.master(ctx, "SET", key, data); err != nil { - logrus.Error(err) - continue - } - - if _, err := s.master(ctx, "EXPIRE", key, nodeHeartbeatExpiry); err != nil { + if err := s.updateLocalNodeInfo(ctx); err != nil { logrus.Error(err) continue } } } + +func (s *Server) updateLocalNodeInfo(ctx context.Context) error { + key := s.getNodeKey(s.cfg.ID) + keyPair, err := s.getOrCreateKeyPair(ctx, s.cfg.ID) + if err != nil { + return err + } + nodeIP, _, err := s.getNodeIP(ctx, s.cfg.ID) + if err != nil { + return err + } + node := &v1.Node{ + Updated: time.Now(), + ID: s.cfg.ID, + Addr: s.cfg.GRPCAddress, + KeyPair: keyPair, + EndpointIP: s.cfg.EndpointIP, + EndpointPort: uint64(s.cfg.EndpointPort), + GatewayIP: nodeIP.String(), + InterfaceName: s.cfg.InterfaceName, + } + + data, err := proto.Marshal(node) + if err != nil { + return err + } + + if _, err := s.master(ctx, "SET", key, data); err != nil { + return err + } + + if _, err := s.master(ctx, "EXPIRE", key, nodeHeartbeatExpiry); err != nil { + return err + } + + return nil +} + +func (s *Server) createNode(ctx context.Context, req *v1.JoinRequest) (*v1.Node, error) { + key := s.getNodeKey(req.ID) + keyPair, err := s.getOrCreateKeyPair(ctx, req.ID) + if err != nil { + return nil, errors.Wrapf(err, "error getting/creating keypair for %s", req.ID) + } + nodeIP, _, err := s.getNodeIP(ctx, req.ID) + if err != nil { + return nil, errors.Wrapf(err, "error getting node ip for %s", req.ID) + } + node := &v1.Node{ + Updated: time.Now(), + ID: req.ID, + Addr: req.GRPCAddress, + KeyPair: keyPair, + EndpointIP: req.EndpointIP, + EndpointPort: uint64(req.EndpointPort), + GatewayIP: nodeIP.String(), + InterfaceName: req.InterfaceName, + } + + data, err := proto.Marshal(node) + if err != nil { + return nil, err + } + + if _, err := s.master(ctx, "SET", key, data); err != nil { + return nil, err + } + + if _, err := s.master(ctx, "EXPIRE", key, nodeHeartbeatExpiry); err != nil { + return nil, err + } + + return node, nil +} diff --git a/server/peer.go b/server/peer.go index c2c8b72..e57aa4d 100644 --- a/server/peer.go +++ b/server/peer.go @@ -69,10 +69,9 @@ func (s *Server) getPeers(ctx context.Context) ([]*v1.Peer, error) { func (s *Server) peerUpdater(ctx context.Context) { logrus.Debugf("starting peer config updater: ttl=%s", peerConfigUpdateInterval) - t := time.NewTicker(peerConfigUpdateInterval) - for range t.C { + logrus.Debug("peer config update") uctx, cancel := context.WithTimeout(ctx, peerConfigUpdateInterval) if err := s.updatePeerInfo(uctx, s.cfg.ID); err != nil { logrus.Errorf("updateLocalPeerInfo: %s", err) @@ -80,7 +79,23 @@ func (s *Server) peerUpdater(ctx context.Context) { continue } - if err := s.updatePeerConfig(uctx); err != nil { + peers, err := s.getPeers(ctx) + if err != nil { + logrus.Error(err) + cancel() + continue + } + + logrus.Debugf("peer update: peers %+v", peers) + + node, err := s.getNode(ctx, s.cfg.ID) + if err != nil { + logrus.Error(err) + cancel() + continue + } + + if err := s.updatePeerConfig(uctx, node, peers); err != nil { logrus.Errorf("updatePeerConfig: %s", err) cancel() continue @@ -208,47 +223,29 @@ func (s *Server) getPeerInfo(ctx context.Context, id string) (*v1.Peer, error) { return &peer, nil } -func (s *Server) updatePeerConfig(ctx context.Context) error { - peerKeys, err := redis.Strings(s.local(ctx, "KEYS", s.getPeerKey("*"))) - if err != nil { - return err - } - var peers []*v1.Peer - for _, peerKey := range peerKeys { - peerData, err := redis.Bytes(s.local(ctx, "GET", peerKey)) - if err != nil { - return err - } - var p v1.Peer - if err := proto.Unmarshal(peerData, &p); err != nil { - return err - } - +func (s *Server) updatePeerConfig(ctx context.Context, node *v1.Node, peers []*v1.Peer) error { + var nodePeers []*v1.Peer + for _, peer := range peers { // do not add self as a peer - if p.ID == s.cfg.ID { + if peer.ID == node.ID { continue } - peers = append(peers, &p) + nodePeers = append(nodePeers, peer) } - keyPair, err := s.getOrCreateKeyPair(ctx, s.cfg.ID) + keyPair, err := s.getOrCreateKeyPair(ctx, node.ID) if err != nil { return err } - gatewayIP, gatewayNet, err := s.getNodeIP(ctx, s.cfg.ID) - if err != nil { - return err - } - - size, _ := gatewayNet.Mask.Size() + //size, _ := gatewayNet.Mask.Size() wireguardCfg := &wg.Config{ - Iface: s.cfg.InterfaceName, + Iface: node.InterfaceName, PrivateKey: keyPair.PrivateKey, - ListenPort: s.cfg.EndpointPort, - Address: fmt.Sprintf("%s/%d", gatewayIP.To4().String(), size), - Peers: peers, + ListenPort: int(node.EndpointPort), + Address: fmt.Sprintf("%s/%d", node.GatewayIP, 16), + Peers: nodePeers, } wireguardConfigPath := s.getWireguardConfigPath() diff --git a/server/server.go b/server/server.go index ec6b087..10b1d60 100644 --- a/server/server.go +++ b/server/server.go @@ -25,6 +25,7 @@ import ( "context" "fmt" "io/ioutil" + "net/url" "path/filepath" "runtime" "runtime/pprof" @@ -81,7 +82,10 @@ type Server struct { // NewServer returns a new Heimdall server func NewServer(cfg *heimdall.Config) (*Server, error) { - pool := getPool(cfg.RedisURL) + pool, err := getPool(cfg.RedisURL) + if err != nil { + return nil, err + } return &Server{ cfg: cfg, rpool: pool, @@ -121,13 +125,28 @@ func (s *Server) Run() error { } defer c.Close() - master, err := c.Join(s.cfg.ClusterKey) + r, err := c.Join(&v1.JoinRequest{ + ID: s.cfg.ID, + ClusterKey: s.cfg.ClusterKey, + GRPCAddress: s.cfg.GRPCAddress, + EndpointIP: s.cfg.EndpointIP, + EndpointPort: uint64(s.cfg.EndpointPort), + InterfaceName: s.cfg.InterfaceName, + }) if err != nil { return err } - logrus.Debugf("master info received: %+v", master) - if err := s.joinMaster(master); err != nil { + logrus.Debugf("response: %+v", r) + // start tunnel + if err := s.updatePeerConfig(ctx, r.Node, r.Peers); err != nil { + return errors.Wrap(err, "error updating peer config") + } + // TODO: wait for tunnel to come up + time.Sleep(time.Second * 20) + + logrus.Debugf("master info received: %+v", r) + if err := s.joinMaster(r.Master); err != nil { return err } @@ -144,12 +163,17 @@ func (s *Server) Run() error { } // ensure node network subnet - if err := s.ensureNetworkSubnet(ctx); err != nil { + if err := s.ensureNetworkSubnet(ctx, s.cfg.ID); err != nil { + return err + } + + // initial node update + if err := s.updateLocalNodeInfo(ctx); err != nil { return err } // start node heartbeat to update in redis - go s.nodeHeartbeat(ctx) + go s.updateNodeInfo(ctx) // initial peer info update if err := s.updatePeerInfo(ctx, s.cfg.ID); err != nil { @@ -157,7 +181,15 @@ func (s *Server) Run() error { } // initial config update - if err := s.updatePeerConfig(ctx); err != nil { + node, err := s.getNode(ctx, s.cfg.ID) + if err != nil { + return err + } + peers, err := s.getPeers(ctx) + if err != nil { + return err + } + if err := s.updatePeerConfig(ctx, node, peers); err != nil { return err } @@ -184,7 +216,7 @@ func (s *Server) Run() error { } }() - err := <-errCh + err = <-errCh return err } @@ -194,20 +226,33 @@ func (s *Server) Stop() error { return nil } -func getPool(u string) *redis.Pool { +func getPool(redisUrl string) (*redis.Pool, error) { pool := redis.NewPool(func() (redis.Conn, error) { - conn, err := redis.DialURL(u) + conn, err := redis.DialURL(redisUrl) if err != nil { return nil, errors.Wrap(err, "unable to connect to redis") } + + u, err := url.Parse(redisUrl) + if err != nil { + return nil, err + } + + auth, ok := u.User.Password() + if ok { + logrus.Debug("setting masterauth for redis") + if _, err := conn.Do("CONFIG", "SET", "MASTERAUTH", auth); err != nil { + return nil, errors.Wrap(err, "error authenticating to redis") + } + } return conn, nil }, 10) - return pool + return pool, nil } -func (s *Server) ensureNetworkSubnet(ctx context.Context) error { - network, err := redis.String(s.local(ctx, "GET", s.getNodeNetworkKey(s.cfg.ID))) +func (s *Server) ensureNetworkSubnet(ctx context.Context, id string) error { + network, err := redis.String(s.local(ctx, "GET", s.getNodeNetworkKey(id))) if err != nil { if err != redis.ErrNil { return err @@ -222,7 +267,6 @@ func (s *Server) ensureNetworkSubnet(ctx context.Context) error { if err != nil { return err } - logrus.Debug(nodeNetworkKeys) lookup := map[string]struct{}{} for _, netKey := range nodeNetworkKeys { n, err := redis.String(s.local(ctx, "GET", netKey)) @@ -244,8 +288,8 @@ func (s *Server) ensureNetworkSubnet(ctx context.Context) error { subnet = n continue } - logrus.Debugf("allocated network %s for %s", n.String(), s.cfg.ID) - if err := s.updateNodeNetwork(ctx, n.String()); err != nil { + logrus.Debugf("allocated network %s for %s", n.String(), id) + if err := s.updateNodeNetwork(ctx, id, n.String()); err != nil { return err } break @@ -253,7 +297,7 @@ func (s *Server) ensureNetworkSubnet(ctx context.Context) error { return nil } - logrus.Debugf("node network: %s", network) + logrus.Debugf("node network for %s: %s", id, network) return nil } From 48d43ee2eed7b2920d5be8c780de0be6323fc131 Mon Sep 17 00:00:00 2001 From: Evan Hazlett Date: Mon, 7 Oct 2019 23:37:13 -0400 Subject: [PATCH 2/3] enable redis over wireguard Signed-off-by: Evan Hazlett --- api/v1/heimdall.pb.go | 146 ++++++++++++++++++++++-------------------- api/v1/heimdall.proto | 1 + go.mod | 1 + go.sum | 16 +++++ server/net.go | 2 + server/node.go | 24 +++++-- server/peer.go | 7 +- server/server.go | 98 ++++++++++++++++++++++++++-- 8 files changed, 210 insertions(+), 85 deletions(-) diff --git a/api/v1/heimdall.pb.go b/api/v1/heimdall.pb.go index 90e875d..b6a3d76 100644 --- a/api/v1/heimdall.pb.go +++ b/api/v1/heimdall.pb.go @@ -32,6 +32,7 @@ type Master struct { ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` GRPCAddress string `protobuf:"bytes,2,opt,name=grpc_address,json=grpcAddress,proto3" json:"grpc_address,omitempty"` RedisURL string `protobuf:"bytes,3,opt,name=redis_url,json=redisUrl,proto3" json:"redis_url,omitempty"` + GatewayIP string `protobuf:"bytes,4,opt,name=gateway_ip,json=gatewayIp,proto3" json:"gateway_ip,omitempty"` Peers []*Peer `protobuf:"bytes,5,rep,name=peers,proto3" json:"peers,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -83,6 +84,13 @@ func (m *Master) GetRedisURL() string { return "" } +func (m *Master) GetGatewayIP() string { + if m != nil { + return m.GatewayIP + } + return "" +} + func (m *Master) GetPeers() []*Peer { if m != nil { return m.Peers @@ -1031,75 +1039,75 @@ func init() { } var fileDescriptor_b6184fc395da86b1 = []byte{ - // 1076 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x5f, 0x6f, 0xe3, 0x44, - 0x10, 0xc7, 0xf9, 0x9f, 0x49, 0xd3, 0x4a, 0xab, 0x53, 0xf1, 0x05, 0x21, 0x97, 0x9c, 0x10, 0x39, - 0x74, 0xb2, 0xdb, 0x02, 0xe2, 0xcf, 0xe9, 0x10, 0x4d, 0x73, 0x1c, 0xa6, 0x50, 0x85, 0x3d, 0xee, - 0x05, 0x9d, 0x14, 0xdc, 0x78, 0x2e, 0x75, 0xeb, 0xd8, 0x8b, 0xbd, 0x69, 0x15, 0x3e, 0x01, 0x8f, - 0x7c, 0x1f, 0x24, 0x9e, 0x79, 0xe1, 0x9d, 0xa7, 0x20, 0xe5, 0x13, 0xf0, 0xc6, 0x2b, 0xda, 0xf5, - 0xda, 0x97, 0xb4, 0x8d, 0xea, 0xf6, 0x8e, 0xb7, 0xee, 0xec, 0xfc, 0x66, 0x32, 0xbf, 0xdf, 0xcc, - 0xac, 0x0b, 0x9f, 0x8c, 0x3c, 0x7e, 0x3c, 0x39, 0x32, 0x87, 0xe1, 0xd8, 0x8a, 0x39, 0xfa, 0xbe, - 0x13, 0xb1, 0x28, 0x3c, 0xc1, 0x21, 0xb7, 0x8e, 0x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4, 0x3f, 0xc0, 0x69, 0xdf, 0xf1, 0xa2, 0x6e, 0x63, 0x3e, 0x33, 0xaa, 0xea, - 0x40, 0xd3, 0x38, 0x44, 0x87, 0xea, 0x52, 0xcf, 0xd3, 0xf4, 0xf8, 0x8a, 0x95, 0x92, 0xbb, 0x50, - 0x74, 0x83, 0x58, 0x2f, 0x6d, 0x15, 0x3b, 0xf5, 0x6e, 0x75, 0x3e, 0x33, 0x8a, 0xbd, 0xc3, 0xa7, - 0x54, 0xd8, 0xda, 0x26, 0xdc, 0xd9, 0x9b, 0xf0, 0xe3, 0x30, 0xf2, 0x7e, 0x46, 0x09, 0xb9, 0x86, - 0x8a, 0x6d, 0xd8, 0xec, 0xa1, 0x73, 0x13, 0x84, 0x0e, 0x9b, 0x59, 0x06, 0x57, 0x00, 0x62, 0x85, - 0x68, 0x7f, 0x08, 0x6f, 0x5e, 0xba, 0x51, 0xec, 0xde, 0x85, 0xa2, 0xe7, 0xc6, 0xba, 0xf6, 0xf2, - 0x17, 0xdb, 0xbd, 0x98, 0x0a, 0x5b, 0xdb, 0x86, 0x94, 0x39, 0x31, 0x63, 0x2c, 0xf2, 0xce, 0x1c, - 0x8e, 0x72, 0xc6, 0xb4, 0x64, 0xc6, 0x94, 0x49, 0xcc, 0xd8, 0xdb, 0x00, 0x6c, 0x72, 0xe4, 0x7b, - 0xc3, 0x85, 0x19, 0xac, 0x27, 0x96, 0x03, 0x9c, 0xb6, 0xff, 0x29, 0x40, 0x49, 0xf4, 0xd3, 0xca, - 0x21, 0x26, 0x50, 0x12, 0x12, 0x28, 0xa4, 0xfc, 0x7b, 0x51, 0xf8, 0xe2, 0x6b, 0x12, 0xfe, 0xff, - 0x19, 0xeb, 0x07, 0x00, 0x23, 0x87, 0xe3, 0xb9, 0x33, 0x15, 0x41, 0xe5, 0x48, 0x77, 0x9b, 0xf3, - 0x99, 0x51, 0x7f, 0x92, 0x58, 0xed, 0x3e, 0xad, 0x2b, 0x07, 0x9b, 0x91, 0x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d3, 0x09, 0x94, 0x93, 0xfe, 0xb3, 0x72, - 0x2e, 0xcf, 0x1b, 0xe5, 0x5a, 0xea, 0xb5, 0xae, 0xf9, 0xc3, 0x83, 0xdc, 0xff, 0xa3, 0x3d, 0x3c, - 0xdb, 0x39, 0xaa, 0x48, 0x5e, 0x3e, 0xf8, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x58, 0x29, 0xda, 0xfa, - 0xda, 0x0d, 0x00, 0x00, + // 1082 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0xcf, 0x6f, 0xe3, 0x44, + 0x14, 0xc6, 0xf9, 0x9d, 0x97, 0xa6, 0x95, 0x46, 0xab, 0xe2, 0x0d, 0x42, 0x2e, 0x59, 0x21, 0xb2, + 0x68, 0x65, 0xb7, 0x05, 0xc4, 0x8f, 0xd5, 0x22, 0xda, 0x66, 0x59, 0x4c, 0xa1, 0x0a, 0xb3, 0xec, + 0x05, 0xad, 0x14, 0xdc, 0xf8, 0x6d, 0xea, 0xd6, 0xf1, 0x0c, 0xf6, 0xa4, 0x55, 0xf8, 0x0b, 0x38, + 0xf2, 0xff, 0x20, 0x71, 0xe6, 0xc2, 0x9d, 0x53, 0x90, 0x72, 0xe6, 0xc0, 0x8d, 0x2b, 0x1a, 0x7b, + 0xec, 0x26, 0x6d, 0xa3, 0xba, 0xdd, 0xdd, 0x5b, 0xe7, 0xcd, 0xfb, 0xde, 0xcb, 0xfb, 0xde, 0x7b, + 0xdf, 0xb8, 0xf0, 0xc9, 0xd0, 0x13, 0x47, 0xe3, 0x43, 0x73, 0xc0, 0x46, 0x56, 0x24, 0xd0, 0xf7, + 0x9d, 0x90, 0x87, 0xec, 0x18, 0x07, 0xc2, 0x3a, 0x42, 0x6f, 0xe4, 0x3a, 0xbe, 0x6f, 0x39, 0xdc, + 0xb3, 0x4e, 0xb7, 0xb2, 0xb3, 0xc9, 0x43, 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, 0x78, 0xde, 0x28, 0xd7, 0xc2, 0xac, 0xed, 0x9a, 0x3f, 0x3c, + 0xc8, 0xfd, 0x1f, 0xdd, 0xc3, 0xd3, 0xad, 0xc3, 0x4a, 0xcc, 0xcb, 0x07, 0xff, 0x07, 0x00, 0x00, + 0xff, 0xff, 0xdf, 0x73, 0xc4, 0x68, 0x08, 0x0e, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/api/v1/heimdall.proto b/api/v1/heimdall.proto index 97d0bdf..c2b0dea 100644 --- a/api/v1/heimdall.proto +++ b/api/v1/heimdall.proto @@ -25,6 +25,7 @@ message Master { string id = 1 [(gogoproto.customname) = "ID"]; string grpc_address = 2 [(gogoproto.customname) = "GRPCAddress"]; string redis_url = 3 [(gogoproto.customname) = "RedisURL"]; + string gateway_ip = 4 [(gogoproto.customname) = "GatewayIP"]; repeated Peer peers = 5; } diff --git a/go.mod b/go.mod index 8acc446..2dc38a6 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/certifi/gocertifi v0.0.0-20190905060710-a5e0173ced67 // indirect github.com/containerd/typeurl v0.0.0-20190911142611-5eb25027c9fd github.com/crosbymichael/guard v0.0.0-20190716141324-5c2daadf8067 // indirect + github.com/digineo/go-ping v1.0.0 github.com/dustin/go-humanize v1.0.0 github.com/getsentry/raven-go v0.2.0 // indirect github.com/gogo/googleapis v1.3.0 diff --git a/go.sum b/go.sum index 89603fb..31810a7 100644 --- a/go.sum +++ b/go.sum @@ -19,9 +19,16 @@ github.com/crosbymichael/guard v0.0.0-20190716141324-5c2daadf8067/go.mod h1:+l2f github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/digineo/go-logwrap v0.0.0-20181106161722-a178c58ea3f0 h1:OT/LKmj81wMymnWXaKaKBR9n1vPlu+GC0VVKaZP6kzs= +github.com/digineo/go-logwrap v0.0.0-20181106161722-a178c58ea3f0/go.mod h1:DmqdumeAKGQNU5E8MN0ruT5ZGx8l/WbAsMbXCXcSEts= +github.com/digineo/go-ping v1.0.0 h1:gOuD3YzkIcW/0Y2IAe27bsMKtpfNZdoX1Rnc1RGYOSI= +github.com/digineo/go-ping v1.0.0/go.mod h1:YLDBnHoAygacawa2aubI4vXhZ4do5f62oJSvRiJVEjw= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/ehazlett/ttlcache v0.0.0-20190820213212-4400e3aef9f0/go.mod h1:D7IiYXsX2n2xixWvFTxGeZucCvvNtI14ikLj6L9Kp9E= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= +github.com/gdamore/tcell v1.1.1/go.mod h1:K1udHkiR3cOtlpKG5tZPD5XxrF7v2y7lDq7Whcj+xkQ= github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs= github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -61,6 +68,10 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGi github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/lucasb-eyer/go-colorful v0.0.0-20181028223441-12d3b2882a08/go.mod h1:NXg0ArsFk0Y01623LgUqoqcouGDB+PwCCQlrwrG6xJ4= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= @@ -89,6 +100,7 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE= github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= +github.com/rivo/tview v0.0.0-20181226202439-36893a669792/go.mod h1:J4W+hErFfITUbyFAEXizpmkuxX7ZN56dopxHB4XQhMw= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= @@ -115,6 +127,7 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU= @@ -125,6 +138,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -144,9 +158,11 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s= google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= +gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw= 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 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/server/net.go b/server/net.go index a766069..9490d4d 100644 --- a/server/net.go +++ b/server/net.go @@ -30,6 +30,7 @@ import ( "github.com/gomodule/redigo/redis" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) type subnetRange struct { @@ -39,6 +40,7 @@ type subnetRange struct { } func (s *Server) updateNodeNetwork(ctx context.Context, id string, subnet string) error { + logrus.Debugf("updating node network: id=%s subnet=%s", id, subnet) if _, err := s.master(ctx, "SET", s.getNodeNetworkKey(id), subnet); err != nil { return err } diff --git a/server/node.go b/server/node.go index c624a35..a8243f3 100644 --- a/server/node.go +++ b/server/node.go @@ -115,12 +115,14 @@ func (s *Server) configureNode() error { continue } - // TODO: start tunnel + // start tunnel if err := s.updatePeerConfig(ctx, r.Node, r.Peers); err != nil { return err } - // TODO: wait for tunnel to come up - time.Sleep(time.Second * 20) + // wait for tunnel to come up + if err := s.waitForMaster(ctx, r.Master); err != nil { + return err + } if err := s.joinMaster(r.Master); err != nil { c.Close() @@ -128,6 +130,11 @@ func (s *Server) configureNode() error { continue } + logrus.Debug("waiting for redis sync") + if err := s.waitForRedisSync(ctx); err != nil { + return err + } + go s.replicaMonitor() return nil @@ -200,10 +207,12 @@ func (s *Server) replicaMonitor() { logrus.Error(err) continue } + logrus.Debugf("replica monitor: node=%s", n) if n == nil || n.ID != s.cfg.ID { - logrus.Debugf("waiting for new master to initialize: %s", n.ID) + logrus.Debug("waiting for new master to initialize") continue } + logrus.Debugf("replica monitor: configuring node with master %+v", n) if err := s.configureNode(); err != nil { logrus.Error(err) continue @@ -285,11 +294,13 @@ func (s *Server) joinMaster(m *v1.Master) error { func (s *Server) updateMasterInfo(ctx context.Context) error { // update master info if _, err := s.master(ctx, "SET", clusterKey, s.cfg.ClusterKey); err != nil { + logrus.Error("updateMasterInfo.setClusterKey") return err } // build redis url with gateway ip gatewayIP, _, err := s.getNodeIP(ctx, s.cfg.ID) if err != nil { + logrus.Error("updateMasterInfo.getNodeIP") return err } u, err := url.Parse(s.cfg.RedisURL) @@ -302,6 +313,7 @@ func (s *Server) updateMasterInfo(ctx context.Context) error { ID: s.cfg.ID, GRPCAddress: s.cfg.AdvertiseGRPCAddress, RedisURL: u.String(), + GatewayIP: gatewayIP.String(), } data, err := proto.Marshal(m) if err != nil { @@ -334,11 +346,11 @@ func (s *Server) updateLocalNodeInfo(ctx context.Context) error { key := s.getNodeKey(s.cfg.ID) keyPair, err := s.getOrCreateKeyPair(ctx, s.cfg.ID) if err != nil { - return err + return errors.Wrapf(err, "error getting keypair for %s", s.cfg.ID) } nodeIP, _, err := s.getNodeIP(ctx, s.cfg.ID) if err != nil { - return err + return errors.Wrapf(err, "error getting node IP for %s", s.cfg.ID) } node := &v1.Node{ Updated: time.Now(), diff --git a/server/peer.go b/server/peer.go index e57aa4d..623e1d7 100644 --- a/server/peer.go +++ b/server/peer.go @@ -234,15 +234,10 @@ func (s *Server) updatePeerConfig(ctx context.Context, node *v1.Node, peers []*v nodePeers = append(nodePeers, peer) } - keyPair, err := s.getOrCreateKeyPair(ctx, node.ID) - if err != nil { - return err - } - //size, _ := gatewayNet.Mask.Size() wireguardCfg := &wg.Config{ Iface: node.InterfaceName, - PrivateKey: keyPair.PrivateKey, + PrivateKey: node.KeyPair.PrivateKey, ListenPort: int(node.EndpointPort), Address: fmt.Sprintf("%s/%d", node.GatewayIP, 16), Peers: nodePeers, diff --git a/server/server.go b/server/server.go index 10b1d60..26f8465 100644 --- a/server/server.go +++ b/server/server.go @@ -22,15 +22,20 @@ package server import ( + "bufio" + "bytes" "context" "fmt" "io/ioutil" + "net" "net/url" "path/filepath" "runtime" "runtime/pprof" + "strings" "time" + ping "github.com/digineo/go-ping" "github.com/gogo/protobuf/proto" ptypes "github.com/gogo/protobuf/types" "github.com/gomodule/redigo/redis" @@ -137,19 +142,27 @@ func (s *Server) Run() error { return err } - logrus.Debugf("response: %+v", r) + logrus.Debugf("master info received: %+v", r) // start tunnel if err := s.updatePeerConfig(ctx, r.Node, r.Peers); err != nil { return errors.Wrap(err, "error updating peer config") } - // TODO: wait for tunnel to come up - time.Sleep(time.Second * 20) - logrus.Debugf("master info received: %+v", r) + // wait for tunnel to come up + if err := s.waitForMaster(ctx, r.Master); err != nil { + return errors.Wrap(err, "error waiting for master") + } + + logrus.Debugf("joining master: %s", r.Master.ID) if err := s.joinMaster(r.Master); err != nil { return err } + logrus.Debug("waiting for redis sync") + if err := s.waitForRedisSync(ctx); err != nil { + return err + } + go s.replicaMonitor() } else { if err := s.configureNode(); err != nil { @@ -251,6 +264,80 @@ func getPool(redisUrl string) (*redis.Pool, error) { return pool, nil } +func (s *Server) waitForMaster(ctx context.Context, m *v1.Master) error { + p, err := ping.New("0.0.0.0", "") + if err != nil { + return err + } + defer p.Close() + + doneCh := make(chan time.Duration) + errCh := make(chan error) + + go func() { + for { + ip, err := net.ResolveIPAddr("ip4", m.GatewayIP) + if err != nil { + errCh <- err + return + } + rtt, err := p.Ping(ip, time.Second*30) + if err != nil { + errCh <- err + } + doneCh <- rtt + } + }() + + select { + case rtt := <-doneCh: + logrus.Debugf("rtt master ping: %s", rtt) + return nil + case err := <-errCh: + return err + } + return nil +} + +func (s *Server) waitForRedisSync(ctx context.Context) error { + doneCh := make(chan bool) + errCh := make(chan error) + + go func() { + for { + info, err := redis.String(s.local(ctx, "INFO", "REPLICATION")) + if err != nil { + logrus.Warn(err) + continue + } + + b := bytes.NewBufferString(info) + s := bufio.NewScanner(b) + + for s.Scan() { + v := s.Text() + parts := strings.SplitN(v, ":", 2) + if parts[0] == "master_link_status" { + if parts[1] == "up" { + doneCh <- true + return + } + } + } + time.Sleep(time.Second * 1) + } + }() + + select { + case <-doneCh: + return nil + case err := <-errCh: + return err + case <-time.After(nodeHeartbeatInterval): + return fmt.Errorf("timeout waiting on sync") + } +} + func (s *Server) ensureNetworkSubnet(ctx context.Context, id string) error { network, err := redis.String(s.local(ctx, "GET", s.getNodeNetworkKey(id))) if err != nil { @@ -267,6 +354,7 @@ func (s *Server) ensureNetworkSubnet(ctx context.Context, id string) error { if err != nil { return err } + logrus.Debugf("node networks: %s", nodeNetworkKeys) lookup := map[string]struct{}{} for _, netKey := range nodeNetworkKeys { n, err := redis.String(s.local(ctx, "GET", netKey)) @@ -276,6 +364,8 @@ func (s *Server) ensureNetworkSubnet(ctx context.Context, id string) error { lookup[n] = struct{}{} } + logrus.Debugf("lookup: %+v", lookup) + subnet := r.Subnet size, _ := subnet.Mask.Size() From d6e6b7e37323fb19f2c14d3cada9abc3280a82fb Mon Sep 17 00:00:00 2001 From: Evan Hazlett Date: Mon, 7 Oct 2019 23:43:51 -0400 Subject: [PATCH 3/3] remove advertise redis url Signed-off-by: Evan Hazlett --- cmd/heimdall/main.go | 6 ------ cmd/heimdall/run.go | 1 - config.go | 2 -- server/node.go | 5 +++-- server/peer.go | 3 --- server/server.go | 4 ++-- 6 files changed, 5 insertions(+), 16 deletions(-) diff --git a/cmd/heimdall/main.go b/cmd/heimdall/main.go index af7f20c..fc12248 100644 --- a/cmd/heimdall/main.go +++ b/cmd/heimdall/main.go @@ -72,12 +72,6 @@ func main() { Value: "redis://127.0.0.1:6379/0", EnvVar: "HEIMDALL_REDIS_URL", }, - cli.StringFlag{ - Name: "advertise-redis-url, p", - Usage: "advertise uri for peers", - Value: fmt.Sprintf("redis://%s:6379/0", heimdall.GetIP()), - EnvVar: "HEIMDALL_ADVERTISE_REDIS_URL", - }, cli.StringFlag{ Name: "peer", Usage: "grpc address to join a peer", diff --git a/cmd/heimdall/run.go b/cmd/heimdall/run.go index 8c51e94..b801f0b 100644 --- a/cmd/heimdall/run.go +++ b/cmd/heimdall/run.go @@ -52,7 +52,6 @@ func runServer(cx *cli.Context) error { EndpointPort: cx.Int("endpoint-port"), InterfaceName: cx.String("interface-name"), RedisURL: cx.String("redis-url"), - AdvertiseRedisURL: cx.String("advertise-redis-url"), } errCh := make(chan error, 1) diff --git a/config.go b/config.go index 76c1dd5..d2f8075 100644 --- a/config.go +++ b/config.go @@ -47,8 +47,6 @@ type Config struct { InterfaceName string // RedisURL is the uri to the redis backend RedisURL string - // AdvertiseRedisURL is the uri to the public redis backend - AdvertiseRedisURL string // TLSCertificate is the certificate used for grpc communication TLSServerCertificate string // TLSKey is the key used for grpc communication diff --git a/server/node.go b/server/node.go index a8243f3..fe4ca00 100644 --- a/server/node.go +++ b/server/node.go @@ -120,6 +120,7 @@ func (s *Server) configureNode() error { return err } // wait for tunnel to come up + logrus.Infof("waiting for master %s", r.Master.ID) if err := s.waitForMaster(ctx, r.Master); err != nil { return err } @@ -130,7 +131,7 @@ func (s *Server) configureNode() error { continue } - logrus.Debug("waiting for redis sync") + logrus.Infof("waiting for redis sync with %s", r.Master.ID) if err := s.waitForRedisSync(ctx); err != nil { return err } @@ -272,7 +273,7 @@ func (s *Server) joinMaster(m *v1.Master) error { conn := pool.Get() defer conn.Close() - logrus.Debugf("configuring redis as slave of %s", m.RedisURL) + logrus.Debugf("configuring redis as slave of %s", m.ID) u, err := url.Parse(m.RedisURL) if err != nil { return errors.Wrap(err, "error parsing master redis url") diff --git a/server/peer.go b/server/peer.go index 623e1d7..fe87327 100644 --- a/server/peer.go +++ b/server/peer.go @@ -71,7 +71,6 @@ func (s *Server) peerUpdater(ctx context.Context) { logrus.Debugf("starting peer config updater: ttl=%s", peerConfigUpdateInterval) t := time.NewTicker(peerConfigUpdateInterval) for range t.C { - logrus.Debug("peer config update") uctx, cancel := context.WithTimeout(ctx, peerConfigUpdateInterval) if err := s.updatePeerInfo(uctx, s.cfg.ID); err != nil { logrus.Errorf("updateLocalPeerInfo: %s", err) @@ -86,8 +85,6 @@ func (s *Server) peerUpdater(ctx context.Context) { continue } - logrus.Debugf("peer update: peers %+v", peers) - node, err := s.getNode(ctx, s.cfg.ID) if err != nil { logrus.Error(err) diff --git a/server/server.go b/server/server.go index 26f8465..9f9f60f 100644 --- a/server/server.go +++ b/server/server.go @@ -149,6 +149,7 @@ func (s *Server) Run() error { } // wait for tunnel to come up + logrus.Infof("waiting for master %s", r.Master.ID) if err := s.waitForMaster(ctx, r.Master); err != nil { return errors.Wrap(err, "error waiting for master") } @@ -158,7 +159,7 @@ func (s *Server) Run() error { return err } - logrus.Debug("waiting for redis sync") + logrus.Infof("waiting for redis sync with %s", r.Master.ID) if err := s.waitForRedisSync(ctx); err != nil { return err } @@ -253,7 +254,6 @@ func getPool(redisUrl string) (*redis.Pool, error) { auth, ok := u.User.Password() if ok { - logrus.Debug("setting masterauth for redis") if _, err := conn.Do("CONFIG", "SET", "MASTERAUTH", auth); err != nil { return nil, errors.Wrap(err, "error authenticating to redis") }