@@ -5,9 +5,87 @@ import (
5
5
6
6
. "github.com/onsi/ginkgo/v2"
7
7
. "github.com/onsi/gomega"
8
+
9
+ upgradev1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
10
+ sucjob "github.com/rancher/system-upgrade-controller/pkg/upgrade/job"
11
+ corev1 "k8s.io/api/core/v1"
12
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8
13
)
9
14
10
15
func TestJob (t * testing.T ) {
11
16
RegisterFailHandler (Fail )
12
17
RunSpecs (t , "Job Suite" )
13
18
}
19
+
20
+ var _ = Describe ("Jobs" , func () {
21
+ var plan * upgradev1.Plan
22
+ var node * corev1.Node
23
+
24
+ BeforeEach (func () {
25
+ plan = & upgradev1.Plan {
26
+ ObjectMeta : metav1.ObjectMeta {
27
+ Name : "test-1" ,
28
+ Namespace : "default" ,
29
+ },
30
+ Spec : upgradev1.PlanSpec {
31
+ Concurrency : 1 ,
32
+ ServiceAccountName : "system-upgrade-controller-foo" ,
33
+ Upgrade : & upgradev1.ContainerSpec {
34
+ Image : "test-image:latest" ,
35
+ },
36
+ },
37
+ }
38
+
39
+ node = & corev1.Node {
40
+ ObjectMeta : metav1.ObjectMeta {
41
+ Name : "prod.test.local" ,
42
+ },
43
+ }
44
+ })
45
+
46
+ Describe ("Setting the batchv1.Job ActiveDeadlineSeconds field" , func () {
47
+ Context ("When the Plan has a positive non-zero value for deadline" , func () {
48
+ It ("Constructs the batchv1.Job with the Plan's given value" , func () {
49
+ plan .Spec .JobActiveDeadlineSecs = 12345
50
+ job := sucjob .New (plan , node , "foo" )
51
+ Expect (* job .Spec .ActiveDeadlineSeconds ).To (Equal (int64 (12345 )))
52
+ })
53
+ })
54
+
55
+ Context ("When the Plan has a zero-value given as its deadline" , func () {
56
+ It ("Constructs the batchv1.Job with a global default" , func () {
57
+ oldActiveDeadlineSeconds := sucjob .ActiveDeadlineSeconds
58
+ sucjob .ActiveDeadlineSeconds = 300
59
+ defer func () { sucjob .ActiveDeadlineSeconds = oldActiveDeadlineSeconds }()
60
+
61
+ plan .Spec .JobActiveDeadlineSecs = 0
62
+ job := sucjob .New (plan , node , "bar" )
63
+ Expect (* job .Spec .ActiveDeadlineSeconds ).To (Equal (int64 (300 )))
64
+ })
65
+ })
66
+
67
+ Context ("When the Plan has a negative value given as its deadline" , func () {
68
+ It ("Constructs the batchv1.Job with a global default" , func () {
69
+ oldActiveDeadlineSeconds := sucjob .ActiveDeadlineSeconds
70
+ sucjob .ActiveDeadlineSeconds = 3600
71
+ defer func () { sucjob .ActiveDeadlineSeconds = oldActiveDeadlineSeconds }()
72
+
73
+ plan .Spec .JobActiveDeadlineSecs = - 1
74
+ job := sucjob .New (plan , node , "baz" )
75
+ Expect (* job .Spec .ActiveDeadlineSeconds ).To (Equal (int64 (3600 )))
76
+ })
77
+ })
78
+
79
+ Context ("When cluster has a maximum deadline and the Plan deadline exceeds that value" , func () {
80
+ It ("Constructs the batchv1.Job with the cluster's maximum deadline value" , func () {
81
+ oldActiveDeadlineSecondsMax := sucjob .ActiveDeadlineSecondsMax
82
+ sucjob .ActiveDeadlineSecondsMax = 300
83
+ defer func () { sucjob .ActiveDeadlineSecondsMax = oldActiveDeadlineSecondsMax }()
84
+
85
+ plan .Spec .JobActiveDeadlineSecs = 600
86
+ job := sucjob .New (plan , node , "foobar" )
87
+ Expect (* job .Spec .ActiveDeadlineSeconds ).To (Equal (int64 (300 )))
88
+ })
89
+ })
90
+ })
91
+ })
0 commit comments