pub struct ConversionWebhookServer { /* private fields */ }
Expand description
A ready-to-use CRD conversion webhook server.
See ConversionWebhookServer::new()
for usage examples.
Implementations§
Source§impl ConversionWebhookServer
impl ConversionWebhookServer
Sourcepub async fn new<H>(
crds_and_handlers: impl IntoIterator<Item = (CustomResourceDefinition, H)>,
options: ConversionWebhookOptions,
client: Client,
) -> Result<Self, ConversionWebhookError>
pub async fn new<H>( crds_and_handlers: impl IntoIterator<Item = (CustomResourceDefinition, H)>, options: ConversionWebhookOptions, client: Client, ) -> Result<Self, ConversionWebhookError>
Creates a new conversion webhook server, which expects POST requests being made to the
/convert/{crd name}
endpoint.
You need to provide a few things for every CRD passed in via the crds_and_handlers
argument:
- The CRD
- A conversion function to convert between CRD versions. Typically you would use the
the auto-generated
try_convert
function on CRD spec definition structs for this. - A [
kube::Client
] used to create/update the CRDs.
The ConversionWebhookServer
takes care of reconciling the CRDs into the Kubernetes
cluster and takes care of adding itself as conversion webhook. This includes TLS
certificates and CA bundles.
§Example
use clap::Parser;
use stackable_webhook::{
servers::{ConversionWebhookServer, ConversionWebhookOptions},
constants::CONVERSION_WEBHOOK_HTTPS_PORT,
WebhookOptions
};
use stackable_operator::{
kube::Client,
crd::s3::{S3Connection, S3ConnectionVersion},
cli::ProductOperatorRun,
};
// Things that should already be in you operator:
const OPERATOR_NAME: &str = "product-operator";
let client = Client::try_default().await.expect("failed to create Kubernetes client");
let ProductOperatorRun {
operator_environment,
disable_crd_maintenance,
..
} = ProductOperatorRun::parse();
let crds_and_handlers = [
(
S3Connection::merged_crd(S3ConnectionVersion::V1Alpha1)
.expect("failed to merge S3Connection CRD"),
S3Connection::try_convert as fn(_) -> _,
),
];
let options = ConversionWebhookOptions {
socket_addr: format!("0.0.0.0:{CONVERSION_WEBHOOK_HTTPS_PORT}")
.parse()
.expect("static address is always valid"),
namespace: operator_environment.operator_namespace,
service_name: operator_environment.operator_service_name,
maintain_crds: !disable_crd_maintenance,
field_manager: OPERATOR_NAME.to_owned(),
};
// Construct the conversion webhook server
let conversion_webhook = ConversionWebhookServer::new(
crds_and_handlers,
options,
client,
)
.await
.expect("failed to create ConversionWebhookServer");
conversion_webhook.run().await.expect("failed to run ConversionWebhookServer");
pub async fn run(self) -> Result<(), ConversionWebhookError>
Auto Trait Implementations§
impl Freeze for ConversionWebhookServer
impl !RefUnwindSafe for ConversionWebhookServer
impl Send for ConversionWebhookServer
impl Sync for ConversionWebhookServer
impl Unpin for ConversionWebhookServer
impl !UnwindSafe for ConversionWebhookServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request
§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered
].