✨ Add ServiceAccount validation to ClusterExtension reconciliation#2488
Conversation
✅ Deploy Preview for olmv1 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.27% 73.24% -0.04%
==========================================
Files 103 103
Lines 8516 8539 +23
==========================================
+ Hits 6240 6254 +14
- Misses 1801 1808 +7
- Partials 475 477 +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
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
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.
internal/operator-controller/controllers/clusterextension_reconcile_steps.go
Outdated
Show resolved
Hide resolved
internal/operator-controller/controllers/clusterextension_controller_test.go
Outdated
Show resolved
Hide resolved
7cd5abe to
d82a364
Compare
d82a364 to
82ad75a
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 no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
camilamacedo86
left a comment
There was a problem hiding this comment.
I am OK with.
Until we go with easy mode makes sense to me, to validate it in the code.
/approved
| return func(ctx context.Context, state *reconcileState, ext *ocv1.ClusterExtension) (*ctrl.Result, error) { | ||
| l := log.FromContext(ctx) | ||
|
|
||
| l.Info("validating cluster extension") |
There was a problem hiding this comment.
I think we should lower this do debug level.
| } | ||
|
|
||
| // Set status conditions with the validation errors | ||
| err := fmt.Errorf("installation cannot proceed due to the following validation error(s): %w", errors.Join(validationErrors...)) |
There was a problem hiding this comment.
can we make a bit more focused or generic message, because we cannot proceed with the installation or an update, right?
internal/operator-controller/controllers/clusterextension_reconcile_steps.go
Show resolved
Hide resolved
| if apierrors.IsNotFound(err) { | ||
| return fmt.Errorf("service account %q not found in namespace %q", ext.Spec.ServiceAccount.Name, ext.Spec.Namespace) | ||
| } | ||
| return fmt.Errorf("error validating service account: %w", err) |
There was a problem hiding this comment.
given that we just try to access the service accound at the line 105, the error message error validating service account is confusing because we did not perform any validation, just tried to access it.
82ad75a to
6e72e47
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>
6e72e47 to
70e5028
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 no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
camilamacedo86
left a comment
There was a problem hiding this comment.
/approved
@pedjak WDYT? Could you LGTM this one?
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rashmigottipati, tmshort The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
ddf921f
into
operator-framework:main
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