ci-operator: refactor FromConfig signature#4947
ci-operator: refactor FromConfig signature#4947danilo-gemoli wants to merge 1 commit intoopenshift:mainfrom
FromConfig signature#4947Conversation
|
Pipeline controller notification For optional jobs, comment This repository is configured in: automatic mode |
WalkthroughThis pull request refactors configuration parameter passing across the CI operator codebase by introducing a centralized Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: danilo-gemoli 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@pkg/defaults/defaults.go`:
- Around line 55-59: In FromConfig, check the error returned by
ctrlruntimeclient.NewWithWatch before applying any wrappers: call
ctrlruntimeclient.NewWithWatch(cfg.ClusterConfig, ...) and immediately if err !=
nil return the error (or handle it), and only after a successful crclient
creation call secretrecordingclient.Wrap(crclient, cfg.Censor) and
labeledclient.WrapWithWatch(...); ensure you move the err check to immediately
follow NewWithWatch to avoid wrapping a nil or invalid client.
| func FromConfig(ctx context.Context, cfg *Config) ([]api.Step, []api.Step, error) { | ||
| crclient, err := ctrlruntimeclient.NewWithWatch(cfg.ClusterConfig, ctrlruntimeclient.Options{}) | ||
| crclient = secretrecordingclient.Wrap(crclient, cfg.Censor) | ||
| crclient = labeledclient.WrapWithWatch(crclient, cfg.JobSpec) | ||
| if err != nil { |
There was a problem hiding this comment.
Check NewWithWatch error before wrapping the client.
crclient is wrapped before err is checked; if creation fails, the wrappers can panic or mask the root error.
🔧 Suggested fix
crclient, err := ctrlruntimeclient.NewWithWatch(cfg.ClusterConfig, ctrlruntimeclient.Options{})
-if err != nil {
- return nil, nil, fmt.Errorf("failed to construct client: %w", err)
-}
-crclient = secretrecordingclient.Wrap(crclient, cfg.Censor)
-crclient = labeledclient.WrapWithWatch(crclient, cfg.JobSpec)
+if err != nil {
+ return nil, nil, fmt.Errorf("failed to construct client: %w", err)
+}
+crclient = secretrecordingclient.Wrap(crclient, cfg.Censor)
+crclient = labeledclient.WrapWithWatch(crclient, cfg.JobSpec)🤖 Prompt for AI Agents
In `@pkg/defaults/defaults.go` around lines 55 - 59, In FromConfig, check the
error returned by ctrlruntimeclient.NewWithWatch before applying any wrappers:
call ctrlruntimeclient.NewWithWatch(cfg.ClusterConfig, ...) and immediately if
err != nil return the error (or handle it), and only after a successful crclient
creation call secretrecordingclient.Wrap(crclient, cfg.Censor) and
labeledclient.WrapWithWatch(...); ensure you move the err check to immediately
follow NewWithWatch to avoid wrapping a nil or invalid client.
|
@danilo-gemoli: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
FromConfigis one of the most critical function because it creates the ci-operator's execution graph. Having more than 20 parameters it started to become unsustainable.This is an attempt to extract them all into a configuration type, therefore making the code more clean (hopefully).
It's just a refactor but, given the importance of the function, I believe it deserves a PR on its own.