Support migrated-namespace and migrated-uid annotations#190
Support migrated-namespace and migrated-uid annotations#190
Conversation
WalkthroughInternal subject construction now uses a new helper that derives namespace and UID from object metadata and optional migration annotations; client and exporter InternalSubject implementations call this helper before composing their subject strings. Two new exported annotation constants were added and unit tests cover the new behavior. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as InternalSubject()
participant Obj as Object (Namespace, UID, Annotations)
participant Helper as getNamespaceAndUID
participant Builder as Subject Builder
Caller->>Obj: read Namespace, UID, Annotations
Caller->>Helper: getNamespaceAndUID(namespace, uid, annotations)
Note right of Helper `#E8F6EF`: If migration annotations present\nand non-empty, return overrides
Helper-->>Caller: namespace', uid'
Caller->>Builder: format subject with prefix, namespace', name, uid'
Builder-->>Caller: "client:<ns>:<Name>:<uid>" / "exporter:<ns>:<name>:<uid>"
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
api/v1alpha1/client_helpers.go (1)
6-17: Duplicate annotation logic (see exporter_helpers.go).This annotation-checking logic is identical to the code in
exporter_helpers.go(lines 13-24). Please refer to the review comment on that file for the recommended refactoring to eliminate this duplication.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
api/v1alpha1/client_helpers.go(1 hunks)api/v1alpha1/exporter_helpers.go(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: lint-go
- GitHub Check: e2e-test-operator
- GitHub Check: deploy-kind
- GitHub Check: e2e-tests-release-0-7
- GitHub Check: e2e-tests (ubuntu-24.04-arm)
- GitHub Check: tests
Enable Client/Exporter migration across clusters using annotations to override namespace and UID in authentication tokens. When these annotations are present, tokens authenticate using the migrated values instead of the current object's namespace/UID. Annotations: - jumpstarter.dev/migrated-namespace - jumpstarter.dev/migrated-uid Fixes-Issue: #188
5ed410e to
55af940
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
api/v1alpha1/client_helpers.go(1 hunks)api/v1alpha1/common_helpers.go(1 hunks)api/v1alpha1/exporter_helpers.go(1 hunks)api/v1alpha1/groupversion_info.go(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- api/v1alpha1/client_helpers.go
- api/v1alpha1/exporter_helpers.go
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: mangelajo
Repo: jumpstarter-dev/jumpstarter-controller PR: 190
File: api/v1alpha1/exporter_helpers.go:16-24
Timestamp: 2025-11-14T15:47:36.325Z
Learning: In the jumpstarter-controller project, migration annotations (jumpstarter.dev/migrated-namespace and jumpstarter.dev/migrated-uid) that override namespace and UID values in authentication tokens are acceptable without additional validation webhooks because the security model assumes only administrators have write access to Exporter and Client resources via K8s RBAC.
📚 Learning: 2025-11-14T15:47:36.325Z
Learnt from: mangelajo
Repo: jumpstarter-dev/jumpstarter-controller PR: 190
File: api/v1alpha1/exporter_helpers.go:16-24
Timestamp: 2025-11-14T15:47:36.325Z
Learning: In the jumpstarter-controller project, migration annotations (jumpstarter.dev/migrated-namespace and jumpstarter.dev/migrated-uid) that override namespace and UID values in authentication tokens are acceptable without additional validation webhooks because the security model assumes only administrators have write access to Exporter and Client resources via K8s RBAC.
Applied to files:
api/v1alpha1/common_helpers.goapi/v1alpha1/groupversion_info.go
🧬 Code graph analysis (1)
api/v1alpha1/common_helpers.go (1)
api/v1alpha1/groupversion_info.go (2)
AnnotationMigratedNamespace(40-40)AnnotationMigratedUID(43-43)
🪛 golangci-lint (2.5.0)
api/v1alpha1/common_helpers.go
[error] 22-22: File is not properly formatted
(gofmt)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: e2e-tests (ubuntu-24.04-arm)
- GitHub Check: e2e-tests (ubuntu-24.04)
- GitHub Check: e2e-tests-release-0-7
- GitHub Check: e2e-test-operator
- GitHub Check: deploy-kind
- GitHub Check: tests
- GitHub Check: lint-go
🔇 Additional comments (2)
api/v1alpha1/groupversion_info.go (1)
38-44: LGTM! Well-defined migration annotation constants.The constants are properly named, documented, and follow Kubernetes annotation naming conventions.
api/v1alpha1/common_helpers.go (1)
5-21: LGTM! Solid implementation with proper defensive checks.The helper function correctly handles namespace and UID overrides from migration annotations. The nil check for annotations and non-empty validation for annotation values provide appropriate defensive programming.
Based on learnings.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
api/v1alpha1/client_helpers_test.go (1)
77-77: Consider defining stringPtr locally for test file independence.The
stringPtrhelper is currently defined only inexporter_helpers_test.go(lines 87-89). While Go's test compilation makes it accessible across test files in the same package, defining it in both test files would make each file independently understandable.You could add the helper to this file as well:
// Helper function to create string pointers func stringPtr(s string) *string { return &s }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.golangci.yml(1 hunks)api/v1alpha1/client_helpers_test.go(1 hunks)api/v1alpha1/common_helpers.go(1 hunks)api/v1alpha1/common_helpers_test.go(1 hunks)api/v1alpha1/exporter_helpers_test.go(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- api/v1alpha1/common_helpers_test.go
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: mangelajo
Repo: jumpstarter-dev/jumpstarter-controller PR: 190
File: api/v1alpha1/exporter_helpers.go:16-24
Timestamp: 2025-11-14T15:47:36.325Z
Learning: In the jumpstarter-controller project, migration annotations (jumpstarter.dev/migrated-namespace and jumpstarter.dev/migrated-uid) that override namespace and UID values in authentication tokens are acceptable without additional validation webhooks because the security model assumes only administrators have write access to Exporter and Client resources via K8s RBAC.
📚 Learning: 2025-11-14T15:47:36.325Z
Learnt from: mangelajo
Repo: jumpstarter-dev/jumpstarter-controller PR: 190
File: api/v1alpha1/exporter_helpers.go:16-24
Timestamp: 2025-11-14T15:47:36.325Z
Learning: In the jumpstarter-controller project, migration annotations (jumpstarter.dev/migrated-namespace and jumpstarter.dev/migrated-uid) that override namespace and UID values in authentication tokens are acceptable without additional validation webhooks because the security model assumes only administrators have write access to Exporter and Client resources via K8s RBAC.
Applied to files:
api/v1alpha1/common_helpers.go
🧬 Code graph analysis (3)
api/v1alpha1/common_helpers.go (1)
api/v1alpha1/groupversion_info.go (2)
AnnotationMigratedNamespace(40-40)AnnotationMigratedUID(43-43)
api/v1alpha1/client_helpers_test.go (2)
api/v1alpha1/client_types.go (2)
Client(44-50)ClientSpec(28-30)api/v1alpha1/groupversion_info.go (2)
AnnotationMigratedNamespace(40-40)AnnotationMigratedUID(43-43)
api/v1alpha1/exporter_helpers_test.go (2)
api/v1alpha1/groupversion_info.go (2)
AnnotationMigratedNamespace(40-40)AnnotationMigratedUID(43-43)api/v1alpha1/exporter_types.go (1)
ExporterSpec(28-30)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: tests
- GitHub Check: e2e-tests (ubuntu-24.04)
- GitHub Check: e2e-tests (ubuntu-24.04-arm)
- GitHub Check: e2e-tests-release-0-7
- GitHub Check: lint-go
- GitHub Check: e2e-test-operator
- GitHub Check: deploy-kind
🔇 Additional comments (7)
api/v1alpha1/common_helpers.go (1)
7-21: LGTM! Clean implementation of migration annotation support.The helper function correctly handles namespace and UID derivation with proper nil and empty-value checks. The logic ensures that empty migration annotations are ignored (lines 12, 15), preventing accidental overrides with blank values.
.golangci.yml (1)
28-30: LGTM! Sensible exclusion for test files.Allowing code duplication in test files is appropriate since test cases often follow similar patterns for consistency and clarity.
api/v1alpha1/client_helpers_test.go (2)
10-60: Excellent test coverage for InternalSubject.The three test cases comprehensively cover the migration annotation behavior:
- Default behavior without annotations
- Override behavior with both annotations present
- Fallback behavior when annotations are empty
The expected subject format is correctly validated in each scenario.
62-84: LGTM! Usernames method is thoroughly tested.Both scenarios (with and without custom username) are properly validated. The test correctly verifies that the internal subject is always included and that custom usernames are appended when present.
api/v1alpha1/exporter_helpers_test.go (3)
10-60: Excellent test coverage for Exporter's InternalSubject.The test suite comprehensively validates the migration annotation behavior across all scenarios, mirroring the client tests appropriately. The expected subject format with the "exporter:" prefix is correctly validated.
62-84: LGTM! Usernames behavior is well-tested.Both test cases properly validate the username augmentation logic, ensuring the internal subject and optional custom username are correctly included.
87-89: Good test helper definition.The
stringPtrhelper is used across multiple test files in this package. The current placement works due to Go's test file compilation, and the.golangci.ymlconfiguration explicitly allows this duplication pattern.
Enable Client/Exporter migration across clusters using annotations to override namespace and UID in authentication tokens. When these annotations are present, tokens authenticate using the migrated values instead of the current object's namespace/UID.
Annotations:
Fixes-Issue: jumpstarter-dev/jumpstarter#25
Summary by CodeRabbit
New Features
Tests
Chores