Skip to content

Commit 54480ad

Browse files
sbernauernightkr
andcommitted
Actually enrich StatefulSets in mutating webhooks
Many parts copied from https://github.com/stackabletech/commons-operator/tree/spike/sts-restarter-webhook Co-authored-by: Natalie Klestrup Röijezon <nat@nullable.se>
1 parent 56f2b2f commit 54480ad

File tree

12 files changed

+478
-161
lines changed

12 files changed

+478
-161
lines changed

Cargo.lock

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 22 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ built = { version = "0.8", features = ["chrono", "git2"] }
1717
clap = "4.5"
1818
futures = { version = "0.3", features = ["compat"] }
1919
http = "1.3"
20+
json-patch = "4.1"
2021
serde = { version = "1.0", features = ["derive"] }
2122
serde_json = "1.0"
2223
snafu = "0.8"

_TEST.yaml

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
---
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: nginx
6+
labels:
7+
app: nginx
8+
spec:
9+
ports:
10+
- port: 80
11+
name: web
12+
clusterIP: None
13+
selector:
14+
app: nginx
15+
---
16+
apiVersion: v1
17+
kind: ConfigMap
18+
metadata:
19+
name: web-config
20+
data:
21+
foo: bar
22+
---
23+
apiVersion: v1
24+
kind: ConfigMap
25+
metadata:
26+
name: web-config-2
27+
data:
28+
foo: bar
29+
---
130
apiVersion: apps/v1
231
kind: StatefulSet
332
metadata:
@@ -32,31 +61,3 @@ spec:
3261
- name: config
3362
configMap:
3463
name: web-config
35-
---
36-
apiVersion: v1
37-
kind: Service
38-
metadata:
39-
name: nginx
40-
labels:
41-
app: nginx
42-
spec:
43-
ports:
44-
- port: 80
45-
name: web
46-
clusterIP: None
47-
selector:
48-
app: nginx
49-
---
50-
apiVersion: v1
51-
kind: ConfigMap
52-
metadata:
53-
name: web-config
54-
data:
55-
foo: bar
56-
---
57-
apiVersion: v1
58-
kind: ConfigMap
59-
metadata:
60-
name: web-config-2
61-
data:
62-
foo: bar

crate-hashes.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/operator-binary/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ anyhow.workspace = true
1515
clap.workspace = true
1616
http.workspace = true
1717
futures.workspace = true
18+
json-patch.workspace = true
1819
serde.workspace = true
1920
serde_json.workspace = true
2021
snafu.workspace = true

rust/operator-binary/src/main.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use anyhow::anyhow;
66
use clap::Parser;
77
use futures::{FutureExt, TryFutureExt};
8+
use restart_controller::statefulset::create_context;
89
use stackable_operator::{
910
YamlSchema as _,
1011
cli::{Command, RunArguments},
@@ -19,6 +20,7 @@ use stackable_operator::{
1920
use webhooks::create_webhook;
2021

2122
mod restart_controller;
23+
mod utils;
2224
mod webhooks;
2325

2426
mod built_info {
@@ -82,7 +84,19 @@ async fn main() -> anyhow::Result<()> {
8284
)
8385
.await?;
8486

87+
let (ctx, cm_store_tx, secret_store_tx) = create_context(client.clone());
88+
let sts_restart_controller = restart_controller::statefulset::start(
89+
ctx.clone(),
90+
cm_store_tx,
91+
secret_store_tx,
92+
&watch_namespace,
93+
)
94+
.map(anyhow::Ok);
95+
let pod_restart_controller =
96+
restart_controller::pod::start(&client, &watch_namespace).map(anyhow::Ok);
97+
8598
let webhook = create_webhook(
99+
ctx,
86100
&operator_environment,
87101
// TODO: Make user configurable
88102
false,
@@ -93,16 +107,11 @@ async fn main() -> anyhow::Result<()> {
93107
.run()
94108
.map_err(|err| anyhow!(err).context("failed to run webhook"));
95109

96-
let sts_restart_controller =
97-
restart_controller::statefulset::start(&client, &watch_namespace).map(anyhow::Ok);
98-
let pod_restart_controller =
99-
restart_controller::pod::start(&client, &watch_namespace).map(anyhow::Ok);
100-
101110
futures::try_join!(
102111
sts_restart_controller,
103112
pod_restart_controller,
113+
webhook,
104114
eos_checker,
105-
webhook
106115
)?;
107116
}
108117
}

rust/operator-binary/src/restart_controller/pod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ enum Error {
4242
#[snafu(display(
4343
"failed to parse expiry timestamp annotation ({annotation:?}: {value:?}) as RFC 3999"
4444
))]
45-
UnparseableExpiryTimestamp {
45+
UnparsableExpiryTimestamp {
4646
source: chrono::ParseError,
4747
annotation: String,
4848
value: String,
@@ -60,7 +60,7 @@ impl ReconcilerError for Error {
6060
match self {
6161
Error::PodHasNoName => None,
6262
Error::PodHasNoNamespace => None,
63-
Error::UnparseableExpiryTimestamp {
63+
Error::UnparsableExpiryTimestamp {
6464
source: _,
6565
annotation: _,
6666
value: _,
@@ -73,6 +73,8 @@ impl ReconcilerError for Error {
7373
pub async fn start(client: &Client, watch_namespace: &WatchNamespace) {
7474
let controller = Controller::new(
7575
watch_namespace.get_api::<PartialObjectMeta<Pod>>(client),
76+
// TODO: Can we only watch a subset of Pods with a specify label, e.g.
77+
// vendor=Stackable to reduce the memory footprint?
7678
watcher::Config::default(),
7779
);
7880
let event_recorder = Arc::new(Recorder::new(
@@ -124,7 +126,7 @@ async fn reconcile(pod: Arc<PartialObjectMeta<Pod>>, ctx: Arc<Ctx>) -> Result<Ac
124126
.flatten()
125127
.filter(|(k, _)| k.starts_with("restarter.stackable.tech/expires-at."))
126128
.map(|(k, v)| {
127-
DateTime::parse_from_rfc3339(v).context(UnparseableExpiryTimestampSnafu {
129+
DateTime::parse_from_rfc3339(v).context(UnparsableExpiryTimestampSnafu {
128130
annotation: k,
129131
value: v,
130132
})

0 commit comments

Comments
 (0)