-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This port Pipeline spec to v1alpha2, nothing really change from v1alpha1. Signed-off-by: Vincent Demeester <[email protected]>
- Loading branch information
1 parent
b859371
commit 8541f1f
Showing
19 changed files
with
2,096 additions
and
2 deletions.
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,40 @@ | ||
/* | ||
Copyright 2020 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 v1alpha2 | ||
|
||
import ( | ||
"context" | ||
|
||
"knative.dev/pkg/apis" | ||
) | ||
|
||
var _ apis.Defaultable = (*Pipeline)(nil) | ||
|
||
func (p *Pipeline) SetDefaults(ctx context.Context) { | ||
p.Spec.SetDefaults(ctx) | ||
} | ||
|
||
func (ps *PipelineSpec) SetDefaults(ctx context.Context) { | ||
for _, pt := range ps.Tasks { | ||
if pt.TaskRef.Kind == "" { | ||
pt.TaskRef.Kind = NamespacedTaskKind | ||
} | ||
} | ||
for i := range ps.Params { | ||
ps.Params[i].SetDefaults(ctx) | ||
} | ||
} |
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,26 @@ | ||
/* | ||
Copyright 2020 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 v1alpha2 | ||
|
||
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
// PipelineInterface is implemented by Pipeline and ClusterPipeline | ||
type PipelineInterface interface { | ||
PipelineMetadata() metav1.ObjectMeta | ||
PipelineSpec() PipelineSpec | ||
Copy() PipelineInterface | ||
} |
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,246 @@ | ||
/* | ||
Copyright 2020 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 v1alpha2 | ||
|
||
import ( | ||
"github.com/tektoncd/pipeline/pkg/reconciler/pipeline/dag" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// Check that Pipeline may be validated and defaulted. | ||
// TaskKind defines the type of Task used by the pipeline. | ||
type TaskKind string | ||
|
||
const ( | ||
// NamespacedTaskKind indicates that the task type has a namepace scope. | ||
NamespacedTaskKind TaskKind = "Task" | ||
// ClusterTaskKind indicates that task type has a cluster scope. | ||
ClusterTaskKind TaskKind = "ClusterTask" | ||
) | ||
|
||
// +genclient | ||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
// +genclient:noStatus | ||
|
||
// Pipeline describes a list of Tasks to execute. It expresses how outputs | ||
// of tasks feed into inputs of subsequent tasks. | ||
// +k8s:openapi-gen=true | ||
type Pipeline struct { | ||
metav1.TypeMeta `json:",inline"` | ||
// +optional | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
// Spec holds the desired state of the Pipeline from the client | ||
// +optional | ||
Spec PipelineSpec `json:"spec"` | ||
|
||
// Status is deprecated. | ||
// It usually is used to communicate the observed state of the Pipeline from | ||
// the controller, but was unused as there is no controller for Pipeline. | ||
// +optional | ||
Status *PipelineStatus `json:"status,omitempty"` | ||
} | ||
|
||
// PipelineStatus does not contain anything because Pipelines on their own | ||
// do not have a status, they just hold data which is later used by a | ||
// PipelineRun. | ||
// Deprecated | ||
type PipelineStatus struct { | ||
} | ||
|
||
func (p *Pipeline) PipelineMetadata() metav1.ObjectMeta { | ||
return p.ObjectMeta | ||
} | ||
|
||
func (p *Pipeline) PipelineSpec() PipelineSpec { | ||
return p.Spec | ||
} | ||
|
||
func (p *Pipeline) Copy() PipelineInterface { | ||
return p.DeepCopy() | ||
} | ||
|
||
// PipelineSpec defines the desired state of Pipeline. | ||
type PipelineSpec struct { | ||
// Resources declares the names and types of the resources given to the | ||
// Pipeline's tasks as inputs and outputs. | ||
Resources []PipelineDeclaredResource `json:"resources,omitempty"` | ||
// Tasks declares the graph of Tasks that execute when this Pipeline is run. | ||
Tasks []PipelineTask `json:"tasks,omitempty"` | ||
// Params declares a list of input parameters that must be supplied when | ||
// this Pipeline is run. | ||
Params []ParamSpec `json:"params,omitempty"` | ||
} | ||
|
||
// PipelineTask defines a task in a Pipeline, passing inputs from both | ||
// Params and from the output of previous tasks. | ||
type PipelineTask struct { | ||
// Name is the name of this task within the context of a Pipeline. Name is | ||
// used as a coordinate with the `from` and `runAfter` fields to establish | ||
// the execution order of tasks relative to one another. | ||
Name string `json:"name,omitempty"` | ||
|
||
// TaskRef is a reference to a task definition. | ||
// +optional | ||
TaskRef *TaskRef `json:"taskRef,omitempty"` | ||
|
||
// TaskSpec is a specification of a task | ||
// +optional | ||
TaskSpec *TaskSpec `json:"taskSpec,omitempty"` | ||
|
||
// Conditions is a list of conditions that need to be true for the task to run | ||
// +optional | ||
Conditions []PipelineTaskCondition `json:"conditions,omitempty"` | ||
|
||
// Retries represents how many times this task should be retried in case of task failure: ConditionSucceeded set to False | ||
// +optional | ||
Retries int `json:"retries,omitempty"` | ||
|
||
// RunAfter is the list of PipelineTask names that should be executed before | ||
// this Task executes. (Used to force a specific ordering in graph execution.) | ||
// +optional | ||
RunAfter []string `json:"runAfter,omitempty"` | ||
|
||
// Resources declares the resources given to this task as inputs and | ||
// outputs. | ||
// +optional | ||
Resources *PipelineTaskResources `json:"resources,omitempty"` | ||
// Parameters declares parameters passed to this task. | ||
// +optional | ||
Params []Param `json:"params,omitempty"` | ||
} | ||
|
||
func (pt PipelineTask) HashKey() string { | ||
return pt.Name | ||
} | ||
|
||
func (pt PipelineTask) Deps() []string { | ||
deps := []string{} | ||
deps = append(deps, pt.RunAfter...) | ||
if pt.Resources != nil { | ||
for _, rd := range pt.Resources.Inputs { | ||
deps = append(deps, rd.From...) | ||
} | ||
} | ||
// Add any dependents from conditional resources. | ||
for _, cond := range pt.Conditions { | ||
for _, rd := range cond.Resources { | ||
deps = append(deps, rd.From...) | ||
} | ||
} | ||
return deps | ||
} | ||
|
||
type PipelineTaskList []PipelineTask | ||
|
||
func (l PipelineTaskList) Items() []dag.Task { | ||
tasks := []dag.Task{} | ||
for _, t := range l { | ||
tasks = append(tasks, dag.Task(t)) | ||
} | ||
return tasks | ||
} | ||
|
||
// PipelineTaskParam is used to provide arbitrary string parameters to a Task. | ||
type PipelineTaskParam struct { | ||
Name string `json:"name"` | ||
Value string `json:"value"` | ||
} | ||
|
||
// PipelineTaskCondition allows a PipelineTask to declare a Condition to be evaluated before | ||
// the Task is run. | ||
type PipelineTaskCondition struct { | ||
// ConditionRef is the name of the Condition to use for the conditionCheck | ||
ConditionRef string `json:"conditionRef"` | ||
|
||
// Params declare parameters passed to this Condition | ||
// +optional | ||
Params []Param `json:"params,omitempty"` | ||
|
||
// Resources declare the resources provided to this Condition as input | ||
Resources []PipelineTaskInputResource `json:"resources,omitempty"` | ||
} | ||
|
||
// PipelineDeclaredResource is used by a Pipeline to declare the types of the | ||
// PipelineResources that it will required to run and names which can be used to | ||
// refer to these PipelineResources in PipelineTaskResourceBindings. | ||
type PipelineDeclaredResource struct { | ||
// Name is the name that will be used by the Pipeline to refer to this resource. | ||
// It does not directly correspond to the name of any PipelineResources Task | ||
// inputs or outputs, and it does not correspond to the actual names of the | ||
// PipelineResources that will be bound in the PipelineRun. | ||
Name string `json:"name"` | ||
// Type is the type of the PipelineResource. | ||
Type PipelineResourceType `json:"type"` | ||
} | ||
|
||
// PipelineTaskResources allows a Pipeline to declare how its DeclaredPipelineResources | ||
// should be provided to a Task as its inputs and outputs. | ||
type PipelineTaskResources struct { | ||
// Inputs holds the mapping from the PipelineResources declared in | ||
// DeclaredPipelineResources to the input PipelineResources required by the Task. | ||
Inputs []PipelineTaskInputResource `json:"inputs,omitempty"` | ||
// Outputs holds the mapping from the PipelineResources declared in | ||
// DeclaredPipelineResources to the input PipelineResources required by the Task. | ||
Outputs []PipelineTaskOutputResource `json:"outputs,omitempty"` | ||
} | ||
|
||
// PipelineTaskInputResource maps the name of a declared PipelineResource input | ||
// dependency in a Task to the resource in the Pipeline's DeclaredPipelineResources | ||
// that should be used. This input may come from a previous task. | ||
type PipelineTaskInputResource struct { | ||
// Name is the name of the PipelineResource as declared by the Task. | ||
Name string `json:"name"` | ||
// Resource is the name of the DeclaredPipelineResource to use. | ||
Resource string `json:"resource"` | ||
// From is the list of PipelineTask names that the resource has to come from. | ||
// (Implies an ordering in the execution graph.) | ||
// +optional | ||
From []string `json:"from,omitempty"` | ||
} | ||
|
||
// PipelineTaskOutputResource maps the name of a declared PipelineResource output | ||
// dependency in a Task to the resource in the Pipeline's DeclaredPipelineResources | ||
// that should be used. | ||
type PipelineTaskOutputResource struct { | ||
// Name is the name of the PipelineResource as declared by the Task. | ||
Name string `json:"name"` | ||
// Resource is the name of the DeclaredPipelineResource to use. | ||
Resource string `json:"resource"` | ||
} | ||
|
||
// TaskRef can be used to refer to a specific instance of a task. | ||
// Copied from CrossVersionObjectReference: https://github.com/kubernetes/kubernetes/blob/169df7434155cbbc22f1532cba8e0a9588e29ad8/pkg/apis/autoscaling/types.go#L64 | ||
type TaskRef struct { | ||
// Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names | ||
Name string `json:"name,omitempty"` | ||
// TaskKind inficates the kind of the task, namespaced or cluster scoped. | ||
Kind TaskKind `json:"kind,omitempty"` | ||
// API version of the referent | ||
// +optional | ||
APIVersion string `json:"apiVersion,omitempty"` | ||
} | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// PipelineList contains a list of Pipeline | ||
type PipelineList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
// +optional | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []Pipeline `json:"items"` | ||
} |
Oops, something went wrong.