Skip to content

Modifying build client to handle different build logics#5224

Draft
hector-vido wants to merge 1 commit into
openshift:mainfrom
hector-vido:buildclient-adjustment
Draft

Modifying build client to handle different build logics#5224
hector-vido wants to merge 1 commit into
openshift:mainfrom
hector-vido:buildclient-adjustment

Conversation

@hector-vido

@hector-vido hector-vido commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

This is the first step to isolate image build logic inside buildClient , so it can handle different builds on different platforms like AWS, Shipwright, etc.

Summary

This PR introduces a build-type abstraction into ci-operator’s build client so the system can host multiple build-platform implementations. It isolates image build logic inside buildClient and wires configuration through to the client so ci-operator can choose platform-specific build behavior (current default: OpenShift).

What changed (practical effect)

  • Build client API: The BuildClient interface gained BuildType() and NewBuildClient now requires an explicit buildType argument; the concrete buildClient stores and returns that type.
  • Configuration: ReleaseBuildConfiguration accepts an optional build_type field (json:"build_type,omitempty"). Defaulting sets build_type to "openshift" when unspecified, so existing configs continue to behave the same.
  • Build execution: source.go’s build orchestration now dispatches by buildClient.BuildType(). OpenShift builds follow a new handleOpenshiftBuild path that encapsulates creation, exponential-retry handling for "already exists", metrics registration and machine snapshot capture, waiting with timeout semantics, failure handling, and best-effort log collection. Unknown build types return an error.
  • Tests/defaults: Call sites and tests were updated to pass api.BuildTypeOpenshift; the fakeBuildClient test helper implements BuildType() to satisfy the interface.

Component impact

  • Affects ci-operator build step implementation (pkg/steps), API types (pkg/api), and defaults (pkg/defaults). For CI operators and job/config authors: you can now declare build_type in ReleaseBuildConfiguration. Until additional implementations are added, behavior remains OpenShift by default, but the codebase is prepared to add alternate build backends (e.g., AWS, Shipwright) with minimal invasive changes.

Backwards compatibility and next steps

  • Backwards compatible: unspecified build_type defaults to "openshift", preserving existing behavior.
  • Next work: implement and wire additional platform-specific BuildClient behaviors and add dispatch paths for them.

Notes for reviewers

  • API/signature changes: new config field and NewBuildClient signature requires updating all callers.
  • Behavior: review the refactored handleBuild/handleOpenshiftBuild retry, timeout and error-aggregation semantics and the best-effort log-gathering behavior.

@openshift-merge-bot

Copy link
Copy Markdown
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

@openshift-ci

openshift-ci Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 1, 2026
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds a BuildType field and openshift constant to release config, defaults BuildType to "openshift", requires a buildType argument when constructing BuildClient, extends BuildClient with BuildType(), and refactors build execution to dispatch by build type with an extracted OpenShift-specific build helper.

Changes

Build-type addition and build execution refactor

Layer / File(s) Summary
API: BuildType field and defaulting
pkg/api/types.go, pkg/api/config.go, pkg/defaults/defaults.go
Add BuildType to ReleaseBuildConfiguration, introduce BuildTypeOpenshift constant, default config.BuildType to BuildTypeOpenshift, and update FromConfig to pass the openshift build type to NewBuildClient.
BuildClient interface and constructor
pkg/steps/build_client.go
Add BuildType() string to BuildClient, store buildType on the concrete buildClient, and change NewBuildClient to accept and initialize the buildType parameter.
Build execution dispatch and openshift helper
pkg/steps/source.go
Refactor handleBuilds to dispatch on buildClient.BuildType() and extract handleOpenshiftBuild to perform create/wait/metrics/failure handling and best-effort log gathering; use wait.Interrupted(err) when classifying terminal retry-loop errors.
Tests and fakes
pkg/defaults/defaults_test.go, pkg/steps/index_generator_test.go, pkg/steps/source_test.go
Update tests to construct NewBuildClient with api.BuildTypeOpenshift and add BuildType() string to fakeBuildClient.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 14 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Coverage For New Features ⚠️ Warning New or modified functionality missing test coverage: handleOpenshiftBuild() function, BuildType() methods, build type dispatch logic in handleBuilds(), and BuildType field defaults lack unit tests. Add unit tests for handleOpenshiftBuild(), BuildType dispatch logic, BuildType field defaults, and test error paths for undefined build types.
Test Structure And Quality ❓ Inconclusive Custom check requests review of Ginkgo test code, but this repository uses standard Go testing.T with table-driven tests, not Ginkgo. Check cannot be applied as written; codebase uses Go testing.T, not Ginkgo. Review criteria should reference Go testing conventions.
✅ Passed checks (14 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: modifying the build client to handle different build types/logics across platforms via a new BuildType field and dispatch mechanism.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Go Error Handling ✅ Passed Error handling follows Go best practices: errors wrapped with fmt.Errorf %w, intentional ignoring justified with comments, no panic() in new code, and nil pointers safely guarded.
Stable And Deterministic Test Names ✅ Passed This PR does not use Ginkgo tests—it uses standard Go testing.T framework. The custom check for Ginkgo test name stability is not applicable to this codebase.
Microshift Test Compatibility ✅ Passed No Ginkgo e2e tests are added in this PR. All modifications are to package code (pkg/defaults, pkg/steps, pkg/api) and unit tests using standard Go testing.T. The custom check is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No Ginkgo e2e tests added. PR only refactors build client and modifies unit tests using standard Go testing patterns. SNO check not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies build client abstraction for different build types; does not add deployment manifests, operator code, or controller changes with scheduling constraints.
Ote Binary Stdout Contract ✅ Passed No process-level stdout writes introduced. PR modifies business logic in build handling functions called from goroutines, not in main(), init(), or suite setup.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests are present in this PR. All changes modify existing standard Go unit tests to pass a new buildType parameter.
No-Weak-Crypto ✅ Passed No weak cryptography patterns found. The PR modifies build client logic and contains no MD5, SHA1, DES, RC4, 3DES, Blowfish, ECB, custom crypto, or non-constant-time secret comparisons.
Container-Privileges ✅ Passed PR modifies only Go application code to refactor build client logic; no Kubernetes manifests or container configurations with privilege escalation settings are introduced.
No-Sensitive-Data-In-Logs ✅ Passed No sensitive data (passwords, tokens, API keys, PII, session IDs) is exposed in logging statements. New code logs only build names, status, and error messages without sensitive content.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci

openshift-ci Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hector-vido

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 Jun 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/steps/build_client.go`:
- Around line 16-19: The exported constant names are misspelled/inconsistent:
rename BuiltTypeOpenshift and BuilTypeAWSCodeBuild to BuildTypeOpenshift and
BuildTypeAWSCodeBuild respectively, update all usages (including the caller in
defaults.go and the Build() dispatch) to the new identifiers, and run
tests/compile to ensure no remaining references to the old names remain.
- Around line 41-51: The test failures come from calling NewBuildClient with the
old 6-arg signature; update each test call (e.g., in
pkg/defaults/defaults_test.go, pkg/steps/source_test.go,
pkg/steps/index_generator_test.go) to pass the new buildType as the second
argument to NewBuildClient and shift the remaining parameters right so the
restClient, nodeArchitectures, manifestToolDockerCfg, localRegistryDNS, and
metricsAgent match the new signature used in the NewBuildClient function.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: a3d85046-4e20-4c0d-9b63-9f2391f2bb2c

📥 Commits

Reviewing files that changed from the base of the PR and between 8c13338 and 3579519.

📒 Files selected for processing (2)
  • pkg/defaults/defaults.go
  • pkg/steps/build_client.go

Comment thread pkg/steps/build_client.go Outdated
Comment thread pkg/steps/build_client.go
@hector-vido hector-vido force-pushed the buildclient-adjustment branch from 3579519 to 3d53579 Compare June 3, 2026 11:03

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/api/types.go (1)

78-78: ⚡ Quick win

Add a doc comment for BuildType on ReleaseBuildConfiguration.

Line 78 introduces an exported API field without documenting purpose/allowed values/default behavior. Add a short field comment to keep config API self-describing.

As per coding guidelines: "**/*.go: Go documentation on Classes/Functions/Fields should be written properly".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/api/types.go` at line 78, Add a concise Go doc comment above the exported
BuildType field on the ReleaseBuildConfiguration struct explaining what the
field represents, the allowed values (e.g., "debug", "release", "optimized" or
whatever applies), and any default behavior when omitted; update the comment to
be a single-line field comment starting with BuildType so Go tooling picks it up
and keep phrasing brief and self-describing for API consumers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/defaults/defaults.go`:
- Line 63: The code is hardcoding api.BuildTypeOpenshift when constructing the
build client; change the call to steps.NewBuildClient to pass the configured
build type from cfg (e.g., cfg.BuildType) instead of api.BuildTypeOpenshift,
ensuring the value you pass matches the expected parameter type for
steps.NewBuildClient (cast to api.BuildType if necessary) so alternate build
implementations configured at runtime are respected.

---

Nitpick comments:
In `@pkg/api/types.go`:
- Line 78: Add a concise Go doc comment above the exported BuildType field on
the ReleaseBuildConfiguration struct explaining what the field represents, the
allowed values (e.g., "debug", "release", "optimized" or whatever applies), and
any default behavior when omitted; update the comment to be a single-line field
comment starting with BuildType so Go tooling picks it up and keep phrasing
brief and self-describing for API consumers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 7067a433-9827-4b0c-9e30-c6cee8061db3

📥 Commits

Reviewing files that changed from the base of the PR and between 3579519 and 3d53579.

📒 Files selected for processing (5)
  • pkg/api/config.go
  • pkg/api/types.go
  • pkg/defaults/defaults.go
  • pkg/steps/build_client.go
  • pkg/steps/source.go

Comment thread pkg/defaults/defaults.go
@hector-vido hector-vido force-pushed the buildclient-adjustment branch from 3d53579 to af741f2 Compare June 3, 2026 11:19

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
pkg/api/types.go (1)

78-78: ⚡ Quick win

Document the exported BuildType field.

Please add a field comment describing supported values/default behavior for BuildType, since this is part of the user-facing config API.

Suggested diff
-	BuildType string `json:"build_type,omitempty"`
+	// BuildType selects the build implementation. Defaults to "openshift".
+	BuildType string `json:"build_type,omitempty"`

As per coding guidelines, "**/*.go: Go documentation on Classes/Functions/Fields should be written properly".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/api/types.go` at line 78, Add a Go doc comment for the exported BuildType
field on the relevant struct (BuildType string `json:"build_type,omitempty"`)
that describes the supported values (e.g., possible enum strings), the default
behavior when omitted, and any validation/semantic meaning; place the comment
immediately above the BuildType field so it appears in generated docs and
follows Go doc conventions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/api/types.go`:
- Line 78: Add a Go doc comment for the exported BuildType field on the relevant
struct (BuildType string `json:"build_type,omitempty"`) that describes the
supported values (e.g., possible enum strings), the default behavior when
omitted, and any validation/semantic meaning; place the comment immediately
above the BuildType field so it appears in generated docs and follows Go doc
conventions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 1d0f9413-0683-4e1f-a066-afe8035b0abf

📥 Commits

Reviewing files that changed from the base of the PR and between 3d53579 and af741f2.

📒 Files selected for processing (8)
  • pkg/api/config.go
  • pkg/api/types.go
  • pkg/defaults/defaults.go
  • pkg/defaults/defaults_test.go
  • pkg/steps/build_client.go
  • pkg/steps/index_generator_test.go
  • pkg/steps/source.go
  • pkg/steps/source_test.go

Comment thread pkg/steps/source.go Outdated
}

func handleBuild(ctx context.Context, client BuildClient, podClient kubernetes.PodClient, build buildapi.Build) error {
func handleBuild(ctx context.Context, buildClient BuildClient, podClient kubernetes.PodClient, build buildapi.Build) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But this handles only openshift builds already. I don't see any point of check the type in this layer. You should do it before this and don't make any changes here at all.

@hector-vido hector-vido force-pushed the buildclient-adjustment branch from af741f2 to 9b93b6f Compare June 9, 2026 12:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/steps/build_client.go (1)

24-24: 💤 Low value

Consider adding a doc comment for the new interface method.

The BuildType() method is now part of the public BuildClient interface. A brief comment describing what build types are expected (e.g., api.BuildTypeOpenshift) would help consumers.

Also applies to: 79-81

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/steps/build_client.go` at line 24, Add a Go doc comment for the new
BuildType() method on the BuildClient interface explaining what values it
returns and what they represent (e.g., returns a string identifying the build
platform/type such as api.BuildTypeOpenshift), so consumers know expected
constants and semantics; update the comment above the BuildType() declaration in
the BuildClient interface and mirror the same descriptive comment near the other
occurrence (lines 79-81) where the method is declared or referenced.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/steps/source.go`:
- Around line 495-506: The code registers the same workload twice:
metricsAgent.AddNodeWorkload is called in the goroutine where builds are
dispatched and again inside handleOpenshiftBuild; remove the duplicate by
deleting the AddNodeWorkload call from the dispatching goroutine (the call shown
in the snippet) and leave the registration in handleOpenshiftBuild, ensuring
RemoveNodeWorkload(b.Name) remains paired for cleanup; keep the rest of the
error handling (err, errChan) and wg.Done as-is.

---

Nitpick comments:
In `@pkg/steps/build_client.go`:
- Line 24: Add a Go doc comment for the new BuildType() method on the
BuildClient interface explaining what values it returns and what they represent
(e.g., returns a string identifying the build platform/type such as
api.BuildTypeOpenshift), so consumers know expected constants and semantics;
update the comment above the BuildType() declaration in the BuildClient
interface and mirror the same descriptive comment near the other occurrence
(lines 79-81) where the method is declared or referenced.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 12449dbe-f6a8-4642-aa74-7497ea463776

📥 Commits

Reviewing files that changed from the base of the PR and between af741f2 and 9b93b6f.

📒 Files selected for processing (8)
  • pkg/api/config.go
  • pkg/api/types.go
  • pkg/defaults/defaults.go
  • pkg/defaults/defaults_test.go
  • pkg/steps/build_client.go
  • pkg/steps/index_generator_test.go
  • pkg/steps/source.go
  • pkg/steps/source_test.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/defaults/defaults_test.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • pkg/defaults/defaults.go
  • pkg/steps/index_generator_test.go
  • pkg/api/config.go
  • pkg/api/types.go
  • pkg/steps/source_test.go

Comment thread pkg/steps/source.go
Comment on lines +495 to 506
var err error
defer wg.Done()
metricsAgent.AddNodeWorkload(ctx, b.Namespace, fmt.Sprintf("%s-build", b.Name), b.Name, podClient)
if err := handleBuild(ctx, buildClient, podClient, b); err != nil {
if buildClient.BuildType() == api.BuildTypeOpenshift {
err = handleOpenshiftBuild(ctx, buildClient, podClient, b)
} else {
err = fmt.Errorf("undefined build type %s", buildClient.BuildType())
}
if err != nil {
errChan <- fmt.Errorf("error occurred handling build %s: %w", b.Name, err)
}
metricsAgent.RemoveNodeWorkload(b.Name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Duplicate workload registration: AddNodeWorkload called twice.

Line 497 calls metricsAgent.AddNodeWorkload(...) before dispatching. Then handleOpenshiftBuild calls the same thing again at line 577. The workload gets registered twice for the same build.

Either remove the call here (lines 497) or remove it from handleOpenshiftBuild — but not both places.

🐛 Proposed fix: remove the call from handleBuilds
 	for _, build := range builds {
 		go func(b buildapi.Build) {
 			var err error
 			defer wg.Done()
-			metricsAgent.AddNodeWorkload(ctx, b.Namespace, fmt.Sprintf("%s-build", b.Name), b.Name, podClient)
 			if buildClient.BuildType() == api.BuildTypeOpenshift {
 				err = handleOpenshiftBuild(ctx, buildClient, podClient, b)
 			} else {
 				err = fmt.Errorf("undefined build type %s", buildClient.BuildType())
 			}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/steps/source.go` around lines 495 - 506, The code registers the same
workload twice: metricsAgent.AddNodeWorkload is called in the goroutine where
builds are dispatched and again inside handleOpenshiftBuild; remove the
duplicate by deleting the AddNodeWorkload call from the dispatching goroutine
(the call shown in the snippet) and leave the registration in
handleOpenshiftBuild, ensuring RemoveNodeWorkload(b.Name) remains paired for
cleanup; keep the rest of the error handling (err, errChan) and wg.Done as-is.

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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants