Skip to content

Commit

Permalink
Use the condition name in tekton.dev/conditionCheck
Browse files Browse the repository at this point in the history
The condition is implemented with a TaskRun. Right now the TaskRun
is labelled with tekton.dev/conditionCheck which contains the
name of the TaskRun itself. We should instead use the label to
carry data that is useful for discovering this TaskRun, and which
is not already available, i.e. the name of the Condition from
which the TaskRun was generated.
  • Loading branch information
afrittoli authored and tekton-robot committed May 7, 2020
1 parent c861b37 commit 6cb9b3f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const (

// ConditionCheckKey is used as the label identifier for a ConditionCheck
ConditionCheckKey = "/conditionCheck"

// ConditionNameKey is used as the label identifier for a Condition
ConditionNameKey = "/conditionName"
)

var (
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ func (c *Reconciler) updateLabelsAndAnnotations(pr *v1alpha1.PipelineRun) (*v1al
func (c *Reconciler) makeConditionCheckContainer(rprt *resources.ResolvedPipelineRunTask, rcc *resources.ResolvedConditionCheck, pr *v1alpha1.PipelineRun) (*v1alpha1.ConditionCheck, error) {
labels := getTaskrunLabels(pr, rprt.PipelineTask.Name)
labels[pipeline.GroupName+pipeline.ConditionCheckKey] = rcc.ConditionCheckName
labels[pipeline.GroupName+pipeline.ConditionNameKey] = rcc.Condition.Name

for key, value := range rcc.Condition.ObjectMeta.Labels {
labels[key] = value
Expand Down
12 changes: 7 additions & 5 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,7 @@ func TestReconcileWithFailingConditionChecks(t *testing.T) {
tb.TaskRunLabel(pipeline.GroupName+pipeline.PipelineLabelKey, "test-pipeline-run-with-conditions"),
tb.TaskRunLabel(pipeline.GroupName+pipeline.PipelineRunLabelKey, "test-pipeline"),
tb.TaskRunLabel(pipeline.GroupName+pipeline.ConditionCheckKey, conditionCheckName),
tb.TaskRunLabel(pipeline.GroupName+pipeline.ConditionNameKey, "always-false"),
tb.TaskRunSpec(tb.TaskRunTaskSpec()),
tb.TaskRunStatus(tb.StatusCondition(apis.Condition{
Type: apis.ConditionSucceeded,
Expand Down Expand Up @@ -1657,9 +1658,9 @@ func TestReconcileWithFailingConditionChecks(t *testing.T) {
tb.OwnerReferenceAPIVersion("tekton.dev/v1alpha1"),
tb.Controller, tb.BlockOwnerDeletion,
),
tb.TaskRunLabel("tekton.dev/pipeline", "test-pipeline"),
tb.TaskRunLabel(pipeline.GroupName+pipeline.PipelineLabelKey, "test-pipeline"),
tb.TaskRunLabel(pipeline.GroupName+pipeline.PipelineTaskLabelKey, "task-3"),
tb.TaskRunLabel("tekton.dev/pipelineRun", "test-pipeline-run-with-conditions"),
tb.TaskRunLabel(pipeline.GroupName+pipeline.PipelineRunLabelKey, "test-pipeline-run-with-conditions"),
tb.TaskRunAnnotation("PipelineRunAnnotation", "PipelineRunValue"),
tb.TaskRunSpec(
tb.TaskRunTaskRef("hello-world"),
Expand All @@ -1679,10 +1680,11 @@ func makeExpectedTr(condName, ccName string, labels map[string]string) *v1alpha1
tb.OwnerReferenceAPIVersion("tekton.dev/v1alpha1"),
tb.Controller, tb.BlockOwnerDeletion,
),
tb.TaskRunLabel("tekton.dev/pipeline", "test-pipeline"),
tb.TaskRunLabel(pipeline.GroupName+pipeline.PipelineLabelKey, "test-pipeline"),
tb.TaskRunLabel(pipeline.GroupName+pipeline.PipelineTaskLabelKey, "hello-world-1"),
tb.TaskRunLabel("tekton.dev/pipelineRun", "test-pipeline-run"),
tb.TaskRunLabel("tekton.dev/conditionCheck", ccName),
tb.TaskRunLabel(pipeline.GroupName+pipeline.PipelineRunLabelKey, "test-pipeline-run"),
tb.TaskRunLabel(pipeline.GroupName+pipeline.ConditionCheckKey, ccName),
tb.TaskRunLabel(pipeline.GroupName+pipeline.ConditionNameKey, condName),
tb.TaskRunLabels(labels),
tb.TaskRunAnnotation("PipelineRunAnnotation", "PipelineRunValue"),
tb.TaskRunSpec(
Expand Down

0 comments on commit 6cb9b3f

Please sign in to comment.