|
4 | 4 | "time"
|
5 | 5 |
|
6 | 6 | batchv1 "k8s.io/api/batch/v1"
|
| 7 | + "k8s.io/utils/pointer" |
7 | 8 |
|
8 | 9 | "github.com/rancher/system-upgrade-controller/e2e/framework"
|
9 | 10 | upgradeapiv1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
|
@@ -59,4 +60,61 @@ var _ = Describe("Job Generation", func() {
|
59 | 60 | Expect(jobs[0].Status.Failed).To(BeNumerically("==", 0))
|
60 | 61 | })
|
61 | 62 | })
|
| 63 | + |
| 64 | + When("fails because of conflicting drain options", func() { |
| 65 | + var ( |
| 66 | + err error |
| 67 | + plan *upgradeapiv1.Plan |
| 68 | + jobs []batchv1.Job |
| 69 | + ) |
| 70 | + BeforeEach(func() { |
| 71 | + plan = e2e.NewPlan("fail-drain-options-", "library/alpine:3.11", []string{"sh", "-c"}, "exit 0") |
| 72 | + plan.Spec.Version = "latest" |
| 73 | + plan.Spec.Concurrency = 1 |
| 74 | + plan.Spec.NodeSelector = &metav1.LabelSelector{ |
| 75 | + MatchExpressions: []metav1.LabelSelectorRequirement{{ |
| 76 | + Key: "node-role.kubernetes.io/master", |
| 77 | + Operator: metav1.LabelSelectorOpDoesNotExist, |
| 78 | + }}, |
| 79 | + } |
| 80 | + plan.Spec.Drain = &upgradeapiv1.DrainSpec{ |
| 81 | + DisableEviction: true, |
| 82 | + DeleteLocalData: pointer.Bool(true), |
| 83 | + DeleteEmptydirData: pointer.Bool(true), |
| 84 | + PodSelector: &metav1.LabelSelector{ |
| 85 | + MatchExpressions: []metav1.LabelSelectorRequirement{{ |
| 86 | + Key: "app", |
| 87 | + Values: []string{"csi-attacher", "csi-provisioner"}, |
| 88 | + Operator: metav1.LabelSelectorOpNotIn, |
| 89 | + }}, |
| 90 | + }, |
| 91 | + } |
| 92 | + plan, err = e2e.CreatePlan(plan) |
| 93 | + Expect(err).ToNot(HaveOccurred()) |
| 94 | + |
| 95 | + plan, err = e2e.WaitForPlanCondition(plan.Name, upgradeapiv1.PlanSpecValidated, 30*time.Second) |
| 96 | + Expect(err).ToNot(HaveOccurred()) |
| 97 | + Expect(upgradeapiv1.PlanSpecValidated.IsTrue(plan)).To(BeFalse()) |
| 98 | + Expect(upgradeapiv1.PlanSpecValidated.GetMessage(plan)).To(ContainSubstring("cannot specify both deleteEmptydirData and deleteLocalData")) |
| 99 | + |
| 100 | + plan.Spec.Drain.DeleteLocalData = nil |
| 101 | + plan, err = e2e.UpdatePlan(plan) |
| 102 | + Expect(err).ToNot(HaveOccurred()) |
| 103 | + |
| 104 | + plan, err = e2e.WaitForPlanCondition(plan.Name, upgradeapiv1.PlanSpecValidated, 30*time.Second) |
| 105 | + Expect(err).ToNot(HaveOccurred()) |
| 106 | + Expect(upgradeapiv1.PlanSpecValidated.IsTrue(plan)).To(BeTrue()) |
| 107 | + |
| 108 | + jobs, err = e2e.WaitForPlanJobs(plan, 1, 120*time.Second) |
| 109 | + Expect(err).ToNot(HaveOccurred()) |
| 110 | + Expect(jobs).To(HaveLen(1)) |
| 111 | + }) |
| 112 | + It("should apply successfully after edit", func() { |
| 113 | + Expect(jobs).To(HaveLen(1)) |
| 114 | + Expect(jobs[0].Status.Succeeded).To(BeNumerically("==", 1)) |
| 115 | + Expect(jobs[0].Status.Failed).To(BeNumerically("==", 0)) |
| 116 | + Expect(jobs[0].Spec.Template.Spec.InitContainers).To(HaveLen(1)) |
| 117 | + Expect(jobs[0].Spec.Template.Spec.InitContainers[0].Args).To(ContainSubstring("csi-attacher")) |
| 118 | + }) |
| 119 | + }) |
62 | 120 | })
|
0 commit comments