Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Switch storage version to v1 and use v1 in the reconciler #6608

Closed
wants to merge 13 commits into from
4 changes: 2 additions & 2 deletions config/300-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
versions:
- name: v1beta1
served: true
storage: true
storage: false
subresources:
status: {}
schema:
Expand All @@ -43,7 +43,7 @@ spec:
x-kubernetes-preserve-unknown-fields: true
- name: v1
served: true
storage: false
storage: true
schema:
openAPIV3Schema:
type: object
Expand Down
4 changes: 2 additions & 2 deletions config/300-pipelinerun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
versions:
- name: v1beta1
served: true
storage: true
storage: false
schema:
openAPIV3Schema:
type: object
Expand Down Expand Up @@ -58,7 +58,7 @@ spec:
status: {}
- name: v1
served: true
storage: false
storage: true
schema:
openAPIV3Schema:
type: object
Expand Down
4 changes: 2 additions & 2 deletions config/300-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
versions:
- name: v1beta1
served: true
storage: true
storage: false
schema:
openAPIV3Schema:
type: object
Expand All @@ -45,7 +45,7 @@ spec:
status: {}
- name: v1
served: true
storage: false
storage: true
schema:
openAPIV3Schema:
type: object
Expand Down
4 changes: 2 additions & 2 deletions config/300-taskrun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
versions:
- name: v1beta1
served: true
storage: true
storage: false
schema:
openAPIV3Schema:
type: object
Expand Down Expand Up @@ -58,7 +58,7 @@ spec:
status: {}
- name: v1
served: true
storage: false
storage: true
schema:
openAPIV3Schema:
type: object
Expand Down
6 changes: 3 additions & 3 deletions docs/pipelineruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ Consult the documentation of the custom task that you are using to determine whe

### Mapping `ServiceAccount` credentials to `Tasks`

If you require more granularity in specifying execution credentials, use the `taskRunSpecs[].taskServiceAccountName` field to
If you require more granularity in specifying execution credentials, use the `taskRunSpecs[].serviceAccountName` field to
map a specific `serviceAccountName` value to a specific `Task` in the `Pipeline`. This overrides the global
`serviceAccountName` you may have set for the `Pipeline` as described in the previous section.

Expand All @@ -728,7 +728,7 @@ spec:
serviceAccountName: sa-1
taskRunSpecs:
- pipelineTaskName: build-task
taskServiceAccountName: sa-for-build
serviceAccountName: sa-for-build
```
{{< /tab >}}
{{< /tabs >}}
Expand Down Expand Up @@ -888,7 +888,7 @@ spec:
fsGroup: 3000
taskRunSpecs:
- pipelineTaskName: build-task
taskServiceAccountName: sa-for-build
serviceAccountName: sa-for-build
taskPodTemplate:
nodeSelector:
disktype: ssd
Expand Down
70 changes: 0 additions & 70 deletions examples/v1/taskruns/dind-sidecar.yaml

This file was deleted.

39 changes: 0 additions & 39 deletions examples/v1/taskruns/sidecar-ready.yaml

This file was deleted.

34 changes: 15 additions & 19 deletions pkg/apis/pipeline/v1/param_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Tekton Authors
Copyright 2019 The Tekton Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,6 @@ import (
"context"
"encoding/json"
"fmt"
"regexp"
"strings"

"github.com/tektoncd/pipeline/pkg/substitution"
Expand All @@ -29,12 +28,6 @@ import (
"knative.dev/pkg/apis"
)

// exactVariableSubstitutionFormat matches strings that only contain a single reference to result or param variables, but nothing else
// i.e. `$(result.resultname)` is a match, but `foo $(result.resultname)` is not.
const exactVariableSubstitutionFormat = `^\$\([_a-zA-Z0-9.-]+(\.[_a-zA-Z0-9.-]+)*(\[([0-9]+|\*)\])?\)$`

var exactVariableSubstitutionRegex = regexp.MustCompile(exactVariableSubstitutionFormat)

// ParamsPrefix is the prefix used in $(...) expressions referring to parameters
const ParamsPrefix = "params"

Expand Down Expand Up @@ -116,6 +109,9 @@ type Param struct {
Value ParamValue `json:"value"`
}

// Params is a list of Param
type Params []Param

// ExtractNames returns a set of unique names
func (ps Params) ExtractNames() sets.String {
names := sets.String{}
Expand Down Expand Up @@ -147,9 +143,6 @@ func (ps Params) extractParamMapArrVals() map[string][]string {
return paramsMap
}

// Params is a list of Param
type Params []Param

// extractParamArrayLengths extract and return the lengths of all array params
// Example of returned value: {"a-array-params": 2,"b-array-params": 2 }
func (ps Params) extractParamArrayLengths() map[string]int {
Expand Down Expand Up @@ -373,7 +366,7 @@ var AllParamTypes = []ParamType{ParamTypeString, ParamTypeArray, ParamTypeObject

// ParamValues is modeled after IntOrString in kubernetes/apimachinery:

// ParamValue is a type that can hold a single string, string array, or string map.
// ParamValue is a type that can hold a single string or string array.
// Used in JSON unmarshalling so that a single JSON field can accept
// either an individual string or an array of strings.
type ParamValue struct {
Expand All @@ -384,6 +377,11 @@ type ParamValue struct {
ObjectVal map[string]string
}

// ArrayOrString is deprecated, this is to keep backward compatibility
//
// Deprecated: Use ParamValue instead.
type ArrayOrString = ParamValue

// UnmarshalJSON implements the json.Unmarshaller interface.
func (paramValues *ParamValue) UnmarshalJSON(value []byte) error {
// ParamValues is used for Results Value as well, the results can be any kind of
Expand Down Expand Up @@ -443,7 +441,7 @@ func (paramValues ParamValue) MarshalJSON() ([]byte, error) {
func (paramValues *ParamValue) ApplyReplacements(stringReplacements map[string]string, arrayReplacements map[string][]string, objectReplacements map[string]map[string]string) {
switch paramValues.Type {
case ParamTypeArray:
var newArrayVal []string
newArrayVal := []string{}
for _, v := range paramValues.ArrayVal {
newArrayVal = append(newArrayVal, substitution.ApplyArrayReplacements(v, stringReplacements, arrayReplacements)...)
}
Expand Down Expand Up @@ -475,7 +473,7 @@ func (paramValues *ParamValue) applyOrCorrect(stringReplacements map[string]stri

// trim the head "$(" and the tail ")" or "[*])"
// i.e. get "params.name" from "$(params.name)" or "$(params.name[*])"
trimedStringVal := StripStarVarSubExpression(stringVal)
trimedStringVal := substitution.StripStarVarSubExpression(stringVal)

// if the stringVal is a reference to a string param
if _, ok := stringReplacements[trimedStringVal]; ok {
Expand All @@ -497,11 +495,6 @@ func (paramValues *ParamValue) applyOrCorrect(stringReplacements map[string]stri
}
}

// StripStarVarSubExpression strips "$(target[*])"" to get "target"
func StripStarVarSubExpression(s string) string {
return strings.TrimSuffix(strings.TrimSuffix(strings.TrimPrefix(s, "$("), ")"), "[*]")
}

// NewStructuredValues creates an ParamValues of type ParamTypeString or ParamTypeArray, based on
// how many inputs are given (>1 input will create an array, not string).
func NewStructuredValues(value string, values ...string) *ParamValue {
Expand All @@ -517,6 +510,9 @@ func NewStructuredValues(value string, values ...string) *ParamValue {
}
}

// NewArrayOrString is the deprecated, this is to keep backward compatibility
var NewArrayOrString = NewStructuredValues

// NewObject creates an ParamValues of type ParamTypeObject using the provided key-value pairs
func NewObject(pairs map[string]string) *ParamValue {
return &ParamValue{
Expand Down
31 changes: 31 additions & 0 deletions pkg/apis/pipeline/v1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1

import (
"context"
"fmt"
"time"

"github.com/tektoncd/pipeline/pkg/apis/config"
Expand Down Expand Up @@ -153,6 +154,23 @@ func (pr *PipelineRun) GetNamespacedName() types.NamespacedName {
return types.NamespacedName{Namespace: pr.Namespace, Name: pr.Name}
}

// TODO: to break down this change in one PR syncing v1beta and v1 before #6444 gets merged
// IsTimeoutConditionSet returns true when the pipelinerun has the pipelinerun timed out reason
func (pr *PipelineRun) IsTimeoutConditionSet() bool {
condition := pr.Status.GetCondition(apis.ConditionSucceeded)
return condition.IsFalse() && condition.Reason == PipelineRunReasonTimedOut.String()
}

// SetTimeoutCondition sets the status of the PipelineRun to timed out.
func (pr *PipelineRun) SetTimeoutCondition(ctx context.Context) {
pr.Status.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: PipelineRunReasonTimedOut.String(),
Message: fmt.Sprintf("PipelineRun %q failed to finish within %q", pr.Name, pr.PipelineTimeout(ctx).String()),
})
}

// HasTimedOut returns true if a pipelinerun has exceeded its spec.Timeout based on its status.Timeout
func (pr *PipelineRun) HasTimedOut(ctx context.Context, c clock.PassiveClock) bool {
timeout := pr.PipelineTimeout(ctx)
Expand All @@ -170,6 +188,19 @@ func (pr *PipelineRun) HasTimedOut(ctx context.Context, c clock.PassiveClock) bo
return false
}

// HasTimedOutForALongTime returns true if a pipelinerun has exceeed its spec.Timeout based its status.StartTime
// by a large margin
func (pr *PipelineRun) HasTimedOutForALongTime(ctx context.Context, c clock.PassiveClock) bool {
if !pr.HasTimedOut(ctx, c) {
return false
}
timeout := pr.PipelineTimeout(ctx)
startTime := pr.Status.StartTime
runtime := c.Since(startTime.Time)
// We are arbitrarily defining large margin as doubling the spec.timeout
return runtime >= 2*timeout
}

// HaveTasksTimedOut returns true if a pipelinerun has exceeded its spec.Timeouts.Tasks
func (pr *PipelineRun) HaveTasksTimedOut(ctx context.Context, c clock.PassiveClock) bool {
timeout := pr.TasksTimeout()
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1/result_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (tr *TaskResult) SetDefaults(context.Context) {
return
}
if tr.Type == "" {
if tr.Properties != nil {
if tr.Properties != nil && len(tr.Properties) != 0 {
// Set type to object if `properties` is given
tr.Type = ResultsTypeObject
} else {
Expand Down
6 changes: 0 additions & 6 deletions pkg/apis/pipeline/v1/result_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ package v1
import (
"context"
"fmt"
"regexp"

"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/version"
"knative.dev/pkg/apis"
)

// ResultNameFormat Constant used to define the regex Result.Name should follow
const ResultNameFormat = `^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$`

var resultNameFormatRegex = regexp.MustCompile(ResultNameFormat)

// Validate implements apis.Validatable
func (tr TaskResult) Validate(ctx context.Context) (errs *apis.FieldError) {
if !resultNameFormatRegex.MatchString(tr.Name) {
Expand Down
Loading