Skip to content

Commit 3625cbe

Browse files
committed
feat: Add PipelineRun support to BuildRun reconciler
This commit introduces PipelineRun support to the BuildRun reconciler, enabling Shipwright to use Tekton PipelineRuns as an alternative to TaskRuns for build execution. Key changes: - Add pipelinerun_runner.go with TektonPipelineRunWrapper implementation that wraps Tekton PipelineRuns and injects TaskRun specs into PipelineRun structures. - Implement ImageBuildRunner and ImageBuildRunnerFactory interfaces for PipelineRun support. - Add reconciliation logic for PipelineRun status updates, including condition handling and failure detection - Add UpdateBuildRunUsingPipelineRunCondition function to update BuildRun status based on PipelineRun conditions (timeout, cancellation, success, failure) - Refactor volume checking to use GetUnderlyingTaskRun() method for both TaskRun and PipelineRun executors, eliminating the need for separate volume checking methods - Add RunnerFactories map to support configurable executor selection between TaskRun and PipelineRun implementations - Update error handling in CreateImageBuildRunner - Add UpdateImageBuildRunFromExecutor to handle updating Buildrun based on used executor (pipelinerun or taskrun) The implementation maintains backward compatibility. Signed-off-by: Hasan Awad <hasan.m.awad94@gmail.com> refactor and e2e tests fix image scanning
1 parent 572e9a5 commit 3625cbe

File tree

15 files changed

+1621
-155
lines changed

15 files changed

+1621
-155
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ jobs:
150150
export IMAGE_PROCESSING_CONTAINER_IMAGE="$(KO_DOCKER_REPO=kind.local ko publish ./cmd/image-processing)"
151151
152152
make test-integration
153+
- name: Test-PipelineRun
154+
run: |
155+
BUILDRUN_EXECUTOR=PipelineRun ginkgo --focus-file="buildruns_to_pipelineruns_test.go" -v test/integration/...
153156
154157
e2e:
155158
strategy:
@@ -239,6 +242,32 @@ jobs:
239242
export TEST_IMAGE_REPO_INSECURE=true
240243
export TEST_E2E_TIMEOUT_MULTIPLIER=2
241244
make test-e2e
245+
- name: Test-PipelineRun
246+
run: |
247+
export TEST_NAMESPACE=shp-e2e
248+
export TEST_IMAGE_REPO=registry.registry.svc.cluster.local:32222/shipwright-io/build-e2e
249+
export TEST_IMAGE_REPO_INSECURE=true
250+
export TEST_E2E_TIMEOUT_MULTIPLIER=2
251+
kubectl patch deployment shipwright-build-controller -n shipwright-build --type='json' -p='[
252+
{
253+
"op": "add",
254+
"path": "/spec/template/spec/containers/0/env/-",
255+
"value": {
256+
"name": "BUILDRUN_EXECUTOR",
257+
"value": "PipelineRun"
258+
}
259+
}
260+
]'
261+
# Wait for the rollout to complete
262+
kubectl rollout status deployment shipwright-build-controller -n shipwright-build
263+
264+
# Run PipelineRun tests
265+
TEST_CONTROLLER_NAMESPACE=${TEST_NAMESPACE} \
266+
TEST_WATCH_NAMESPACE=${TEST_NAMESPACE} \
267+
TEST_E2E_SERVICEACCOUNT_NAME=pipeline \
268+
TEST_E2E_TIMEOUT_MULTIPLIER=${TEST_E2E_TIMEOUT_MULTIPLIER} \
269+
TEST_E2E_VERIFY_TEKTONOBJECTS=true \
270+
ginkgo --focus="PipelineRun Integration Tests" -p -v test/e2e/v1beta1/
242271
- name: Build controller logs
243272
if: ${{ failure() }}
244273
run: |

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ test-integration: install-apis ginkgo
213213
--randomize-all \
214214
--randomize-suites \
215215
--fail-on-pending \
216+
--skip-file=buildruns_to_pipelineruns_test.go \
216217
-trace \
217218
test/integration/...
218219

@@ -226,7 +227,7 @@ test-e2e-plain: ginkgo
226227
TEST_E2E_SERVICEACCOUNT_NAME=${TEST_E2E_SERVICEACCOUNT_NAME} \
227228
TEST_E2E_TIMEOUT_MULTIPLIER=${TEST_E2E_TIMEOUT_MULTIPLIER} \
228229
TEST_E2E_VERIFY_TEKTONOBJECTS=${TEST_E2E_VERIFY_TEKTONOBJECTS} \
229-
$(GINKGO) ${TEST_E2E_FLAGS} test/e2e/
230+
$(GINKGO) --skip-file=e2e_pipelinerun_test.go ${TEST_E2E_FLAGS} test/e2e/
230231

231232
.PHONY: test-e2e-kind-with-prereq-install
232233
test-e2e-kind-with-prereq-install: ginkgo install-controller-kind install-strategies test-e2e-plain

pkg/config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const (
6666
controllerBuildRunMaxConcurrentReconciles = "BUILDRUN_MAX_CONCURRENT_RECONCILES"
6767
controllerBuildStrategyMaxConcurrentReconciles = "BUILDSTRATEGY_MAX_CONCURRENT_RECONCILES"
6868
controllerClusterBuildStrategyMaxConcurrentReconciles = "CLUSTERBUILDSTRATEGY_MAX_CONCURRENT_RECONCILES"
69+
controllerBuildrunExecutorEnvVar = "BUILDRUN_EXECUTOR"
6970

7071
// environment variables for the kube API
7172
kubeAPIBurst = "KUBE_API_BURST"
@@ -107,6 +108,7 @@ type Config struct {
107108
KubeAPIOptions KubeAPIOptions
108109
GitRewriteRule bool
109110
VulnerabilityCountLimit int
111+
BuildrunExecutor string
110112
}
111113

112114
// PrometheusConfig contains the specific configuration for the
@@ -163,6 +165,7 @@ func NewDefaultConfig() *Config {
163165
TerminationLogPath: terminationLogPathDefault,
164166
GitRewriteRule: false,
165167
VulnerabilityCountLimit: 50,
168+
BuildrunExecutor: "TaskRun",
166169

167170
GitContainerTemplate: Step{
168171
Image: gitDefaultImage,
@@ -361,6 +364,11 @@ func (c *Config) SetConfigFromEnv() error {
361364
c.VulnerabilityCountLimit = vc
362365
}
363366

367+
// set environment variable for executor type
368+
if executor := os.Getenv(controllerBuildrunExecutorEnvVar); executor != "" {
369+
c.BuildrunExecutor = executor
370+
}
371+
364372
// Mark that the Git wrapper is suppose to use Git rewrite rule
365373
if useGitRewriteRule := os.Getenv(useGitRewriteRule); useGitRewriteRule != "" {
366374
c.GitRewriteRule = strings.ToLower(useGitRewriteRule) == "true"

pkg/reconciler/buildrun/buildrun.go

Lines changed: 130 additions & 72 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)