Skip to content

Conversation

@rafabene
Copy link
Contributor

@rafabene rafabene commented Dec 4, 2025

Summary

  • Implement BROKER_TOPIC_PREFIX environment variable and topic_prefix config option for multi-tenant isolation
  • Topics are named {prefix}-{resourceKind} (e.g., hyperfleet-dev-rafael-Cluster)
  • Environment variable takes precedence over config file
  • Empty prefix maintains backwards compatibility (no prefix added)
  • Update documentation with naming conventions following architecture repo PR #41
  • Remove AWS SQS reference (only RabbitMQ and Google Pub/Sub supported)

Test plan

  • Run unit tests: make test
  • Deploy to GKE with custom topic prefix
  • Verify topics are created with correct prefix in Google Pub/Sub
  • Verify metrics include correct namespace filter

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added configurable broker topic via BROKER_TOPIC and a broker.topic setting to control full topic naming for multi-tenant/environment isolation.
  • Documentation

    • Expanded deployment and run guides with topic naming examples, Helm values, GKE steps, Pub/Sub emulator guidance, and updated README references.
    • Added commented example for topic-prefix usage in sample config.
  • Chores

    • Removed AWS SQS entry from testcontainers docs.

✏️ Tip: You can customize this high-level summary in your review settings.

@openshift-ci
Copy link

openshift-ci bot commented Dec 4, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai
Copy link

coderabbitai bot commented Dec 4, 2025

Walkthrough

This pull request introduces a configurable broker topic value exposed as a new Topic field in the Sentinel configuration and as a Helm value broker.topic. The container deployment exposes a new BROKER_TOPIC environment variable which, when set, overrides the topic from the config file. Sentinel's publish logic now uses the configured topic instead of a hardcoded resource kind. Tests and documentation (README, running guides, Helm values and examples) were updated to cover and describe the new configuration and environment variable behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • internal/config/config.go: verify env var lookup, unmarshalling, and override precedence (including empty value clearing behavior).
  • internal/sentinel/sentinel.go and tests: ensure publish uses cfg.Topic correctly and logging/format is accurate.
  • Helm charts (values.yaml, deployment.yaml): validate templating for broker.topic and correct quoting/templating in env var injection.
  • docs and examples: confirm consistency between README, running-sentinel.md, configs/dev-example.yaml, and testcontainers.md.
  • config tests: check coverage for env var override, empty env var behavior, and config-file fallback.

Suggested labels

lgtm

Suggested reviewers

  • rh-amarin

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding topic prefix support for multi-tenant isolation. It directly matches the primary objective of the PR and is clear and specific.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5bd4444 and 56c84dc.

📒 Files selected for processing (8)
  • README.md (1 hunks)
  • deployments/helm/sentinel/templates/deployment.yaml (1 hunks)
  • deployments/helm/sentinel/values.yaml (1 hunks)
  • docs/running-sentinel.md (10 hunks)
  • internal/config/config.go (3 hunks)
  • internal/config/config_test.go (1 hunks)
  • internal/sentinel/sentinel.go (2 hunks)
  • internal/sentinel/sentinel_test.go (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • internal/config/config.go
  • internal/sentinel/sentinel.go
  • deployments/helm/sentinel/templates/deployment.yaml
  • deployments/helm/sentinel/values.yaml
  • README.md
🧰 Additional context used
🧬 Code graph analysis (1)
internal/config/config_test.go (1)
internal/config/config.go (1)
  • LoadConfig (74-114)
🪛 LanguageTool
docs/running-sentinel.md

[grammar] ~317-~317: Ensure spelling is correct
Context: ...rep hyperfleet_sentinel ``` #### Check PodMonitoring Status List PodMonitoring resources: ...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🔇 Additional comments (5)
internal/config/config_test.go (1)

410-525: LGTM! Comprehensive test coverage for Topic configuration.

The test suite thoroughly covers all Topic loading scenarios:

  • Environment variable takes precedence
  • Config file fallback when env var is absent
  • Empty defaults when neither source provides a value
  • Explicit clearing via empty env var

The tests follow Go best practices with proper cleanup (t.Setenv, manual save/restore) and clear test names.

internal/sentinel/sentinel_test.go (2)

101-106: LGTM! Test correctly updated for configurable Topic.

The addition of Topic: "test-topic" to the SentinelConfig properly reflects the new topic configuration behavior.


126-128: LGTM! Assertion correctly verifies configured topic.

The test now properly asserts that the topic from the config is used for publishing, rather than a hardcoded value.

docs/running-sentinel.md (2)

114-126: LGTM! Clear documentation for topic configuration.

The new section clearly explains how to set the BROKER_TOPIC environment variable with practical examples for both clusters and nodepools. The reference to the Naming Strategy document provides helpful context for multi-tenant isolation.


268-279: LGTM! Well-documented Helm deployment with helpful tip.

The Helm deployment command is clear and uses proper variable substitution. The tip about default topic naming and the ability to override with --set broker.topic is valuable guidance for users.


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

@openshift-ci openshift-ci bot added the approved label Dec 4, 2025
@rafabene rafabene force-pushed the HYPERFLEET-283-topic-prefix branch 9 times, most recently from eb61aa5 to 38a0d3a Compare December 4, 2025 14:01
Implement BROKER_TOPIC_PREFIX environment variable and topic_prefix config
option to enable isolation between different environments or tenants sharing
the same message broker.

Changes:
- Add TopicPrefix field to SentinelConfig with env var override
- Update Sentinel to prefix topics: {prefix}-{resourceKind}
- Add Helm chart support for broker.topicPrefix
- Update documentation with naming conventions for namespace, image tags,
  and topic prefixes following architecture repo conventions
- Remove AWS SQS reference (only RabbitMQ and Google Pub/Sub supported)

When BROKER_TOPIC_PREFIX is set to "hyperfleet-dev-rafael", topics become
"hyperfleet-dev-rafael-Cluster" instead of just "Cluster".

Empty prefix maintains backwards compatibility (no prefix added).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@rafabene rafabene force-pushed the HYPERFLEET-283-topic-prefix branch from 38a0d3a to 5bd4444 Compare December 4, 2025 14:02
@rafabene rafabene marked this pull request as ready for review December 4, 2025 14:04
Copy link

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
README.md (1)

176-182: Add blank lines around the Topic Naming table for markdownlint

The Topic Naming / BROKER_TOPIC_PREFIX docs look correct and aligned with the implementation. To satisfy MD058 (“blanks-around-tables”), add a blank line before and after the table:

-**Topic Naming (Multi-tenant Isolation):**
-| Variable | Description | Example |
+**Topic Naming (Multi-tenant Isolation):**
+
+| Variable | Description | Example |
 ...
-| `BROKER_TOPIC_PREFIX` | Prefix for topic names (optional) | `hyperfleet-dev` |
-
-When `BROKER_TOPIC_PREFIX` is set, topics are named `{prefix}-{resourceKind}` ...
+| `BROKER_TOPIC_PREFIX` | Prefix for topic names (optional) | `hyperfleet-dev` |
+
+When `BROKER_TOPIC_PREFIX` is set, topics are named `{prefix}-{resourceKind}` ...
internal/sentinel/sentinel.go (1)

121-125: Topic prefix application is correct; consider logging the topic

The topic construction logic correctly falls back to resource.Kind and uses {TopicPrefix}-{resource.Kind} when a prefix is set, preserving existing behavior.

For easier debugging of multi-tenant setups, consider including the resolved topic in the publish log message:

-			s.logger.Infof(ctx, "Published event resource_id=%s phase=%s reason=%s",
-				resource.ID, resource.Status.Phase, decision.Reason)
+			s.logger.Infof(ctx, "Published event resource_id=%s phase=%s reason=%s topic=%s",
+				resource.ID, resource.Status.Phase, decision.Reason, topic)
deployments/helm/sentinel/values.yaml (1)

107-111: broker.topicPrefix default and docs look good

The topicPrefix field and comments accurately describe the {topicPrefix}-{resourceKind} behavior and defaulting to “no prefix” when empty. This aligns with the Deployment template and config loader.

If you want to avoid any confusion, you could clarify that {{ .Release.Namespace }} is an example value to pass via --set broker.topicPrefix=..., not a template evaluated inside values.yaml.

internal/config/config.go (1)

32-33: Clarify env override semantics for TopicPrefix (and optionally support clearing)

The TopicPrefix field and BROKER_TOPIC_PREFIX override are wired correctly and match the rest of the feature.

Two small follow-ups to consider:

  1. The comment says “Override … from environment variable if set”, but the code only overrides when the value is non-empty. You could clarify this as “if non-empty” to avoid confusion.
  2. If you ever need to clear a topic_prefix from config via env, the current os.Getenv check won’t allow that. Using os.LookupEnv would let you treat “present but empty” as an explicit override:
-	// Override topic_prefix from environment variable if set
-	// Environment variable takes precedence over config file
-	if prefix := os.Getenv("BROKER_TOPIC_PREFIX"); prefix != "" {
-		cfg.TopicPrefix = prefix
-	}
+	// Override topic_prefix from environment variable if explicitly provided
+	// Environment variable takes precedence over config file (including empty value)
+	if prefix, ok := os.LookupEnv("BROKER_TOPIC_PREFIX"); ok {
+		cfg.TopicPrefix = prefix
+	}

This keeps precedence guarantees while allowing explicit “no prefix” via env if needed.

Also applies to: 95-99

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c1da56 and 5bd4444.

📒 Files selected for processing (9)
  • README.md (1 hunks)
  • configs/dev-example.yaml (1 hunks)
  • deployments/helm/sentinel/templates/deployment.yaml (1 hunks)
  • deployments/helm/sentinel/values.yaml (1 hunks)
  • docs/running-sentinel.md (10 hunks)
  • docs/testcontainers.md (0 hunks)
  • internal/config/config.go (3 hunks)
  • internal/config/config_test.go (1 hunks)
  • internal/sentinel/sentinel.go (1 hunks)
💤 Files with no reviewable changes (1)
  • docs/testcontainers.md
🧰 Additional context used
🧬 Code graph analysis (1)
internal/config/config_test.go (1)
internal/config/config.go (1)
  • LoadConfig (74-114)
🪛 LanguageTool
docs/running-sentinel.md

[grammar] ~314-~314: Ensure spelling is correct
Context: ...rep hyperfleet_sentinel ``` #### Check PodMonitoring Status List PodMonitoring resources: ...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🪛 markdownlint-cli2 (0.18.1)
README.md

177-177: Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

🔇 Additional comments (6)
deployments/helm/sentinel/templates/deployment.yaml (1)

63-67: BROKER_TOPIC_PREFIX wiring in Deployment looks correct

Conditional emission on .Values.broker.topicPrefix with a quoted value is consistent with the config loader and keeps the env var optional. No issues found.

configs/dev-example.yaml (1)

13-15: Dev example topic-prefix docs are consistent with behavior

The BROKER_TOPIC_PREFIX example and resulting topic names match the implementation and higher-level docs. Looks good.

internal/config/config_test.go (1)

411-494: TopicPrefix config loader tests are comprehensive

The new tests cover all key cases (env-only, env-overrides-config, config-only, and empty/default) and align with the current LoadConfig semantics. Environment setup/teardown is handled explicitly, so there’s no hidden cross-test coupling. Looks solid.

docs/running-sentinel.md (3)

18-24: GKE section restructuring and ToC anchors are coherent

The updated GKE flow (env vars → connect cluster → build → push → Helm → verify → cleanup) is clear, and the ToC anchors correctly match the new headings. This makes the doc much easier to follow for end-to-end testing.

Also applies to: 195-224


62-67: Local broker + topic prefix guidance matches implementation

The Pub/Sub emulator setup and the new “Set Topic Prefix (Optional)” section are consistent with the actual config behavior:

  • PUBSUB_EMULATOR_HOST usage aligns with typical emulator workflows.
  • BROKER_TOPIC_PREFIX=hyperfleet-dev-${USER} and the example topic names {prefix}-{resourceKind} match the logic in internal/sentinel/sentinel.go.

No issues from a correctness standpoint.

Also applies to: 89-123


238-277: GKE deployment flags correctly wire topicPrefix and metrics verification

The Helm command wiring:

  • --set image.repository=gcr.io/${GCP_PROJECT}/sentinel
  • --set image.tag=${IMAGE_TAG}
  • --set broker.googlepubsub.projectId=${GCP_PROJECT}
  • --set broker.topicPrefix=${NAMESPACE}

matches the chart’s values and the Deployment template, ensuring BROKER_TOPIC_PREFIX is set and topics are namespaced per developer. The subsequent port-forward, metrics, and PodMonitoring instructions are consistent with the earlier configuration.

Looks accurate and actionable.

Also applies to: 295-346, 361-386

value: /etc/sentinel/broker.yaml
# Topic prefix for multi-tenant isolation
{{- if .Values.broker.topicPrefix }}
- name: BROKER_TOPIC_PREFIX
Copy link
Contributor

@rh-amarin rh-amarin Dec 4, 2025

Choose a reason for hiding this comment

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

Could we set directly the TOPIC_NAME and not build it internally within the code?

I think it makes it more explicit to have it in the configuration for the Sentinel what topic it is writing to. Just describe the pod and you find the name of the topic being used.

Of course, this doesn't apply if one Sentinel is writing to different topics, which is not the current design.

One thing with the current approach is that we end up with topic names like amarin-Cluster notice the uppercase C

We could have something already pre-set like:

- name: BROKER_TOPIC
  value: {{ .Release.Namespace}}-cluster

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. PR for architecture needs to be merge to have this aligned: https://github.com/openshift-hyperfleet/architecture/pull/42/files

Changes based on PR openshift-hyperfleet#22 review comments:

- Replace BROKER_TOPIC_PREFIX with BROKER_TOPIC (full topic name)
- Move topic construction to Helm: {namespace}-{resourceType}
- Default in values.yaml: {{ .Release.Namespace }}-{{ .Values.config.resourceType }}
- Use os.LookupEnv to allow empty env var to clear config value
- Add topic to log message for debugging
- Fix lint errors in tests using t.Setenv
- Update documentation with new examples

Examples:
- clusters in hyperfleet-dev-rafael -> hyperfleet-dev-rafael-clusters
- nodepools in hyperfleet-dev-rafael -> hyperfleet-dev-rafael-nodepools
@rh-amarin
Copy link
Contributor

/approve

@openshift-ci
Copy link

openshift-ci bot commented Dec 4, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rafabene, rh-amarin

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

The pull request process is described 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

@rafabene rafabene merged commit 81dfa3a into openshift-hyperfleet:main Dec 4, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants