@@ -6,27 +6,27 @@ import (
6
6
"io"
7
7
"time"
8
8
9
+ . "github.com/onsi/ginkgo/v2" //nolint:revive
10
+ . "github.com/onsi/gomega" //nolint:revive
9
11
batchv1 "k8s.io/api/batch/v1"
10
12
v1 "k8s.io/api/core/v1"
11
- "k8s.io/utils/pointer "
13
+ "k8s.io/utils/ptr "
12
14
13
- "github.com/onsi/ginkgo/v2"
14
- "github.com/onsi/gomega"
15
15
"github.com/rancher/system-upgrade-controller/e2e/framework"
16
16
upgradeapiv1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
17
17
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18
18
)
19
19
20
- var _ = ginkgo . Describe ("Job Generation" , func () {
20
+ var _ = Describe ("Job Generation" , func () {
21
21
e2e := framework .New ("generate" )
22
22
23
- ginkgo . When ("fails because of a bad plan" , func () {
23
+ When ("fails because of a bad plan" , func () {
24
24
var (
25
25
err error
26
26
plan * upgradeapiv1.Plan
27
27
jobs []batchv1.Job
28
28
)
29
- ginkgo . BeforeEach (func () {
29
+ BeforeEach (func () {
30
30
plan = e2e .NewPlan ("fail-then-succeed-" , "library/alpine:3.18" , []string {"sh" , "-c" }, "exit 1" )
31
31
plan .Spec .Version = "latest"
32
32
plan .Spec .Concurrency = 1
@@ -38,54 +38,54 @@ var _ = ginkgo.Describe("Job Generation", func() {
38
38
}},
39
39
}
40
40
plan , err = e2e .CreatePlan (plan )
41
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
41
+ Expect (err ).ToNot (HaveOccurred ())
42
42
43
43
plan , err = e2e .WaitForPlanCondition (plan .Name , upgradeapiv1 .PlanLatestResolved , 30 * time .Second )
44
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
45
- gomega . Expect (upgradeapiv1 .PlanLatestResolved .IsTrue (plan )).To (gomega . BeTrue ())
44
+ Expect (err ).ToNot (HaveOccurred ())
45
+ Expect (upgradeapiv1 .PlanLatestResolved .IsTrue (plan )).To (BeTrue ())
46
46
47
47
jobs , err = e2e .WaitForPlanJobs (plan , 1 , 120 * time .Second )
48
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
49
- gomega . Expect (jobs ).To (gomega . HaveLen (1 ))
50
- gomega . Expect (jobs [0 ].Status .Succeeded ).To (gomega . BeNumerically ("==" , 0 ))
51
- gomega . Expect (jobs [0 ].Status .Active ).To (gomega . BeNumerically ("==" , 0 ))
52
- gomega . Expect (jobs [0 ].Status .Failed ).To (gomega . BeNumerically (">=" , 1 ))
48
+ Expect (err ).ToNot (HaveOccurred ())
49
+ Expect (jobs ).To (HaveLen (1 ))
50
+ Expect (jobs [0 ].Status .Succeeded ).To (BeNumerically ("==" , 0 ))
51
+ Expect (jobs [0 ].Status .Active ).To (BeNumerically ("==" , 0 ))
52
+ Expect (jobs [0 ].Status .Failed ).To (BeNumerically (">=" , 1 ))
53
53
54
- gomega . Eventually (e2e .GetPlan ).
54
+ Eventually (e2e .GetPlan ).
55
55
WithArguments (plan .Name , metav1.GetOptions {}).
56
56
WithTimeout (30 * time .Second ).
57
- Should (gomega . WithTransform (upgradeapiv1 .PlanComplete .IsTrue , gomega . BeFalse ()))
57
+ Should (WithTransform (upgradeapiv1 .PlanComplete .IsTrue , BeFalse ()))
58
58
59
59
plan , err = e2e .GetPlan (plan .Name , metav1.GetOptions {})
60
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
60
+ Expect (err ).ToNot (HaveOccurred ())
61
61
plan .Spec .Upgrade .Args = []string {"exit 0" }
62
62
plan , err = e2e .UpdatePlan (plan )
63
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
63
+ Expect (err ).ToNot (HaveOccurred ())
64
64
65
65
jobs , err = e2e .WaitForPlanJobs (plan , 1 , 120 * time .Second )
66
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
67
- gomega . Expect (jobs ).To (gomega . HaveLen (1 ))
66
+ Expect (err ).ToNot (HaveOccurred ())
67
+ Expect (jobs ).To (HaveLen (1 ))
68
68
})
69
- ginkgo . It ("should apply successfully after edit" , func () {
70
- gomega . Expect (jobs ).To (gomega . HaveLen (1 ))
71
- gomega . Expect (jobs [0 ].Status .Succeeded ).To (gomega . BeNumerically ("==" , 1 ))
72
- gomega . Expect (jobs [0 ].Status .Active ).To (gomega . BeNumerically ("==" , 0 ))
73
- gomega . Expect (jobs [0 ].Status .Failed ).To (gomega . BeNumerically ("==" , 0 ))
69
+ It ("should apply successfully after edit" , func () {
70
+ Expect (jobs ).To (HaveLen (1 ))
71
+ Expect (jobs [0 ].Status .Succeeded ).To (BeNumerically ("==" , 1 ))
72
+ Expect (jobs [0 ].Status .Active ).To (BeNumerically ("==" , 0 ))
73
+ Expect (jobs [0 ].Status .Failed ).To (BeNumerically ("==" , 0 ))
74
74
75
- gomega . Eventually (e2e .GetPlan ).
75
+ Eventually (e2e .GetPlan ).
76
76
WithArguments (plan .Name , metav1.GetOptions {}).
77
77
WithTimeout (30 * time .Second ).
78
- Should (gomega . WithTransform (upgradeapiv1 .PlanComplete .IsTrue , gomega . BeTrue ()))
78
+ Should (WithTransform (upgradeapiv1 .PlanComplete .IsTrue , BeTrue ()))
79
79
})
80
80
})
81
81
82
- ginkgo . When ("fails because of conflicting drain options" , func () {
82
+ When ("fails because of conflicting drain options" , func () {
83
83
var (
84
84
err error
85
85
plan * upgradeapiv1.Plan
86
86
jobs []batchv1.Job
87
87
)
88
- ginkgo . BeforeEach (func () {
88
+ BeforeEach (func () {
89
89
plan = e2e .NewPlan ("fail-drain-options-" , "library/alpine:3.18" , []string {"sh" , "-c" }, "exit 0" )
90
90
plan .Spec .Version = "latest"
91
91
plan .Spec .Concurrency = 1
@@ -98,8 +98,8 @@ var _ = ginkgo.Describe("Job Generation", func() {
98
98
}
99
99
plan .Spec .Drain = & upgradeapiv1.DrainSpec {
100
100
DisableEviction : true ,
101
- DeleteLocalData : pointer . Bool (true ),
102
- DeleteEmptydirData : pointer . Bool (true ),
101
+ DeleteLocalData : ptr . To (true ),
102
+ DeleteEmptydirData : ptr . To (true ),
103
103
PodSelector : & metav1.LabelSelector {
104
104
MatchExpressions : []metav1.LabelSelectorRequirement {{
105
105
Key : "component" ,
@@ -109,36 +109,36 @@ var _ = ginkgo.Describe("Job Generation", func() {
109
109
},
110
110
}
111
111
plan , err = e2e .CreatePlan (plan )
112
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
112
+ Expect (err ).ToNot (HaveOccurred ())
113
113
114
114
plan , err = e2e .WaitForPlanCondition (plan .Name , upgradeapiv1 .PlanSpecValidated , 30 * time .Second )
115
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
116
- gomega . Expect (upgradeapiv1 .PlanSpecValidated .IsTrue (plan )).To (gomega . BeFalse ())
117
- gomega . Expect (upgradeapiv1 .PlanSpecValidated .GetMessage (plan )).To (gomega . ContainSubstring ("cannot specify both deleteEmptydirData and deleteLocalData" ))
115
+ Expect (err ).ToNot (HaveOccurred ())
116
+ Expect (upgradeapiv1 .PlanSpecValidated .IsTrue (plan )).To (BeFalse ())
117
+ Expect (upgradeapiv1 .PlanSpecValidated .GetMessage (plan )).To (ContainSubstring ("cannot specify both deleteEmptydirData and deleteLocalData" ))
118
118
119
119
plan .Spec .Drain .DeleteLocalData = nil
120
120
plan , err = e2e .UpdatePlan (plan )
121
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
121
+ Expect (err ).ToNot (HaveOccurred ())
122
122
123
123
plan , err = e2e .WaitForPlanCondition (plan .Name , upgradeapiv1 .PlanSpecValidated , 30 * time .Second )
124
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
125
- gomega . Expect (upgradeapiv1 .PlanSpecValidated .IsTrue (plan )).To (gomega . BeTrue ())
124
+ Expect (err ).ToNot (HaveOccurred ())
125
+ Expect (upgradeapiv1 .PlanSpecValidated .IsTrue (plan )).To (BeTrue ())
126
126
127
127
jobs , err = e2e .WaitForPlanJobs (plan , 1 , 120 * time .Second )
128
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
129
- gomega . Expect (jobs ).To (gomega . HaveLen (1 ))
128
+ Expect (err ).ToNot (HaveOccurred ())
129
+ Expect (jobs ).To (HaveLen (1 ))
130
130
})
131
- ginkgo . It ("should apply successfully after edit" , func () {
132
- gomega . Expect (jobs ).To (gomega . HaveLen (1 ))
133
- gomega . Expect (jobs [0 ].Status .Succeeded ).To (gomega . BeNumerically ("==" , 1 ))
134
- gomega . Expect (jobs [0 ].Status .Active ).To (gomega . BeNumerically ("==" , 0 ))
135
- gomega . Expect (jobs [0 ].Status .Failed ).To (gomega . BeNumerically ("==" , 0 ))
136
- gomega . Expect (jobs [0 ].Spec .Template .Spec .InitContainers ).To (gomega . HaveLen (1 ))
137
- gomega . Expect (jobs [0 ].Spec .Template .Spec .InitContainers [0 ].Args ).To (gomega . ContainElement (gomega . ContainSubstring ("!upgrade.cattle.io/controller" )))
138
- gomega . Expect (jobs [0 ].Spec .Template .Spec .InitContainers [0 ].Args ).To (gomega . ContainElement (gomega . ContainSubstring ("component notin (sonobuoy)" )))
131
+ It ("should apply successfully after edit" , func () {
132
+ Expect (jobs ).To (HaveLen (1 ))
133
+ Expect (jobs [0 ].Status .Succeeded ).To (BeNumerically ("==" , 1 ))
134
+ Expect (jobs [0 ].Status .Active ).To (BeNumerically ("==" , 0 ))
135
+ Expect (jobs [0 ].Status .Failed ).To (BeNumerically ("==" , 0 ))
136
+ Expect (jobs [0 ].Spec .Template .Spec .InitContainers ).To (HaveLen (1 ))
137
+ Expect (jobs [0 ].Spec .Template .Spec .InitContainers [0 ].Args ).To (ContainElement (ContainSubstring ("!upgrade.cattle.io/controller" )))
138
+ Expect (jobs [0 ].Spec .Template .Spec .InitContainers [0 ].Args ).To (ContainElement (ContainSubstring ("component notin (sonobuoy)" )))
139
139
})
140
- ginkgo . AfterEach (func () {
141
- if ginkgo . CurrentSpecReport ().Failed () {
140
+ AfterEach (func () {
141
+ if CurrentSpecReport ().Failed () {
142
142
podList , _ := e2e .ClientSet .CoreV1 ().Pods (e2e .Namespace .Name ).List (context .Background (), metav1.ListOptions {})
143
143
for _ , pod := range podList .Items {
144
144
containerNames := []string {}
@@ -153,7 +153,7 @@ var _ = ginkgo.Describe("Job Generation", func() {
153
153
logs := e2e .ClientSet .CoreV1 ().Pods (e2e .Namespace .Name ).GetLogs (pod .Name , & v1.PodLogOptions {Container : container })
154
154
if logStreamer , err := logs .Stream (context .Background ()); err == nil {
155
155
if podLogs , err := io .ReadAll (logStreamer ); err == nil {
156
- ginkgo . AddReportEntry (reportName , string (podLogs ))
156
+ AddReportEntry (reportName , string (podLogs ))
157
157
}
158
158
}
159
159
}
@@ -162,22 +162,22 @@ var _ = ginkgo.Describe("Job Generation", func() {
162
162
})
163
163
})
164
164
165
- ginkgo . When ("updated secret should not change hash" , func () {
165
+ When ("updated secret should not change hash" , func () {
166
166
var (
167
167
err error
168
168
plan * upgradeapiv1.Plan
169
169
secret * v1.Secret
170
170
hash string
171
171
)
172
- ginkgo . BeforeEach (func () {
172
+ BeforeEach (func () {
173
173
secret , err = e2e .CreateSecret (& v1.Secret {
174
174
ObjectMeta : metav1.ObjectMeta {
175
175
Name : "test" ,
176
176
Namespace : e2e .Namespace .Name ,
177
177
},
178
178
Data : map [string ][]byte {"config" : []byte ("test" )},
179
179
})
180
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
180
+ Expect (err ).ToNot (HaveOccurred ())
181
181
182
182
plan = e2e .NewPlan ("updated-secret-" , "library/alpine:3.18" , []string {"sh" , "-c" }, "exit 0" )
183
183
plan .Spec .Version = "latest"
@@ -195,19 +195,19 @@ var _ = ginkgo.Describe("Job Generation", func() {
195
195
IgnoreUpdates : true ,
196
196
}}
197
197
plan , err = e2e .CreatePlan (plan )
198
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
198
+ Expect (err ).ToNot (HaveOccurred ())
199
199
200
200
plan , err = e2e .WaitForPlanCondition (plan .Name , upgradeapiv1 .PlanLatestResolved , 30 * time .Second )
201
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
202
- gomega . Expect (plan .Status .LatestHash ).ToNot (gomega . BeEmpty ())
201
+ Expect (err ).ToNot (HaveOccurred ())
202
+ Expect (plan .Status .LatestHash ).ToNot (BeEmpty ())
203
203
hash = plan .Status .LatestHash
204
204
205
205
secret .Data = map [string ][]byte {"config" : []byte ("test2" )}
206
206
secret , err = e2e .UpdateSecret (secret )
207
- gomega . Expect (err ).ToNot (gomega . HaveOccurred ())
207
+ Expect (err ).ToNot (HaveOccurred ())
208
208
})
209
- ginkgo . It ("hash should be Equal " , func () {
210
- gomega . Expect (plan .Status .LatestHash ).Should (gomega . Equal (hash ))
209
+ It ("hash should be equal " , func () {
210
+ Expect (plan .Status .LatestHash ).Should (Equal (hash ))
211
211
})
212
212
})
213
213
})
0 commit comments