✨ Add ServiceAccount validation to ClusterExtension reconciliation#2488
✨ Add ServiceAccount validation to ClusterExtension reconciliation#2488perdasilva wants to merge 1 commit intooperator-framework:mainfrom
Conversation
✅ Deploy Preview for olmv1 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Pull request overview
This PR adds ServiceAccount validation to the ClusterExtension reconciliation pipeline. The validation checks whether the ServiceAccount specified in .spec.serviceAccount exists on the cluster before proceeding with bundle installation, moving this check from RetrieveRevisionStates to an earlier validation stage.
Changes:
- Introduces a new validation framework with
ValidateClusterExtensionorchestrator andServiceAccountValidatorimplementation - Moves ServiceAccount existence checks earlier in the reconciliation pipeline (after finalizer handling)
- Updates both Boxcutter and Helm reconciler configurations to include the validation step
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
internal/operator-controller/controllers/clusterextension_reconcile_steps.go |
Adds validation framework (ValidateClusterExtension, ClusterExtensionValidator, ServiceAccountValidator) and removes ServiceAccount error handling from RetrieveRevisionStates |
internal/operator-controller/controllers/clusterextension_reconcile_steps_test.go |
Adds comprehensive unit tests for validator functions (10 test cases total) |
internal/operator-controller/controllers/clusterextension_controller_test.go |
Updates existing ServiceAccount test to use new validation approach with mock TokenGetter |
cmd/operator-controller/main.go |
Integrates validation step into both Boxcutter and Helm reconciler configurations |
test/e2e/features/install.feature |
Adds E2E Gherkin scenario for ServiceAccount validation error case |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/operator-controller/controllers/clusterextension_controller_test.go
Outdated
Show resolved
Hide resolved
internal/operator-controller/controllers/clusterextension_reconcile_steps.go
Outdated
Show resolved
Hide resolved
internal/operator-controller/controllers/clusterextension_reconcile_steps.go
Outdated
Show resolved
Hide resolved
internal/operator-controller/controllers/clusterextension_reconcile_steps_test.go
Outdated
Show resolved
Hide resolved
internal/operator-controller/controllers/clusterextension_reconcile_steps.go
Outdated
Show resolved
Hide resolved
internal/operator-controller/controllers/clusterextension_reconcile_steps_test.go
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2488 +/- ##
==========================================
- Coverage 73.21% 73.13% -0.09%
==========================================
Files 102 103 +1
Lines 8505 8539 +34
==========================================
+ Hits 6227 6245 +18
- Misses 1799 1813 +14
- Partials 479 481 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
26b9052 to
58f8e47
Compare
58f8e47 to
64a00b6
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/operator-controller/controllers/clusterextension_reconcile_steps.go
Outdated
Show resolved
Hide resolved
internal/operator-controller/controllers/clusterextension_reconcile_steps_test.go
Outdated
Show resolved
Hide resolved
internal/operator-controller/controllers/clusterextension_reconcile_steps_test.go
Outdated
Show resolved
Hide resolved
internal/operator-controller/controllers/clusterextension_reconcile_steps.go
Outdated
Show resolved
Hide resolved
64a00b6 to
8e814fb
Compare
| revisionStates, err := r.GetRevisionStates(ctx, ext) | ||
| if err != nil { | ||
| setInstallStatus(ext, nil) | ||
| var saerr *authentication.ServiceAccountNotFoundError |
There was a problem hiding this comment.
this got split between the service account validator and the cluster extension validator
8e814fb to
cf4cdb1
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/operator-controller/controllers/clusterextension_controller_test.go
Outdated
Show resolved
Hide resolved
internal/operator-controller/controllers/clusterextension_controller_test.go
Show resolved
Hide resolved
cf4cdb1 to
a946319
Compare
a946319 to
81c68c3
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/operator-controller/controllers/clusterextension_controller_test.go
Outdated
Show resolved
Hide resolved
81c68c3 to
6d40acc
Compare
18ede8a to
6bad46a
Compare
| require.NoError(t, cl.DeleteAllOf(ctx, &ocv1.ClusterExtension{})) | ||
| } | ||
|
|
||
| func TestClusterExtensionServiceAccountNotFound(t *testing.T) { |
There was a problem hiding this comment.
I moved this use-case into a more general test against validation
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // validators sequentially. All validators are executed even if some fail, | ||
| // and all errors are collected and returned as a joined error. | ||
| // This provides complete validation feedback in a single reconciliation cycle. | ||
| func ValidateClusterExtension(validators ...ClusterExtensionValidator) ReconcileStepFunc { |
There was a problem hiding this comment.
it would be nice to add some unit tests for the new reconcile step.
6bad46a to
773c8f2
Compare
773c8f2 to
a352ccc
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/operator-controller/controllers/clusterextension_controller_test.go
Show resolved
Hide resolved
a352ccc to
8638859
Compare
…erExtension Introduces an extensible validation framework that runs early in the ClusterExtension reconciliation pipeline (after finalizer handling, before revision state retrieval) to catch configuration errors before expensive operations begin. Key changes: - New ClusterExtensionValidator type and ValidateClusterExtension reconcile step that executes all validators and collects all errors (no fail-fast behavior) - ServiceAccountValidator checks SA existence via direct CoreV1 API Get call, providing clear "not found" feedback - Sets Installed=Unknown and Progressing=Retrying conditions on validation failure - Removed SA-specific error handling from RetrieveRevisionStates, since validation now catches these errors earlier - Added RBAC permission (get serviceaccounts) to the operator-controller manager ClusterRole and regenerated manifests Testing: - Table-driven unit tests covering 7 scenarios (all pass, single fail, multiple fail, mixed, SA not found, SA found) - E2E scenario for missing ServiceAccount validation error Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com> Signed-off-by: Per G. da Silva <pegoncal@redhat.com>
8638859 to
7cd5abe
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return nil, nil | ||
| } | ||
|
|
||
| // Set status condition with the validation error for other validation failures |
There was a problem hiding this comment.
The comment "Set status condition with the validation error for other validation failures" is misleading. The word "other" suggests there are different types of validation failures handled differently, but this code path handles all validation failures uniformly. Consider changing to "Set status conditions with the validation errors" for clarity.
| // Set status condition with the validation error for other validation failures | |
| // Set status conditions with the validation errors |
| serviceAccountValidatorWithFakeClient(&corev1.ServiceAccount{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "missing-sa", |
There was a problem hiding this comment.
The test setup is confusing because it creates a ServiceAccount named "missing-sa" in the fake client, but the test name "service account not found" and the expected error message suggest we're testing for "test-sa" not being found. While the test logic is correct (it verifies that when "test-sa" doesn't exist, we get the expected error), the setup could be clearer. Consider either: (1) Renaming the ServiceAccount to clarify it's a decoy (e.g., "other-sa"), (2) Adding a comment explaining that this creates a different SA to ensure "test-sa" is not found, or (3) Passing nil to serviceAccountValidatorWithFakeClient to make it explicit that no SA exists.
| serviceAccountValidatorWithFakeClient(&corev1.ServiceAccount{ | |
| ObjectMeta: metav1.ObjectMeta{ | |
| Name: "missing-sa", | |
| // Create a different ServiceAccount to ensure "test-sa" is not found. | |
| serviceAccountValidatorWithFakeClient(&corev1.ServiceAccount{ | |
| ObjectMeta: metav1.ObjectMeta{ | |
| Name: "other-sa", |
Summary
Introduces an extensible validation framework for ClusterExtension reconciliation that validates configuration before attempting bundle installation. The first validator ensures the specified ServiceAccount exists.
Problem
Previously, ServiceAccount validation happened during revision state retrieval, which meant:
Solution
New Validation Framework
ValidateClusterExtension(validators ...ClusterExtensionValidator)Installed: UnknownProgressing: True (Reason: Retrying)ServiceAccountValidator(saClient)Getcallservice account "name" not found in namespace "ns"Integration Points
Added as a reconcile step (after finalizer handling, before revision state retrieval) in both:
RBAC Changes
getpermission forserviceaccountsresources to the operator-controller manager ClusterRoleCleanup
RetrieveRevisionStatessince validation now happens earlier in the pipelineauthentication.ServiceAccountNotFoundErrordependency from reconcile steps and testsTesting
Unit Tests (
clusterextension_controller_test.go)TestValidateClusterExtension- 7 table-driven scenarios:E2E Tests (
test/e2e/features/install.feature)Files Changed
cmd/operator-controller/main.go- Added validation step with ServiceAccountValidator to both boxcutter and helm reconciler configurationsinternal/operator-controller/controllers/clusterextension_reconcile_steps.go- New validation framework (ClusterExtensionValidator type, ValidateClusterExtension, ServiceAccountValidator), removed SA error handling from RetrieveRevisionStatesinternal/operator-controller/controllers/clusterextension_controller_test.go- Replaced TestClusterExtensionServiceAccountNotFound with comprehensive TestValidateClusterExtension table-driven tests (7 scenarios)internal/operator-controller/controllers/suite_test.go- Added Validators field to test deps and included ValidateClusterExtension in default reconcile stepshelm/olmv1/templates/rbac/clusterrole-operator-controller-manager-role.yml- Added get permission for serviceaccountsmanifests/*.yaml- Regenerated manifests reflecting RBAC changestest/e2e/features/install.feature- E2E validation scenario for missing ServiceAccount🤖 Generated with Claude Code