Skip to content
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(): offboard ns when invalid labels are applied to ns #409

Closed
wants to merge 24 commits into from

Conversation

gourishkb
Copy link
Contributor

Description

When a namespace is applied labels and/or annotations that are not part of the sliceconfig spec,
worker operator does remove the labels/annotations and hence, the workloads may come up with unnecessary labels/annotations.
This issue is now fixed under the changes in this PR
Fixes #

How Has This Been Tested?

test-cases

  • namespace with the kubeslice labels but not part of any sliceconfig is offboarded
  • namespace with the kubeslice annotations but not part of any sliceconfig is offboarded
  • namespace with valid kubeslice labels/annotations work as expected
  • namespace when replicated from cluster "worker-1" having valid sliceconfig to another cluster "worker-2", the workloads do not have invalid kubeslice labels/annotations

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR requires documentation updates?
  • I've updated documentation as required by this PR.
  • I have ran go fmt
  • I have updated the helm chart as required by this PR.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have tested it for all user roles.
  • I have added all the required unit test cases.
  • I have verified the E2E test cases with new code changes.
  • I have added all the required E2E test cases.

Does this PR introduce a breaking change?


KRANTHI0918 and others added 12 commits November 5, 2024 15:33
worker-operator

Updated the docs URL link
* fix(): configurable ns exclusion list

Signed-off-by: Priyank Upadhyay <[email protected]>

* fix(): refactors

Signed-off-by: Priyank Upadhyay <[email protected]>

---------

Signed-off-by: Priyank Upadhyay <[email protected]>
Signed-off-by: Mridul Gain <[email protected]>
Signed-off-by: Mridul Gain <[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

Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi
to a lower bit size type int32 without an upper bound check.

Copilot Autofix AI about 1 month ago

To fix the problem, we need to ensure that the integer value obtained from strconv.Atoi is within the bounds of the int32 type before casting it. 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 after ensuring it is within the valid range.

  1. Replace the use of strconv.Atoi with strconv.ParseInt specifying a bit size of 32.
  2. Add bounds checking to ensure the parsed integer is within the range of int32 before casting.
Suggested changeset 2
controllers/slicegateway/slicegateway.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/controllers/slicegateway/slicegateway.go b/controllers/slicegateway/slicegateway.go
--- a/controllers/slicegateway/slicegateway.go
+++ b/controllers/slicegateway/slicegateway.go
@@ -683,3 +683,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("remote port out of int32 range"), "Invalid remote port", "remotePortInUse", remotePortInUse)
+				gwPod.RemotePort = 0 // or some default value
+			}
 		}
EOF
@@ -683,3 +683,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("remote port out of int32 range"), "Invalid remote port", "remotePortInUse", remotePortInUse)
gwPod.RemotePort = 0 // or some default value
}
}
controllers/slicegateway/utils.go
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/controllers/slicegateway/utils.go b/controllers/slicegateway/utils.go
--- a/controllers/slicegateway/utils.go
+++ b/controllers/slicegateway/utils.go
@@ -336,5 +336,6 @@
 				if envVar.Name == "NODE_PORT" {
-					nodePort, err := strconv.Atoi(envVar.Value)
+					nodePort64, err := strconv.ParseInt(envVar.Value, 10, 32)
 					if err == nil {
-						return true, nodePort
+						nodePort := int32(nodePort64)
+						return true, int(nodePort)
 					}
EOF
@@ -336,5 +336,6 @@
if envVar.Name == "NODE_PORT" {
nodePort, err := strconv.Atoi(envVar.Value)
nodePort64, err := strconv.ParseInt(envVar.Value, 10, 32)
if err == nil {
return true, nodePort
nodePort := int32(nodePort64)
return true, int(nodePort)
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@gourishkb gourishkb closed this Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants