Add is applying config grpc command to check config status
This commit is contained in:
parent
b0de9be277
commit
c9bfcf2ebe
@ -20,11 +20,20 @@ func (s *GRPCServer) SaveConfig(ctx context.Context, in *pb.Empty) (*pb.Empty, e
|
||||
// Reload the configuration from the yaml file.
|
||||
func (s *GRPCServer) ReloadConfig(ctx context.Context, in *pb.Empty) (*pb.Empty, error) {
|
||||
log.Println("Reloading configurations.")
|
||||
app.ApplyingConfig = true
|
||||
config := ReadConfig()
|
||||
err := ApplyConfig(config)
|
||||
app.ApplyingConfig = false
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
return new(pb.Empty), nil
|
||||
}
|
||||
|
||||
// Check if the config is being applied.
|
||||
func (s *GRPCServer) IsApplyingConfig(ctx context.Context, in *pb.Empty) (*pb.IsApplyingConfigReply, error) {
|
||||
reply := new(pb.IsApplyingConfigReply)
|
||||
reply.IsApplying = app.ApplyingConfig
|
||||
return reply, nil
|
||||
}
|
||||
|
14
go.mod
14
go.mod
@ -14,7 +14,7 @@ require (
|
||||
github.com/shibukawa/configdir v0.0.0-20170330084843-e180dbdc8da0
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/vishvananda/netlink v1.3.0
|
||||
golang.org/x/sys v0.29.0
|
||||
golang.org/x/sys v0.30.0
|
||||
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2
|
||||
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
|
||||
golang.zx2c4.com/wireguard/windows v0.5.3
|
||||
@ -45,14 +45,14 @@ require (
|
||||
github.com/ulikunitz/xz v0.5.12 // indirect
|
||||
github.com/vishvananda/netns v0.0.4 // indirect
|
||||
github.com/xanzy/go-gitlab v0.112.0 // indirect
|
||||
golang.org/x/crypto v0.32.0 // indirect
|
||||
golang.org/x/mod v0.22.0 // indirect
|
||||
golang.org/x/net v0.34.0 // indirect
|
||||
golang.org/x/crypto v0.33.0 // indirect
|
||||
golang.org/x/mod v0.23.0 // indirect
|
||||
golang.org/x/net v0.35.0 // indirect
|
||||
golang.org/x/oauth2 v0.24.0 // indirect
|
||||
golang.org/x/sync v0.10.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
golang.org/x/sync v0.11.0 // indirect
|
||||
golang.org/x/text v0.22.0 // indirect
|
||||
golang.org/x/time v0.7.0 // indirect
|
||||
golang.org/x/tools v0.29.0 // indirect
|
||||
golang.org/x/tools v0.30.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
)
|
||||
|
32
go.sum
32
go.sum
@ -115,24 +115,24 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
|
||||
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
|
||||
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
|
||||
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
|
||||
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
|
||||
golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
|
||||
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
|
||||
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
|
||||
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
|
||||
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
|
||||
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@ -140,21 +140,21 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
|
||||
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
|
||||
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
|
||||
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
||||
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
|
||||
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE=
|
||||
golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588=
|
||||
golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=
|
||||
golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 h1:B82qJJgjvYKsXS9jeunTOisW56dUokqW/FOteYJJ/yg=
|
||||
|
2
main.go
2
main.go
@ -6,7 +6,7 @@ const (
|
||||
serviceDisplayName = "Virtual VXLAN"
|
||||
serviceVendor = "com.mrgeckosmedia"
|
||||
serviceDescription = "Virtual VXLAN using TUN interfaces"
|
||||
serviceVersion = "0.1.8"
|
||||
serviceVersion = "0.2.0"
|
||||
defaultConfigFile = "config.yaml"
|
||||
)
|
||||
|
||||
|
@ -24,6 +24,7 @@ type App struct {
|
||||
}
|
||||
ControllerMac net.HardwareAddr
|
||||
grpcServer *GRPCServer
|
||||
ApplyingConfig bool
|
||||
Stop chan struct{}
|
||||
UpdateConfig *UpdateConfig
|
||||
}
|
||||
@ -41,6 +42,9 @@ func (a *ServerCmd) Run() error {
|
||||
config := ReadConfig()
|
||||
app.UpdateConfig = config.Update
|
||||
|
||||
// So that other services interacting can confirm the config is applied prior to working.
|
||||
app.ApplyingConfig = true
|
||||
|
||||
// Start the GRPC server for cli communication.
|
||||
_, err := NewGRPCServer(config.RPCPath)
|
||||
if err != nil {
|
||||
@ -55,6 +59,9 @@ func (a *ServerCmd) Run() error {
|
||||
if err != nil {
|
||||
log.Println("An error occurred applying configuration:", err)
|
||||
}
|
||||
|
||||
// Other services may now work.
|
||||
app.ApplyingConfig = false
|
||||
}()
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,7 @@ service vxlan {
|
||||
// Config commands.
|
||||
rpc SaveConfig (Empty) returns (Empty) {}
|
||||
rpc ReloadConfig (Empty) returns (Empty) {}
|
||||
rpc IsApplyingConfig (Empty) returns (IsApplyingConfigReply) {}
|
||||
|
||||
// Listener commands.
|
||||
rpc ListListeners (Empty) returns (ListListenersReply) {}
|
||||
@ -39,6 +40,11 @@ service vxlan {
|
||||
message Empty {
|
||||
}
|
||||
|
||||
// Response to is applying config.
|
||||
message IsApplyingConfigReply {
|
||||
bool isApplying = 1;
|
||||
}
|
||||
|
||||
// Listener messages.
|
||||
message ListenerRequestWithName {
|
||||
string name = 1;
|
||||
|
@ -21,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion9
|
||||
const (
|
||||
Vxlan_SaveConfig_FullMethodName = "/vxlan.vxlan/SaveConfig"
|
||||
Vxlan_ReloadConfig_FullMethodName = "/vxlan.vxlan/ReloadConfig"
|
||||
Vxlan_IsApplyingConfig_FullMethodName = "/vxlan.vxlan/IsApplyingConfig"
|
||||
Vxlan_ListListeners_FullMethodName = "/vxlan.vxlan/ListListeners"
|
||||
Vxlan_AddListener_FullMethodName = "/vxlan.vxlan/AddListener"
|
||||
Vxlan_RemoveListener_FullMethodName = "/vxlan.vxlan/RemoveListener"
|
||||
@ -52,6 +53,7 @@ type VxlanClient interface {
|
||||
// Config commands.
|
||||
SaveConfig(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
|
||||
ReloadConfig(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
|
||||
IsApplyingConfig(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*IsApplyingConfigReply, error)
|
||||
// Listener commands.
|
||||
ListListeners(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*ListListenersReply, error)
|
||||
AddListener(ctx context.Context, in *Listener, opts ...grpc.CallOption) (*Empty, error)
|
||||
@ -106,6 +108,16 @@ func (c *vxlanClient) ReloadConfig(ctx context.Context, in *Empty, opts ...grpc.
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *vxlanClient) IsApplyingConfig(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*IsApplyingConfigReply, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(IsApplyingConfigReply)
|
||||
err := c.cc.Invoke(ctx, Vxlan_IsApplyingConfig_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *vxlanClient) ListListeners(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*ListListenersReply, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ListListenersReply)
|
||||
@ -333,6 +345,7 @@ type VxlanServer interface {
|
||||
// Config commands.
|
||||
SaveConfig(context.Context, *Empty) (*Empty, error)
|
||||
ReloadConfig(context.Context, *Empty) (*Empty, error)
|
||||
IsApplyingConfig(context.Context, *Empty) (*IsApplyingConfigReply, error)
|
||||
// Listener commands.
|
||||
ListListeners(context.Context, *Empty) (*ListListenersReply, error)
|
||||
AddListener(context.Context, *Listener) (*Empty, error)
|
||||
@ -373,6 +386,9 @@ func (UnimplementedVxlanServer) SaveConfig(context.Context, *Empty) (*Empty, err
|
||||
func (UnimplementedVxlanServer) ReloadConfig(context.Context, *Empty) (*Empty, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ReloadConfig not implemented")
|
||||
}
|
||||
func (UnimplementedVxlanServer) IsApplyingConfig(context.Context, *Empty) (*IsApplyingConfigReply, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method IsApplyingConfig not implemented")
|
||||
}
|
||||
func (UnimplementedVxlanServer) ListListeners(context.Context, *Empty) (*ListListenersReply, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListListeners not implemented")
|
||||
}
|
||||
@ -496,6 +512,24 @@ func _Vxlan_ReloadConfig_Handler(srv interface{}, ctx context.Context, dec func(
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Vxlan_IsApplyingConfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Empty)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(VxlanServer).IsApplyingConfig(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Vxlan_IsApplyingConfig_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(VxlanServer).IsApplyingConfig(ctx, req.(*Empty))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Vxlan_ListListeners_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Empty)
|
||||
if err := dec(in); err != nil {
|
||||
@ -907,6 +941,10 @@ var Vxlan_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "ReloadConfig",
|
||||
Handler: _Vxlan_ReloadConfig_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "IsApplyingConfig",
|
||||
Handler: _Vxlan_IsApplyingConfig_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListListeners",
|
||||
Handler: _Vxlan_ListListeners_Handler,
|
||||
|
Loading…
x
Reference in New Issue
Block a user