Skip to content

Commit

Permalink
Revert removal of PipelineResources related fields
Browse files Browse the repository at this point in the history
This commit brings back PipelineResources related fields to the API structs,
marking them as deprecated and unused. The JSON tags are removed, so CRDs
cannot be defined with these fields. Keeping these fields in the Go structs
allows clients to maintain backwards compatibility with older servers, and
allows downstream projects such as chains to continue to work with older CRDs
that may define these fields.
  • Loading branch information
lbernick committed Mar 27, 2023
1 parent af30ab5 commit b72cf46
Show file tree
Hide file tree
Showing 45 changed files with 5,478 additions and 94 deletions.
1,349 changes: 1,255 additions & 94 deletions docs/pipeline-api.md

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ GOFLAGS="-mod=vendor"
# --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.

# This generates deepcopy,client,informer and lister for the resource package (v1alpha1)
# This is separate from the pipeline package as resource are staying in v1alpha1 and they
# need to be separated (at least in terms of go package) from the pipeline's packages to
# not having dependency cycle.
bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/tektoncd/pipeline/pkg/client/resource github.com/tektoncd/pipeline/pkg/apis \
"resource:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt

# This generates deepcopy,client,informer and lister for the pipeline package (v1alpha1, v1beta1, and v1)
bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/tektoncd/pipeline/pkg/client github.com/tektoncd/pipeline/pkg/apis \
Expand Down Expand Up @@ -70,6 +80,14 @@ ${PREFIX}/deepcopy-gen \
-i github.com/tektoncd/pipeline/pkg/apis/run/v1alpha1

# Knative Injection

# This generates the knative injection packages for the resource package (v1alpha1).
# This is separate from the pipeline package for the same reason as client and all (see above).
bash ${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \
github.com/tektoncd/pipeline/pkg/client/resource github.com/tektoncd/pipeline/pkg/apis \
"resource:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt

# This generates the knative inject packages for the pipeline package (v1alpha1, v1beta1, v1).
bash ${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \
github.com/tektoncd/pipeline/pkg/client github.com/tektoncd/pipeline/pkg/apis \
Expand Down
609 changes: 609 additions & 0 deletions pkg/apis/pipeline/v1beta1/openapi_generated.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ type PipelineSpec struct {
// used to populate a UI.
// +optional
Description string `json:"description,omitempty"`
// Deprecated: Unused, preserved only for backwards compatibility
// +listType=atomic
Resources []PipelineDeclaredResource `json:"-"`
// Tasks declares the graph of Tasks that execute when this Pipeline is run.
// +listType=atomic
Tasks []PipelineTask `json:"tasks,omitempty"`
Expand Down Expand Up @@ -187,6 +190,10 @@ type PipelineTask struct {
// +listType=atomic
RunAfter []string `json:"runAfter,omitempty"`

// Deprecated: Unused, preserved only for backwards compatibility
// +optional
Resources *PipelineTaskResources `json:"-"`

// Parameters declares parameters passed to this task.
// +optional
// +listType=atomic
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ type PipelineRunSpec struct {
PipelineRef *PipelineRef `json:"pipelineRef,omitempty"`
// +optional
PipelineSpec *PipelineSpec `json:"pipelineSpec,omitempty"`
// Resources is a list of bindings specifying which actual instances of
// PipelineResources to use for the resources the Pipeline has declared
// it needs.
//
// Deprecated: Unused, preserved only for backwards compatibility
// +listType=atomic
Resources []PipelineResourceBinding `json:"-"`
// Params is a list of parameter names and values.
// +listType=atomic
Params []Param `json:"params,omitempty"`
Expand Down
229 changes: 229 additions & 0 deletions pkg/apis/pipeline/v1beta1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"

"github.com/hashicorp/go-multierror"
resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
v1 "k8s.io/api/core/v1"
)

// PipelineResourceResult is used to write key/value pairs to TaskRun pod termination messages.
Expand Down Expand Up @@ -77,3 +79,230 @@ func (r *ResultType) UnmarshalJSON(data []byte) error {

return nil
}

// ResourceParam declares a string value to use for the parameter called Name, and is used in
// the specific context of PipelineResources.
//
// Deprecated: Unused, preserved only for backwards compatibility
type ResourceParam = resource.ResourceParam

// PipelineResourceType represents the type of endpoint the pipelineResource is, so that the
// controller will know this pipelineResource should be fetched and optionally what
// additional metatdata should be provided for it.
//
// Deprecated: Unused, preserved only for backwards compatibility
type PipelineResourceType = resource.PipelineResourceType

// 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.
//
// Deprecated: Unused, preserved only for backwards compatibility
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"`
// Optional declares the resource as optional.
// optional: true - the resource is considered optional
// optional: false - the resource is considered required (default/equivalent of not specifying it)
Optional bool `json:"optional,omitempty"`
}

// TaskResources allows a Pipeline to declare how its DeclaredPipelineResources
// should be provided to a Task as its inputs and outputs.
//
// Deprecated: Unused, preserved only for backwards compatibility
type TaskResources struct {
// Inputs holds the mapping from the PipelineResources declared in
// DeclaredPipelineResources to the input PipelineResources required by the Task.
// +listType=atomic
Inputs []TaskResource `json:"inputs,omitempty"`
// Outputs holds the mapping from the PipelineResources declared in
// DeclaredPipelineResources to the input PipelineResources required by the Task.
// +listType=atomic
Outputs []TaskResource `json:"outputs,omitempty"`
}

// TaskResource defines an input or output Resource declared as a requirement
// by a Task. The Name field will be used to refer to these Resources within
// the Task definition, and when provided as an Input, the Name will be the
// path to the volume mounted containing this Resource as an input (e.g.
// an input Resource named `workspace` will be mounted at `/workspace`).
//
// Deprecated: Unused, preserved only for backwards compatibility
type TaskResource struct {
ResourceDeclaration `json:",inline"`
}

// TaskRunResources allows a TaskRun to declare inputs and outputs TaskResourceBinding
//
// Deprecated: Unused, preserved only for backwards compatibility
type TaskRunResources struct {
// Inputs holds the inputs resources this task was invoked with
// +listType=atomic
Inputs []TaskResourceBinding `json:"inputs,omitempty"`
// Outputs holds the inputs resources this task was invoked with
// +listType=atomic
Outputs []TaskResourceBinding `json:"outputs,omitempty"`
}

// TaskResourceBinding points to the PipelineResource that
// will be used for the Task input or output called Name.
//
// Deprecated: Unused, preserved only for backwards compatibility
type TaskResourceBinding struct {
PipelineResourceBinding `json:",inline"`
// Paths will probably be removed in #1284, and then PipelineResourceBinding can be used instead.
// The optional Path field corresponds to a path on disk at which the Resource can be found
// (used when providing the resource via mounted volume, overriding the default logic to fetch the Resource).
// +optional
// +listType=atomic
Paths []string `json:"paths,omitempty"`
}

// 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`).
//
// Deprecated: Unused, preserved only for backwards compatibility
type ResourceDeclaration = resource.ResourceDeclaration

// PipelineResourceBinding connects a reference to an instance of a PipelineResource
// with a PipelineResource dependency that the Pipeline has declared
//
// Deprecated: Unused, preserved only for backwards compatibility
type PipelineResourceBinding struct {
// Name is the name of the PipelineResource in the Pipeline's declaration
Name string `json:"name,omitempty"`
// ResourceRef is a reference to the instance of the actual PipelineResource
// that should be used
// +optional
ResourceRef *PipelineResourceRef `json:"resourceRef,omitempty"`

// ResourceSpec is specification of a resource that should be created and
// consumed by the task
// +optional
ResourceSpec *resource.PipelineResourceSpec `json:"resourceSpec,omitempty"`
}

// PipelineTaskResources allows a Pipeline to declare how its DeclaredPipelineResources
// should be provided to a Task as its inputs and outputs.
//
// Deprecated: Unused, preserved only for backwards compatibility
type PipelineTaskResources struct {
// Inputs holds the mapping from the PipelineResources declared in
// DeclaredPipelineResources to the input PipelineResources required by the Task.
// +listType=atomic
Inputs []PipelineTaskInputResource `json:"inputs,omitempty"`
// Outputs holds the mapping from the PipelineResources declared in
// DeclaredPipelineResources to the input PipelineResources required by the Task.
// +listType=atomic
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.
//
// Deprecated: Unused, preserved only for backwards compatibility
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
// +listType=atomic
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.
//
// Deprecated: Unused, preserved only for backwards compatibility
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"`
}

// TaskRunInputs holds the input values that this task was invoked with.
//
// Deprecated: Unused, preserved only for backwards compatibility
type TaskRunInputs struct {
// +optional
// +listType=atomic
Resources []TaskResourceBinding `json:"resources,omitempty"`
// +optional
// +listType=atomic
Params []Param `json:"params,omitempty"`
}

// TaskRunOutputs holds the output values that this task was invoked with.
//
// Deprecated: Unused, preserved only for backwards compatibility
type TaskRunOutputs struct {
// +optional
// +listType=atomic
Resources []TaskResourceBinding `json:"resources,omitempty"`
}

// PipelineResourceRef can be used to refer to a specific instance of a Resource
//
// Deprecated: Unused, preserved only for backwards compatibility
type PipelineResourceRef struct {
// Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names
Name string `json:"name,omitempty"`
// API version of the referent
// +optional
APIVersion string `json:"apiVersion,omitempty"`
}

// PipelineResourceInterface interface to be implemented by different PipelineResource types
//
// Deprecated: Unused, preserved only for backwards compatibility
type PipelineResourceInterface interface {
// GetName returns the name of this PipelineResource instance.
GetName() string
// GetType returns the type of this PipelineResource (often a super type, e.g. in the case of storage).
GetType() PipelineResourceType
// Replacements returns all the attributes that this PipelineResource has that
// can be used for variable replacement.
Replacements() map[string]string
// GetOutputTaskModifier returns the TaskModifier instance that should be used on a Task
// in order to add this kind of resource when it is being used as an output.
GetOutputTaskModifier(ts *TaskSpec, path string) (TaskModifier, error)
// GetInputTaskModifier returns the TaskModifier instance that should be used on a Task
// in order to add this kind of resource when it is being used as an input.
GetInputTaskModifier(ts *TaskSpec, path string) (TaskModifier, error)
}

// TaskModifier is an interface to be implemented by different PipelineResources
//
// Deprecated: Unused, preserved only for backwards compatibility
type TaskModifier interface {
GetStepsToPrepend() []Step
GetStepsToAppend() []Step
GetVolumes() []v1.Volume
}

// InternalTaskModifier implements TaskModifier for resources that are built-in to Tekton Pipelines.
//
// Deprecated: Unused, preserved only for backwards compatibility
type InternalTaskModifier struct {
// +listType=atomic
StepsToPrepend []Step `json:"stepsToPrepend"`
// +listType=atomic
StepsToAppend []Step `json:"stepsToAppend"`
// +listType=atomic
Volumes []v1.Volume `json:"volumes"`
}
Loading

0 comments on commit b72cf46

Please sign in to comment.