@@ -10,13 +10,16 @@ use kube::{
1010 api:: { Patch , PatchParams } ,
1111} ;
1212use snafu:: { ResultExt , Snafu , ensure} ;
13- use stackable_webhook:: x509_cert:: { self , Certificate , EncodePem , LineEnding } ;
1413use tokio:: sync:: { mpsc, oneshot} ;
14+ use x509_cert:: {
15+ Certificate ,
16+ der:: { EncodePem , pem:: LineEnding } ,
17+ } ;
1518
1619#[ derive( Debug , Snafu ) ]
1720pub enum Error {
1821 #[ snafu( display( "failed to encode CA certificate as PEM format" ) ) ]
19- EncodeCertificateAuthorityAsPem { source : x509_cert:: Error } ,
22+ EncodeCertificateAuthorityAsPem { source : x509_cert:: der :: Error } ,
2023
2124 #[ snafu( display( "failed to send initial CRD reconcile heartbeat" ) ) ]
2225 SendInitialReconcileHeartbeat ,
@@ -34,17 +37,17 @@ pub enum Error {
3437///
3538/// - Apply the CRDs when starting up
3639/// - Reconcile the CRDs when the conversion webhook certificate is rotated
37- pub struct CustomResourceDefinitionMaintainer {
40+ pub struct CustomResourceDefinitionMaintainer < ' a > {
3841 client : Client ,
3942 certificate_rx : mpsc:: Receiver < Certificate > ,
4043
4144 definitions : Vec < CustomResourceDefinition > ,
42- options : CustomResourceDefinitionMaintainerOptions ,
45+ options : CustomResourceDefinitionMaintainerOptions < ' a > ,
4346
4447 initial_reconcile_tx : oneshot:: Sender < ( ) > ,
4548}
4649
47- impl CustomResourceDefinitionMaintainer {
50+ impl < ' a > CustomResourceDefinitionMaintainer < ' a > {
4851 /// Creates and returns a new [`CustomResourceDefinitionMaintainer`] which manages one or more
4952 /// custom resource definitions.
5053 ///
@@ -79,10 +82,10 @@ impl CustomResourceDefinitionMaintainer {
7982 ///
8083 /// ```no_run
8184 /// # use stackable_operator::crd::s3::{S3Connection, S3ConnectionVersion, S3Bucket, S3BucketVersion};
82- /// # use stackable_webhook::x509_cert::Certificate;
8385 /// # use tokio::sync::mpsc::channel;
86+ /// # use x509_cert::Certificate;
8487 /// # use kube::Client;
85- /// use stackable_operator::crd ::maintainer::{
88+ /// use stackable_webhook ::maintainer::{
8689 /// CustomResourceDefinitionMaintainerOptions,
8790 /// CustomResourceDefinitionMaintainer,
8891 /// };
@@ -91,9 +94,8 @@ impl CustomResourceDefinitionMaintainer {
9194 /// # async fn main() {
9295 /// # let (certificate_tx, certificate_rx) = channel(1);
9396 /// let options = CustomResourceDefinitionMaintainerOptions {
94- /// operator_service_name: "my-service-name".to_owned(),
95- /// operator_namespace: "my-namespace".to_owned(),
96- /// field_manager: "my-operator".to_owned(),
97+ /// operator_name: "my-service-name",
98+ /// operator_namespace: "my-namespace",
9799 /// webhook_https_port: 8443,
98100 /// disabled: true,
99101 /// };
@@ -117,7 +119,7 @@ impl CustomResourceDefinitionMaintainer {
117119 client : Client ,
118120 certificate_rx : mpsc:: Receiver < Certificate > ,
119121 definitions : impl IntoIterator < Item = CustomResourceDefinition > ,
120- options : CustomResourceDefinitionMaintainerOptions ,
122+ options : CustomResourceDefinitionMaintainerOptions < ' a > ,
121123 ) -> ( Self , oneshot:: Receiver < ( ) > ) {
122124 let ( initial_reconcile_tx, initial_reconcile_rx) = oneshot:: channel ( ) ;
123125
@@ -139,10 +141,9 @@ impl CustomResourceDefinitionMaintainer {
139141 /// [`std::task::Poll::Ready`] and thus doesn't consume any resources.
140142 pub async fn run ( mut self ) -> Result < ( ) , Error > {
141143 let CustomResourceDefinitionMaintainerOptions {
142- operator_service_name,
143144 operator_namespace,
144- field_manager ,
145- webhook_https_port : https_port ,
145+ webhook_https_port ,
146+ operator_name ,
146147 disabled,
147148 } = self . options ;
148149
@@ -173,7 +174,7 @@ impl CustomResourceDefinitionMaintainer {
173174
174175 let crd_api: Api < CustomResourceDefinition > = Api :: all ( self . client . clone ( ) ) ;
175176
176- for mut crd in self . definitions . iter ( ) . cloned ( ) {
177+ for crd in self . definitions . iter_mut ( ) {
177178 let crd_kind = & crd. spec . names . kind ;
178179 let crd_name = crd. name_any ( ) ;
179180
@@ -195,10 +196,10 @@ impl CustomResourceDefinitionMaintainer {
195196 conversion_review_versions : vec ! [ "v1" . to_owned( ) ] ,
196197 client_config : Some ( WebhookClientConfig {
197198 service : Some ( ServiceReference {
198- name : operator_service_name . clone ( ) ,
199- namespace : operator_namespace. clone ( ) ,
199+ name : operator_name . to_owned ( ) ,
200+ namespace : operator_namespace. to_owned ( ) ,
200201 path : Some ( format ! ( "/convert/{crd_name}" ) ) ,
201- port : Some ( https_port . into ( ) ) ,
202+ port : Some ( webhook_https_port . into ( ) ) ,
202203 } ) ,
203204 // Here, ByteString takes care of encoding the provided content as
204205 // base64.
@@ -210,7 +211,7 @@ impl CustomResourceDefinitionMaintainer {
210211
211212 // Deploy the updated CRDs using a server-side apply.
212213 let patch = Patch :: Apply ( & crd) ;
213- let patch_params = PatchParams :: apply ( & field_manager ) ;
214+ let patch_params = PatchParams :: apply ( operator_name ) ;
214215 crd_api
215216 . patch ( & crd_name, & patch_params, & patch)
216217 . await
@@ -233,15 +234,12 @@ impl CustomResourceDefinitionMaintainer {
233234
234235// TODO (@Techassi): Make this a builder instead
235236/// This contains required options to customize a [`CustomResourceDefinitionMaintainer`].
236- pub struct CustomResourceDefinitionMaintainerOptions {
237- /// The service name used by the operator/conversion webhook.
238- pub operator_service_name : String ,
237+ pub struct CustomResourceDefinitionMaintainerOptions < ' a > {
238+ /// The service name used by the operator/conversion webhook and as a field manager .
239+ pub operator_name : & ' a str ,
239240
240241 /// The namespace the operator/conversion webhook runs in.
241- pub operator_namespace : String ,
242-
243- /// The name of the field manager used for the server-side apply.
244- pub field_manager : String ,
242+ pub operator_namespace : & ' a str ,
245243
246244 /// The HTTPS port the conversion webhook listens on.
247245 pub webhook_https_port : u16 ,
0 commit comments