resources

package
v0.0.0-...-4fc8c9b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PipelineTaskStateNone indicates that the execution status of a pipelineTask is unknown
	PipelineTaskStateNone = "None"
	// PipelineTaskStatusPrefix is a prefix of the param representing execution state of pipelineTask
	PipelineTaskStatusPrefix = "tasks."
	// PipelineTaskStatusSuffix is a suffix of the param representing execution state of pipelineTask
	PipelineTaskStatusSuffix = ".status"
)
View Source
const (
	// ReasonConditionCheckFailed indicates that the reason for the failure status is that the
	// condition check associated to the pipeline task evaluated to false
	ReasonConditionCheckFailed = "ConditionCheckFailed"
)

Variables

View Source
var (
	// ErrInvalidTaskResultReference indicates that the reason for the failure status is that there
	// is an invalid task result reference
	ErrInvalidTaskResultReference = errors.New("Invalid task result reference")
)

Functions

func ApplyContexts

func ApplyContexts(spec *v1.PipelineSpec, pipelineName string, pr *v1.PipelineRun) *v1.PipelineSpec

ApplyContexts applies the substitution from $(context.(pipelineRun|pipeline).*) with the specified values. Currently supports only name substitution. Uses "" as a default if name is not specified.

func ApplyParameters

func ApplyParameters(ctx context.Context, kubeClientSet kubernetes.Interface, p *v1.PipelineSpec, pr *v1.PipelineRun) (*v1.PipelineSpec, error)

ApplyParameters applies the params from a PipelineRun.Params to a PipelineSpec.

func ApplyPipelineTaskContexts

func ApplyPipelineTaskContexts(pt *v1.PipelineTask, pipelineRunStatus v1.PipelineRunStatus, facts *PipelineRunFacts) *v1.PipelineTask

ApplyPipelineTaskContexts applies the substitution from $(context.pipelineTask.*) with the specified values. Uses "0" as a default if a value is not available as well as matrix context variables $(tasks.<pipelineTaskName>.matrix.length) and $(tasks.<pipelineTaskName>.matrix.<resultName>.length)

func ApplyPipelineTaskStateContext

func ApplyPipelineTaskStateContext(state PipelineRunState, replacements map[string]string)

ApplyPipelineTaskStateContext replaces context variables referring to execution status with the specified status

func ApplyReplacements

func ApplyReplacements(p *v1.PipelineSpec, replacements map[string]string, arrayReplacements map[string][]string, objectReplacements map[string]map[string]string) *v1.PipelineSpec

ApplyReplacements replaces placeholders for declared parameters with the specified replacements.

func ApplyTaskResults

func ApplyTaskResults(targets PipelineRunState, resolvedResultRefs ResolvedResultRefs)

ApplyTaskResults applies the ResolvedResultRef to each PipelineTask.Params and Pipeline.When in targets

func ApplyTaskResultsToPipelineResults

func ApplyTaskResultsToPipelineResults(
	_ context.Context,
	results []v1.PipelineResult,
	taskRunResults map[string][]v1.TaskRunResult,
	customTaskResults map[string][]v1beta1.CustomRunResult,
	taskstatus map[string]string) ([]v1.PipelineRunResult, error)

ApplyTaskResultsToPipelineResults applies the results of completed TasksRuns and Runs to a Pipeline's list of PipelineResults, returning the computed set of PipelineRunResults. References to non-existent TaskResults or failed TaskRuns or Runs result in a PipelineResult being considered invalid and omitted from the returned slice. A nil slice is returned if no results are passed in or all results are invalid.

func ApplyWorkspaces

func ApplyWorkspaces(p *v1.PipelineSpec, pr *v1.PipelineRun) *v1.PipelineSpec

ApplyWorkspaces replaces workspace variables in the given pipeline spec with their concrete values.

func CheckMissingResultReferences

func CheckMissingResultReferences(pipelineRunState PipelineRunState, targets PipelineRunState) error

CheckMissingResultReferences returns an error if it is missing any result references. Missing result references can occur if task fails to produce a result but has OnError: continue (ie TestMissingResultWhenStepErrorIsIgnored)

func ConvertResultsMapToTaskRunResults

func ConvertResultsMapToTaskRunResults(resultsMap map[string][]string) []v1.TaskRunResult

ConvertResultsMapToTaskRunResults converts the map of results from Matrixed PipelineTasks to a list of TaskRunResults to standard the format

func GetContextReplacements

func GetContextReplacements(pipelineName string, pr *v1.PipelineRun) map[string]string

GetContextReplacements returns the pipelineRun context which can be used to replace context variables in the specifications

func GetNamesOfTaskRuns

func GetNamesOfTaskRuns(childRefs []v1.ChildStatusReference, ptName, prName string, numberOfTaskRuns int) []string

GetNamesOfTaskRuns should return unique names for `TaskRuns` if one has not already been defined, and the existing one otherwise.

func GetPipelineFunc

func GetPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekton clientset.Interface, requester remoteresource.Requester, pipelineRun *v1.PipelineRun, verificationPolicies []*v1alpha1.VerificationPolicy) (rprp.GetPipeline, error)

GetPipelineFunc is a factory function that will use the given PipelineRef to return a valid GetPipeline function that looks up the pipeline. It uses as context a k8s client, tekton client, namespace, and service account name to return the pipeline. It knows whether it needs to look in the cluster or in a remote location to fetch the reference. OCI bundle and remote resolution pipelines will be verified by trusted resources if the feature is enabled

func GetTaskRunName

func GetTaskRunName(childRefs []v1.ChildStatusReference, ptName, prName string) string

GetTaskRunName should return a unique name for a `TaskRun` if one has not already been defined, and the existing one otherwise.

func PropagateResults

func PropagateResults(rpt *ResolvedPipelineTask, runStates PipelineRunState)

PropagateResults propagate the result of the completed task to the unfinished task that is not explicitly specify in the params

func ValidateObjectParamRequiredKeys

func ValidateObjectParamRequiredKeys(pipelineParameters []v1.ParamSpec, pipelineRunParameters []v1.Param) error

ValidateObjectParamRequiredKeys validates that the required keys of all the object parameters expected by the Pipeline are provided by the PipelineRun.

func ValidateOptionalWorkspaces

func ValidateOptionalWorkspaces(pipelineWorkspaces []v1.PipelineWorkspaceDeclaration, state PipelineRunState) error

ValidateOptionalWorkspaces validates that any workspaces in the Pipeline that are marked as optional are also marked optional in the Tasks that receive them. This prevents a situation where a Task requires a workspace but a Pipeline does not offer the same guarantee the workspace will be provided at runtime.

func ValidateParamArrayIndex

func ValidateParamArrayIndex(ps *v1.PipelineSpec, params v1.Params) error

ValidateParamArrayIndex validates if the param reference to an array param is out of bound. error is returned when the array indexing reference is out of bound of the array param e.g. if a param reference of $(params.array-param[2]) and the array param is of length 2.

func ValidateParamTypesMatching

func ValidateParamTypesMatching(p *v1.PipelineSpec, pr *v1.PipelineRun) error

ValidateParamTypesMatching validate that parameters in PipelineRun override corresponding parameters in Pipeline of the same type.

func ValidateParameterTypesInMatrix

func ValidateParameterTypesInMatrix(state PipelineRunState) error

ValidateParameterTypesInMatrix validates the type of Parameter for Matrix.Params and Matrix.Include.Params after any replacements are made from Task parameters or results Matrix.Params must be of type array. Matrix.Include.Params must be of type string.

func ValidatePipelineResults

func ValidatePipelineResults(ps *v1.PipelineSpec, state PipelineRunState) error

ValidatePipelineResults ensures that any result references used by PipelineResults resolve to valid results. This prevents a situation where a PipelineResult references a result in a PipelineTask that doesn't exist or where the user has either misspelled a result name or the referenced task just doesn't return a result with that name.

func ValidatePipelineTaskResults

func ValidatePipelineTaskResults(state PipelineRunState) error

ValidatePipelineTaskResults ensures that any result references used by pipeline tasks resolve to valid results. This prevents a situation where a PipelineTask references a result in another PipelineTask that doesn't exist or where the user has either misspelled a result name or the referenced task just doesn't return a result with that name.

func ValidateRequiredParametersProvided

func ValidateRequiredParametersProvided(pipelineParameters *v1.ParamSpecs, pipelineRunParameters *v1.Params) error

ValidateRequiredParametersProvided validates that all the parameters expected by the Pipeline are provided by the PipelineRun. Extra Parameters are allowed, the Pipeline will use the Parameters it needs and ignore the other Parameters.

func ValidateTaskRunSpecs

func ValidateTaskRunSpecs(p *v1.PipelineSpec, pr *v1.PipelineRun) error

ValidateTaskRunSpecs that the TaskRunSpecs defined by a PipelineRun are correct.

func ValidateWorkspaceBindings

func ValidateWorkspaceBindings(p *v1.PipelineSpec, pr *v1.PipelineRun) error

ValidateWorkspaceBindings validates that the Workspaces expected by a Pipeline are provided by a PipelineRun.

Types

type GetRun

type GetRun func(name string) (*v1beta1.CustomRun, error)

GetRun is a function that will retrieve a CustomRun by name.

type LocalPipelineRefResolver

type LocalPipelineRefResolver struct {
	Namespace    string
	Tektonclient clientset.Interface
}

LocalPipelineRefResolver uses the current cluster to resolve a pipeline reference.

func (*LocalPipelineRefResolver) GetPipeline

GetPipeline will resolve a Pipeline from the local cluster using a versioned Tekton client. It will return an error if it can't find an appropriate Pipeline for any reason. TODO: if we want to set RefSource for in-cluster pipeline, set it here. https://github.com/tektoncd/pipeline/issues/5522 TODO(#6666): Support local resources verification

type PipelineRunFacts

type PipelineRunFacts struct {
	State           PipelineRunState
	SpecStatus      v1.PipelineRunSpecStatus
	TasksGraph      *dag.Graph
	FinalTasksGraph *dag.Graph
	TimeoutsState   PipelineRunTimeoutsState

	// SkipCache is a hash of PipelineTask names that stores whether a task will be
	// executed or not, because it's either not reachable via the DAG due to the pipeline
	// state, or because it was skipped due to when expressions.
	// We cache this data along the state, because it's expensive to compute, it requires
	// traversing potentially the whole graph; this way it can built incrementally, when
	// needed, via the `Skip` method in pipelinerunresolution.go
	// The skip data is sensitive to changes in the state. The ResetSkippedCache method
	// can be used to clean the cache and force re-computation when needed.
	SkipCache map[string]TaskSkipStatus
}

PipelineRunFacts holds the state of all the components that make up the Pipeline graph that are used to track the PipelineRun state without passing all these components separately. It helps simplify our implementation for getting and scheduling the next tasks. It is a collection of list of ResolvedPipelineTask, graph of DAG tasks, graph of finally tasks, cache of skipped tasks.

func (*PipelineRunFacts) DAGExecutionQueue

func (facts *PipelineRunFacts) DAGExecutionQueue() (PipelineRunState, error)

DAGExecutionQueue returns a list of DAG tasks which needs to be scheduled next

func (*PipelineRunFacts) GetChildReferences

func (facts *PipelineRunFacts) GetChildReferences() []v1.ChildStatusReference

GetChildReferences returns a slice of references, including version, kind, name, and pipeline task name, for all TaskRuns and Runs in the state.

func (*PipelineRunFacts) GetFinalTaskNames

func (facts *PipelineRunFacts) GetFinalTaskNames() sets.String

GetFinalTaskNames returns a list of all final task names

func (*PipelineRunFacts) GetFinalTasks

func (facts *PipelineRunFacts) GetFinalTasks() PipelineRunState

GetFinalTasks returns a list of final tasks which needs to be executed next GetFinalTasks returns final tasks only when all DAG tasks have finished executing or have been skipped

func (*PipelineRunFacts) GetPipelineConditionStatus

func (facts *PipelineRunFacts) GetPipelineConditionStatus(ctx context.Context, pr *v1.PipelineRun, logger *zap.SugaredLogger, c clock.PassiveClock) *apis.Condition

GetPipelineConditionStatus will return the Condition that the PipelineRun prName should be updated with, based on the status of the TaskRuns in state.

func (*PipelineRunFacts) GetPipelineTaskStatus

func (facts *PipelineRunFacts) GetPipelineTaskStatus() map[string]string

GetPipelineTaskStatus returns the status of a PipelineTask depending on its taskRun the checks are implemented such that the finally tasks are requesting status of the dag tasks

func (*PipelineRunFacts) GetSkippedTasks

func (facts *PipelineRunFacts) GetSkippedTasks() []v1.SkippedTask

GetSkippedTasks constructs a list of SkippedTask struct to be included in the PipelineRun Status

func (*PipelineRunFacts) GetTaskNames

func (facts *PipelineRunFacts) GetTaskNames() sets.String

GetTaskNames returns a list of all non-final task names

func (*PipelineRunFacts) IsCancelled

func (facts *PipelineRunFacts) IsCancelled() bool

IsCancelled returns true if the PipelineRun was cancelled

func (*PipelineRunFacts) IsGracefullyCancelled

func (facts *PipelineRunFacts) IsGracefullyCancelled() bool

IsGracefullyCancelled returns true if the PipelineRun was gracefully cancelled

func (*PipelineRunFacts) IsGracefullyStopped

func (facts *PipelineRunFacts) IsGracefullyStopped() bool

IsGracefullyStopped returns true if the PipelineRun was gracefully stopped

func (*PipelineRunFacts) IsRunning

func (facts *PipelineRunFacts) IsRunning() bool

IsRunning returns true if the PipelineRun is still running tasks in the specified dag

func (*PipelineRunFacts) IsStopping

func (facts *PipelineRunFacts) IsStopping() bool

IsStopping returns true if the PipelineRun won't be scheduling any new Task because at least one task already failed or was cancelled in the specified dag

func (*PipelineRunFacts) ResetSkippedCache

func (facts *PipelineRunFacts) ResetSkippedCache()

ResetSkippedCache resets the skipped cache in the facts map

type PipelineRunState

type PipelineRunState []*ResolvedPipelineTask

PipelineRunState is a slice of ResolvedPipelineRunTasks the represents the current execution state of the PipelineRun.

func (PipelineRunState) AdjustStartTime

func (state PipelineRunState) AdjustStartTime(unadjustedStartTime *metav1.Time) *metav1.Time

AdjustStartTime adjusts potential drift in the PipelineRun's start time.

The StartTime will only adjust earlier, so that the PipelineRun's StartTime is no later than any of its constituent TaskRuns.

This drift could be due to us either failing to record the Run's start time previously, or our own failure to observe a prior update before reconciling the resource again.

func (PipelineRunState) GetRunsResults

func (state PipelineRunState) GetRunsResults() map[string][]v1beta1.CustomRunResult

GetRunsResults returns a map of all successfully completed Runs in the state, with the pipeline task name as the key and the results from the corresponding TaskRun as the value. It only includes runs which have completed successfully.

func (PipelineRunState) GetTaskRunsResults

func (state PipelineRunState) GetTaskRunsResults() map[string][]v1.TaskRunResult

GetTaskRunsResults returns a map of all successfully completed TaskRuns in the state, with the pipeline task name as the key and the results from the corresponding TaskRun as the value. It only includes tasks which have completed successfully.

func (PipelineRunState) IsBeforeFirstTaskRun

func (state PipelineRunState) IsBeforeFirstTaskRun() bool

IsBeforeFirstTaskRun returns true if the PipelineRun has not yet started its first TaskRun

func (PipelineRunState) ToMap

func (state PipelineRunState) ToMap() map[string]*ResolvedPipelineTask

ToMap returns a map that maps pipeline task name to the resolved pipeline run task

type PipelineRunTimeoutsState

type PipelineRunTimeoutsState struct {
	StartTime        *time.Time
	FinallyStartTime *time.Time
	PipelineTimeout  *time.Duration
	TasksTimeout     *time.Duration
	FinallyTimeout   *time.Duration
	Clock            clock.PassiveClock
}

PipelineRunTimeoutsState records information about start times and timeouts for the PipelineRun, so that the PipelineRunFacts can reference those values in its functions.

type ResolvedPipelineTask

type ResolvedPipelineTask struct {
	TaskRunNames []string
	TaskRuns     []*v1.TaskRun
	// If the PipelineTask is a Custom Task, CustomRunName and CustomRun will be set.
	CustomTask     bool
	CustomRunNames []string
	CustomRuns     []*v1beta1.CustomRun
	PipelineTask   *v1.PipelineTask
	ResolvedTask   *resources.ResolvedTask
	ResultsCache   map[string][]string
	// EvaluatedCEL is used to store the results of evaluated CEL expression
	EvaluatedCEL map[string]bool
}

ResolvedPipelineTask contains a PipelineTask and its associated TaskRun(s) or CustomRuns, if they exist.

func ResolvePipelineTask

func ResolvePipelineTask(
	ctx context.Context,
	pipelineRun v1.PipelineRun,
	getTask resources.GetTask,
	getTaskRun resources.GetTaskRun,
	getRun GetRun,
	pipelineTask v1.PipelineTask,
	pst PipelineRunState,
) (*ResolvedPipelineTask, error)

ResolvePipelineTask returns a new ResolvedPipelineTask representing any TaskRuns or CustomRuns associated with this Pipeline Task, if they exist.

If the Pipeline Task is a Task, it retrieves any TaskRuns, plus the Task spec, and updates the ResolvedPipelineTask with this information. It also sets the ResolvedPipelineTask's TaskRunName(s) with the names of TaskRuns that should be or already have been created.

If the Pipeline Task is a Custom Task, it retrieves any CustomRuns and updates the ResolvedPipelineTask with this information. It also sets the ResolvedPipelineTask's RunName(s) with the names of CustomRuns that should be or already have been created.

func (*ResolvedPipelineTask) EvaluateCEL

func (t *ResolvedPipelineTask) EvaluateCEL() error

EvaluateCEL evaluate the CEL expressions, and store the evaluated results in EvaluatedCEL

func (ResolvedPipelineTask) IsCustomTask

func (t ResolvedPipelineTask) IsCustomTask() bool

IsCustomTask returns true if the PipelineTask references a Custom Task.

func (*ResolvedPipelineTask) IsFinalTask

func (t *ResolvedPipelineTask) IsFinalTask(facts *PipelineRunFacts) bool

IsFinalTask returns true if a task is a finally task

func (*ResolvedPipelineTask) IsFinallySkipped

func (t *ResolvedPipelineTask) IsFinallySkipped(facts *PipelineRunFacts) TaskSkipStatus

IsFinallySkipped returns true if a finally task is not executed and skipped due to task result validation failure

func (ResolvedPipelineTask) IsRunning

func (t ResolvedPipelineTask) IsRunning() bool

IsRunning returns true only if the task is neither succeeded, cancelled nor failed

func (*ResolvedPipelineTask) Skip

Skip returns true if a PipelineTask will not be run because (1) its When Expressions evaluated to false (2) its Condition Checks failed (3) its parent task was skipped (4) Pipeline is in stopping state (one of the PipelineTasks failed) (5) Pipeline is gracefully cancelled or stopped

type ResolvedResultRef

type ResolvedResultRef struct {
	Value           v1.ResultValue
	ResultReference v1.ResultRef
	FromTaskRun     string
	FromRun         string
}

ResolvedResultRef represents a result ref reference that has been fully resolved (value has been populated). If the value is from a Result, then the ResultReference will be populated to point to the ResultReference which resulted in the value

type ResolvedResultRefs

type ResolvedResultRefs []*ResolvedResultRef

ResolvedResultRefs represents all of the ResolvedResultRef for a pipeline task

func ResolveResultRef

func ResolveResultRef(pipelineRunState PipelineRunState, target *ResolvedPipelineTask) (ResolvedResultRefs, string, error)

ResolveResultRef resolves any ResultReference that are found in the target ResolvedPipelineTask

func ResolveResultRefs

func ResolveResultRefs(pipelineRunState PipelineRunState, targets PipelineRunState) (ResolvedResultRefs, string, error)

ResolveResultRefs resolves any ResultReference that are found in the target ResolvedPipelineTask

type TaskNotFoundError

type TaskNotFoundError struct {
	Name string
	Msg  string
}

TaskNotFoundError indicates that the resolution failed because a referenced Task couldn't be retrieved

func (*TaskNotFoundError) Error

func (e *TaskNotFoundError) Error() string

type TaskSkipStatus

type TaskSkipStatus struct {
	IsSkipped      bool
	SkippingReason v1.SkippingReason
}

TaskSkipStatus stores whether a task was skipped and why

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL