github.com/redhat-appstudio/release-service@v0.0.0-20240507045911-a8558ef3422a/tekton/utils/pipeline.go (about) 1 /* 2 Copyright 2023. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package utils 18 19 import tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" 20 21 // Param defines the parameters for a given resolver in PipelineRef 22 type Param struct { 23 // Name is the name of the parameter 24 Name string `json:"name"` 25 26 // Value is the value of the parameter 27 Value string `json:"value"` 28 } 29 30 // PipelineRef represents a reference to a Pipeline using a resolver. 31 // +kubebuilder:object:generate=true 32 type PipelineRef struct { 33 // Resolver is the name of a Tekton resolver to be used (e.g. git) 34 Resolver string `json:"resolver"` 35 36 // Params is a slice of parameters for a given resolver 37 Params []Param `json:"params"` 38 } 39 40 // Pipeline contains a reference to a Pipeline and the name of the service account to use while executing it. 41 // +kubebuilder:object:generate=true 42 type Pipeline struct { 43 // PipelineRef is the reference to the Pipeline 44 PipelineRef PipelineRef `json:"pipelineRef"` 45 46 // ServiceAccount is the ServiceAccount to use during the execution of the Pipeline 47 // +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ 48 // +optional 49 ServiceAccount string `json:"serviceAccountName,omitempty"` 50 51 // Timeouts defines the different Timeouts to use in the PipelineRun execution 52 // +optional 53 Timeouts tektonv1.TimeoutFields `json:"timeouts,omitempty"` 54 } 55 56 // ParameterizedPipeline is an extension of the Pipeline struct, adding an array of parameters that will be passed to 57 // the Pipeline. 58 // +kubebuilder:object:generate=true 59 type ParameterizedPipeline struct { 60 Pipeline 61 Params []Param `json:"params,omitempty"` 62 } 63 64 // ToTektonPipelineRef converts a PipelineRef object to Tekton's own PipelineRef type and returns it. 65 func (pr *PipelineRef) ToTektonPipelineRef() *tektonv1.PipelineRef { 66 params := tektonv1.Params{} 67 68 for _, p := range pr.Params { 69 params = append(params, tektonv1.Param{ 70 Name: p.Name, 71 Value: tektonv1.ParamValue{ 72 Type: tektonv1.ParamTypeString, 73 StringVal: p.Value, 74 }, 75 }) 76 } 77 78 tektonPipelineRef := &tektonv1.PipelineRef{ 79 ResolverRef: tektonv1.ResolverRef{ 80 Resolver: tektonv1.ResolverName(pr.Resolver), 81 Params: params, 82 }, 83 } 84 85 return tektonPipelineRef 86 } 87 88 // IsClusterScoped returns whether the PipelineRef uses a cluster resolver or not. 89 func (pr *PipelineRef) IsClusterScoped() bool { 90 return pr.Resolver == "cluster" 91 }