Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions controllers/jenkins/pipelinerun/pipelinerun_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const BuildNotExistMsg = "not found resources"
// Reconciler reconciles a PipelineRun object
type Reconciler struct {
client.Client
req ctrl.Request
ctx context.Context
log logr.Logger
Scheme *runtime.Scheme
DevOpsClient devopsClient.Interface
Expand All @@ -70,8 +68,6 @@ type Reconciler struct {
// move the current state of the cluster closer to the desired state.
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.log.WithValues("PipelineRun", req.NamespacedName)
r.ctx = ctx
r.req = req

// get PipelineRun
pipelineRun := &v1alpha3.PipelineRun{}
Expand Down Expand Up @@ -169,7 +165,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
}

// store pipelinerun stage to configmap
if err = r.storePipelineRunData(string(nodeDetailsJSON), pipelineRunCopied); err != nil {
if err = r.storePipelineRunData(ctx, req, string(nodeDetailsJSON), pipelineRunCopied); err != nil {
log.Error(err, "unable to store pipeline stages to configmap.")
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -247,20 +243,20 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return ctrl.Result{}, nil
}

func (r *Reconciler) storePipelineRunData(nodeDetailsJSON string, pipelineRunCopied *v1alpha3.PipelineRun) (err error) {
func (r *Reconciler) storePipelineRunData(ctx context.Context, req ctrl.Request, nodeDetailsJSON string, pipelineRunCopied *v1alpha3.PipelineRun) (err error) {
if r.PipelineRunDataStore == "" {
if pipelineRunCopied.Annotations == nil {
pipelineRunCopied.Annotations = make(map[string]string)
}
pipelineRunCopied.Annotations[v1alpha3.JenkinsPipelineRunStagesStatusAnnoKey] = nodeDetailsJSON

// update labels and annotations
if err = r.updateLabelsAndAnnotations(r.ctx, pipelineRunCopied); err != nil {
if err = r.updateLabelsAndAnnotations(ctx, pipelineRunCopied); err != nil {
r.log.Error(err, "unable to update PipelineRun labels and annotations.")
}
} else if r.PipelineRunDataStore == "configmap" {
var cmStore storeInter.ConfigMapStore
if cmStore, err = cmstore.NewConfigMapStore(r.ctx, r.req.NamespacedName, r.Client); err == nil {
if cmStore, err = cmstore.NewConfigMapStore(ctx, req.NamespacedName, r.Client); err == nil {
cmStore.SetStages(nodeDetailsJSON)
cmStore.SetOwnerReference(v1.OwnerReference{
APIVersion: pipelineRunCopied.APIVersion,
Expand Down