Repository navigation
Commit c4be308
refactor: Extract build and apply steps in the zk- and znode-controller (#1069)
* refactor: Build the discovery ConfigMap in the build step
The discovery ConfigMap advertises the addresses that the listener
operator publishes on the ZooKeeper role Listener, so it used to be
built and applied inline in reconcile_zk, from the Listener that had
just been applied. That Listener carries no addresses yet on the first
reconciliation, so the controller relied on the reconciliation failing
and being requeued five seconds later.
Follow the pattern the OpenSearch operator already uses: dereference the
role Listener, validate its addresses into the ValidatedCluster, and let
build() emit an Option<ConfigMap>. The controller now watches Listeners,
so the reconciliation that writes the discovery ConfigMap is triggered as
soon as the addresses appear, and it also reruns when they change.
The listener address extraction moves into a shared listener_addresses
module, because the ZookeeperZnode controller needs it too.
The operator ClusterRole gains the watch verb on listeners, which is
required for the new watch.
* refactor: Extract the apply step into an Applier
reconcile_zk built the ClusterResources itself and applied every
collection with its own inline loop, so the driver carried the apply
order, the orphan deletion and the resource specific error variants.
Extract all of that into an Applier, following the airflow and hbase
operators. KubernetesResources is now marked as either Prepared or
Applied, which makes it impossible to derive the cluster status from
resources that were only built. apply() destructures the resource set
exhaustively, so a new field fails to compile here instead of silently
never being applied.
Unlike the sibling operators, the apply module is declared in
zk_controller.rs itself, so the Applier is imported without `self` to
avoid a name collision with the module declaration.
* refactor: Extract the update status step
The cluster conditions and the discovery hash were computed inline at
the end of reconcile_zk, from resources that happened to be in scope.
Move both into an update_status step, following the airflow and hbase
operators. It takes KubernetesResources<Applied>, so the type system
proves the status is derived from resources that were actually applied
rather than merely built. The discovery hash, which the sibling
operators do not have, becomes a private helper next to it.
reconcile_zk is now the dereference, validate, build, apply and
update_status pipeline and nothing else.
* refactor: Extract build and apply steps in the znode controller
reconcile_apply created the ClusterResources, talked to ZooKeeper,
fetched the role Listener, built the discovery ConfigMap and applied it,
all inline, so the ZookeeperZnode controller was the only one left
without a pipeline.
Give it the same dereference, validate, build and apply structure as the
ZookeeperCluster controller. The Listener fetch moves into the
dereference step, where a missing Listener stays a non error so it can
never block finalizer removal, and its addresses become a validated
field on ValidatedZnode. Creating the znode inside the ZooKeeper
ensemble lives in the apply step as a free function, next to the
Applier, because it is a client side effect that the client free build()
cannot perform.
The discovery ConfigMap builders move to a shared discovery module, so
the znode controller no longer reaches into the cluster controller's
build tree.
Unlike the cluster controller, the resources carry no Prepared or
Applied marker: the ZookeeperZnode has no cluster conditions, so there
is no status step the marker could protect.
* chore: adapted changelog
* docs: fix rustdoc warnings in discovery and znode apply
* fix: Always build the discovery ConfigMap
Skipping the discovery ConfigMap while the role Listener publishes no
addresses let the apply step delete the already published one as an
orphan, breaking consumers that mount it. Before the pipeline
extraction, the missing addresses aborted the run before
delete_orphaned_resources() ran, so this only surfaced now.
Follow the kafka-operator pattern instead: always write the ConfigMap,
with an empty ZOOKEEPER value while no address is known. The Listener
watch triggers a new run that fills the value in.
* test: Cover the znode validate step's role Listener errors
The znode controller had no tests at all. Add fixtures for it and cover
both ways the role Listener can block validation: addresses published
under an unexpected port name (ReadRoleListenerAddresses), and no
addresses at all, either because the Listener does not exist yet or
because the listener operator has not published its status
(NoRoleListenerAddresses).
The Listener fixtures move into a shared test_support module in
listener_addresses, so the cluster controller's tests can use them too.
* test: Cover the role Listener addresses in the cluster validate step
Add a try_validate variant that takes a role Listener, and cover the
three outcomes: addresses published under an unexpected port name fail
with ReadRoleListenerAddresses, published addresses reach the validated
cluster sorted, and a missing or unpublished Listener validates to no
addresses rather than an error, which is what lets the build step still
write the discovery ConfigMap.
* test: Cover the discovery hash in the update status step
* test: Cover the discovery ConfigMap builders
Assert the ZOOKEEPER, ZOOKEEPER_HOSTS, ZOOKEEPER_CLIENT_PORT and
ZOOKEEPER_CHROOT content for both the cluster and the znode variant,
that only ZOOKEEPER carries the chroot, and that a relative chroot is
rejected. The empty-address case is covered too, pinning that the
ConfigMap is written even while the role Listener publishes nothing.
The Listener fixtures now publish the secure client port, which is what
the role Listener serves while the fixture keeps TLS enabled.
* Update CHANGELOG.md
Co-authored-by: Andrew Kenworthy <1712947+adwk67@users.noreply.github.com>
---------
Co-authored-by: Andrew Kenworthy <1712947+adwk67@users.noreply.github.com>1 parent b791a3c commit c4be308
18 files changed
Lines changed: 1470 additions & 571 deletions
File tree
- deploy/helm/zookeeper-operator/templates
- rust/operator-binary/src
- zk_controller
- build/resource
- znode_controller
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| |||
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| 36 | + | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
122 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
| |||
130 | 131 | | |
131 | 132 | | |
132 | 133 | | |
| 134 | + | |
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
0 commit comments