@@ -6,6 +6,7 @@ package e2e_test
6
6
7
7
import (
8
8
"os"
9
+ "time"
9
10
10
11
v1 "github.com/google/go-containerregistry/pkg/v1"
11
12
. "github.com/onsi/ginkgo/v2"
@@ -15,6 +16,8 @@ import (
15
16
16
17
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
17
18
shpgit "github.com/shipwright-io/build/pkg/git"
19
+
20
+ corev1 "k8s.io/api/core/v1"
18
21
)
19
22
20
23
var _ = Describe ("For a Kubernetes cluster with Tekton and build installed" , func () {
@@ -706,4 +709,63 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun
706
709
})
707
710
})
708
711
712
+ Context ("when tolerations are specified" , Serial , func () {
713
+
714
+ BeforeEach (func () {
715
+ testID = generateTestID ("tolerations" )
716
+
717
+ // create the build definition
718
+ build = createBuild (
719
+ testBuild ,
720
+ testID ,
721
+ "test/data/v1beta1/build_buildah_tolerations_cr.yaml" ,
722
+ )
723
+
724
+ // Add a taint to both of the kind worker nodes
725
+ nodes , err := testBuild .GetNodes ()
726
+ Expect (err ).ToNot (HaveOccurred ())
727
+ for _ , node := range nodes .Items {
728
+ if node .Name == "kind-worker" || node .Name == "kind-worker2" {
729
+ taint := corev1.Taint {Key : "test-key" , Value : "test-value" , Effect : "NoSchedule" }
730
+ err := testBuild .AddNodeTaint (node .Name , & taint )
731
+ Expect (err ).ToNot (HaveOccurred ())
732
+ }
733
+ }
734
+ })
735
+
736
+ AfterEach (func () {
737
+ nodes , err := testBuild .GetNodes ()
738
+ Expect (err ).ToNot (HaveOccurred ())
739
+ for _ , node := range nodes .Items {
740
+ if node .Name == "kind-worker" || node .Name == "kind-worker2" {
741
+ err := testBuild .RemoveNodeTaints (node .Name )
742
+ Expect (err ).ToNot (HaveOccurred ())
743
+ }
744
+ }
745
+ })
746
+
747
+ It ("successfully runs a build when it tolerates the node taint" , func () {
748
+ buildRun , err = buildRunTestData (testBuild .Namespace , testID , "test/data/v1beta1/buildrun_buildah_tolerations_cr.yaml" )
749
+ Expect (err ).ToNot (HaveOccurred (), "Error retrieving buildrun test data" )
750
+
751
+ buildRun = validateBuildRunToSucceed (testBuild , buildRun )
752
+ })
753
+
754
+ It ("fails to schedule when the build does not tolerate the node taint" , func () {
755
+ // set untolerated value and a low timeout since we do not expect this to be scheduled
756
+ build .Spec .Tolerations [0 ].Value = "untolerated"
757
+ build .Spec .Timeout .Duration = time .Minute
758
+
759
+ buildRun , err = buildRunTestData (testBuild .Namespace , testID , "test/data/v1beta1/buildrun_buildah_tolerations_cr.yaml" )
760
+ Expect (err ).ToNot (HaveOccurred (), "Error retrieving buildrun test data" )
761
+
762
+ validateBuildRunToFail (testBuild , buildRun )
763
+ buildRun , err = testBuild .LookupBuildRun (types.NamespacedName {Name : buildRun .Name , Namespace : testBuild .Namespace })
764
+
765
+ // Pod should fail to schedule and the BuildRun should timeout.
766
+ Expect (buildRun .Status .GetCondition (buildv1beta1 .Succeeded ).Status ).To (Equal (corev1 .ConditionFalse ))
767
+ Expect (buildRun .Status .GetCondition (buildv1beta1 .Succeeded ).Reason ).To (Equal ("BuildRunTimeout" ))
768
+ Expect (buildRun .Status .GetCondition (buildv1beta1 .Succeeded ).Message ).To (ContainSubstring ("failed to finish within" ))
769
+ })
770
+ })
709
771
})
0 commit comments