-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconversion.rs
More file actions
56 lines (47 loc) · 1.94 KB
/
conversion.rs
File metadata and controls
56 lines (47 loc) · 1.94 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
use snafu::{ResultExt, Snafu};
use stackable_operator::{
cli::OperatorEnvironmentOptions,
kube::{Client, core::crd::MergeError},
webhook::{
WebhookServer, WebhookServerError, WebhookServerOptions,
webhooks::{ConversionWebhook, ConversionWebhookOptions},
},
};
use tokio::sync::oneshot;
use crate::crd::{AirflowCluster, AirflowClusterVersion, FIELD_MANAGER};
/// 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, oneshot::Receiver<()>), Error> {
let crds_and_handlers = vec![(
AirflowCluster::merged_crd(AirflowClusterVersion::V1Alpha2).context(MergeCrdSnafu)?,
AirflowCluster::try_convert,
)];
let conversion_webhook_options = ConversionWebhookOptions {
disable_crd_maintenance,
field_manager: FIELD_MANAGER.to_owned(),
};
let (conversion_webhook, initial_reconcile_rx) =
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(),
};
let webhook_server =
WebhookServer::new(vec![Box::new(conversion_webhook)], webhook_server_options)
.await
.context(CreateWebhookSnafu)?;
Ok((webhook_server, initial_reconcile_rx))
}