-
Notifications
You must be signed in to change notification settings - Fork 116
/
build.go
1741 lines (1509 loc) · 83.6 KB
/
build.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package build
import (
"encoding/json"
"fmt"
"os"
"strings"
"time"
"github.com/devfile/library/v2/pkg/util"
"github.com/google/go-github/v44/github"
appservice "github.com/konflux-ci/application-api/api/v1alpha1"
"github.com/konflux-ci/build-service/controllers"
tektonutils "github.com/konflux-ci/release-service/tekton/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/openshift/library-go/pkg/image/reference"
pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
v1 "k8s.io/api/core/v1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"github.com/konflux-ci/e2e-tests/pkg/clients/git"
"github.com/konflux-ci/e2e-tests/pkg/clients/has"
"github.com/konflux-ci/e2e-tests/pkg/constants"
"github.com/konflux-ci/e2e-tests/pkg/framework"
"github.com/konflux-ci/e2e-tests/pkg/utils"
"github.com/konflux-ci/e2e-tests/pkg/utils/build"
"github.com/konflux-ci/e2e-tests/pkg/utils/tekton"
)
var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-service"), func() {
var f *framework.Framework
AfterEach(framework.ReportFailure(&f))
var err error
defer GinkgoRecover()
var gitClient git.Client
DescribeTableSubtree("test PaC component build", Ordered, Label("github-webhook", "pac-build", "pipeline", "image-controller"), func(gitProvider git.GitProvider, gitPrefix string) {
var applicationName, customDefaultComponentName, customBranchComponentName, componentBaseBranchName string
var pacBranchName, testNamespace, imageRepoName, pullRobotAccountName, pushRobotAccountName string
var helloWorldComponentGitSourceURL, customDefaultComponentBranch string
var component *appservice.Component
var plr *pipeline.PipelineRun
var timeout, interval time.Duration
var prNumber int
var prHeadSha string
var buildPipelineAnnotation map[string]string
var helloWorldRepository string
BeforeAll(func() {
if os.Getenv(constants.SKIP_PAC_TESTS_ENV) == "true" {
Skip("Skipping this test due to configuration issue with Spray proxy")
}
f, err = framework.NewFramework(utils.GetGeneratedNamespace("build-e2e"))
Expect(err).NotTo(HaveOccurred())
testNamespace = f.UserNamespace
if utils.IsPrivateHostname(f.OpenshiftConsoleHost) {
Skip("Using private cluster (not reachable from Github), skipping...")
}
quayOrg := utils.GetEnv("DEFAULT_QUAY_ORG", "")
supports, err := build.DoesQuayOrgSupportPrivateRepo()
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("error while checking if quay org supports private repo: %+v", err))
if !supports {
if quayOrg == "redhat-appstudio-qe" {
Fail("Failed to create private image repo in redhat-appstudio-qe org")
} else {
Skip("Quay org does not support private quay repository creation, please add support for private repo creation before running this test")
}
}
Expect(err).ShouldNot(HaveOccurred())
applicationName = fmt.Sprintf("build-suite-test-application-%s", util.GenerateRandomString(4))
_, err = f.AsKubeAdmin.HasController.CreateApplication(applicationName, testNamespace)
Expect(err).NotTo(HaveOccurred())
customDefaultComponentName = fmt.Sprintf("%s-%s-%s", gitPrefix, "test-custom-default", util.GenerateRandomString(6))
customBranchComponentName = fmt.Sprintf("%s-%s-%s", gitPrefix, "test-custom-branch", util.GenerateRandomString(6))
pacBranchName = constants.PaCPullRequestBranchPrefix + customBranchComponentName
customDefaultComponentBranch = constants.PaCPullRequestBranchPrefix + customDefaultComponentName
componentBaseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6))
gitClient, helloWorldComponentGitSourceURL, helloWorldRepository = setupGitProvider(f, gitProvider)
// get the build pipeline bundle annotation
buildPipelineAnnotation = build.GetDockerBuildPipelineBundle()
err = gitClient.CreateBranch(helloWorldRepository, helloWorldComponentDefaultBranch, helloWorldComponentRevision, componentBaseBranchName)
Expect(err).ShouldNot(HaveOccurred())
})
AfterAll(func() {
if !CurrentSpecReport().Failed() {
Expect(f.AsKubeAdmin.HasController.DeleteApplication(applicationName, testNamespace, false)).To(Succeed())
Expect(f.SandboxController.DeleteUserSignup(f.UserName)).To(BeTrue())
}
err = gitClient.DeleteBranch(helloWorldRepository, pacBranchName)
if err != nil {
Expect(err.Error()).To(Or(ContainSubstring("Reference does not exist"), ContainSubstring("404")))
}
err = gitClient.DeleteBranch(helloWorldRepository, componentBaseBranchName)
if err != nil {
Expect(err.Error()).To(Or(ContainSubstring("Reference does not exist"), ContainSubstring("404")))
}
err := gitClient.DeleteBranchAndClosePullRequest(helloWorldRepository, prNumber)
if err != nil {
Expect(err.Error()).To(Or(ContainSubstring("Reference does not exist"), ContainSubstring("404")))
}
Expect(gitClient.CleanupWebhooks(helloWorldRepository, f.ClusterAppDomain)).To(Succeed())
})
When("a new component without specified branch is created and with visibility private", Label("pac-custom-default-branch"), func() {
var componentObj appservice.ComponentSpec
BeforeAll(func() {
componentObj = appservice.ComponentSpec{
ComponentName: customDefaultComponentName,
Application: applicationName,
Source: appservice.ComponentSource{
ComponentSourceUnion: appservice.ComponentSourceUnion{
GitSource: &appservice.GitSource{
URL: helloWorldComponentGitSourceURL,
Revision: "",
DockerfileURL: constants.DockerFilePath,
},
},
},
}
_, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, false, utils.MergeMaps(utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.ImageControllerAnnotationRequestPrivateRepo), buildPipelineAnnotation))
Expect(err).ShouldNot(HaveOccurred())
})
It("correctly targets the default branch (that is not named 'main') with PaC", func() {
timeout = time.Second * 300
interval = time.Second * 1
Eventually(func() bool {
prs, err := gitClient.ListPullRequests(helloWorldRepository)
Expect(err).ShouldNot(HaveOccurred())
for _, pr := range prs {
if pr.SourceBranch == customDefaultComponentBranch {
Expect(pr.TargetBranch).To(Equal(helloWorldComponentDefaultBranch))
return true
}
}
return false
}, timeout, interval).Should(BeTrue(), fmt.Sprintf("timed out when waiting for init PaC PR to be created against %s branch in %s repository", helloWorldComponentDefaultBranch, helloWorldComponentGitSourceRepoName))
})
It("workspace parameter is set correctly in PaC repository CR", func() {
nsObj, err := f.AsKubeAdmin.CommonController.GetNamespace(testNamespace)
Expect(err).ShouldNot(HaveOccurred())
wsName := nsObj.Labels["appstudio.redhat.com/workspace_name"]
repositoryParams, err := f.AsKubeAdmin.TektonController.GetRepositoryParams(customDefaultComponentName, testNamespace)
Expect(err).ShouldNot(HaveOccurred(), "error while trying to get repository params")
paramExists := false
for _, param := range repositoryParams {
if param.Name == "appstudio_workspace" {
paramExists = true
Expect(param.Value).To(Equal(wsName), fmt.Sprintf("got workspace param value: %s, expected %s", param.Value, wsName))
}
}
Expect(paramExists).To(BeTrue(), "appstudio_workspace param does not exists in repository CR")
})
It("triggers a PipelineRun", func() {
timeout = time.Minute * 5
Eventually(func() error {
plr, err = f.AsKubeAdmin.HasController.GetComponentPipelineRun(customDefaultComponentName, applicationName, testNamespace, "")
if err != nil {
GinkgoWriter.Printf("PipelineRun has not been created yet for the component %s/%s\n", testNamespace, customBranchComponentName)
return err
}
if !plr.HasStarted() {
return fmt.Errorf("pipelinerun %s/%s hasn't started yet", plr.GetNamespace(), plr.GetName())
}
return nil
}, timeout, constants.PipelineRunPollingInterval).Should(Succeed(), fmt.Sprintf("timed out when waiting for the PipelineRun to start for the component %s/%s", customBranchComponentName, testNamespace))
})
It("component build status is set correctly", func() {
var buildStatus *controllers.BuildStatus
Eventually(func() (bool, error) {
component, err := f.AsKubeAdmin.HasController.GetComponent(customDefaultComponentName, testNamespace)
if err != nil {
return false, err
}
buildStatusAnnotationValue := component.Annotations[controllers.BuildStatusAnnotationName]
GinkgoWriter.Printf(buildStatusAnnotationValueLoggingFormat, buildStatusAnnotationValue)
statusBytes := []byte(buildStatusAnnotationValue)
err = json.Unmarshal(statusBytes, &buildStatus)
if err != nil {
return false, err
}
if buildStatus.PaC != nil {
GinkgoWriter.Printf("state: %s\n", buildStatus.PaC.State)
GinkgoWriter.Printf("mergeUrl: %s\n", buildStatus.PaC.MergeUrl)
GinkgoWriter.Printf("errId: %d\n", buildStatus.PaC.ErrId)
GinkgoWriter.Printf("errMessage: %s\n", buildStatus.PaC.ErrMessage)
GinkgoWriter.Printf("configurationTime: %s\n", buildStatus.PaC.ConfigurationTime)
} else {
GinkgoWriter.Println("build status does not have PaC field")
}
return buildStatus.PaC != nil && buildStatus.PaC.State == "enabled" && buildStatus.PaC.MergeUrl != "" && buildStatus.PaC.ErrId == 0 && buildStatus.PaC.ConfigurationTime != "", nil
}, timeout, interval).Should(BeTrue(), "component build status has unexpected content")
})
It("image repo and robot account created successfully", func() {
imageRepoName, err = f.AsKubeAdmin.ImageController.GetImageName(testNamespace, customDefaultComponentName)
Expect(err).ShouldNot(HaveOccurred(), "failed to read image repo for component %s", customDefaultComponentName)
Expect(imageRepoName).ShouldNot(BeEmpty(), "image repo name is empty")
imageExist, err := build.DoesImageRepoExistInQuay(imageRepoName)
Expect(err).ShouldNot(HaveOccurred(), "failed while checking if image repo exists in quay with error: %+v", err)
Expect(imageExist).To(BeTrue(), "quay image does not exists")
pullRobotAccountName, pushRobotAccountName, err = f.AsKubeAdmin.ImageController.GetRobotAccounts(testNamespace, customDefaultComponentName)
Expect(err).ShouldNot(HaveOccurred(), "failed to get robot account names")
pullRobotAccountExist, err := build.DoesRobotAccountExistInQuay(pullRobotAccountName)
Expect(err).ShouldNot(HaveOccurred(), "failed while checking if pull robot account exists in quay with error: %+v", err)
Expect(pullRobotAccountExist).To(BeTrue(), "pull robot account does not exists in quay")
pushRobotAccountExist, err := build.DoesRobotAccountExistInQuay(pushRobotAccountName)
Expect(err).ShouldNot(HaveOccurred(), "failed while checking if push robot account exists in quay with error: %+v", err)
Expect(pushRobotAccountExist).To(BeTrue(), "push robot account does not exists in quay")
})
It("created image repo is private", func() {
isPublic, err := build.IsImageRepoPublic(imageRepoName)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed while checking if the image repo %s is private", imageRepoName))
Expect(isPublic).To(BeFalse(), "Expected image repo to be private, but it is public")
})
It("a related PipelineRun should be deleted after deleting the component", func() {
timeout = time.Second * 60
interval = time.Second * 1
Expect(f.AsKubeAdmin.HasController.DeleteComponent(customDefaultComponentName, testNamespace, true)).To(Succeed())
// Test removal of PipelineRun
Eventually(func() error {
plr, err = f.AsKubeAdmin.HasController.GetComponentPipelineRun(customDefaultComponentName, applicationName, testNamespace, "")
if err == nil {
return fmt.Errorf("pipelinerun %s/%s is not removed yet", plr.GetNamespace(), plr.GetName())
}
return err
}, timeout, interval).Should(MatchError(ContainSubstring("no pipelinerun found")), fmt.Sprintf("timed out when waiting for the PipelineRun to be removed for Component %s/%s", testNamespace, customBranchComponentName))
})
It("PR branch should not exist in the repo", func() {
timeout = time.Second * 60
interval = time.Second * 1
Eventually(func() bool {
exists, err := gitClient.BranchExists(helloWorldRepository, customDefaultComponentBranch)
Expect(err).ShouldNot(HaveOccurred())
return exists
}, timeout, interval).Should(BeFalse(), fmt.Sprintf("timed out when waiting for the branch %s to be deleted from %s repository", customDefaultComponentBranch, helloWorldComponentGitSourceRepoName))
})
It("related image repo and the robot account should be deleted after deleting the component", func() {
timeout = time.Second * 60
interval = time.Second * 1
// Check image repo should be deleted
Eventually(func() (bool, error) {
return build.DoesImageRepoExistInQuay(imageRepoName)
}, timeout, interval).Should(BeFalse(), fmt.Sprintf("timed out when waiting for image repo %s to be deleted", imageRepoName))
// Check robot account should be deleted
Eventually(func() (bool, error) {
pullRobotAccountExists, err := build.DoesRobotAccountExistInQuay(pullRobotAccountName)
if err != nil {
return false, err
}
pushRobotAccountExists, err := build.DoesRobotAccountExistInQuay(pushRobotAccountName)
if err != nil {
return false, err
}
return pullRobotAccountExists || pushRobotAccountExists, nil
}, timeout, interval).Should(BeFalse(), fmt.Sprintf("timed out when checking if robot accounts %s and %s got deleted", pullRobotAccountName, pushRobotAccountName))
})
})
When("a new Component with specified custom branch is created", Label("build-custom-branch"), func() {
var outputImage string
var componentObj appservice.ComponentSpec
BeforeAll(func() {
componentObj = appservice.ComponentSpec{
ComponentName: customBranchComponentName,
Application: applicationName,
Source: appservice.ComponentSource{
ComponentSourceUnion: appservice.ComponentSourceUnion{
GitSource: &appservice.GitSource{
URL: helloWorldComponentGitSourceURL,
Revision: componentBaseBranchName,
DockerfileURL: constants.DockerFilePath,
},
},
},
}
// Create a component with Git Source URL, a specified git branch and marking delete-repo=true
component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, false, utils.MergeMaps(utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.ImageControllerAnnotationRequestPublicRepo), buildPipelineAnnotation))
Expect(err).ShouldNot(HaveOccurred())
})
It("triggers a PipelineRun", func() {
timeout = time.Second * 600
interval = time.Second * 1
Eventually(func() error {
plr, err = f.AsKubeAdmin.HasController.GetComponentPipelineRun(customBranchComponentName, applicationName, testNamespace, "")
if err != nil {
GinkgoWriter.Printf("PipelineRun has not been created yet for the component %s/%s\n", testNamespace, customBranchComponentName)
return err
}
if !plr.HasStarted() {
return fmt.Errorf("pipelinerun %s/%s hasn't started yet", plr.GetNamespace(), plr.GetName())
}
return nil
}, timeout, constants.PipelineRunPollingInterval).Should(Succeed(), fmt.Sprintf("timed out when waiting for the PipelineRun to start for the component %s/%s", testNamespace, customBranchComponentName))
})
It("should lead to a PaC init PR creation", func() {
timeout = time.Second * 300
interval = time.Second * 1
Eventually(func() bool {
prs, err := gitClient.ListPullRequests(helloWorldRepository)
Expect(err).ShouldNot(HaveOccurred())
for _, pr := range prs {
if pr.SourceBranch == pacBranchName {
prNumber = pr.Number
prHeadSha = pr.HeadSHA
return true
}
}
return false
}, timeout, interval).Should(BeTrue(), fmt.Sprintf("timed out when waiting for init PaC PR (branch name '%s') to be created in %s repository", pacBranchName, helloWorldComponentGitSourceRepoName))
})
It("the PipelineRun should eventually finish successfully", func() {
Expect(f.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(component, "",
f.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true}, plr)).To(Succeed())
// in case the first pipelineRun attempt has failed and was retried, we need to update the git branch head ref
prHeadSha = plr.Labels["pipelinesascode.tekton.dev/sha"]
})
It("image repo and robot account created successfully", func() {
imageRepoName, err = f.AsKubeAdmin.ImageController.GetImageName(testNamespace, customBranchComponentName)
Expect(err).ShouldNot(HaveOccurred(), "failed to read image repo for component %s", customBranchComponentName)
Expect(imageRepoName).ShouldNot(BeEmpty(), "image repo name is empty")
imageExist, err := build.DoesImageRepoExistInQuay(imageRepoName)
Expect(err).ShouldNot(HaveOccurred(), "failed while checking if image repo exists in quay with error: %+v", err)
Expect(imageExist).To(BeTrue(), "quay image does not exists")
pullRobotAccountName, pushRobotAccountName, err = f.AsKubeAdmin.ImageController.GetRobotAccounts(testNamespace, customBranchComponentName)
Expect(err).ShouldNot(HaveOccurred(), "failed to get robot account names")
pullRobotAccountExist, err := build.DoesRobotAccountExistInQuay(pullRobotAccountName)
Expect(err).ShouldNot(HaveOccurred(), "failed while checking if pull robot account exists in quay with error: %+v", err)
Expect(pullRobotAccountExist).To(BeTrue(), "pull robot account does not exists in quay")
pushRobotAccountExist, err := build.DoesRobotAccountExistInQuay(pushRobotAccountName)
Expect(err).ShouldNot(HaveOccurred(), "failed while checking if push robot account exists in quay with error: %+v", err)
Expect(pushRobotAccountExist).To(BeTrue(), "push robot account does not exists in quay")
})
It("floating tags are created successfully", func() {
builtImage := build.GetBinaryImage(plr)
Expect(builtImage).ToNot(BeEmpty(), "built image url is empty")
builtImageRef, err := reference.Parse(builtImage)
Expect(err).ShouldNot(HaveOccurred(),
fmt.Sprintf("cannot parse image pullspec: %s", builtImage))
for _, tagName := range additionalTags {
_, err := build.GetImageTag(builtImageRef.Namespace, builtImageRef.Name, tagName)
Expect(err).ShouldNot(HaveOccurred(),
fmt.Sprintf("failed to get tag %s from image repo", tagName),
)
}
})
It("created image repo is public", func() {
isPublic, err := build.IsImageRepoPublic(imageRepoName)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed while checking if the image repo %s is public", imageRepoName))
Expect(isPublic).To(BeTrue(), fmt.Sprintf("Expected image repo '%s' to be changed to public, but it is private", imageRepoName))
})
It("image tag is updated successfully", func() {
// check if the image tag exists in quay
plr, err = f.AsKubeAdmin.HasController.GetComponentPipelineRun(customBranchComponentName, applicationName, testNamespace, "")
Expect(err).ShouldNot(HaveOccurred())
for _, p := range plr.Spec.Params {
if p.Name == "output-image" {
outputImage = p.Value.StringVal
}
}
Expect(outputImage).ToNot(BeEmpty(), "output image %s of the component could not be found", outputImage)
isExists, err := build.DoesTagExistsInQuay(outputImage)
Expect(err).ShouldNot(HaveOccurred(), "error while checking if the output image %s exists in quay", outputImage)
Expect(isExists).To(BeTrue(), "image tag does not exists in quay")
})
It("should ensure pruning labels are set", func() {
plr, err = f.AsKubeAdmin.HasController.GetComponentPipelineRun(customBranchComponentName, applicationName, testNamespace, "")
Expect(err).ShouldNot(HaveOccurred())
image, err := build.ImageFromPipelineRun(plr)
Expect(err).ShouldNot(HaveOccurred())
labels := image.Config.Config.Labels
Expect(labels).ToNot(BeEmpty())
expiration, ok := labels["quay.expires-after"]
Expect(ok).To(BeTrue())
Expect(expiration).To(Equal(utils.GetEnv(constants.IMAGE_TAG_EXPIRATION_ENV, constants.DefaultImageTagExpiration)))
})
It("eventually leads to the PipelineRun status report at Checks tab", func() {
switch gitProvider {
case git.GitHubProvider:
expectedCheckRunName := fmt.Sprintf("%s-%s", customBranchComponentName, "on-pull-request")
Expect(f.AsKubeAdmin.CommonController.Github.GetCheckRunConclusion(expectedCheckRunName, helloWorldComponentGitSourceRepoName, prHeadSha, prNumber)).To(Equal(constants.CheckrunConclusionSuccess))
case git.GitLabProvider:
expectedNote := fmt.Sprintf("**Pipelines as Code CI/%s-on-pull-request** has successfully validated your commit", customBranchComponentName)
f.AsKubeAdmin.HasController.GitLab.ValidateNoteInMergeRequestComment(helloWorldComponentGitLabProjectID, expectedNote, prNumber)
}
})
})
When("the PaC init branch is updated", Label("build-custom-branch"), func() {
var createdFileSHA string
BeforeAll(func() {
fileToCreatePath := fmt.Sprintf(".tekton/%s-readme.md", customBranchComponentName)
createdFile, err := gitClient.CreateFile(helloWorldRepository, fileToCreatePath, fmt.Sprintf("test PaC branch %s update", pacBranchName), pacBranchName)
Expect(err).ShouldNot(HaveOccurred())
createdFileSHA = createdFile.CommitSHA
GinkgoWriter.Println("created file sha:", createdFileSHA)
})
It("eventually leads to triggering another PipelineRun", func() {
timeout = time.Minute * 5
Eventually(func() error {
plr, err = f.AsKubeAdmin.HasController.GetComponentPipelineRun(customBranchComponentName, applicationName, testNamespace, createdFileSHA)
if err != nil {
GinkgoWriter.Printf("PipelineRun has not been created yet for the component %s/%s\n", testNamespace, customBranchComponentName)
return err
}
if !plr.HasStarted() {
return fmt.Errorf("pipelinerun %s/%s hasn't started yet", plr.GetNamespace(), plr.GetName())
}
return nil
}, timeout, constants.PipelineRunPollingInterval).Should(Succeed(), fmt.Sprintf("timed out when waiting for the PipelineRun to start for the component %s/%s", testNamespace, customBranchComponentName))
})
It("should lead to a PaC init PR update", func() {
timeout = time.Second * 300
interval = time.Second * 1
Eventually(func() bool {
prs, err := gitClient.ListPullRequests(helloWorldRepository)
Expect(err).ShouldNot(HaveOccurred())
for _, pr := range prs {
if pr.SourceBranch == pacBranchName {
Expect(prHeadSha).NotTo(Equal(pr.HeadSHA))
prNumber = pr.Number
prHeadSha = pr.HeadSHA
return true
}
}
return false
}, timeout, interval).Should(BeTrue(), fmt.Sprintf("timed out when waiting for init PaC PR (branch name '%s') to be created in %s repository", pacBranchName, helloWorldComponentGitSourceRepoName))
})
It("PipelineRun should eventually finish", func() {
Expect(f.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(component, createdFileSHA,
f.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true}, plr)).To(Succeed())
// in case the first pipelineRun attempt has failed and was retried, we need to update the git branch head ref
createdFileSHA = plr.Labels["pipelinesascode.tekton.dev/sha"]
})
It("eventually leads to another update of a PR about the PipelineRun status report at Checks tab", func() {
switch gitProvider {
case git.GitHubProvider:
expectedCheckRunName := fmt.Sprintf("%s-%s", customBranchComponentName, "on-pull-request")
Expect(f.AsKubeAdmin.CommonController.Github.GetCheckRunConclusion(expectedCheckRunName, helloWorldComponentGitSourceRepoName, createdFileSHA, prNumber)).To(Equal(constants.CheckrunConclusionSuccess))
case git.GitLabProvider:
expectedNote := fmt.Sprintf("**Pipelines as Code CI/%s-on-pull-request** has successfully validated your commit", customBranchComponentName)
f.AsKubeAdmin.HasController.GitLab.ValidateNoteInMergeRequestComment(helloWorldComponentGitLabProjectID, expectedNote, prNumber)
}
})
})
When("the PaC init branch is merged", Label("build-custom-branch"), func() {
var mergeResult *git.PullRequest
var mergeResultSha string
BeforeAll(func() {
Eventually(func() error {
mergeResult, err = gitClient.MergePullRequest(helloWorldRepository, prNumber)
return err
}, time.Minute).Should(BeNil(), fmt.Sprintf("error when merging PaC pull request #%d in repo %s", prNumber, helloWorldComponentGitSourceRepoName))
mergeResultSha = mergeResult.MergeCommitSHA
GinkgoWriter.Println("merged result sha:", mergeResultSha)
})
It("eventually leads to triggering another PipelineRun", func() {
timeout = time.Minute * 10
Eventually(func() error {
plr, err = f.AsKubeAdmin.HasController.GetComponentPipelineRun(customBranchComponentName, applicationName, testNamespace, mergeResultSha)
if err != nil {
GinkgoWriter.Printf("PipelineRun has not been created yet for the component %s/%s\n", testNamespace, customBranchComponentName)
return err
}
if !plr.HasStarted() {
return fmt.Errorf("pipelinerun %s/%s hasn't started yet", plr.GetNamespace(), plr.GetName())
}
return nil
}, timeout, constants.PipelineRunPollingInterval).Should(Succeed(), fmt.Sprintf("timed out when waiting for the PipelineRun to start for the component %s/%s", testNamespace, customBranchComponentName))
})
It("pipelineRun should eventually finish", func() {
Expect(f.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(component,
mergeResultSha, f.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true}, plr)).To(Succeed())
mergeResultSha = plr.Labels["pipelinesascode.tekton.dev/sha"]
})
It("does not have expiration set", func() {
image, err := build.ImageFromPipelineRun(plr)
Expect(err).ShouldNot(HaveOccurred())
labels := image.Config.Config.Labels
Expect(labels).ToNot(BeEmpty())
expiration, ok := labels["quay.expires-after"]
Expect(ok).To(BeFalse())
Expect(expiration).To(BeEmpty())
})
It("After updating image visibility to private, it should not trigger another PipelineRun", func() {
Expect(f.AsKubeAdmin.TektonController.DeleteAllPipelineRunsInASpecificNamespace(testNamespace)).To(Succeed())
Eventually(func() error {
_, err := f.AsKubeAdmin.ImageController.ChangeVisibilityToPrivate(testNamespace, applicationName, customBranchComponentName)
if err != nil {
GinkgoWriter.Printf("failed to change visibility to private with error %v\n", err)
return err
}
return nil
}, time.Second*20, time.Second*1).Should(Succeed(), fmt.Sprintf("timed out when trying to change visibility of the image repos to private in %s/%s", testNamespace, customBranchComponentName))
GinkgoWriter.Printf("waiting for one minute and expecting to not trigger a PipelineRun")
Consistently(func() bool {
componentPipelineRun, _ := f.AsKubeAdmin.HasController.GetComponentPipelineRun(customBranchComponentName, applicationName, testNamespace, "")
return componentPipelineRun == nil
}, time.Minute, constants.PipelineRunPollingInterval).Should(BeTrue(), fmt.Sprintf("expected no PipelineRun to be triggered for the component %s in %s namespace", customBranchComponentName, testNamespace))
})
It("image repo is updated to private", func() {
isPublic, err := build.IsImageRepoPublic(imageRepoName)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed while checking if the image repo %s is private", imageRepoName))
Expect(isPublic).To(BeFalse(), "Expected image repo to changed to private, but it is public")
})
})
When("the component is removed and recreated (with the same name in the same namespace)", Label("build-custom-branch"), func() {
var componentObj appservice.ComponentSpec
BeforeAll(func() {
Expect(f.AsKubeAdmin.HasController.DeleteComponent(customBranchComponentName, testNamespace, true)).To(Succeed())
timeout = 1 * time.Minute
interval = 1 * time.Second
Eventually(func() bool {
_, err := f.AsKubeAdmin.HasController.GetComponent(customBranchComponentName, testNamespace)
return k8sErrors.IsNotFound(err)
}, timeout, interval).Should(BeTrue(), fmt.Sprintf("timed out when waiting for the app %s/%s to be deleted", testNamespace, applicationName))
// Check removal of image repo
Eventually(func() (bool, error) {
return build.DoesImageRepoExistInQuay(imageRepoName)
}, timeout, interval).Should(BeFalse(), fmt.Sprintf("timed out when waiting for image repo %s to be deleted", imageRepoName))
// Check removal of robot accounts
Eventually(func() (bool, error) {
pullRobotAccountExists, err := build.DoesRobotAccountExistInQuay(pullRobotAccountName)
if err != nil {
return false, err
}
pushRobotAccountExists, err := build.DoesRobotAccountExistInQuay(pushRobotAccountName)
if err != nil {
return false, err
}
return pullRobotAccountExists || pushRobotAccountExists, nil
}, timeout, interval).Should(BeFalse(), fmt.Sprintf("timed out when checking if robot accounts %s and %s got deleted", pullRobotAccountName, pushRobotAccountName))
})
BeforeAll(func() {
componentObj = appservice.ComponentSpec{
ComponentName: customBranchComponentName,
Source: appservice.ComponentSource{
ComponentSourceUnion: appservice.ComponentSourceUnion{
GitSource: &appservice.GitSource{
URL: helloWorldComponentGitSourceURL,
Revision: componentBaseBranchName,
DockerfileURL: constants.DockerFilePath,
},
},
},
}
_, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, false, utils.MergeMaps(utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.ImageControllerAnnotationRequestPublicRepo), buildPipelineAnnotation))
Expect(err).ShouldNot(HaveOccurred())
})
It("should no longer lead to a creation of a PaC PR", func() {
timeout = time.Second * 10
interval = time.Second * 2
Consistently(func() error {
prs, err := gitClient.ListPullRequests(helloWorldRepository)
Expect(err).ShouldNot(HaveOccurred())
for _, pr := range prs {
if pr.SourceBranch == pacBranchName {
return fmt.Errorf("did not expect a new PR created in %s repository after initial PaC configuration was already merged for the same component name and a namespace", helloWorldRepository)
}
}
return nil
}, timeout, interval).Should(BeNil())
})
})
},
Entry("github", git.GitHubProvider, "gh"),
Entry("gitlab", git.GitLabProvider, "gl"),
)
Describe("test pac with multiple components using same repository", Ordered, Label("pac-build", "multi-component"), func() {
var applicationName, testNamespace, multiComponentBaseBranchName, multiComponentPRBranchName, mergeResultSha string
var pacBranchNames []string
var prNumber int
var mergeResult *github.PullRequestMergeResult
var timeout time.Duration
var buildPipelineAnnotation map[string]string
BeforeAll(func() {
if os.Getenv(constants.SKIP_PAC_TESTS_ENV) == "true" {
Skip("Skipping this test due to configuration issue with Spray proxy")
}
f, err = framework.NewFramework(utils.GetGeneratedNamespace("build-e2e"))
Expect(err).NotTo(HaveOccurred())
testNamespace = f.UserNamespace
if utils.IsPrivateHostname(f.OpenshiftConsoleHost) {
Skip("Using private cluster (not reachable from Github), skipping...")
}
applicationName = fmt.Sprintf("build-suite-positive-mc-%s", util.GenerateRandomString(4))
_, err = f.AsKubeAdmin.HasController.CreateApplication(applicationName, testNamespace)
Expect(err).NotTo(HaveOccurred())
multiComponentBaseBranchName = fmt.Sprintf("multi-component-base-%s", util.GenerateRandomString(6))
err = f.AsKubeAdmin.CommonController.Github.CreateRef(multiComponentGitSourceRepoName, multiComponentDefaultBranch, multiComponentGitRevision, multiComponentBaseBranchName)
Expect(err).ShouldNot(HaveOccurred())
//Branch for creating pull request
multiComponentPRBranchName = fmt.Sprintf("%s-%s", "pr-branch", util.GenerateRandomString(6))
// get the build pipeline bundle annotation
buildPipelineAnnotation = build.GetDockerBuildPipelineBundle()
})
AfterAll(func() {
if !CurrentSpecReport().Failed() {
Expect(f.AsKubeAdmin.HasController.DeleteApplication(applicationName, testNamespace, false)).To(Succeed())
Expect(f.SandboxController.DeleteUserSignup(f.UserName)).To(BeTrue())
}
// Delete new branches created by PaC and a testing branch used as a component's base branch
for _, pacBranchName := range pacBranchNames {
err = f.AsKubeAdmin.CommonController.Github.DeleteRef(multiComponentGitSourceRepoName, pacBranchName)
if err != nil {
Expect(err.Error()).To(ContainSubstring("Reference does not exist"))
}
}
// Delete the created base branch
err = f.AsKubeAdmin.CommonController.Github.DeleteRef(multiComponentGitSourceRepoName, multiComponentBaseBranchName)
if err != nil {
Expect(err.Error()).To(ContainSubstring("Reference does not exist"))
}
// Delete the created pr branch
err = f.AsKubeAdmin.CommonController.Github.DeleteRef(multiComponentGitSourceRepoName, multiComponentPRBranchName)
if err != nil {
Expect(err.Error()).To(ContainSubstring("Reference does not exist"))
}
})
When("components are created in same namespace", func() {
var component *appservice.Component
for _, contextDir := range multiComponentContextDirs {
contextDir := contextDir
componentName := fmt.Sprintf("%s-%s", contextDir, util.GenerateRandomString(6))
pacBranchName := constants.PaCPullRequestBranchPrefix + componentName
pacBranchNames = append(pacBranchNames, pacBranchName)
It(fmt.Sprintf("creates component with context directory %s", contextDir), func() {
componentObj := appservice.ComponentSpec{
ComponentName: componentName,
Application: applicationName,
Source: appservice.ComponentSource{
ComponentSourceUnion: appservice.ComponentSourceUnion{
GitSource: &appservice.GitSource{
URL: multiComponentGitHubURL,
Revision: multiComponentBaseBranchName,
Context: contextDir,
DockerfileURL: constants.DockerFilePath,
},
},
},
}
component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, false, utils.MergeMaps(utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.ImageControllerAnnotationRequestPublicRepo), buildPipelineAnnotation))
Expect(err).ShouldNot(HaveOccurred())
})
It(fmt.Sprintf("triggers a PipelineRun for component %s", componentName), func() {
timeout = time.Minute * 5
Eventually(func() error {
pr, err := f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, "")
if err != nil {
GinkgoWriter.Printf("PipelineRun has not been created yet for the component %s/%s\n", testNamespace, componentName)
return err
}
if !pr.HasStarted() {
return fmt.Errorf("pipelinerun %s/%s hasn't started yet", pr.GetNamespace(), pr.GetName())
}
return nil
}, timeout, constants.PipelineRunPollingInterval).Should(Succeed(), fmt.Sprintf("timed out when waiting for the PipelineRun to start for the component %s/%s", componentName, testNamespace))
})
It(fmt.Sprintf("should lead to a PaC PR creation for component %s", componentName), func() {
timeout = time.Second * 300
interval := time.Second * 1
Eventually(func() bool {
prs, err := f.AsKubeAdmin.CommonController.Github.ListPullRequests(multiComponentGitSourceRepoName)
Expect(err).ShouldNot(HaveOccurred())
for _, pr := range prs {
if pr.Head.GetRef() == pacBranchName {
prNumber = pr.GetNumber()
return true
}
}
return false
}, timeout, interval).Should(BeTrue(), fmt.Sprintf("timed out when waiting for PaC PR (branch name '%s') to be created in %s repository", pacBranchName, multiComponentGitSourceRepoName))
})
It(fmt.Sprintf("the PipelineRun should eventually finish successfully for component %s", componentName), func() {
Expect(f.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(component, "",
f.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true}, nil)).To(Succeed())
})
It("merging the PR should be successful", func() {
Eventually(func() error {
mergeResult, err = f.AsKubeAdmin.CommonController.Github.MergePullRequest(multiComponentGitSourceRepoName, prNumber)
return err
}, time.Minute).Should(BeNil(), fmt.Sprintf("error when merging PaC pull request #%d in repo %s", prNumber, multiComponentGitSourceRepoName))
mergeResultSha = mergeResult.GetSHA()
GinkgoWriter.Printf("merged result sha: %s for PR #%d\n", mergeResultSha, prNumber)
})
It("leads to triggering on push PipelineRun", func() {
timeout = time.Minute * 5
Eventually(func() error {
pipelineRun, err := f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, mergeResultSha)
if err != nil {
GinkgoWriter.Printf("Push PipelineRun has not been created yet for the component %s/%s\n", testNamespace, componentName)
return err
}
if !pipelineRun.HasStarted() {
return fmt.Errorf("push pipelinerun %s/%s hasn't started yet", pipelineRun.GetNamespace(), pipelineRun.GetName())
}
return nil
}, timeout, constants.PipelineRunPollingInterval).Should(Succeed(), fmt.Sprintf("timed out when waiting for the PipelineRun to start for the component %s/%s", testNamespace, componentName))
})
}
It("only one component is changed", func() {
//Delete all the pipelineruns in the namespace before sending PR
Expect(f.AsKubeAdmin.TektonController.DeleteAllPipelineRunsInASpecificNamespace(testNamespace)).To(Succeed())
//Create the ref, add the file and create the PR
err = f.AsKubeAdmin.CommonController.Github.CreateRef(multiComponentGitSourceRepoName, multiComponentDefaultBranch, mergeResultSha, multiComponentPRBranchName)
Expect(err).ShouldNot(HaveOccurred())
fileToCreatePath := fmt.Sprintf("%s/sample-file.txt", multiComponentContextDirs[0])
createdFileSha, err := f.AsKubeAdmin.CommonController.Github.CreateFile(multiComponentGitSourceRepoName, fileToCreatePath, fmt.Sprintf("sample test file inside %s", multiComponentContextDirs[0]), multiComponentPRBranchName)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("error while creating file: %s", fileToCreatePath))
pr, err := f.AsKubeAdmin.CommonController.Github.CreatePullRequest(multiComponentGitSourceRepoName, "sample pr title", "sample pr body", multiComponentPRBranchName, multiComponentBaseBranchName)
Expect(err).ShouldNot(HaveOccurred())
GinkgoWriter.Printf("PR #%d got created with sha %s\n", pr.GetNumber(), createdFileSha.GetSHA())
})
It("only related pipelinerun should be triggered", func() {
Eventually(func() error {
pipelineRuns, err := f.AsKubeAdmin.HasController.GetAllPipelineRunsForApplication(applicationName, testNamespace)
if err != nil {
GinkgoWriter.Println("on pull PiplelineRun has not been created yet for the PR")
return err
}
if len(pipelineRuns.Items) != 1 || !strings.HasPrefix(pipelineRuns.Items[0].Name, multiComponentContextDirs[0]) {
return fmt.Errorf("pipelinerun created in the namespace %s is not as expected, got pipelineruns %v", testNamespace, pipelineRuns.Items)
}
return nil
}, time.Minute*5, constants.PipelineRunPollingInterval).Should(Succeed(), "timeout while waiting for PR pipeline to start")
})
})
// Skipping this scenario due to the issue: https://issues.redhat.com/browse/KFLUXBUGS-1820 , reenable this test once issue is fixed
When("a components is created with same git url in different namespace", Pending, func() {
var namespace, appName, compName string
var fw *framework.Framework
BeforeAll(func() {
fw, err = framework.NewFramework(utils.GetGeneratedNamespace("build-e2e"))
Expect(err).NotTo(HaveOccurred())
namespace = fw.UserNamespace
appName = fmt.Sprintf("build-suite-negative-mc-%s", util.GenerateRandomString(4))
_, err = f.AsKubeAdmin.HasController.CreateApplication(appName, namespace)
Expect(err).NotTo(HaveOccurred())
compName = fmt.Sprintf("%s-%s", multiComponentContextDirs[0], util.GenerateRandomString(6))
componentObj := appservice.ComponentSpec{
ComponentName: compName,
Application: appName,
Source: appservice.ComponentSource{
ComponentSourceUnion: appservice.ComponentSourceUnion{
GitSource: &appservice.GitSource{
URL: multiComponentGitHubURL,
Revision: multiComponentBaseBranchName,
Context: multiComponentContextDirs[0],
DockerfileURL: constants.DockerFilePath,
},
},
},
}
_, err = fw.AsKubeAdmin.HasController.CreateComponent(componentObj, namespace, "", "", appName, false, utils.MergeMaps(utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.ImageControllerAnnotationRequestPublicRepo), buildPipelineAnnotation))
Expect(err).ShouldNot(HaveOccurred())
})
AfterAll(func() {
if !CurrentSpecReport().Failed() {
Expect(fw.AsKubeAdmin.HasController.DeleteApplication(appName, namespace, false)).To(Succeed())
Expect(fw.SandboxController.DeleteUserSignup(fw.UserName)).To(BeTrue())
}
})
It("should fail to configure PaC for the component", func() {
var buildStatus *controllers.BuildStatus
Eventually(func() (bool, error) {
component, err := fw.AsKubeAdmin.HasController.GetComponent(compName, namespace)
if err != nil {
GinkgoWriter.Printf("error while getting the component: %v\n", err)
return false, err
}
buildStatusAnnotationValue := component.Annotations[controllers.BuildStatusAnnotationName]
GinkgoWriter.Printf(buildStatusAnnotationValueLoggingFormat, buildStatusAnnotationValue)
statusBytes := []byte(buildStatusAnnotationValue)
err = json.Unmarshal(statusBytes, &buildStatus)
if err != nil {
GinkgoWriter.Printf("cannot unmarshal build status from component annotation: %v\n", err)
return false, err
}
GinkgoWriter.Printf("build status: %+v\n", buildStatus.PaC)
return buildStatus.PaC != nil && buildStatus.PaC.State == "error" && strings.Contains(buildStatus.PaC.ErrMessage, "Git repository is already handled by Pipelines as Code"), nil
}, time.Minute*2, time.Second*2).Should(BeTrue(), "build status is unexpected")
})
})
})
Describe("test build secret lookup", Label("pac-build", "secret-lookup"), Ordered, func() {
var testNamespace, applicationName, firstComponentBaseBranchName, secondComponentBaseBranchName, firstComponentName, secondComponentName, firstPacBranchName, secondPacBranchName string
var buildPipelineAnnotation map[string]string
BeforeAll(func() {
if os.Getenv(constants.SKIP_PAC_TESTS_ENV) == "true" {
Skip("Skipping this test due to configuration issue with Spray proxy")
}
f, err = framework.NewFramework(utils.GetGeneratedNamespace("build-e2e"))
Expect(err).NotTo(HaveOccurred())
testNamespace = f.UserNamespace
applicationName = fmt.Sprintf("build-secret-lookup-%s", util.GenerateRandomString(4))
_, err = f.AsKubeAdmin.HasController.CreateApplication(applicationName, testNamespace)
Expect(err).NotTo(HaveOccurred())
firstComponentBaseBranchName = fmt.Sprintf("component-one-base-%s", util.GenerateRandomString(6))
err = f.AsKubeAdmin.CommonController.Github.CreateRefInOrg(noAppOrgName, secretLookupGitSourceRepoOneName, secretLookupDefaultBranchOne, secretLookupGitRevisionOne, firstComponentBaseBranchName)
Expect(err).ShouldNot(HaveOccurred())
secondComponentBaseBranchName = fmt.Sprintf("component-two-base-%s", util.GenerateRandomString(6))
err = f.AsKubeAdmin.CommonController.Github.CreateRefInOrg(noAppOrgName, secretLookupGitSourceRepoTwoName, secretLookupDefaultBranchTwo, secretLookupGitRevisionTwo, secondComponentBaseBranchName)
Expect(err).ShouldNot(HaveOccurred())
// use custom bundle if env defined
// get the build pipeline bundle annotation
buildPipelineAnnotation = build.GetDockerBuildPipelineBundle()
})
AfterAll(func() {
if !CurrentSpecReport().Failed() {
Expect(f.AsKubeAdmin.HasController.DeleteApplication(applicationName, testNamespace, false)).To(Succeed())
Expect(f.SandboxController.DeleteUserSignup(f.UserName)).To(BeTrue())
}
// Delete new branches created by PaC
err = f.AsKubeAdmin.CommonController.Github.DeleteRefFromOrg(noAppOrgName, secretLookupGitSourceRepoOneName, firstPacBranchName)
if err != nil {
Expect(err.Error()).To(ContainSubstring("Reference does not exist"))
}
err = f.AsKubeAdmin.CommonController.Github.DeleteRefFromOrg(noAppOrgName, secretLookupGitSourceRepoTwoName, secondPacBranchName)
if err != nil {
Expect(err.Error()).To(ContainSubstring("Reference does not exist"))
}
// Delete the created first component base branch
err = f.AsKubeAdmin.CommonController.Github.DeleteRefFromOrg(noAppOrgName, secretLookupGitSourceRepoOneName, firstComponentBaseBranchName)
if err != nil {
Expect(err.Error()).To(ContainSubstring("Reference does not exist"))
}
// Delete the created second component base branch
err = f.AsKubeAdmin.CommonController.Github.DeleteRefFromOrg(noAppOrgName, secretLookupGitSourceRepoTwoName, secondComponentBaseBranchName)
if err != nil {
Expect(err.Error()).To(ContainSubstring("Reference does not exist"))
}
// Delete created webhook from GitHub
Expect(build.CleanupWebhooks(f, secretLookupGitSourceRepoTwoName)).ShouldNot(HaveOccurred())
})
When("two secrets are created", func() {
BeforeAll(func() {
// create the correct build secret for second component
secretName1 := "build-secret-1"
secretAnnotations := map[string]string{
"appstudio.redhat.com/scm.repository": noAppOrgName + "/" + secretLookupGitSourceRepoTwoName,
}
token := os.Getenv("GITHUB_TOKEN")
err = createBuildSecret(f, secretName1, secretAnnotations, token)
Expect(err).ShouldNot(HaveOccurred())
// create incorrect build-secret for the first component
secretName2 := "build-secret-2"
dummyToken := "ghp_dummy_secret"
err = createBuildSecret(f, secretName2, nil, dummyToken)
Expect(err).ShouldNot(HaveOccurred())
// component names and pac branch names
firstComponentName = fmt.Sprintf("%s-%s", "component-one", util.GenerateRandomString(4))
secondComponentName = fmt.Sprintf("%s-%s", "component-two", util.GenerateRandomString(4))
firstPacBranchName = constants.PaCPullRequestBranchPrefix + firstComponentName
secondPacBranchName = constants.PaCPullRequestBranchPrefix + secondComponentName
})
It("creates first component", func() {
componentObj1 := appservice.ComponentSpec{
ComponentName: firstComponentName,
Application: applicationName,
Source: appservice.ComponentSource{
ComponentSourceUnion: appservice.ComponentSourceUnion{
GitSource: &appservice.GitSource{
URL: secretLookupComponentOneGitSourceURL,
Revision: firstComponentBaseBranchName,
DockerfileURL: constants.DockerFilePath,
},
},
},
}
_, err := f.AsKubeAdmin.HasController.CreateComponent(componentObj1, testNamespace, "", "", applicationName, false, utils.MergeMaps(utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.ImageControllerAnnotationRequestPublicRepo), buildPipelineAnnotation))
Expect(err).ShouldNot(HaveOccurred())
})
It("creates second component", func() {
componentObj2 := appservice.ComponentSpec{
ComponentName: secondComponentName,
Application: applicationName,
Source: appservice.ComponentSource{
ComponentSourceUnion: appservice.ComponentSourceUnion{
GitSource: &appservice.GitSource{