Skip to content

Commit 02f1aaa

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 <[email protected]>
1 parent 69fe3a4 commit 02f1aaa

File tree

16 files changed

+1885
-140
lines changed

16 files changed

+1885
-140
lines changed

.github/workflows/ci.yml

Lines changed: 30 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:
@@ -240,6 +243,33 @@ jobs:
240243
export TEST_E2E_FLAGS="-r --procs 8 --randomize-all --timeout=1h --trace --vv"
241244
export TEST_E2E_TIMEOUT_MULTIPLIER=2
242245
make test-e2e
246+
- name: Test-PipelineRun
247+
run: |
248+
export TEST_NAMESPACE=shp-e2e
249+
export TEST_IMAGE_REPO=registry.registry.svc.cluster.local:32222/shipwright-io/build-e2e
250+
export TEST_IMAGE_REPO_INSECURE=true
251+
export TEST_E2E_TIMEOUT_MULTIPLIER=1
252+
kubectl patch deployment shipwright-build-controller -n shipwright-build --type='json' -p='[
253+
{
254+
"op": "add",
255+
"path": "/spec/template/spec/containers/0/env/-",
256+
"value": {
257+
"name": "BUILDRUN_EXECUTOR",
258+
"value": "PipelineRun"
259+
}
260+
}
261+
]'
262+
# Wait for the rollout to complete
263+
kubectl rollout restart deployment shipwright-build-controller -n shipwright-build
264+
kubectl rollout status deployment shipwright-build-controller -n shipwright-build
265+
266+
# Run PipelineRun tests
267+
TEST_CONTROLLER_NAMESPACE=${TEST_NAMESPACE} \
268+
TEST_WATCH_NAMESPACE=${TEST_NAMESPACE} \
269+
TEST_E2E_SERVICEACCOUNT_NAME=pipeline \
270+
TEST_E2E_TIMEOUT_MULTIPLIER=${TEST_E2E_TIMEOUT_MULTIPLIER} \
271+
TEST_E2E_VERIFY_TEKTONOBJECTS=true \
272+
ginkgo --focus="PipelineRun E2E Tests" --procs 8 --timeout=1h --vv test/e2e/v1beta1/
243273
- name: Build controller logs
244274
if: ${{ failure() }}
245275
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

deploy/200-role.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ rules:
6767
# With the OwnerReferencesPermissionEnforcement admission controller enabled, controllers need the "delete" permission on objects that they set owner references on.
6868
verbs: ['get', 'list', 'watch', 'create', 'delete', 'patch']
6969

70+
- apiGroups: ['tekton.dev']
71+
resources: ['pipelineruns']
72+
verbs: ['get', 'list', 'watch', 'create', 'delete', 'patch']
73+
7074
- apiGroups: ['']
7175
resources: ['pods']
7276
verbs: ['get', 'list', 'watch']

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ The following environment variables are available:
3737
| `KUBE_API_BURST` | Burst to use for the Kubernetes API client. See [Config.Burst]. A value of 0 or lower will use the default from client-go, which currently is 10. Default is 0. |
3838
| `KUBE_API_QPS` | QPS to use for the Kubernetes API client. See [Config.QPS]. A value of 0 or lower will use the default from client-go, which currently is 5. Default is 0. |
3939
| `VULNERABILITY_COUNT_LIMIT` | holds vulnerability count limit if vulnerability scan is enabled for the output image. If it is defined as 10, then it will output only 10 vulnerabilities sorted by severity in the buildrun status.Output. Default is 50. |
40+
| `BUILDRUN_EXECUTOR` | Sets the kind of buildrun exectutor that will be used. Value can be `TaskRun` or `PipelineRun`. By default buildrun will use `TaskRun` for its build executor. |
4041

4142
[^1]: The `runAsUser` and `runAsGroup` are dynamically overwritten depending on the build strategy that is used. See [Security Contexts](buildstrategies.md#security-contexts) for more information.
4243

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"

0 commit comments

Comments
 (0)