|
12 | 12 | # when the polling condition was inverted. Each of those turns this file red. |
13 | 13 | # |
14 | 14 | # What is pinned here: |
15 | | -# * only objects whose Helm annotations name this release are deleted or |
16 | | -# patched: an object of another release, or one Helm does not own, is left |
17 | | -# alone; |
| 15 | +# * only objects whose Helm annotations name this release, by name and |
| 16 | +# namespace both, are deleted or patched: an object of another release, of |
| 17 | +# a same-named release in another namespace, or one Helm does not own, is |
| 18 | +# left alone; |
18 | 19 | # * with the operator gone, the hook waits before touching finalizers, then |
19 | 20 | # clears them, and nothing of this release is left behind; |
20 | 21 | # * with the operator alive, it finalizes the objects itself and the hook |
@@ -114,14 +115,17 @@ KEOF |
114 | 115 | } |
115 | 116 |
|
116 | 117 | # write_state <file> |
117 | | -# Two objects of this release in two namespaces, one VMRule of another release |
118 | | -# and one VMServiceScrape that carries no Helm annotations. |
| 118 | +# Three objects of this release in two namespaces; a VMRule of another release; |
| 119 | +# a VMRule whose release name matches but whose release namespace does not, so |
| 120 | +# only the pair of annotations tells it apart; and a VMServiceScrape that |
| 121 | +# carries no Helm annotations. |
119 | 122 | write_state() { |
120 | 123 | cat > "$1" <<EOF |
121 | 124 | vmagents|$MA_RELEASE|$MA_NAMESPACE|$MA_NAMESPACE|vmagent |
122 | 125 | vmrules|$MA_RELEASE|$MA_NAMESPACE|$MA_NAMESPACE|alerts-node |
123 | 126 | vmservicescrapes|$MA_RELEASE|$MA_NAMESPACE|cozy-victoria-metrics-operator|operator |
124 | 127 | vmrules|other|$MA_NAMESPACE|$MA_NAMESPACE|foreign-rule |
| 128 | +vmrules|$MA_RELEASE|other-namespace|$MA_NAMESPACE|foreign-ns-rule |
125 | 129 | vmservicescrapes|||$MA_NAMESPACE|unmanaged-scrape |
126 | 130 | EOF |
127 | 131 | } |
@@ -171,19 +175,20 @@ run_hook() { |
171 | 175 | done |
172 | 176 | # The objects of this release must be gone, which the fake only does for a |
173 | 177 | # patch that really clears the finalizers. |
174 | | - if grep -q "^[a-z]*|$MA_RELEASE|" "$tmp/state"; then |
| 178 | + if grep -q "^[a-z]*|$MA_RELEASE|$MA_NAMESPACE|" "$tmp/state"; then |
175 | 179 | echo "FAIL: objects of this release are still there, Terminating" |
176 | 180 | cat "$tmp/state" "$tmp/calls" |
177 | 181 | false |
178 | 182 | fi |
179 | | - # Another release's object and an object Helm does not own are never touched. |
180 | | - if grep -E -q -- ' (delete|patch) [a-z.]+ (foreign-rule|unmanaged-scrape)( |$)' "$tmp/calls"; then |
| 183 | + # Another release's object, one of a same-named release in another |
| 184 | + # namespace, and an object Helm does not own are never touched. |
| 185 | + if grep -E -q -- ' (delete|patch) [a-z.]+ (foreign-rule|foreign-ns-rule|unmanaged-scrape)( |$)' "$tmp/calls"; then |
181 | 186 | echo "FAIL: the hook touched an object this release does not own" |
182 | 187 | cat "$tmp/calls" |
183 | 188 | false |
184 | 189 | fi |
185 | | - if [ "$(grep -c '|' "$tmp/state")" -ne 2 ]; then |
186 | | - echo "FAIL: the objects this release does not own should both remain" |
| 190 | + if [ "$(grep -c '|' "$tmp/state")" -ne 3 ]; then |
| 191 | + echo "FAIL: the three objects this release does not own should remain" |
187 | 192 | cat "$tmp/state" |
188 | 193 | false |
189 | 194 | fi |
@@ -287,7 +292,8 @@ run_hook() { |
287 | 292 | @test "vm cleanup hook exits 0 without deleting anything when the release owns nothing" { |
288 | 293 | tmp=$(mktemp -d) |
289 | 294 | write_fakes "$tmp" |
290 | | - printf 'vmrules|other|%s|%s|foreign-rule\n' "$MA_NAMESPACE" "$MA_NAMESPACE" > "$tmp/state" |
| 295 | + printf 'vmrules|other|%s|%s|foreign-rule\nvmrules|%s|other-namespace|%s|foreign-ns-rule\n' \ |
| 296 | + "$MA_NAMESPACE" "$MA_NAMESPACE" "$MA_RELEASE" "$MA_NAMESPACE" > "$tmp/state" |
291 | 297 | render_hook vm-objects-cleanup "$tmp/hook.sh" |
292 | 298 | export OPERATOR_LIVE=0 MISSING_KINDS="" |
293 | 299 | run_hook "$tmp" |
|
0 commit comments