Skip to content

Commit

Permalink
[wip] cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandesMF committed Dec 9, 2024
1 parent 02ddb31 commit 74b0cae
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions internal/controller/pipelinerun_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"knative.dev/pkg/apis"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
Expand All @@ -42,22 +41,6 @@ type PipelineRunReconciler struct {
Scheme *runtime.Scheme
}

type ConditionAccessorFn func(ca apis.ConditionAccessor) (bool, error)

func Running(name string) ConditionAccessorFn {
return func(ca apis.ConditionAccessor) (bool, error) {
c := ca.GetCondition(apis.ConditionSucceeded)
if c != nil {
if c.Status == corev1.ConditionTrue || c.Status == corev1.ConditionFalse {
return true, fmt.Errorf(`%q already finished`, name)
} else if c.Status == corev1.ConditionUnknown && (c.Reason == "Running" || c.Reason == "Pending") {
return true, nil
}
}
return false, nil
}
}

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// TODO(user): Modify the Reconcile function to compare the state specified by
Expand All @@ -75,30 +58,27 @@ func (r *PipelineRunReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, nil
}

// Get pipelineruns
var childPipelineRuns tektonv1beta1.PipelineRunList
err := r.Client.List(ctx, &childPipelineRuns, client.InNamespace(req.Namespace))
if err != nil {
log.Error(err, "Unable to list child pipelineruns")
return ctrl.Result{}, err
}

// Collect pipelineruns with state 'running' or 'started'
var runningPipelineRuns []*tektonv1beta1.PipelineRun
for i, pipelineRun := range childPipelineRuns.Items {

if pipelineRun.Status.Conditions[0].Status == corev1.ConditionUnknown &&
if len(pipelineRun.Status.Conditions) > 0 &&
pipelineRun.Status.Conditions[0].Status == corev1.ConditionUnknown &&
(pipelineRun.Status.Conditions[0].Reason == tektonv1beta1.PipelineRunReasonRunning.String() ||
pipelineRun.Status.Conditions[0].Reason == tektonv1beta1.PipelineRunReasonStarted.String()) {
runningPipelineRuns = append(runningPipelineRuns, &childPipelineRuns.Items[i])
}

if pipelineRun.Status.Conditions[0].Status == corev1.ConditionFalse {
log.Info("yabadabadoo")
}
}
numRunning := len(runningPipelineRuns)

log.Info("running pipelineRuns count", "numRunning", numRunning)

// Launch one pipelinerun if less than the maximum number is currently running
if numRunning < MaxSimultaneousPipelineRuns {
for _, pipelineRun := range childPipelineRuns.Items {
if pipelineRun.IsPending() {
Expand Down

0 comments on commit 74b0cae

Please sign in to comment.