Skip to content

Commit 576659a

Browse files
committed
Pull in new op-rs version
1 parent ab362fe commit 576659a

File tree

5 files changed

+45
-36
lines changed

5 files changed

+45
-36
lines changed

Cargo.lock

Lines changed: 9 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: 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/src/restart_controller/statefulset.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ pub async fn get_updated_restarter_annotations(
226226
sts: &StatefulSet,
227227
ctx: Arc<Ctx>,
228228
) -> Result<BTreeMap<String, String>, Error> {
229-
let ns = sts.metadata.namespace.as_deref().unwrap();
229+
let ns = sts.metadata.namespace.as_deref().expect(
230+
"A StatefulSet observed by a reflector (so send by Kubernetes) always has a namespace set",
231+
);
230232
let mut annotations = BTreeMap::<String, String>::new();
231233
let pod_specs = sts
232234
.spec

rust/operator-binary/src/webhook/mod.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use std::sync::Arc;
22

3-
use restarter_mutate_sts::{add_sts_restarter_annotation, get_mutating_webhook_configuration};
3+
use restarter_mutate_sts::{
4+
add_sts_restarter_annotations_handler, get_sts_restarter_mutating_webhook_configuration,
5+
};
46
use snafu::{ResultExt, Snafu};
57
use stackable_operator::{
68
cli::OperatorEnvironmentOptions,
79
kube::Client,
810
webhook::{
9-
WebhookError, WebhookOptions, WebhookServer,
10-
servers::{MutatingWebhookServer, WebhookServerImplementation},
11+
WebhookServer, WebhookServerError, WebhookServerOptions,
12+
webhooks::{MutatingWebhook, Webhook},
1113
},
1214
};
1315

@@ -18,7 +20,7 @@ mod restarter_mutate_sts;
1820
#[derive(Debug, Snafu)]
1921
pub enum Error {
2022
#[snafu(display("failed to create webhook server"))]
21-
CreateWebhookServer { source: WebhookError },
23+
CreateWebhookServer { source: WebhookServerError },
2224
}
2325

2426
pub async fn create_webhook_server(
@@ -27,22 +29,22 @@ pub async fn create_webhook_server(
2729
disable_restarter_mutating_webhook: bool,
2830
client: Client,
2931
) -> Result<WebhookServer, Error> {
30-
let mut webhooks: Vec<Box<dyn WebhookServerImplementation>> = vec![];
32+
let mut webhooks: Vec<Box<dyn Webhook>> = vec![];
3133
if !disable_restarter_mutating_webhook {
32-
webhooks.push(Box::new(MutatingWebhookServer::new(
33-
get_mutating_webhook_configuration(),
34-
add_sts_restarter_annotation,
34+
webhooks.push(Box::new(MutatingWebhook::new(
35+
get_sts_restarter_mutating_webhook_configuration(),
36+
add_sts_restarter_annotations_handler,
3537
ctx,
3638
disable_restarter_mutating_webhook,
3739
client,
3840
FIELD_MANAGER.to_owned(),
3941
)));
4042
}
4143

42-
let webhook_options = WebhookOptions {
44+
let webhook_options = WebhookServerOptions {
4345
socket_addr: WebhookServer::DEFAULT_SOCKET_ADDRESS,
44-
operator_namespace: operator_environment.operator_namespace.to_owned(),
45-
operator_service_name: operator_environment.operator_service_name.to_owned(),
46+
webhook_namespace: operator_environment.operator_namespace.to_owned(),
47+
webhook_service_name: operator_environment.operator_service_name.to_owned(),
4648
};
4749
WebhookServer::new(webhook_options, webhooks)
4850
.await

rust/operator-binary/src/webhook/restarter_mutate_sts.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
restart_controller::statefulset::{Ctx, get_updated_restarter_annotations},
2323
};
2424

25-
pub fn get_mutating_webhook_configuration() -> MutatingWebhookConfiguration {
25+
pub fn get_sts_restarter_mutating_webhook_configuration() -> MutatingWebhookConfiguration {
2626
let webhook_name = "restarter-sts-enricher.stackable.tech";
2727
let metadata = ObjectMetaBuilder::new()
2828
.name(webhook_name)
@@ -56,21 +56,26 @@ pub fn get_mutating_webhook_configuration() -> MutatingWebhookConfiguration {
5656
}),
5757
// Will be set by the stackable_webhook code
5858
client_config: WebhookClientConfig::default(),
59-
// Worst case the annotations are missing cause a restart of Pod 0, basically the same
60-
// behavior which we had for years.
59+
// Worst case if the annotations are missing they cause a restart of Pod 0, basically
60+
// the same behavior which we had for years.
6161
// See https://github.com/stackabletech/commons-operator/issues/111 for details
6262
failure_policy: Some("Ignore".to_owned()),
63-
// It could be the case that other mutating webhooks add more ConfigMpa/Secret mounts,
63+
// It could be the case that other mutating webhooks add more ConfigMap/Secret mounts,
6464
// in which case it would be nice if we detect that.
6565
reinvocation_policy: Some("IfNeeded".to_owned()),
66-
// We don't have side effects
66+
// > Webhooks typically operate only on the content of the AdmissionReview sent to them.
67+
// > Some webhooks, however, make out-of-band changes as part of processing admission requests.
68+
//
69+
// We read in the state of the world using the ConfigMap and Secret store.
70+
// So, technically our outcome depends on external factors, *but* this webhook is not
71+
// creating any external objects, so from our understanding it's side-effect free.
6772
side_effects: "None".to_owned(),
6873
..Default::default()
6974
}]),
7075
}
7176
}
7277

73-
pub async fn add_sts_restarter_annotation(
78+
pub async fn add_sts_restarter_annotations_handler(
7479
ctx: Arc<Ctx>,
7580
request: AdmissionRequest<StatefulSet>,
7681
) -> AdmissionResponse {

0 commit comments

Comments
 (0)