Skip to content

ci-operator: refactor FromConfig signature#4947

Open
danilo-gemoli wants to merge 1 commit intoopenshift:mainfrom
danilo-gemoli:feat/ci-operator/refactor-from-config-signature
Open

ci-operator: refactor FromConfig signature#4947
danilo-gemoli wants to merge 1 commit intoopenshift:mainfrom
danilo-gemoli:feat/ci-operator/refactor-from-config-signature

Conversation

@danilo-gemoli
Copy link
Contributor

FromConfig is 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.

@openshift-ci-robot
Copy link
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

Walkthrough

This pull request refactors configuration parameter passing across the CI operator codebase by introducing a centralized Config struct in the defaults package. The change consolidates numerous individual parameters into a single configuration object, simplifying function signatures and improving maintainability. The refactoring is propagated from the main entry point through the defaults package and its call sites.

Changes

Cohort / File(s) Summary
Configuration struct definition
pkg/defaults/config.go
Introduces new public Config and Clients structs that consolidate configuration objects, runtime parameters, and client interfaces. Config embeds Clients and contains fields for CI/graph configurations, secrets, timeouts, feature flags, and runtime state.
Defaults package refactoring
pkg/defaults/defaults.go, pkg/defaults/defaults_test.go
Refactors FromConfig() signature to accept a single Config object instead of 20+ explicit parameters. Updates internal wiring to source dependencies from config fields. Test cases updated to construct Config struct for function invocations.
Main entry point
cmd/ci-operator/main.go
Adds new ToGraphConfig() method to options that constructs a Config populated with runtime fields. Refactors Run() to use the new method, augmenting the config with additional fields before calling defaults.FromConfig(ctx, cfg).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci bot requested review from deepsm007 and jmguzik February 13, 2026 16:42
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 13, 2026

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 13, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +55 to 59
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 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

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.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 13, 2026

@danilo-gemoli: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/breaking-changes 913cd75 link false /test breaking-changes
ci/prow/images 913cd75 link true /test images
ci/prow/codegen 913cd75 link true /test codegen

Full PR test history. Your PR dashboard.

Details

Instructions 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants