-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial Implementation of conditionals #1093
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Conditions | ||
|
||
This document defines `Conditions` and their capabilities. | ||
|
||
*NOTE*: This feature is currently a WIP being tracked in [#1137](https://github.com/tektoncd/pipeline/issues/1137) | ||
|
||
--- | ||
|
||
- [Syntax](#syntax) | ||
- [Check](#check) | ||
- [Examples](#examples) | ||
|
||
## Syntax | ||
|
||
To define a configuration file for a `Condition` resource, you can specify the | ||
following fields: | ||
|
||
- Required: | ||
- [`apiVersion`][kubernetes-overview] - Specifies the API version, for example | ||
`tekton.dev/v1alpha1`. | ||
- [`kind`][kubernetes-overview] - Specify the `Condition` resource object. | ||
- [`metadata`][kubernetes-overview] - Specifies data to uniquely identify the | ||
`Condition` resource object, for example a `name`. | ||
- [`spec`][kubernetes-overview] - Specifies the configuration information for | ||
your `Condition` resource object. In order for a `Condition` to do anything, | ||
the spec must include: | ||
- [`check`](#check) - Specifies a container that you want to run for evaluating the condition | ||
|
||
[kubernetes-overview]: | ||
https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#required-fields | ||
|
||
### Check | ||
|
||
The `check` field is required. You define a single check to define the body of a `Condition`. The | ||
check must specify a container image that adheres to the [container contract](./container-contract.md). The container image | ||
runs till completion. The container must exit successfully i.e. with an exit code 0 for the | ||
condition evaluation to be successful. All other exit codes are considered to be a condition check | ||
failure. | ||
|
||
## Examples | ||
|
||
For complete examples, see | ||
[the examples folder](https://github.com/tektoncd/pipeline/tree/master/examples). | ||
|
||
--- | ||
|
||
Except as otherwise noted, the content of this page is licensed under the | ||
[Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), | ||
and code samples are licensed under the | ||
[Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Condition | ||
metadata: | ||
name: always-true | ||
spec: | ||
check: | ||
image: alpine | ||
command: ["/bin/sh"] | ||
args: ['-c', 'exit 0'] | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: PipelineResource | ||
metadata: | ||
name: pipeline-git | ||
spec: | ||
type: git | ||
params: | ||
- name: revision | ||
value: master | ||
- name: url | ||
value: https://github.com/tektoncd/pipeline | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Task | ||
metadata: | ||
name: list-files | ||
spec: | ||
inputs: | ||
resources: | ||
- name: workspace | ||
type: git | ||
steps: | ||
- name: run-ls | ||
image: ubuntu | ||
command: ["/bin/bash"] | ||
args: ['-c', 'ls -al ${inputs.resources.workspace.path}'] | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Pipeline | ||
metadata: | ||
name: list-files-pipeline | ||
spec: | ||
resources: | ||
- name: source-repo | ||
type: git | ||
tasks: | ||
- name: list-files-1 | ||
taskRef: | ||
name: list-files | ||
conditions: | ||
- conditionRef: "always-true" | ||
dibyom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
resources: | ||
inputs: | ||
- name: workspace | ||
resource: source-repo | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: PipelineRun | ||
metadata: | ||
name: demo-condtional-pr | ||
spec: | ||
pipelineRef: | ||
name: list-files-pipeline | ||
serviceAccount: 'default' | ||
resources: | ||
- name: source-repo | ||
resourceRef: | ||
name: pipeline-git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,25 @@ limitations under the License. | |
|
||
package pipeline | ||
|
||
// GroupName is the Kubernetes resource group name for Pipeline types. | ||
const ( | ||
GroupName = "tekton.dev" | ||
TaskLabelKey = "/task" | ||
TaskRunLabelKey = "/taskRun" | ||
PipelineLabelKey = "/pipeline" | ||
PipelineRunLabelKey = "/pipelineRun" | ||
// GroupName is the Kubernetes resource group name for Pipeline types. | ||
GroupName = "tekton.dev" | ||
|
||
// TaskLabelKey is used as the label identifier for a task | ||
TaskLabelKey = "/task" | ||
|
||
// TaskRunLabelKey is used as the label identifier for a TaskRun | ||
TaskRunLabelKey = "/taskRun" | ||
|
||
// PipelineLabelKey is used as the label identifier for a Pipeline | ||
PipelineLabelKey = "/pipeline" | ||
|
||
// PipelineRunLabelKey is used as the label identifier for a PipelineRun | ||
PipelineRunLabelKey = "/pipelineRun" | ||
|
||
// PipelineRunLabelKey is used as the label identifier for a PipelineTask | ||
PipelineTaskLabelKey = "/pipelineTask" | ||
|
||
// ConditionCheck is used as the label identifier for a ConditionCheck | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for adding these!! |
||
ConditionCheckKey = "/conditionCheck" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright 2019 The Tekton Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1_test | ||
|
||
import ( | ||
"testing" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"knative.dev/pkg/apis" | ||
|
||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" | ||
tb "github.com/tektoncd/pipeline/test/builder" | ||
) | ||
|
||
func TestConditionCheck_IsDone(t *testing.T) { | ||
tr := tb.TaskRun("", "", tb.TaskRunStatus(tb.StatusCondition( | ||
apis.Condition{ | ||
Type: apis.ConditionSucceeded, | ||
Status: corev1.ConditionFalse, | ||
}, | ||
))) | ||
|
||
cc := v1alpha1.ConditionCheck(*tr) | ||
if !cc.IsDone() { | ||
t.Fatal("Expected conditionCheck status to be done") | ||
} | ||
} | ||
|
||
func TestConditionCheck_IsSuccessful(t *testing.T) { | ||
tr := tb.TaskRun("", "", tb.TaskRunStatus(tb.StatusCondition( | ||
apis.Condition{ | ||
Type: apis.ConditionSucceeded, | ||
Status: corev1.ConditionTrue, | ||
}, | ||
))) | ||
|
||
cc := v1alpha1.ConditionCheck(*tr) | ||
if !cc.IsSuccessful() { | ||
t.Fatal("Expected conditionCheck status to be done") | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice :D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉