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

feat: adapt for tekton 0.55 #83

Merged
merged 4 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
453 changes: 453 additions & 0 deletions .build/build.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .build/opensource-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.55.0
6 changes: 6 additions & 0 deletions .ko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
defaultBaseImage: build-harbor.alauda.cn/ops/distroless-static-nonroot:20220806
baseImageOverrides:
# git-init uses a base image that includes Git, and supports running either
# as root or as user nonroot with UID 65532.
# image latest-glibc-hack is from katanomi tekton-operator hack Dockerfile
github.com/tektoncd/pipeline/cmd/git-init: build-harbor.alauda.cn/3rdparty/cgr.dev/chainguard/git:latest-glibc-hack-20231016
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/ahmetb/gen-crd-api-reference-docs v0.3.1-0.20220720053627-e327d0730470 // Waiting for https://github.com/ahmetb/gen-crd-api-reference-docs/pull/43/files to merge
github.com/cloudevents/sdk-go/v2 v2.14.0
github.com/containerd/containerd v1.7.8
github.com/go-git/go-git/v5 v5.10.0
github.com/go-git/go-git/v5 v5.11.0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修复安全问题。

github.com/google/go-cmp v0.6.0
github.com/google/go-containerregistry v0.16.1
github.com/google/uuid v1.4.0
Expand Down Expand Up @@ -65,7 +65,6 @@ require (

require (
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0
Expand Down Expand Up @@ -93,7 +92,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/kms v1.27.2 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.2 // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davidmz/go-pageant v1.0.2 // indirect
Expand Down Expand Up @@ -127,7 +126,7 @@ require (
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 // indirect
github.com/zeebo/errs v1.3.0 // indirect
Expand Down Expand Up @@ -223,7 +222,7 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/automaxprocs v1.4.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0
Expand Down
19 changes: 8 additions & 11 deletions go.sum

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

53 changes: 47 additions & 6 deletions pkg/apis/pipeline/pod/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,8 @@ func MergePodTemplateWithDefault(tpl, defaultTpl *PodTemplate) *PodTemplate {
return defaultTpl
default:
// Otherwise, merge fields
if tpl.Env == nil {
tpl.Env = defaultTpl.Env
}
tpl.Env = mergeByName(defaultTpl.Env, tpl.Env)
tpl.Volumes = mergeByName(defaultTpl.Volumes, tpl.Volumes)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

等更新到社区的 v0.56.0 后,这部分就不需要了。
变动已经在该 PR 中合并了:tektoncd#7552

if tpl.NodeSelector == nil {
tpl.NodeSelector = defaultTpl.NodeSelector
}
Expand All @@ -187,9 +186,6 @@ func MergePodTemplateWithDefault(tpl, defaultTpl *PodTemplate) *PodTemplate {
if tpl.SecurityContext == nil {
tpl.SecurityContext = defaultTpl.SecurityContext
}
if tpl.Volumes == nil {
tpl.Volumes = defaultTpl.Volumes
}
if tpl.RuntimeClassName == nil {
tpl.RuntimeClassName = defaultTpl.RuntimeClassName
}
Expand Down Expand Up @@ -254,3 +250,48 @@ func MergeAAPodTemplateWithDefault(tpl, defaultTpl *AAPodTemplate) *AAPodTemplat
return tpl
}
}

// mergeByName merges two slices of items with names based on the getName
// function, giving priority to the items in the override slice.
func mergeByName[T any](base, overrides []T) []T {
if len(overrides) == 0 {
return base
}

// create a map to store the names of the volumeVars in the override slice
seen := make(map[string]struct{})
result := make([]T, 0, len(base)+len(overrides))

for _, item := range overrides {
name := getName(item)
if name != "" {
result = append(result, item)
seen[name] = struct{}{}
}
}

// append the volumeVars in the original slice if they have a different name
for _, item := range base {
name := getName(item)
if name != "" {
if _, found := seen[name]; !found {
result = append(result, item)
}
}
}

return result
}

// getName returns the name of the given item, or an empty string if the item
// is not a supported type.
func getName(item interface{}) string {
switch item := item.(type) {
case corev1.EnvVar:
return item.Name
case corev1.Volume:
return item.Name
default:
return ""
}
}
1 change: 0 additions & 1 deletion pkg/apis/pipeline/v1/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ type Step struct {
Ref *Ref `json:"ref,omitempty"`
// Params declares parameters passed to this step action.
// +optional
// +listType=atomic
Params Params `json:"params,omitempty"`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改了后,controller-gen 生成 crds 时才不报错。
社区没有这个问题是他们的 crds 都是精简版的,可能并没有用 controller-gen 来生成。

// Results declares StepResults produced by the Step.
//
Expand Down
4 changes: 1 addition & 3 deletions pkg/apis/pipeline/v1/matrix_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ type Matrix struct {
// Params takes only `Parameters` of type `"array"`
// Each array element is supplied to the `PipelineTask` by substituting `params` of type `"string"` in the underlying `Task`.
// The names of the `params` in the `Matrix` must match the names of the `params` in the underlying `Task` that they will be substituting.
// +listType=atomic
Params Params `json:"params,omitempty"`

// Include is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix.
// +optional
// +listType=atomic
Include IncludeParamsList `json:"include,omitempty"`
}

// IncludeParamsList is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix.
// +listType=atomic
type IncludeParamsList []IncludeParams

// IncludeParams allows passing in a specific combinations of Parameters into the Matrix.
Expand All @@ -50,7 +49,6 @@ type IncludeParams struct {

// Params takes only `Parameters` of type `"string"`
// The names of the `params` must match the names of the `params` in the underlying `Task`
// +listType=atomic
Params Params `json:"params,omitempty"`
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/apis/pipeline/v1/param_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type ParamSpec struct {
}

// ParamSpecs is a list of ParamSpec
// +listType=atomic
type ParamSpecs []ParamSpec

// PropertySpec defines the struct for object keys
Expand Down Expand Up @@ -268,6 +269,7 @@ func (p Param) ParseTaskandResultName() (string, string) {
}

// Params is a list of Param
// +listType=atomic
type Params []Param

// ExtractParamArrayLengths extract and return the lengths of all array params
Expand Down Expand Up @@ -482,11 +484,11 @@ var AllParamTypes = []ParamType{ParamTypeString, ParamTypeArray, ParamTypeObject
// Used in JSON unmarshalling so that a single JSON field can accept
// either an individual string or an array of strings.
type ParamValue struct {
Type ParamType // Represents the stored type of ParamValues.
StringVal string
Type ParamType `json:"type"` // Represents the stored type of ParamValues.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

社区在这个 PR 中移除了 json 的 tag,他们给出了解释。但我们生成 crds 还是需要该 tag,所以加回来了。
tektoncd#6445

StringVal string `json:"stringVal"`
// +listType=atomic
ArrayVal []string
ObjectVal map[string]string
ArrayVal []string `json:"arrayVal"`
ObjectVal map[string]string `json:"objectVal"`
}

// UnmarshalJSON implements the json.Unmarshaller interface.
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/pipeline/v1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ type PipelineSpec struct {
Tasks []PipelineTask `json:"tasks,omitempty"`
// Params declares a list of input parameters that must be supplied when
// this Pipeline is run.
// +listType=atomic
Params ParamSpecs `json:"params,omitempty"`
// Workspaces declares a set of named workspaces that are expected to be
// provided by a PipelineRun.
Expand Down Expand Up @@ -218,7 +217,6 @@ type PipelineTask struct {

// Parameters declares parameters passed to this task.
// +optional
// +listType=atomic
Params Params `json:"params,omitempty"`

// Matrix declares parameters used to fan out this task.
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/pipeline/v1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ type PipelineRunSpec struct {
// +optional
PipelineSpec *PipelineSpec `json:"pipelineSpec,omitempty"`
// Params is a list of parameter names and values.
// +listType=atomic
Params Params `json:"params,omitempty"`

// Used for cancelling a pipelinerun (and maybe more later on)
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/pipeline/v1/resolver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ type ResolverRef struct {
// "repo" or "path" but the set of params ultimately depends on
// the chosen resolver.
// +optional
// +listType=atomic
Params Params `json:"params,omitempty"`
}
1 change: 0 additions & 1 deletion pkg/apis/pipeline/v1/task_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ type TaskSpec struct {
// must be supplied as inputs in TaskRuns unless they declare a default
// value.
// +optional
// +listType=atomic
Params ParamSpecs `json:"params,omitempty"`

// DisplayName is a user-facing name of the task that may be
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/pipeline/v1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type TaskRunSpec struct {
// +optional
Debug *TaskRunDebug `json:"debug,omitempty"`
// +optional
// +listType=atomic
Params Params `json:"params,omitempty"`
// +optional
ServiceAccountName string `json:"serviceAccountName"`
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/pipeline/v1alpha1/stepaction_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ type StepActionSpec struct {
// Params is a list of input parameters required to run the stepAction.
// Params must be supplied as inputs in Steps unless they declare a defaultvalue.
// +optional
// +listType=atomic
Params v1.ParamSpecs `json:"params,omitempty"`
// Results are values that this StepAction can output
// +optional
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/pipeline/v1beta1/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ type Step struct {
Ref *Ref `json:"ref,omitempty"`
// Params declares parameters passed to this step action.
// +optional
// +listType=atomic
Params Params `json:"params,omitempty"`
// Results declares StepResults produced by the Step.
//
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/pipeline/v1beta1/customrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type CustomRunSpec struct {
CustomSpec *EmbeddedCustomRunSpec `json:"customSpec,omitempty"`

// +optional
// +listType=atomic
Params Params `json:"params,omitempty"`

// Used for cancelling a customrun (and maybe more later on)
Expand Down
4 changes: 1 addition & 3 deletions pkg/apis/pipeline/v1beta1/matrix_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ type Matrix struct {
// Params takes only `Parameters` of type `"array"`
// Each array element is supplied to the `PipelineTask` by substituting `params` of type `"string"` in the underlying `Task`.
// The names of the `params` in the `Matrix` must match the names of the `params` in the underlying `Task` that they will be substituting.
// +listType=atomic
Params Params `json:"params,omitempty"`

// Include is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix.
// +optional
// +listType=atomic
Include IncludeParamsList `json:"include,omitempty"`
}

// IncludeParamsList is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix.
// +listType=atomic
type IncludeParamsList []IncludeParams

// IncludeParams allows passing in a specific combinations of Parameters into the Matrix.
Expand All @@ -50,7 +49,6 @@ type IncludeParams struct {

// Params takes only `Parameters` of type `"string"`
// The names of the `params` must match the names of the `params` in the underlying `Task`
// +listType=atomic
Params Params `json:"params,omitempty"`
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/apis/pipeline/v1beta1/param_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type ParamSpec struct {
}

// ParamSpecs is a list of ParamSpec
// +listType=atomic
type ParamSpecs []ParamSpec

// PropertySpec defines the struct for object keys
Expand Down Expand Up @@ -191,6 +192,7 @@ type Param struct {
}

// Params is a list of Param
// +listType=atomic
type Params []Param

// ExtractNames returns a set of unique names
Expand Down Expand Up @@ -436,11 +438,11 @@ var AllParamTypes = []ParamType{ParamTypeString, ParamTypeArray, ParamTypeObject
// Used in JSON unmarshalling so that a single JSON field can accept
// either an individual string or an array of strings.
type ParamValue struct {
Type ParamType // Represents the stored type of ParamValues.
StringVal string
Type ParamType `json:"type"` // Represents the stored type of ParamValues.
StringVal string `json:"stringVal"`
// +listType=atomic
ArrayVal []string
ObjectVal map[string]string
ArrayVal []string `json:"arrayVal"`
ObjectVal map[string]string `json:"objectVal"`
}

// ArrayOrString is deprecated, this is to keep backward compatibility
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/pipeline/v1beta1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ type PipelineSpec struct {
Tasks []PipelineTask `json:"tasks,omitempty"`
// Params declares a list of input parameters that must be supplied when
// this Pipeline is run.
// +listType=atomic
Params ParamSpecs `json:"params,omitempty"`
// Workspaces declares a set of named workspaces that are expected to be
// provided by a PipelineRun.
Expand Down Expand Up @@ -232,7 +231,6 @@ type PipelineTask struct {

// Parameters declares parameters passed to this task.
// +optional
// +listType=atomic
Params Params `json:"params,omitempty"`

// Matrix declares parameters used to fan out this task.
Expand Down
Loading