Add is applying config grpc command to check config status.

This commit is contained in:
GRMrGecko 2025-02-12 14:37:46 -06:00
parent b0de9be277
commit a6bb83947a
6 changed files with 504 additions and 389 deletions

View File

@ -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
}

View File

@ -6,7 +6,7 @@ const (
serviceDisplayName = "Virtual VXLAN"
serviceVendor = "com.mrgeckosmedia"
serviceDescription = "Virtual VXLAN using TUN interfaces"
serviceVersion = "0.1.8"
serviceVersion = "0.2"
defaultConfigFile = "config.yaml"
)

View File

@ -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

View File

@ -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;

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v3.21.12
// - protoc v5.29.2
// source: vxlan/vxlan.proto
package vxlan
@ -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,