@@ -6,6 +6,7 @@ package integration_test
6
6
7
7
import (
8
8
"context"
9
+ "encoding/json"
9
10
"fmt"
10
11
"strings"
11
12
"time"
@@ -21,6 +22,7 @@ import (
21
22
corev1 "k8s.io/api/core/v1"
22
23
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
24
"k8s.io/apimachinery/pkg/types"
25
+ "k8s.io/apimachinery/pkg/util/sets"
24
26
"k8s.io/apimachinery/pkg/util/validation"
25
27
"k8s.io/apimachinery/pkg/util/wait"
26
28
"k8s.io/apimachinery/pkg/watch"
@@ -212,10 +214,32 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
212
214
})
213
215
214
216
Context ("when a buildrun is created" , func () {
217
+
218
+ var (
219
+ buildRunObject * v1beta1.BuildRun
220
+ taskRunObject * pipelineapi.TaskRun
221
+ )
222
+
223
+ AfterEach (func () {
224
+ if ! CurrentSpecReport ().Failed () {
225
+ return
226
+ }
227
+ if buildRunObject != nil {
228
+ jsonData , err := json .MarshalIndent (buildRunObject , "" , " " )
229
+ Expect (err ).NotTo (HaveOccurred (), "failed to marshal buildRunObject to JSON" )
230
+ GinkgoWriter .Printf ("buildRunObject JSON:\n %s\n " , string (jsonData ))
231
+ }
232
+ if taskRunObject != nil {
233
+ jsonData , err := json .MarshalIndent (taskRunObject , "" , " " )
234
+ Expect (err ).NotTo (HaveOccurred (), "failed to marshal taskRunObject to JSON" )
235
+ GinkgoWriter .Printf ("taskRunObject JSON:\n %s\n " , string (jsonData ))
236
+ }
237
+ })
238
+
215
239
It ("should reflect a Pending and Running reason" , func () {
216
240
// use a custom strategy here that just sleeps 30 seconds to prevent it from completing too fast so that we do not get the Running state
217
241
WithCustomClusterBuildStrategy ([]byte (test .ClusterBuildStrategySleep30s ), func () {
218
- _ , _ , buildRunObject : = setupBuildAndBuildRun ([]byte (test .BuildCBSMinimal ), []byte (test .MinimalBuildRun ), STRATEGY + tb .Namespace + "custom" )
242
+ _ , _ , buildRunObject = setupBuildAndBuildRun ([]byte (test .BuildCBSMinimal ), []byte (test .MinimalBuildRun ), STRATEGY + tb .Namespace + "custom" )
219
243
220
244
_ , err = tb .GetBRTillStartTime (buildRunObject .Name )
221
245
Expect (err ).To (BeNil ())
@@ -242,6 +266,33 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
242
266
Expect (err ).To (BeNil (), fmt .Sprintf ("failed to get desired reason; expected %s, got %s" , expectedReason , actualReason ))
243
267
})
244
268
})
269
+
270
+ It ("should create a taskrun that is owned by the buildrun" , func () {
271
+ WithCustomClusterBuildStrategy ([]byte (test .ClusterBuildStrategyNoOp ), func () {
272
+ _ , _ , buildRunObject = setupBuildAndBuildRun ([]byte (test .BuildCBSMinimal ), []byte (test .MinimalBuildRun ), STRATEGY + tb .Namespace + "custom" )
273
+
274
+ _ , err = tb .GetBRTillStartTime (buildRunObject .Name )
275
+ Expect (err ).To (BeNil ())
276
+
277
+ taskRunObject , err = tb .GetTaskRunFromBuildRun (buildRunObject .Name )
278
+ Expect (err ).To (BeNil ())
279
+
280
+ // Check that the taskrun is owned by the buildrun
281
+ Expect (taskRunObject .OwnerReferences ).To (HaveLen (1 ), "taskrun should have exactly one owner reference" )
282
+ ownerRef := taskRunObject .OwnerReferences [0 ]
283
+ Expect (ownerRef .Kind ).To (Equal ("BuildRun" ), "taskrun should have a buildrun owner reference" )
284
+ Expect (ownerRef .Name ).To (Equal (buildRunObject .Name ), "taskrun should have a buildrun owner reference" )
285
+
286
+ // Check that the buildrun controller is registered as a field manager
287
+ fieldManagers := sets .NewString ()
288
+ for _ , field := range taskRunObject .GetObjectMeta ().GetManagedFields () {
289
+ fieldManagers .Insert (field .Manager )
290
+ }
291
+ // Sets uses a map[string]struct{} internally, so we need to check for the key.
292
+ // We can't use ContainElement because it would check for the value, not the key.
293
+ Expect (fieldManagers ).To (HaveKey ("shipwright-buildrun-controller" ), "buildrun controller should be registered as a field manager" )
294
+ })
295
+ })
245
296
})
246
297
247
298
Context ("when a buildrun is created but fails because of a timeout" , func () {
0 commit comments