Skip to content

Commit

Permalink
works when conditions are false
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyom committed Jul 1, 2019
1 parent b2575f2 commit dc750ff
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 14 deletions.
12 changes: 12 additions & 0 deletions examples/conditions/always-false.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: tekton.dev/v1alpha1
kind: Condition
metadata:
# General purpose condition for checking if a file exists at the given
name: always-false
spec:
check:
# Check is a container spec describing the container to be run to
# check the condition
image: ubuntu
command: ["/bin/bash"]
args: ['exit 1']
46 changes: 34 additions & 12 deletions pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ const (
// ReasonInvalidGraph indicates that the reason for the failure status is that the
// associated Pipeline is an invalid graph (a.k.a wrong order, cycle, …)
ReasonInvalidGraph = "PipelineInvalidGraph"
// ReasonConditionCheckFailed indicates that the reason for the failure status is that the
// condition check associated to the pipeline task evaluated to false
ReasonConditionCheckFailed = "ConditionCheckFailed"
// pipelineRunAgentName defines logging agent name for PipelineRun Controller
pipelineRunAgentName = "pipeline-controller"
// pipelineRunControllerName defines name for PipelineRun Controller
Expand Down Expand Up @@ -384,8 +387,12 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1alpha1.PipelineRun) er
if err != nil {
c.Logger.Errorf("Error getting potential next tasks for valid pipelinerun %s: %v", pr.Name, err)
}


rprts := pipelineState.GetNextTasks(candidateTasks)



var as artifacts.ArtifactStorageInterface
if as, err = artifacts.InitializeArtifactStorage(pr, p.Spec.Tasks, c.KubeClientSet, c.Logger); err != nil {
c.Logger.Infof("PipelineRun failed to initialize artifact storage %s", pr.Name)
Expand All @@ -394,21 +401,24 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1alpha1.PipelineRun) er

for _, rprt := range rprts {
if rprt != nil {
c.Logger.Warnf("RPRT NOT NIL")
c.Logger.Warnf("IS SUCCESS??? %v", rprt.ResolvedConditionChecks.IsSuccess())
if rprt.ResolvedConditionChecks == nil || rprt.ResolvedConditionChecks.IsSuccess() {
c.Logger.Warnf("!!!!!!!!CREATE TASKRUN BLOCK")
c.Logger.Infof("Creating a new TaskRun object %s", rprt.TaskRunName)
rprt.TaskRun, err = c.createTaskRun(c.Logger, rprt, pr, as.StorageBasePath(pr))
if err != nil {
c.Recorder.Eventf(pr, corev1.EventTypeWarning, "TaskRunCreationFailed", "Failed to create TaskRun %q: %v", rprt.TaskRunName, err)
return xerrors.Errorf("error creating TaskRun called %s for PipelineTask %s from PipelineRun %s: %w", rprt.TaskRunName, rprt.PipelineTask.Name, pr.Name, err)
}
}
c.Logger.Warnf("RCC IN PROGRESS?: %v", rprt.ResolvedConditionChecks.IsInProgress())
if !rprt.ResolvedConditionChecks.IsInProgress() {
for _, rcc := range rprt.ResolvedConditionChecks {
rcc.ConditionCheck, err = c.makeConditionCheckContainer(c.Logger, rprt, rcc, pr)
} else {
hasStarted := true
for _, j := range rprt.ResolvedConditionChecks {
if j.ConditionCheck == nil {
hasStarted = false
}
}
if !hasStarted {
for _, rcc := range rprt.ResolvedConditionChecks {
rcc.ConditionCheck, err = c.makeConditionCheckContainer(c.Logger, rprt, rcc, pr)
}
}
}
}
Expand All @@ -418,13 +428,13 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1alpha1.PipelineRun) er
pr.Status.SetCondition(after)
reconciler.EmitEvent(c.Recorder, before, after, pr)

updateTaskRunsStatus(pr, pipelineState)
updateTaskRunsStatus(pr, pipelineState, c.Logger)

c.Logger.Infof("PipelineRun %s status is being set to %s", pr.Name, pr.Status.GetCondition(apis.ConditionSucceeded))
return nil
}

func updateTaskRunsStatus(pr *v1alpha1.PipelineRun, pipelineState []*resources.ResolvedPipelineRunTask) {
func updateTaskRunsStatus(pr *v1alpha1.PipelineRun, pipelineState []*resources.ResolvedPipelineRunTask, logger *zap.SugaredLogger) {
for _, rprt := range pipelineState {
if rprt.TaskRun == nil && rprt.ResolvedConditionChecks == nil {
continue
Expand All @@ -436,7 +446,6 @@ func updateTaskRunsStatus(pr *v1alpha1.PipelineRun, pipelineState []*resources.R
if prtrs == nil {
prtrs = &v1alpha1.PipelineRunTaskRunStatus{
PipelineTaskName: rprt.PipelineTask.Name,

}
} else {
prtrs.Status = &rprt.TaskRun.Status
Expand All @@ -449,17 +458,31 @@ func updateTaskRunsStatus(pr *v1alpha1.PipelineRun, pipelineState []*resources.R
ConditionName: c.Condition.Name,
}
if c.ConditionCheck != nil {
logger.Warnf("c.ConditionCheck status: %+v", c.ConditionCheck.Status)
cStatus[c.ConditionCheckName].Status = &c.ConditionCheck.Status
}
}
prtrs.ConditionChecks = cStatus
if !rprt.ResolvedConditionChecks.IsInProgress() && !rprt.ResolvedConditionChecks.IsSuccess() {
if prtrs.Status == nil {
prtrs.Status = &v1alpha1.TaskRunStatus{}
prtrs.Status.InitializeConditions()
}
prtrs.Status.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: ReasonConditionCheckFailed,
Message: fmt.Sprintf("ConditionChecks failed for Task %s in PipelineRun %s", rprt.TaskRunName, pr.Name),
})
}
}
pr.Status.TaskRuns[rprt.TaskRunName] = prtrs
}
}

func (c *Reconciler) updateTaskRunsStatusDirectly(pr *v1alpha1.PipelineRun) error {
for taskRunName := range pr.Status.TaskRuns {
// TODO: Add conditionCheck statuses here
prtrs := pr.Status.TaskRuns[taskRunName]
tr, err := c.taskRunLister.TaskRuns(pr.Namespace).Get(taskRunName)
if err != nil {
Expand All @@ -471,7 +494,6 @@ func (c *Reconciler) updateTaskRunsStatusDirectly(pr *v1alpha1.PipelineRun) erro
prtrs.Status = &tr.Status
}
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func (state TaskConditionCheckState) IsInProgress() bool {
return false
}
status := rcc.ConditionCheck.Status.GetCondition(apis.ConditionSucceeded)
//logger.Warnf("STATUS BLOB: %+v", rcc.ConditionCheck.Status)
//logger.Warnf("STATUS IS %v", status)
if status == nil { // object exists but status.Conditions does not exist. So, in progress
return true
}
Expand All @@ -53,8 +55,21 @@ func (state TaskConditionCheckState) IsComplete() bool{
}

func (state TaskConditionCheckState) IsSuccess() bool {
// TODO(dibyom): Complete && all containers true
return state.IsComplete()
if !state.IsComplete() {
return false
}
isSuccess := true
for _, rcc := range state {
if rcc == nil || rcc.ConditionCheck == nil {
// TODO: error
return false
}
// TODO: Err/Nil checking here
// Assumption right now is that there is one step for a conditional
exitCode := rcc.ConditionCheck.Status.Steps[0].Terminated.ExitCode
isSuccess = isSuccess && (exitCode == 0)
}
return isSuccess
}

// Convert a Condition to a TaskSpec
Expand Down

0 comments on commit dc750ff

Please sign in to comment.