|
| 1 | +/* |
| 2 | +Copyright (C) 2022-2025 ApeCloud Co., Ltd |
| 3 | +
|
| 4 | +This file is part of KubeBlocks project |
| 5 | +
|
| 6 | +This program is free software: you can redistribute it and/or modify |
| 7 | +it under the terms of the GNU Affero General Public License as published by |
| 8 | +the Free Software Foundation, either version 3 of the License, or |
| 9 | +(at your option) any later version. |
| 10 | +
|
| 11 | +This program is distributed in the hope that it will be useful |
| 12 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +GNU Affero General Public License for more details. |
| 15 | +
|
| 16 | +You should have received a copy of the GNU Affero General Public License |
| 17 | +along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +*/ |
| 19 | + |
| 20 | +package parameters |
| 21 | + |
| 22 | +import ( |
| 23 | + "fmt" |
| 24 | + |
| 25 | + . "github.com/onsi/ginkgo/v2" |
| 26 | + . "github.com/onsi/gomega" |
| 27 | +) |
| 28 | + |
| 29 | +var _ = Describe("Reconfigure combinedPolicy test", func() { |
| 30 | + var ( |
| 31 | + rctx reconfigureContext |
| 32 | + ) |
| 33 | + |
| 34 | + BeforeEach(func() { |
| 35 | + rctx = newMockReconfigureParams("combinedPolicy", k8sClient, |
| 36 | + withConfigSpec("test", map[string]string{ |
| 37 | + "key": "value", |
| 38 | + }), |
| 39 | + withClusterComponent(2)) |
| 40 | + }) |
| 41 | + |
| 42 | + AfterEach(func() { |
| 43 | + }) |
| 44 | + |
| 45 | + Context("combine reconfigure policy", func() { |
| 46 | + It("dummy policy", func() { |
| 47 | + policies := &combinedPolicy{ |
| 48 | + policies: []reconfigurePolicy{ |
| 49 | + &dummyPolicy{ |
| 50 | + status: ESNone, |
| 51 | + err: nil, |
| 52 | + }}, |
| 53 | + } |
| 54 | + status, err := policies.Upgrade(rctx) |
| 55 | + Expect(err).Should(BeNil()) |
| 56 | + Expect(status.Status).Should(BeEquivalentTo(ESNone)) |
| 57 | + }) |
| 58 | + |
| 59 | + It("error policy", func() { |
| 60 | + policies := &combinedPolicy{ |
| 61 | + policies: []reconfigurePolicy{ |
| 62 | + &dummyPolicy{ |
| 63 | + status: ESFailedAndRetry, |
| 64 | + err: fmt.Errorf("error"), |
| 65 | + }}, |
| 66 | + } |
| 67 | + status, err := policies.Upgrade(rctx) |
| 68 | + Expect(err).ShouldNot(BeNil()) |
| 69 | + Expect(status.Status).Should(BeEquivalentTo(ESFailedAndRetry)) |
| 70 | + }) |
| 71 | + |
| 72 | + It("ok + error policy", func() { |
| 73 | + policies := &combinedPolicy{ |
| 74 | + policies: []reconfigurePolicy{ |
| 75 | + &dummyPolicy{ |
| 76 | + status: ESNone, |
| 77 | + err: nil, |
| 78 | + }, |
| 79 | + &dummyPolicy{ |
| 80 | + status: ESFailedAndRetry, |
| 81 | + err: fmt.Errorf("error"), |
| 82 | + }}, |
| 83 | + } |
| 84 | + status, err := policies.Upgrade(rctx) |
| 85 | + Expect(err).ShouldNot(BeNil()) |
| 86 | + Expect(status.Status).Should(BeEquivalentTo(ESFailedAndRetry)) |
| 87 | + }) |
| 88 | + |
| 89 | + It("error + ok policy", func() { |
| 90 | + policies := &combinedPolicy{ |
| 91 | + policies: []reconfigurePolicy{ |
| 92 | + &dummyPolicy{ |
| 93 | + status: ESFailedAndRetry, |
| 94 | + err: fmt.Errorf("error"), |
| 95 | + }, |
| 96 | + &dummyPolicy{ |
| 97 | + status: ESNone, |
| 98 | + err: nil, |
| 99 | + }, |
| 100 | + }, |
| 101 | + } |
| 102 | + status, err := policies.Upgrade(rctx) |
| 103 | + Expect(err).ShouldNot(BeNil()) |
| 104 | + Expect(status.Status).Should(BeEquivalentTo(ESFailedAndRetry)) |
| 105 | + }) |
| 106 | + |
| 107 | + It("retry + none policy", func() { |
| 108 | + policies := &combinedPolicy{ |
| 109 | + policies: []reconfigurePolicy{ |
| 110 | + &dummyPolicy{ |
| 111 | + status: ESRetry, |
| 112 | + err: nil, |
| 113 | + }, |
| 114 | + &dummyPolicy{ |
| 115 | + status: ESNone, |
| 116 | + err: nil, |
| 117 | + }, |
| 118 | + }, |
| 119 | + } |
| 120 | + status, err := policies.Upgrade(rctx) |
| 121 | + Expect(err).Should(BeNil()) |
| 122 | + Expect(status.Status).Should(BeEquivalentTo(ESNone)) // TODO: should be ESRetry |
| 123 | + }) |
| 124 | + }) |
| 125 | +}) |
| 126 | + |
| 127 | +type dummyPolicy struct { |
| 128 | + status ExecStatus |
| 129 | + err error |
| 130 | +} |
| 131 | + |
| 132 | +func (t *dummyPolicy) Upgrade(reconfigureContext) (returnedStatus, error) { |
| 133 | + return makeReturnedStatus(t.status), t.err |
| 134 | +} |
0 commit comments