forked from stackabletech/zookeeper-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconversion.rs
More file actions
61 lines (53 loc) · 2.07 KB
/
Copy pathconversion.rs
File metadata and controls
61 lines (53 loc) · 2.07 KB
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
use snafu::{ResultExt, Snafu};
use stackable_operator::{
cli::OperatorEnvironmentOptions,
kube::{Client, core::crd::MergeError},
webhook::{
WebhookServer, WebhookServerError, WebhookServerOptions,
webhooks::{ConversionWebhook, ConversionWebhookOptions},
},
};
use crate::crd::{
FIELD_MANAGER, ZookeeperCluster, ZookeeperClusterVersion, ZookeeperZnode, ZookeeperZnodeVersion,
};
/// Contains errors which can be encountered when creating the conversion webhook server and the
/// CRD maintainer.
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("failed to merge CRD"))]
MergeCrd { source: MergeError },
#[snafu(display("failed to create conversion webhook server"))]
CreateWebhook { source: WebhookServerError },
}
/// Creates and returns a [`WebhookServer`].
pub async fn create_webhook_server(
operator_environment: &OperatorEnvironmentOptions,
disable_crd_maintenance: bool,
client: Client,
) -> Result<WebhookServer, Error> {
let crds_and_handlers = vec![
(
ZookeeperCluster::merged_crd(ZookeeperClusterVersion::V1Alpha1)
.context(MergeCrdSnafu)?,
ZookeeperCluster::try_convert as fn(_) -> _,
),
(
ZookeeperZnode::merged_crd(ZookeeperZnodeVersion::V1Alpha1).context(MergeCrdSnafu)?,
ZookeeperZnode::try_convert as fn(_) -> _,
),
];
let conversion_webhook_options = ConversionWebhookOptions {
disable_crd_maintenance,
field_manager: FIELD_MANAGER.to_owned(),
};
let (conversion_webhook, _) =
ConversionWebhook::new(crds_and_handlers, client, conversion_webhook_options);
let webhook_server_options = WebhookServerOptions {
socket_addr: WebhookServer::DEFAULT_SOCKET_ADDRESS,
webhook_namespace: operator_environment.operator_namespace.to_owned(),
webhook_service_name: operator_environment.operator_service_name.to_owned(),
};
WebhookServer::new(vec![Box::new(conversion_webhook)], webhook_server_options)
.await
.context(CreateWebhookSnafu)
}