Commit db1ea33
authored
feat: add Internal support for cloud-managed roles (#1230)
* refactor(roles): extract helper functions to reduce duplication
Extract two helper functions in the roles client to eliminate code
duplication and improve maintainability:
- validateRole: Centralizes role validation logic (nil check and empty
name check) that was duplicated across 5 methods (Has, Create, Delete,
Update, ClearPrincipals). Includes documentation explaining the
defensive programming rationale despite Kubernetes name guarantees.
- membersToStringSlice: Converts RoleMember slice to principal string
slice using "PrincipalType:Name" format. Replaces duplicate conversion
logic in Update and ClearPrincipals methods, reducing 10+ lines to
simple function calls.
All existing tests pass, confirming behavior is unchanged.
* refactor(controller): extract isRoleRename helper function
Extract isRoleRename helper function to eliminate duplicated complex
conditional logic in the role controller.
The function encapsulates the three-part condition that determines when
a role rename operation is needed:
- Previous effective name exists (not empty)
- Effective name has changed
- Role is currently managed
This helper is used in two locations:
- SyncResource: Triggers rename workflow when effective name changes
- DeleteResource: Cleans up previous role from incomplete renames
Makes the code more readable and self-documenting by replacing complex
boolean expressions with a clear function name. All tests pass.
* feat(api): add internal role support with prefix handling
Add support for Redpanda internal roles that use the "__" prefix
convention. This allows Kubernetes resources to manage roles that
are internal to Redpanda.
Changes:
- Add Internal boolean field to RoleSpec to mark roles as internal
- Add GetEffectiveRoleName() method that returns "__<name>" when
Internal is true, otherwise returns "<name>"
- Add EffectiveRoleName field to RoleStatus to track the last
reconciled role name for detecting renames
- Update GetPrincipal() to use the effective role name
- Add InternalRolePrefix constant ("__")
The effective role name is used throughout the reconciliation logic
to ensure the correct role is created/updated/deleted in Redpanda,
while the status field enables proper cleanup during rename operations.
Generated files updated:
- CRD schema (cluster.redpanda.com_redpandaroles.yaml)
- Apply configurations (rolespec.go, rolestatus.go)
- API documentation (crd-docs.adoc)
* test(roles): add tests for internal role functionality
Add comprehensive test coverage for internal role feature:
API tests (role_types_test.go):
- GetEffectiveRoleName returns name with "__" prefix when Internal=true
- GetEffectiveRoleName returns plain name when Internal=false
- GetPrincipal uses effective role name in principal string
Controller tests (role_controller_test.go):
- TestRoleRename: Validates rename workflow when Internal flag toggles
- Creates role without internal flag
- Renames to internal role (adds "__" prefix)
- Renames back to non-internal role (removes prefix)
- Verifies old roles are cleaned up after renames
- Confirms proper role existence at each step
All tests verify that:
- Effective role names are correctly computed
- Role creation uses the effective name
- Renames properly create new and delete old roles
- Status tracking enables cleanup of previous roles
* test(acceptance): add internal role scenarios
Add Gherkin acceptance tests for internal role feature with complete
end-to-end validation.
New scenarios in role-crds.feature:
- "Role with internal flag": Validates that roles with Internal=true
are created with "__" prefix in Redpanda and can be queried correctly
- "Role rename via internal flag toggle": Validates the rename workflow
when toggling the Internal flag, ensuring old roles are cleaned up
Test implementation (roles.go):
- Add roleHasInternalFlagSet step to configure Internal field
- Add roleExistsInRedpandaWithName step to verify effective names
- Add roleDoesNotExistInRedpandaWithName step for cleanup validation
- Enhance role existence checking to support both CRD name and
effective role name validation
- Add internal flag support to role creation helpers
Infrastructure (register.go):
- Register new step definitions for internal role scenarios
These acceptance tests validate the complete workflow including:
- Kubernetes CRD creation with Internal flag
- Redpanda role creation with correct prefix
- Role rename handling and cleanup
- Principal and ACL management with effective names
* chore: add changelog entry for internal role feature
Document the addition of the Internal field to RedpandaRole spec for
managing Redpanda internal roles with "__" prefix.1 parent cce6185 commit db1ea33
File tree
13 files changed
+761
-139
lines changed- .changes/unreleased
- acceptance
- features
- steps
- operator
- api
- applyconfiguration/redpanda/v1alpha2
- redpanda/v1alpha2
- testdata
- config/crd/bases
- internal/controller/redpanda
- pkg/client/roles
13 files changed
+761
-139
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
71 | 76 | | |
72 | 77 | | |
73 | 78 | | |
| |||
0 commit comments