@@ -103,7 +103,7 @@ func (r *IntegrationPipelineRun) AsPipelineRun() *tektonv1.PipelineRun {
103
103
104
104
// NewIntegrationPipelineRun creates an empty PipelineRun in the given namespace. The name will be autogenerated,
105
105
// using the prefix passed as an argument to the function.
106
- func NewIntegrationPipelineRun (prefix , namespace string , integrationTestScenario v1beta2.IntegrationTestScenario ) * IntegrationPipelineRun {
106
+ func NewIntegrationPipelineRun (client client. Client , ctx context. Context , prefix , namespace string , integrationTestScenario v1beta2.IntegrationTestScenario ) ( * IntegrationPipelineRun , err ) {
107
107
resolverParams := []tektonv1.Param {}
108
108
109
109
for _ , scenarioParam := range integrationTestScenario .Spec .ResolverRef .Params {
@@ -117,6 +117,19 @@ func NewIntegrationPipelineRun(prefix, namespace string, integrationTestScenario
117
117
resolverParams = append (resolverParams , resolverParam )
118
118
}
119
119
120
+ resolver := tektonv1 .ResolverName (integrationTestScenario .Spec .ResolverRef .Resolver )
121
+ if integrationTestScenario .Spec .ResolverType == "pipeline" {
122
+ return generateIntegrationPipelineRunFromPipelineResolver (prefix , namespace , resolver , resolverParams ), nil
123
+ } else if integrationTestScenario .Spec .ResolverType == "pipelinerun" {
124
+ base64plr , err := getPipelineRunYamlFromPipelineRunResolver (clilent , ctx , prefix , namespace , resolver , resolverParams )
125
+ if err != nil {
126
+ return nil , err
127
+ }
128
+ return generateIntegrationPipelineRunFromBase64 (base64plr )
129
+ }
130
+ }
131
+
132
+ func generateIntegrationPipelineRunFromPipelineResolver (prefix , namespace , resolver string , resolverParams []tektonv1.Param ) * IntegrationPipelineRun {
120
133
pipelineRun := tektonv1.PipelineRun {
121
134
ObjectMeta : metav1.ObjectMeta {
122
135
GenerateName : prefix + "-" ,
@@ -125,15 +138,87 @@ func NewIntegrationPipelineRun(prefix, namespace string, integrationTestScenario
125
138
Spec : tektonv1.PipelineRunSpec {
126
139
PipelineRef : & tektonv1.PipelineRef {
127
140
ResolverRef : tektonv1.ResolverRef {
128
- Resolver : tektonv1 . ResolverName ( integrationTestScenario . Spec . ResolverRef . Resolver ) ,
141
+ Resolver : resolver ,
129
142
Params : resolverParams ,
130
143
},
131
144
},
132
145
},
133
146
}
147
+
134
148
return & IntegrationPipelineRun {pipelineRun }
135
149
}
136
150
151
+ func getPipelineRunYamlFromPipelineRunResolver (client client.Client , ctx context.Context , prefix , namespace , resolver string , resolverParams []tektonv1.Param ) (* IntegrationPipelineRun , error ) {
152
+ request = tektonv1.ResolutionRequest {
153
+ ObjectMeta : metav1.ObjectMeta {
154
+ GenerateName : prefix + "-" ,
155
+ Namespace : namespace ,
156
+ },
157
+ Labels : map [string ]string {
158
+ "resolution.tekton.dev/type" : resolver ,
159
+ },
160
+ Annotations : map [string ]string {
161
+ "konflux-ci.dev/created-by" : "integration-service" , // for backup garbage collection
162
+ },
163
+ Spec : tektonv1.ResolverRequestSpec {
164
+ Params : resolverParams ,
165
+ },
166
+ }
167
+
168
+ err := retry .OnError (retry .DefaultBackoff , client .Create (ctx , request ))
169
+ if err != nil {
170
+ return "" , err
171
+ }
172
+ resolutionRequestName := request .ObjectMeta .Name
173
+ defer func () {
174
+ _ = retry .OnError (retry .DefaultBackoff , client .Delete (ctx , request ))
175
+ }()
176
+
177
+ resolverBackoff := wait.Backoff {
178
+ Steps : 60 ,
179
+ Duration : 1 * time .Second ,
180
+ Factor : 1.0 ,
181
+ Jitter : 0.5 ,
182
+ }
183
+ var resolvedRequest tektonv1.ResolutionRequest
184
+ err = retry .OnError (resolverBackoff , func () {
185
+ namespace := "foo"
186
+ name := "bar"
187
+ err = client .Get (ctx , types.NamespacedName {Namespace : resolutionRequestName , Name : name }, & resolvedRequest )
188
+ if err != nil {
189
+ return err
190
+ }
191
+ for _ , cond := range resolvedRequest .Status .Conditions {
192
+ if strings .EqualFold (cond .Type , "succeeded" ) {
193
+ if cond .Status == metav1 .ConditionTrue {
194
+ // request resolved successfully, we can terminate retry block
195
+ return nil
196
+ }
197
+ }
198
+ }
199
+ return fmt .Errorf ("Resolution for '%s' in namespace '%s' did not complete" , namespace , name )
200
+ })
201
+
202
+ if err != nil {
203
+ return "" , err
204
+ }
205
+ return resolvedRequest .Status .Data , nil
206
+ }
207
+
208
+ func generateIntegrationPipelineRunFromBase64 (base64plr string ) (* IntegrationPipelineRun , error ) {
209
+ plrYaml , err := base64 .StdEncoding .DecodeString (base64plr )
210
+ if err != nil {
211
+ return err
212
+ }
213
+ // TODO: Make sure this is sufficient to verify that kind is pipelineRun
214
+ var pipelineRun tektonv1.PipelineRun
215
+ err = yaml .Unmarshal (plrYaml , & pipelineRun )
216
+ if err != nil {
217
+ return err
218
+ }
219
+ return & IntegrationPipelineRun {pipelineRun }, nil
220
+ }
221
+
137
222
// Updates git resolver values parameters with values of params specified in the input map
138
223
// updates only exsitings parameters, doens't create new ones
139
224
func (iplr * IntegrationPipelineRun ) WithUpdatedTestsGitResolver (params map [string ]string ) * IntegrationPipelineRun {
0 commit comments