Skip to content

Commit

Permalink
fix: removed redundant ResponseResult return value on grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
fra98 committed Nov 19, 2024
1 parent cbd5a70 commit 49facb9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 108 deletions.
2 changes: 1 addition & 1 deletion cmd/liqo-controller-manager/modules/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type NetworkingOption struct {
}

// SetupNetworkingModule setup the networking module and initializes its controllers .
func SetupNetworkingModule(ctx context.Context, mgr manager.Manager, opts *NetworkingOption) error {
func SetupNetworkingModule(_ context.Context, mgr manager.Manager, opts *NetworkingOption) error {
networkReconciler := networkctrl.NewNetworkReconciler(mgr.GetClient(), mgr.GetScheme(), opts.IpamClient)
if err := networkReconciler.SetupWithManager(mgr, opts.NetworkWorkers); err != nil {
klog.Errorf("Unable to start the networkReconciler: %v", err)
Expand Down
47 changes: 7 additions & 40 deletions pkg/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,72 +75,39 @@ func New(ctx context.Context, cl client.Client, opts *ServerOptions) (*LiqoIPAM,
func (lipam *LiqoIPAM) IPAcquire(_ context.Context, req *IPAcquireRequest) (*IPAcquireResponse, error) {
remappedIP, err := lipam.acquireIP(req.GetCidr())
if err != nil {
return &IPAcquireResponse{
Result: &ResponseResult{
Success: false,
Error: err.Error(),
},
}, err
return &IPAcquireResponse{}, err
}

return &IPAcquireResponse{
Ip: remappedIP,
Result: &ResponseResult{
Success: true,
},
}, nil
return &IPAcquireResponse{Ip: remappedIP}, nil
}

// IPRelease releases an IP from a given CIDR.
func (lipam *LiqoIPAM) IPRelease(_ context.Context, req *IPReleaseRequest) (*IPReleaseResponse, error) {
lipam.freeIP(ipCidr{ip: req.GetIp(), cidr: req.GetCidr()})

return &IPReleaseResponse{
Result: &ResponseResult{
Success: true,
},
}, nil
return &IPReleaseResponse{}, nil
}

// NetworkAcquire acquires a network. If it is already reserved, it allocates and reserves a new free one with the same prefix length.
func (lipam *LiqoIPAM) NetworkAcquire(_ context.Context, req *NetworkAcquireRequest) (*NetworkAcquireResponse, error) {
remappedCidr, err := lipam.acquireNetwork(req.GetCidr(), req.GetImmutable())
if err != nil {
return &NetworkAcquireResponse{
Result: &ResponseResult{
Success: false,
Error: err.Error(),
},
}, err
return &NetworkAcquireResponse{}, err
}

return &NetworkAcquireResponse{
Cidr: remappedCidr,
Result: &ResponseResult{
Success: true,
},
}, nil
return &NetworkAcquireResponse{Cidr: remappedCidr}, nil
}

// NetworkRelease releases a network.
func (lipam *LiqoIPAM) NetworkRelease(_ context.Context, req *NetworkReleaseRequest) (*NetworkReleaseResponse, error) {
lipam.freeNetwork(req.GetCidr())

return &NetworkReleaseResponse{
Result: &ResponseResult{
Success: true,
},
}, nil
return &NetworkReleaseResponse{}, nil
}

// NetworkIsAvailable checks if a network is available.
func (lipam *LiqoIPAM) NetworkIsAvailable(_ context.Context, req *NetworkAvailableRequest) (*NetworkAvailableResponse, error) {
available := lipam.isNetworkAvailable(req.GetCidr())

return &NetworkAvailableResponse{
Available: available,
Result: &ResponseResult{
Success: true,
},
}, nil
return &NetworkAvailableResponse{Available: available}, nil
}
98 changes: 39 additions & 59 deletions pkg/ipam/ipam.pb.go

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

14 changes: 6 additions & 8 deletions pkg/ipam/ipam.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ service IPAM {
}

message ResponseResult {
bool success = 1;
string error = 2;
}

message IPAcquireRequest {
string cidr = 1;
}

message IPAcquireResponse {
ResponseResult result = 1;
string ip = 2;
string ip = 1;
ResponseResult result = 2;
}

message IPReleaseRequest {
Expand All @@ -39,8 +37,8 @@ message NetworkAcquireRequest {
}

message NetworkAcquireResponse {
ResponseResult result = 1;
string cidr = 2;
string cidr = 1;
ResponseResult result = 2;
}

message NetworkReleaseRequest {
Expand All @@ -56,6 +54,6 @@ message NetworkAvailableRequest {
}

message NetworkAvailableResponse {
ResponseResult result = 1;
bool available = 2;
bool available = 1;
ResponseResult result = 2;
}

0 comments on commit 49facb9

Please sign in to comment.