Skip to content

Commit

Permalink
Add a new method to the PipelineResource interface for customization …
Browse files Browse the repository at this point in the history
…of the Output directory

We previously initialized each Output Resource with an empty directory. This changes the
behavior to initialize this with a custom set of files per resource. The behavior now is
the same as before, with each resource embedding a helper to create empty directories.

Over time we can customize this where necessary.
  • Loading branch information
dlorenc committed Aug 19, 2019
1 parent 5638925 commit 842cb57
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1alpha1/build_gcs_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type BuildGCSResource struct {
Type PipelineResourceType
Location string
ArtifactType GCSArtifactType

// Initialize an empty output directory
EmptyDirOutputResource
}

// NewBuildGCSResource creates a new BuildGCS resource to pass to a Task
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/pipeline/v1alpha1/cloud_event_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type CloudEventResource struct {
Type PipelineResourceType `json:"type"`
// TargetURI is the URI of the sink which the cloud event is develired to
TargetURI string `json:"targetURI"`
// Initialize an empty output directory
EmptyDirOutputResource
}

// NewCloudEventResource creates a new CloudEvent resource to pass to a Task
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1alpha1/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ type ClusterResource struct {
CAData []byte `json:"cadata"`
//Secrets holds a struct to indicate a field name and corresponding secret name to populate it
Secrets []SecretParam `json:"secrets"`

// Initialize an empty output directory
EmptyDirOutputResource
}

// NewClusterResource create a new k8s cluster resource to pass to a pipeline task
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1alpha1/gcs_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type GCSResource struct {
TypeDir bool `json:"typeDir"`
//Secret holds a struct to indicate a field name and corresponding secret name to populate it
Secrets []SecretParam `json:"secrets"`

// Initialize an empty output directory
EmptyDirOutputResource
}

// NewGCSResource creates a new GCS resource to pass to a Task
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1alpha1/git_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type GitResource struct {
// https://git-scm.com/docs/gitrevisions#_specifying_revisions for more
// information.
Revision string `json:"revision"`

// Initialize an empty output directory
EmptyDirOutputResource
}

// NewGitResource creates a new git resource to pass to a Task
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1alpha1/image_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type ImageResource struct {
URL string `json:"url"`
Digest string `json:"digest"`
OutputImageDir string

// Initialize an empty output directory
EmptyDirOutputResource
}

// GetName returns the name of the resource
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1alpha1/pull_request_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ type PullRequestResource struct {
URL string `json:"url"`
// Secrets holds a struct to indicate a field name and corresponding secret name to populate it.
Secrets []SecretParam `json:"secrets"`

// Initialize an empty output directory
EmptyDirOutputResource
}

// NewPullRequestResource create a new git resource to pass to a Task
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/pipeline/v1alpha1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type PipelineResourceInterface interface {
GetType() PipelineResourceType
Replacements() map[string]string
GetDownloadSteps(sourcePath string) ([]Step, error)
GetOutputInitializationSteps(name, sourcePath string) []Step
GetUploadSteps(sourcePath string) ([]Step, error)
GetUploadVolumeSpec(spec *TaskSpec) ([]corev1.Volume, error)
GetDownloadVolumeSpec(spec *TaskSpec) ([]corev1.Volume, error)
Expand Down Expand Up @@ -152,3 +153,13 @@ func ResourceFromType(r *PipelineResource) (PipelineResourceInterface, error) {
}
return nil, xerrors.Errorf("%s is an invalid or unimplemented PipelineResource", r.Spec.Type)
}

// EmptyDirOutputResource is a partial struct that can be embedded into other resources.
// The behavior is to create an empty output directory.
type EmptyDirOutputResource struct {
}

// GetOutputInitializationSteps returns a set of steps to be used to initialize an output directory.
func (e *EmptyDirOutputResource) GetOutputInitializationSteps(name, sourcePath string) []Step {
return []Step{CreateDirStep(name, sourcePath)}
}
23 changes: 23 additions & 0 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.

6 changes: 3 additions & 3 deletions pkg/reconciler/v1alpha1/taskrun/resources/output_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ func AddOutputResources(
resourceVolumes = append(resourceVolumes, as.GetSecretsVolumes()...)
}

// Add containers to mkdir each output directory. This should run before the build steps themselves.
mkdirSteps := []v1alpha1.Step{v1alpha1.CreateDirStep(boundResource.Name, sourcePath)}
taskSpec.Steps = append(mkdirSteps, taskSpec.Steps...)
// Add containers to initialize each output directory. This should run before the build steps themselves.
initOutputSteps := resource.GetOutputInitializationSteps(boundResource.Name, sourcePath)
taskSpec.Steps = append(initOutputSteps, taskSpec.Steps...)
taskSpec.Steps = append(taskSpec.Steps, resourceSteps...)
taskSpec.Volumes = append(taskSpec.Volumes, resourceVolumes...)

Expand Down

0 comments on commit 842cb57

Please sign in to comment.