Skip to content

Commit 67bbce8

Browse files
committed
Update e2e for new features
Signed-off-by: Brad Davidson <[email protected]>
1 parent 0b25e9c commit 67bbce8

File tree

2 files changed

+156
-2
lines changed

2 files changed

+156
-2
lines changed

e2e/framework/controller/deployment.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ type DeploymentOption func(*appsv1.Deployment)
1919

2020
func NewDeployment(name string, opt ...DeploymentOption) *appsv1.Deployment {
2121
labels := map[string]string{
22-
upgradeapi.LabelController: name,
22+
upgradeapi.LabelController: name,
23+
"app.kubernetes.io/name": name,
24+
"app.kubernetes.io/component": "controller",
2325
}
2426
securityContext := &corev1.SecurityContext{
2527
AllowPrivilegeEscalation: pointer.Bool(false),
@@ -46,6 +48,9 @@ func NewDeployment(name string, opt ...DeploymentOption) *appsv1.Deployment {
4648
container.Env = []corev1.EnvVar{{
4749
Name: "SYSTEM_UPGRADE_CONTROLLER_NAME",
4850
Value: name,
51+
}, {
52+
Name: "SYSTEM_UPGRADE_CONTROLLER_LEADER_ELECT",
53+
Value: "true",
4954
}, {
5055
Name: "SYSTEM_UPGRADE_CONTROLLER_NAMESPACE",
5156
ValueFrom: &corev1.EnvVarSource{

e2e/suite/job_generate_test.go

Lines changed: 150 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ var _ = Describe("Job Generation", func() {
114114
plan, err = e2e.WaitForPlanCondition(plan.Name, upgradeapiv1.PlanSpecValidated, 30*time.Second)
115115
Expect(err).ToNot(HaveOccurred())
116116
Expect(upgradeapiv1.PlanSpecValidated.IsTrue(plan)).To(BeFalse())
117-
Expect(upgradeapiv1.PlanSpecValidated.GetMessage(plan)).To(ContainSubstring("cannot specify both deleteEmptydirData and deleteLocalData"))
117+
Expect(upgradeapiv1.PlanSpecValidated.GetMessage(plan)).To(ContainSubstring("spec.drain cannot specify both deleteEmptydirData and deleteLocalData"))
118118

119119
plan.Spec.Drain.DeleteLocalData = nil
120120
plan, err = e2e.UpdatePlan(plan)
@@ -162,6 +162,155 @@ var _ = Describe("Job Generation", func() {
162162
})
163163
})
164164

165+
When("fails because of invalid time window", func() {
166+
var (
167+
err error
168+
plan *upgradeapiv1.Plan
169+
jobs []batchv1.Job
170+
)
171+
BeforeEach(func() {
172+
plan = e2e.NewPlan("fail-window-", "library/alpine:3.18", []string{"sh", "-c"}, "exit 0")
173+
plan.Spec.Version = "latest"
174+
plan.Spec.Concurrency = 1
175+
plan.Spec.ServiceAccountName = e2e.Namespace.Name
176+
plan.Spec.Window = &upgradeapiv1.TimeWindowSpec{
177+
Days: []string{"never"},
178+
StartTime: "00:00:00",
179+
EndTime: "23:59:59",
180+
TimeZone: "UTC",
181+
}
182+
plan.Spec.NodeSelector = &metav1.LabelSelector{
183+
MatchExpressions: []metav1.LabelSelectorRequirement{{
184+
Key: "node-role.kubernetes.io/control-plane",
185+
Operator: metav1.LabelSelectorOpDoesNotExist,
186+
}},
187+
}
188+
plan, err = e2e.CreatePlan(plan)
189+
Expect(err).ToNot(HaveOccurred())
190+
191+
plan, err = e2e.WaitForPlanCondition(plan.Name, upgradeapiv1.PlanSpecValidated, 30*time.Second)
192+
Expect(err).ToNot(HaveOccurred())
193+
Expect(upgradeapiv1.PlanSpecValidated.IsTrue(plan)).To(BeFalse())
194+
Expect(upgradeapiv1.PlanSpecValidated.GetMessage(plan)).To(ContainSubstring("spec.window is invalid"))
195+
196+
plan.Spec.Window.Days = []string{"su", "mo", "tu", "we", "th", "fr", "sa"}
197+
plan, err = e2e.UpdatePlan(plan)
198+
Expect(err).ToNot(HaveOccurred())
199+
200+
plan, err = e2e.WaitForPlanCondition(plan.Name, upgradeapiv1.PlanSpecValidated, 30*time.Second)
201+
Expect(err).ToNot(HaveOccurred())
202+
Expect(upgradeapiv1.PlanSpecValidated.IsTrue(plan)).To(BeTrue())
203+
204+
jobs, err = e2e.WaitForPlanJobs(plan, 1, 120*time.Second)
205+
Expect(err).ToNot(HaveOccurred())
206+
Expect(jobs).To(HaveLen(1))
207+
})
208+
It("should apply successfully after edit", func() {
209+
Expect(jobs).To(HaveLen(1))
210+
Expect(jobs[0].Status.Succeeded).To(BeNumerically("==", 1))
211+
Expect(jobs[0].Status.Active).To(BeNumerically("==", 0))
212+
Expect(jobs[0].Status.Failed).To(BeNumerically("==", 0))
213+
Expect(jobs[0].Spec.Template.Spec.InitContainers).To(HaveLen(1))
214+
Expect(jobs[0].Spec.Template.Spec.InitContainers[0].Args).To(ContainElement(ContainSubstring("!upgrade.cattle.io/controller")))
215+
Expect(jobs[0].Spec.Template.Spec.InitContainers[0].Args).To(ContainElement(ContainSubstring("component notin (sonobuoy)")))
216+
})
217+
AfterEach(func() {
218+
if CurrentSpecReport().Failed() {
219+
podList, _ := e2e.ClientSet.CoreV1().Pods(e2e.Namespace.Name).List(context.Background(), metav1.ListOptions{})
220+
for _, pod := range podList.Items {
221+
containerNames := []string{}
222+
for _, container := range pod.Spec.InitContainers {
223+
containerNames = append(containerNames, container.Name)
224+
}
225+
for _, container := range pod.Spec.Containers {
226+
containerNames = append(containerNames, container.Name)
227+
}
228+
for _, container := range containerNames {
229+
reportName := fmt.Sprintf("podlogs-%s-%s", pod.Name, container)
230+
logs := e2e.ClientSet.CoreV1().Pods(e2e.Namespace.Name).GetLogs(pod.Name, &v1.PodLogOptions{Container: container})
231+
if logStreamer, err := logs.Stream(context.Background()); err == nil {
232+
if podLogs, err := io.ReadAll(logStreamer); err == nil {
233+
AddReportEntry(reportName, string(podLogs))
234+
}
235+
}
236+
}
237+
}
238+
}
239+
})
240+
})
241+
242+
When("fails because of invalid post complete delay", func() {
243+
var (
244+
err error
245+
plan *upgradeapiv1.Plan
246+
jobs []batchv1.Job
247+
)
248+
BeforeEach(func() {
249+
plan = e2e.NewPlan("fail-post-complete-delay-", "library/alpine:3.18", []string{"sh", "-c"}, "exit 0")
250+
plan.Spec.Version = "latest"
251+
plan.Spec.Concurrency = 1
252+
plan.Spec.ServiceAccountName = e2e.Namespace.Name
253+
plan.Spec.PostCompleteDelay = &metav1.Duration{Duration: -30 * time.Second}
254+
plan.Spec.NodeSelector = &metav1.LabelSelector{
255+
MatchExpressions: []metav1.LabelSelectorRequirement{{
256+
Key: "node-role.kubernetes.io/control-plane",
257+
Operator: metav1.LabelSelectorOpDoesNotExist,
258+
}},
259+
}
260+
plan, err = e2e.CreatePlan(plan)
261+
Expect(err).ToNot(HaveOccurred())
262+
263+
plan, err = e2e.WaitForPlanCondition(plan.Name, upgradeapiv1.PlanSpecValidated, 30*time.Second)
264+
Expect(err).ToNot(HaveOccurred())
265+
Expect(upgradeapiv1.PlanSpecValidated.IsTrue(plan)).To(BeFalse())
266+
Expect(upgradeapiv1.PlanSpecValidated.GetMessage(plan)).To(ContainSubstring("spec.postCompleteDelay is negative"))
267+
268+
plan.Spec.PostCompleteDelay.Duration = time.Second
269+
plan, err = e2e.UpdatePlan(plan)
270+
Expect(err).ToNot(HaveOccurred())
271+
272+
plan, err = e2e.WaitForPlanCondition(plan.Name, upgradeapiv1.PlanSpecValidated, 30*time.Second)
273+
Expect(err).ToNot(HaveOccurred())
274+
Expect(upgradeapiv1.PlanSpecValidated.IsTrue(plan)).To(BeTrue())
275+
276+
jobs, err = e2e.WaitForPlanJobs(plan, 1, 120*time.Second)
277+
Expect(err).ToNot(HaveOccurred())
278+
Expect(jobs).To(HaveLen(1))
279+
})
280+
It("should apply successfully after edit", func() {
281+
Expect(jobs).To(HaveLen(1))
282+
Expect(jobs[0].Status.Succeeded).To(BeNumerically("==", 1))
283+
Expect(jobs[0].Status.Active).To(BeNumerically("==", 0))
284+
Expect(jobs[0].Status.Failed).To(BeNumerically("==", 0))
285+
Expect(jobs[0].Spec.Template.Spec.InitContainers).To(HaveLen(1))
286+
Expect(jobs[0].Spec.Template.Spec.InitContainers[0].Args).To(ContainElement(ContainSubstring("!upgrade.cattle.io/controller")))
287+
Expect(jobs[0].Spec.Template.Spec.InitContainers[0].Args).To(ContainElement(ContainSubstring("component notin (sonobuoy)")))
288+
})
289+
AfterEach(func() {
290+
if CurrentSpecReport().Failed() {
291+
podList, _ := e2e.ClientSet.CoreV1().Pods(e2e.Namespace.Name).List(context.Background(), metav1.ListOptions{})
292+
for _, pod := range podList.Items {
293+
containerNames := []string{}
294+
for _, container := range pod.Spec.InitContainers {
295+
containerNames = append(containerNames, container.Name)
296+
}
297+
for _, container := range pod.Spec.Containers {
298+
containerNames = append(containerNames, container.Name)
299+
}
300+
for _, container := range containerNames {
301+
reportName := fmt.Sprintf("podlogs-%s-%s", pod.Name, container)
302+
logs := e2e.ClientSet.CoreV1().Pods(e2e.Namespace.Name).GetLogs(pod.Name, &v1.PodLogOptions{Container: container})
303+
if logStreamer, err := logs.Stream(context.Background()); err == nil {
304+
if podLogs, err := io.ReadAll(logStreamer); err == nil {
305+
AddReportEntry(reportName, string(podLogs))
306+
}
307+
}
308+
}
309+
}
310+
}
311+
})
312+
})
313+
165314
When("updated secret should not change hash", func() {
166315
var (
167316
err error

0 commit comments

Comments
 (0)