Skip to content

Commit

Permalink
poc
Browse files Browse the repository at this point in the history
  • Loading branch information
Yongxuanzhang committed Sep 26, 2023
1 parent 0354635 commit a087fe3
Show file tree
Hide file tree
Showing 14 changed files with 595 additions and 9 deletions.
24 changes: 24 additions & 0 deletions examples/v1/pipelineruns/alpha/pipelinerun-inputs-params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
generateName: inputs-params-
spec:
inputs:
params:
param1: "1"
param2: "2"
pipelineSpec:
inputs:
params:
param1:
type: string
param2:
type: string
tasks:
- name: generate-suffix
taskSpec:
steps:
- name: echo
image: alpine
script: |
echo $(params.param1)$(params.param2)
29 changes: 29 additions & 0 deletions examples/v1/pipelineruns/alpha/pipelinerun-outputs-results.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
generateName: outputs-results-
spec:
pipelineSpec:
outputs:
results:
commit:
value: $(tasks.task1.results.commit)
type: string
sha:
value: $(tasks.task1.results.sha)
type: string
tasks:
- name: task1
taskSpec:
outputs:
results:
commit:
type: string
sha:
type: string
steps:
- name: echo
image: bash:latest
script: |
echo "abc" | tee $(results.commit.path)
echo "123" | tee $(results.sha.path)
253 changes: 244 additions & 9 deletions pkg/apis/pipeline/v1/openapi_generated.go

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions pkg/apis/pipeline/v1/param_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ type ParamSpec struct {
// ParamSpecs is a list of ParamSpec
type ParamSpecs []ParamSpec

type ParamSpecsMap map[string]ParamSpec

type ParamsMap map[string]ParamValue

type InputSpecs struct{
ParamSpecs ParamSpecsMap `json:"params,omitempty"`
}

type Inputs struct{
Params ParamsMap `json:"params,omitempty"`
}

// PropertySpec defines the struct for object keys
type PropertySpec struct {
Type ParamType `json:"type,omitempty"`
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/pipeline/v1/pipeline_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ func (p *Pipeline) SetDefaults(ctx context.Context) {

// SetDefaults sets default values for the PipelineSpec's Params, Tasks, and Finally
func (ps *PipelineSpec) SetDefaults(ctx context.Context) {
if len(ps.Inputs.ParamSpecs)!=0 && len(ps.Params)==0{
for name,value := range ps.Inputs.ParamSpecs{
value.Name=name
psc:=value.DeepCopy()
ps.Params = append(ps.Params, *psc)
}
}
if len(ps.Outputs.ResultSpecs)!=0 && len(ps.Results)==0{
for name,value := range ps.Outputs.ResultSpecs{
rs:=PipelineResult{Name: name, Type: value.Type, Value: *value.Value, Description: value.Description}
ps.Results = append(ps.Results, rs)
}
}
for i := range ps.Params {
ps.Params[i].SetDefaults(ctx)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ type PipelineSpec struct {
// this Pipeline is run.
// +listType=atomic
Params ParamSpecs `json:"params,omitempty"`

Inputs InputSpecs `json:"inputs,omitempty"`

Outputs OutputSpecs `json:"outputs,omitempty"`
// Workspaces declares a set of named workspaces that are expected to be
// provided by a PipelineRun.
// +optional
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1/pipelinerun_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func (pr *PipelineRun) SetDefaults(ctx context.Context) {

// SetDefaults implements apis.Defaultable
func (prs *PipelineRunSpec) SetDefaults(ctx context.Context) {
if len(prs.Inputs.Params)!=0{
for name,value := range prs.Inputs.Params{
prs.Params = append(prs.Params, Param{Name: name, Value: value})
}
}
cfg := config.FromContextOrDefaults(ctx)
if prs.PipelineRef != nil && prs.PipelineRef.Name == "" && prs.PipelineRef.Resolver == "" {
prs.PipelineRef.Resolver = ResolverName(cfg.Defaults.DefaultResolverType)
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ type PipelineRunSpec struct {
// +listType=atomic
Params Params `json:"params,omitempty"`

Inputs Inputs `json:"inputs,omitempty"`
// Used for cancelling a pipelinerun (and maybe more later on)
// +optional
Status PipelineRunSpecStatus `json:"status,omitempty"`
Expand Down Expand Up @@ -494,6 +495,8 @@ type PipelineRunStatusFields struct {
// +listType=atomic
Results []PipelineRunResult `json:"results,omitempty"`

Outputs Outputs `json:"outputs,omitempty"`

// PipelineRunSpec contains the exact spec used to instantiate the run
PipelineSpec *PipelineSpec `json:"pipelineSpec,omitempty"`

Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/pipeline/v1/result_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,23 @@ var AllResultsTypes = []ResultsType{ResultsTypeString, ResultsTypeArray, Results
func ResultsArrayReference(a string) string {
return strings.TrimSuffix(strings.TrimSuffix(strings.TrimPrefix(a, "$("), ")"), "[*]")
}

type ResultsSpecsMap map[string]ResultSpec

type ResultsMap map[string]ResultValue

type ResultSpec struct{
Name string `json:"name"`
Type ResultsType `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Properties map[string]PropertySpec `json:"properties,omitempty"`
Value *ResultValue `json:"value,omitempty"`
}

type OutputSpecs struct{
ResultSpecs map[string]ResultSpec `json:"results,omitempty"`
}

type Outputs struct{
ResultsMap map[string]ResultValue `json:"results,omitempty"`
}
13 changes: 13 additions & 0 deletions pkg/apis/pipeline/v1/task_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ func (t *Task) SetDefaults(ctx context.Context) {

// SetDefaults set any defaults for the task spec
func (ts *TaskSpec) SetDefaults(ctx context.Context) {
if len(ts.Inputs.ParamSpecs)!=0 && len(ts.Params)==0{
for name,value := range ts.Inputs.ParamSpecs{
psc:=value
psc.Name=name
ts.Params = append(ts.Params, psc)
}
}
if len(ts.Outputs.ResultSpecs)!=0 && len(ts.Results)==0{
for name,value := range ts.Outputs.ResultSpecs{
rs:=TaskResult{Name: name, Type: value.Type, Properties: value.Properties, Description: value.Description}
ts.Results = append(ts.Results, rs)
}
}
for i := range ts.Params {
ts.Params[i].SetDefaults(ctx)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1/task_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ type TaskSpec struct {
// +listType=atomic
Params ParamSpecs `json:"params,omitempty"`

Inputs InputSpecs `json:"inputs,omitempty"`

Outputs OutputSpecs `json:"outputs,omitempty"`
// DisplayName is a user-facing name of the task that may be
// used to populate a UI.
// +optional
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1/taskrun_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func (tr *TaskRun) SetDefaults(ctx context.Context) {

// SetDefaults implements apis.Defaultable
func (trs *TaskRunSpec) SetDefaults(ctx context.Context) {
if len(trs.Inputs.Params)!=0{
for name,value := range trs.Inputs.Params{
trs.Params = append(trs.Params, Param{Name: name, Value: value})
}
}
cfg := config.FromContextOrDefaults(ctx)
if trs.TaskRef != nil {
if trs.TaskRef.Kind == "" {
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type TaskRunSpec struct {
// +optional
// +listType=atomic
Params Params `json:"params,omitempty"`

Inputs Inputs `json:"inputs,omitempty"`
// +optional
ServiceAccountName string `json:"serviceAccountName"`
// no more than one of the TaskRef and TaskSpec may be specified.
Expand Down Expand Up @@ -227,6 +229,8 @@ type TaskRunStatusFields struct {
// +listType=atomic
Results []TaskRunResult `json:"results,omitempty"`

Outputs Outputs `json:"outputs,omitempty"`

// The list has one entry per sidecar in the manifest. Each entry is
// represents the imageid of the corresponding sidecar.
// +listType=atomic
Expand Down
Loading

0 comments on commit a087fe3

Please sign in to comment.