Skip to content

Commit

Permalink
Replace ConditionResource with ResourceDeclaration
Browse files Browse the repository at this point in the history
Creates a new internal struct called `ResourceDeclaration`.
TaskResources now embed this and add additional fields such as
`OutputImageDir` while `ConditionResource` has simply been replaced
with this new type.

Signed-off-by: Dibyo Mukherjee <dibyo@google.com>
  • Loading branch information
dibyom authored and tekton-robot committed Aug 30, 2019
1 parent ad0facd commit 92d5bcc
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 257 deletions.
18 changes: 1 addition & 17 deletions pkg/apis/pipeline/v1alpha1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,7 @@ type ConditionSpec struct {

// Resources is a list of the ConditionResources required to run the condition.
// +optional
Resources []ConditionResource `json:"resources,omitempty"`
}

// ConditionResource defines an input PipelineResource declared as a requirement
// by a Task. The Name field will be used to refer to these Resources within
// the Condition definition and will be the path to the volume mounted containing this
// Resource as an input (e.g. an Resource named `workspace` will be mounted at `/workspace`).
type ConditionResource struct {
// Name declares the name by which a resource is referenced in the Condition's
// definition.
Name string `json:"name"`
// Type is the type of this resource;
Type PipelineResourceType `json:"type"`
// TargetPath is the path in workspace directory where the resource
// will be copied.
// +optional
TargetPath string `json:"targetPath"`
Resources []ResourceDeclaration `json:"resources,omitempty"`
}

// ConditionCheck represents a single evaluation of a Condition step.
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/pipeline/v1alpha1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ type PipelineResourceList struct {
Items []PipelineResource `json:"items"`
}

// ResourceDeclaration defines an input or output PipelineResource declared as a requirement
// by another type such as a Task or Condition. The Name field will be used to refer to these
// PipelineResources within the type's definition, and when provided as an Input, the Name will be the
// path to the volume mounted containing this PipelineResource as an input (e.g.
// an input Resource named `workspace` will be mounted at `/workspace`).
type ResourceDeclaration struct {
// Name declares the name by which a resource is referenced in the
// definition. Resources may be referenced by name in the definition of a
// Task's steps.
Name string `json:"name"`
// Type is the type of this resource;
Type PipelineResourceType `json:"type"`
// TargetPath is the path in workspace directory where the resource
// will be copied.
// +optional
TargetPath string `json:"targetPath,omitempty"`
}

// ResourceFromType returns a PipelineResourceInterface from a PipelineResource's type.
func ResourceFromType(r *PipelineResource) (PipelineResourceInterface, error) {
switch r.Spec.Type {
Expand Down
12 changes: 1 addition & 11 deletions pkg/apis/pipeline/v1alpha1/task_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,7 @@ type Inputs struct {
// path to the volume mounted containing this Resource as an input (e.g.
// an input Resource named `workspace` will be mounted at `/workspace`).
type TaskResource struct {
// Name declares the name by which a resource is referenced in the Task's
// definition. Resources may be referenced by name in the definition of a
// Task's steps.
Name string `json:"name"`
// Type is the type of this resource;
Type PipelineResourceType `json:"type"`
// TargetPath is the path in workspace directory where the task resource
// will be copied.
// +optional
TargetPath string `json:"targetPath,omitempty"`
// Path to the index.json file for output container images.
ResourceDeclaration
// +optional
OutputImageDir string `json:"outputImageDir,omitempty"`
}
Expand Down
99 changes: 34 additions & 65 deletions pkg/apis/pipeline/v1alpha1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,24 @@ import (
)

var validResource = v1alpha1.TaskResource{
Name: "source",
Type: "git",
ResourceDeclaration: v1alpha1.ResourceDeclaration{
Name: "source",
Type: "git",
},
}

var validImageResource = v1alpha1.TaskResource{
Name: "source",
Type: "image",
ResourceDeclaration: v1alpha1.ResourceDeclaration{
Name: "source",
Type: "image",
},
}

var invalidResource = v1alpha1.TaskResource{
ResourceDeclaration: v1alpha1.ResourceDeclaration{
Name: "source",
Type: "what",
},
}

var validSteps = []v1alpha1.Step{{Container: corev1.Container{
Expand Down Expand Up @@ -128,10 +139,7 @@ func TestTaskSpecValidate(t *testing.T) {
name: "valid template variable",
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "foo",
Type: v1alpha1.PipelineResourceTypeImage,
}},
Resources: []v1alpha1.TaskResource{validImageResource},
Params: []v1alpha1.ParamSpec{{
Name: "baz",
}, {
Expand All @@ -143,7 +151,7 @@ func TestTaskSpecValidate(t *testing.T) {
},
Steps: []v1alpha1.Step{{Container: corev1.Container{
Name: "mystep",
Image: "$(inputs.resources.foo.url)",
Image: "$(inputs.resources.source.url)",
Args: []string{"--flag=$(inputs.params.baz) && $(input.params.foo-is-baz)"},
WorkingDir: "/foo/bar/$(outputs.resources.source)",
}}},
Expand All @@ -152,10 +160,7 @@ func TestTaskSpecValidate(t *testing.T) {
name: "valid array template variable",
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "foo",
Type: v1alpha1.PipelineResourceTypeImage,
}},
Resources: []v1alpha1.TaskResource{validImageResource},
Params: []v1alpha1.ParamSpec{{
Name: "baz",
Type: v1alpha1.ParamTypeArray,
Expand All @@ -169,7 +174,7 @@ func TestTaskSpecValidate(t *testing.T) {
},
Steps: []v1alpha1.Step{{Container: corev1.Container{
Name: "mystep",
Image: "$(inputs.resources.foo.url)",
Image: "$(inputs.resources.source.url)",
Command: []string{"$(inputs.param.foo-is-baz)"},
Args: []string{"$(inputs.params.baz)", "middle string", "$(input.params.foo-is-baz)"},
WorkingDir: "/foo/bar/$(outputs.resources.source)",
Expand All @@ -180,10 +185,7 @@ func TestTaskSpecValidate(t *testing.T) {
name: "deprecated valid template variable",
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "foo",
Type: v1alpha1.PipelineResourceTypeImage,
}},
Resources: []v1alpha1.TaskResource{validImageResource},
Params: []v1alpha1.ParamSpec{{
Name: "baz",
}, {
Expand All @@ -195,7 +197,7 @@ func TestTaskSpecValidate(t *testing.T) {
},
Steps: []v1alpha1.Step{{Container: corev1.Container{
Name: "mystep",
Image: "${inputs.resources.foo.url}",
Image: "${inputs.resources.source.url}",
Args: []string{"--flag=${inputs.params.baz} && ${input.params.foo-is-baz}"},
WorkingDir: "/foo/bar/${outputs.resources.source}",
}}},
Expand All @@ -205,10 +207,7 @@ func TestTaskSpecValidate(t *testing.T) {
name: "deprecated valid array template variable",
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "foo",
Type: v1alpha1.PipelineResourceTypeImage,
}},
Resources: []v1alpha1.TaskResource{validImageResource},
Params: []v1alpha1.ParamSpec{{
Name: "baz",
Type: v1alpha1.ParamTypeArray,
Expand All @@ -222,7 +221,7 @@ func TestTaskSpecValidate(t *testing.T) {
},
Steps: []v1alpha1.Step{{Container: corev1.Container{
Name: "mystep",
Image: "${inputs.resources.foo.url}",
Image: "${inputs.resources.source.url}",
Command: []string{"${inputs.param.foo-is-baz}"},
Args: []string{"${inputs.params.baz}", "middle string", "${input.params.foo-is-baz}"},
WorkingDir: "/foo/bar/${outputs.resources.source}",
Expand Down Expand Up @@ -290,10 +289,7 @@ func TestTaskSpecValidateError(t *testing.T) {
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{
{
Name: "source",
Type: "what",
},
invalidResource,
validResource,
},
},
Expand Down Expand Up @@ -383,18 +379,15 @@ func TestTaskSpecValidateError(t *testing.T) {
},
Outputs: &v1alpha1.Outputs{
Resources: []v1alpha1.TaskResource{
{
Name: "who",
Type: "what",
},
invalidResource,
validResource,
},
},
Steps: validSteps,
},
expectedError: apis.FieldError{
Message: `invalid value: what`,
Paths: []string{"taskspec.Outputs.Resources.who.Type"},
Paths: []string{"taskspec.Outputs.Resources.source.Type"},
},
}, {
name: "duplicated inputs",
Expand Down Expand Up @@ -492,10 +485,7 @@ func TestTaskSpecValidateError(t *testing.T) {
name: "array used in unaccepted field",
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "foo",
Type: v1alpha1.PipelineResourceTypeImage,
}},
Resources: []v1alpha1.TaskResource{validImageResource},
Params: []v1alpha1.ParamSpec{{
Name: "baz",
Type: v1alpha1.ParamTypeArray,
Expand Down Expand Up @@ -523,10 +513,7 @@ func TestTaskSpecValidateError(t *testing.T) {
name: "array not properly isolated",
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "foo",
Type: v1alpha1.PipelineResourceTypeImage,
}},
Resources: []v1alpha1.TaskResource{validImageResource},
Params: []v1alpha1.ParamSpec{{
Name: "baz",
Type: v1alpha1.ParamTypeArray,
Expand Down Expand Up @@ -554,10 +541,7 @@ func TestTaskSpecValidateError(t *testing.T) {
name: "array not properly isolated",
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "foo",
Type: v1alpha1.PipelineResourceTypeImage,
}},
Resources: []v1alpha1.TaskResource{validImageResource},
Params: []v1alpha1.ParamSpec{{
Name: "baz",
Type: v1alpha1.ParamTypeArray,
Expand Down Expand Up @@ -597,10 +581,7 @@ func TestTaskSpecValidateError(t *testing.T) {
name: "inferred array not properly isolated",
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "foo",
Type: v1alpha1.PipelineResourceTypeImage,
}},
Resources: []v1alpha1.TaskResource{validImageResource},
Params: []v1alpha1.ParamSpec{{
Name: "baz",
Default: &v1alpha1.ArrayOrString{
Expand Down Expand Up @@ -682,10 +663,7 @@ func TestTaskSpecValidateError(t *testing.T) {
name: "deprected array used in unaccepted field",
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "foo",
Type: v1alpha1.PipelineResourceTypeImage,
}},
Resources: []v1alpha1.TaskResource{validImageResource},
Params: []v1alpha1.ParamSpec{{
Name: "baz",
Type: v1alpha1.ParamTypeArray,
Expand Down Expand Up @@ -714,10 +692,7 @@ func TestTaskSpecValidateError(t *testing.T) {
name: "depreated array not properly isolated",
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "foo",
Type: v1alpha1.PipelineResourceTypeImage,
}},
Resources: []v1alpha1.TaskResource{validImageResource},
Params: []v1alpha1.ParamSpec{{
Name: "baz",
Type: v1alpha1.ParamTypeArray,
Expand Down Expand Up @@ -746,10 +721,7 @@ func TestTaskSpecValidateError(t *testing.T) {
name: "deprecated array not properly isolated",
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "foo",
Type: v1alpha1.PipelineResourceTypeImage,
}},
Resources: []v1alpha1.TaskResource{validImageResource},
Params: []v1alpha1.ParamSpec{{
Name: "baz",
Type: v1alpha1.ParamTypeArray,
Expand Down Expand Up @@ -791,10 +763,7 @@ func TestTaskSpecValidateError(t *testing.T) {
name: "deprecated inferred array not properly isolated",
fields: fields{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "foo",
Type: v1alpha1.PipelineResourceTypeImage,
}},
Resources: []v1alpha1.TaskResource{validImageResource},
Params: []v1alpha1.ParamSpec{{
Name: "baz",
Default: &v1alpha1.ArrayOrString{
Expand Down
35 changes: 18 additions & 17 deletions pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 92d5bcc

Please sign in to comment.