-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(): Fixed tunnel status reporting in the slicegw CR #406
Conversation
Signed-off-by: Bharath Horatti <[email protected]>
if isClient(slicegateway) { | ||
// get the remote port number this gw pod is connected to on the remote cluster | ||
_, remotePortInUse := getClientGwRemotePortInUse(ctx, r.Client, slicegateway, GetDepNameFromPodName(slicegateway.Status.Config.SliceGatewayID, gwPod.PodName)) | ||
gwPod.RemotePort = int32(remotePortInUse) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.Atoi
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we need to ensure that the integer value parsed from the string does not exceed the bounds of the int32
type before performing the conversion. This can be achieved by using strconv.ParseInt
with a specified bit size of 32, which directly returns an int64
that can be safely cast to int32
if within bounds.
- Replace the use of
strconv.Atoi
withstrconv.ParseInt
specifying a bit size of 32. - Ensure that the parsed value is within the bounds of
int32
before performing the conversion.
-
Copy modified lines R679-R684
@@ -678,3 +678,8 @@ | ||
_, remotePortInUse := getClientGwRemotePortInUse(ctx, r.Client, slicegateway, GetDepNameFromPodName(slicegateway.Status.Config.SliceGatewayID, gwPod.PodName)) | ||
gwPod.RemotePort = int32(remotePortInUse) | ||
if remotePortInUse >= math.MinInt32 && remotePortInUse <= math.MaxInt32 { | ||
gwPod.RemotePort = int32(remotePortInUse) | ||
} else { | ||
log.Error(fmt.Errorf("remotePortInUse out of int32 bounds"), "Invalid remote port", "remotePortInUse", remotePortInUse) | ||
gwPod.RemotePort = 0 // or some default value | ||
} | ||
} |
-
Copy modified lines R337-R339
@@ -336,5 +336,5 @@ | ||
if envVar.Name == "NODE_PORT" { | ||
nodePort, err := strconv.Atoi(envVar.Value) | ||
if err == nil { | ||
return true, nodePort | ||
nodePort64, err := strconv.ParseInt(envVar.Value, 10, 32) | ||
if err == nil && nodePort64 >= math.MinInt32 && nodePort64 <= math.MaxInt32 { | ||
return true, int(nodePort64) | ||
} |
Signed-off-by: Bharath Horatti <[email protected]>
The gw tunnel status is recorded in the slicegateway CR status field. There are a number of fields like the interface name, rx and tx rates, latency and pkt loss in the status field but not all of them are getting filled. This is occurring because of an incorrect type conversion between gwpod.TunnelStatus and gwsidecar.TunnelStatus. The former struct is what is written to the status field of the CR and the latter is the struct that is filled by the grpc messaging between the operator and the gw sidecar.
The code changes in this PR address the above issue. It also adds additional info in the status field of the CR like the remote port number an instance of gw client is connecting to, and the tunnel state in string format for ease of debugging. The code also contains a couple of fixes for issues reported by the Go static analysis tool: removed unnecessary input params from a couple of functions and updated error messages to start with lowercase.