Skip to content

Minor fixes/improvements to the spoke submariner agent controllers#2649

Open
tpantelis wants to merge 5 commits intostolostron:mainfrom
tpantelis:spoke_mods
Open

Minor fixes/improvements to the spoke submariner agent controllers#2649
tpantelis wants to merge 5 commits intostolostron:mainfrom
tpantelis:spoke_mods

Conversation

@tpantelis
Copy link
Copy Markdown
Collaborator

@tpantelis tpantelis commented Apr 3, 2026

See commits for details.

Summary by CodeRabbit

  • Bug Fixes

    • Improved deployment error messages to include namespace-qualified details for clearer troubleshooting.
  • Performance

    • Optimized memory allocations and simplified internal caching for more efficient runtime behavior.
  • Tests

    • Updated test suites and helpers to uniformly accept and propagate contexts for more reliable test execution.

Update the error message when a deployment has no available replicas to
include the namespace and actual deployment name instead of a transformed
version.

Also fixes grammar: "replica" -> "replicas"

Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
Replace the map[string]*SubmarinerConfig with a simple pointer since
this controller only manages a single SubmarinerConfig instance (the
spoke cluster's own config on the hub). The map was unnecessary overhead
as it would only ever contain the single instance.

This simplifies the code and makes the singleton nature explicit.

Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 12f0f7f6-66bd-4a21-9ae4-48693179df87

📥 Commits

Reviewing files that changed from the base of the PR and between 95c693a and 1454c18.

📒 Files selected for processing (5)
  • pkg/spoke/submarineragent/config_controller_test.go
  • pkg/spoke/submarineragent/connections_controller_test.go
  • pkg/spoke/submarineragent/deployment_controller_test.go
  • pkg/spoke/submarineragent/gateways_controller_test.go
  • pkg/spoke/submarineragent/submarineragent_suite_test.go

📝 Walkthrough

Walkthrough

Refactored submariner agent internals: consolidated config cache to a single pointer, adjusted deployment degraded messaging and error handling, preallocated several slices, and threaded context.Context through numerous Ginkgo test helpers and test setups.

Changes

Cohort / File(s) Summary
Config Controller
pkg/spoke/submarineragent/config_controller.go
Replaced per-namespace knownConfigs map with a single lastKnownConfig pointer; updated skip-sync logic to compare lastKnownConfig.Spec; assigned lastKnownConfig when conditions become True; preallocated gateway/error/name slices via make(..., 0, ...).
Deployment Controller
pkg/spoke/submarineragent/deployment_controller.go
Preallocated degradedConditionReasons/degradedConditionMessages with capacity 10; changed degraded message to namespace-qualified format (namespace/name); standardized DaemonSet error handling switch cases to use default: for non-nil errors while preserving wrapped error returns.
Test Context Propagation (spoke/submarineragent)
pkg/spoke/submarineragent/config_controller_test.go, pkg/spoke/submarineragent/deployment_controller_test.go, pkg/spoke/submarineragent/connections_controller_test.go, pkg/spoke/submarineragent/gateways_controller_test.go, pkg/spoke/submarineragent/submarineragent_suite_test.go
Threaded context.Context through Ginkgo It/JustBeforeEach callbacks and many helper functions; updated helper signatures to accept ctx context.Context; replaced context.TODO() uses with passed ctx; introduced internal controllerCtx for informer startup and controller.Run in several tests.
General Tests Helpers
pkg/spoke/submarineragent/..._test.go (multiple helpers across files)
Refactored numerous test-driver helper methods to accept and forward ctx for Kubernetes client calls and await helpers; one test callback changed to func(_ context.Context) to ignore the context parameter.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble at code, a carrot of change,
One config to mind, slices prearranged,
Contexts now travel where tests used to roam,
Namespaced messages guide deployments home,
A hop, a refactor — the meadow's my codegroom. 🍃

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Minor fixes/improvements to the spoke submariner agent controllers' is vague and uses generic language ('misc updates' style phrasing) that doesn't convey specific meaningful information about the changeset. Clarify the title to be more specific about the primary changes, such as 'Propagate Ginkgo context through test helpers and improve controller cache management' or similar.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pkg/spoke/submarineragent/config_controller.go (1)

130-139: Event filter is now less restrictive.

The filter changed from matching a specific object name to matching any object in the cluster namespace. Since the informers are already namespace-scoped via WithNamespace(o.ClusterName), this filter is effectively a no-op—all events in the namespace will pass through.

The sync function still fetches objects by their specific names (constants.SubmarinerAddOnName, constants.SubmarinerConfigName), so correctness is maintained. However, this may cause extra reconcile loops for unrelated objects in the namespace. If the namespace is expected to contain only these specific resources, this is a minor concern.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/spoke/submarineragent/config_controller.go` around lines 130 - 139, The
event filters passed to WithFilteredEventsInformers are too broad (they only
check namespace equality) and cause reconciles for any object in the namespace;
narrow them to only allow events for the specific resources the sync expects by
checking object name as well (e.g., in the AddOn informer filter verify
metaObj.GetNamespace()==c.clusterName &&
metaObj.GetName()==constants.SubmarinerAddOnName, and in the Config informer
filter verify metaObj.GetNamespace()==c.clusterName &&
metaObj.GetName()==constants.SubmarinerConfigName) so that the filters on
input.AddOnInformer.Informer() and input.ConfigInformer.Informer() only pass
events for the targeted resources.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/spoke/submarineragent/config_controller.go`:
- Around line 130-139: The event filters passed to WithFilteredEventsInformers
are too broad (they only check namespace equality) and cause reconciles for any
object in the namespace; narrow them to only allow events for the specific
resources the sync expects by checking object name as well (e.g., in the AddOn
informer filter verify metaObj.GetNamespace()==c.clusterName &&
metaObj.GetName()==constants.SubmarinerAddOnName, and in the Config informer
filter verify metaObj.GetNamespace()==c.clusterName &&
metaObj.GetName()==constants.SubmarinerConfigName) so that the filters on
input.AddOnInformer.Informer() and input.ConfigInformer.Informer() only pass
events for the targeted resources.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1f0d8372-ddd4-404b-8573-dc4cae8aaa03

📥 Commits

Reviewing files that changed from the base of the PR and between ec7c129 and c9aea43.

📒 Files selected for processing (7)
  • pkg/spoke/submarineragent/config_controller.go
  • pkg/spoke/submarineragent/config_controller_test.go
  • pkg/spoke/submarineragent/connections_controller_test.go
  • pkg/spoke/submarineragent/deployment_controller.go
  • pkg/spoke/submarineragent/deployment_controller_test.go
  • pkg/spoke/submarineragent/gateways_controller_test.go
  • pkg/spoke/submarineragent/submarineragent_suite_test.go

In error handling switch statements with the pattern:
  case apierrors.IsNotFound(err):
  case err == nil:
  case err != nil:

The third case is redundant since if we reach it, err must be non-nil
(the previous cases already handled NotFound and nil). Using 'default'
is more idiomatic and clearer in intent.

Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
Pre-allocate slice capacity where the final size is known or can be
reasonably estimated. This reduces memory allocations and copies during
append operations.

Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
Update all test files to properly propagate the Ginkgo-injected context
through helper function chains, eliminating inappropriate uses of
context.TODO(). Note that context.TODO() is still used for long-running
controller contexts rather than the request-scoped Ginkgo-injected
context. Added nolint:contextcheck directives to ignore these.

Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
@tpantelis
Copy link
Copy Markdown
Collaborator Author

/override ci/prow/sonarcloud

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 3, 2026

@tpantelis: Overrode contexts on behalf of tpantelis: ci/prow/sonarcloud

Details

In response to this:

/override ci/prow/sonarcloud

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 7, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: aswinsuryan
Once this PR has been reviewed and has the lgtm label, please assign skeeey for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants