Skip to content

Commit

Permalink
Allow manually trigger PaC builds,
Browse files Browse the repository at this point in the history
by adding request 'trigger-pac-build'

STONEBLD-1438

Signed-off-by: Robert Cerven <[email protected]>
  • Loading branch information
rcerven committed Oct 26, 2023
1 parent 99cebd0 commit 1289b5f
Show file tree
Hide file tree
Showing 7 changed files with 979 additions and 42 deletions.
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ rules:
- secrets
verbs:
- create
- delete
- get
- list
- patch
Expand Down
25 changes: 24 additions & 1 deletion controllers/component_build_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
const (
BuildRequestAnnotationName = "build.appstudio.openshift.io/request"
BuildRequestTriggerSimpleBuildAnnotationValue = "trigger-simple-build"
BuildRequestTriggerPaCBuildAnnotationValue = "trigger-pac-build"
BuildRequestConfigurePaCAnnotationValue = "configure-pac"
BuildRequestUnconfigurePaCAnnotationValue = "unconfigure-pac"

Expand Down Expand Up @@ -182,7 +183,7 @@ func (r *ComponentBuildReconciler) SetupWithManager(mgr ctrl.Manager) error {
//+kubebuilder:rbac:groups=tekton.dev,resources=pipelineruns,verbs=create
//+kubebuilder:rbac:groups=pipelinesascode.tekton.dev,resources=repositories,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch
//+kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;patch;update
//+kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;patch;update;delete
//+kubebuilder:rbac:groups="",resources=serviceaccounts,verbs=get;list;watch;create;update;patch
//+kubebuilder:rbac:groups="",resources=events,verbs=create;patch
//+kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=get;list;watch
Expand Down Expand Up @@ -352,6 +353,28 @@ func (r *ComponentBuildReconciler) Reconcile(ctx context.Context, req ctrl.Reque
buildStatus.Message = "done"
writeBuildStatus(&component, buildStatus)

case BuildRequestTriggerPaCBuildAnnotationValue:
buildStatus := readBuildStatus(&component)
if !(buildStatus.PaC != nil && buildStatus.PaC.State == "enabled") {
log.Info("Can't rerun push pipeline because Pipelines as Code isn't provisioned for the Component")
return ctrl.Result{}, nil
}

reconcileRequired, err := r.TriggerPaCBuild(ctx, &component)

if err != nil {
if boErr, ok := err.(*boerrors.BuildOpError); ok && boErr.IsPersistent() {
log.Error(err, "Failed to rerun push pipeline for the Component")
} else {
// transient error, retry
log.Error(err, "Failed to rerun push pipeline for the Component with transient error")
}
return ctrl.Result{}, err
}
if reconcileRequired {
return ctrl.Result{Requeue: true}, nil
}

case BuildRequestConfigurePaCAnnotationValue:
pacBuildStatus := &PaCBuildStatus{}
if mergeUrl, err := r.ProvisionPaCForComponent(ctx, &component); err != nil {
Expand Down
Loading

0 comments on commit 1289b5f

Please sign in to comment.