@@ -10,13 +10,16 @@ use kube::{
10
10
api:: { Patch , PatchParams } ,
11
11
} ;
12
12
use snafu:: { ResultExt , Snafu , ensure} ;
13
- use stackable_webhook:: x509_cert:: { self , Certificate , EncodePem , LineEnding } ;
14
13
use tokio:: sync:: { mpsc, oneshot} ;
14
+ use x509_cert:: {
15
+ Certificate ,
16
+ der:: { EncodePem , pem:: LineEnding } ,
17
+ } ;
15
18
16
19
#[ derive( Debug , Snafu ) ]
17
20
pub enum Error {
18
21
#[ snafu( display( "failed to encode CA certificate as PEM format" ) ) ]
19
- EncodeCertificateAuthorityAsPem { source : x509_cert:: Error } ,
22
+ EncodeCertificateAuthorityAsPem { source : x509_cert:: der :: Error } ,
20
23
21
24
#[ snafu( display( "failed to send initial CRD reconcile heartbeat" ) ) ]
22
25
SendInitialReconcileHeartbeat ,
@@ -34,17 +37,17 @@ pub enum Error {
34
37
///
35
38
/// - Apply the CRDs when starting up
36
39
/// - Reconcile the CRDs when the conversion webhook certificate is rotated
37
- pub struct CustomResourceDefinitionMaintainer {
40
+ pub struct CustomResourceDefinitionMaintainer < ' a > {
38
41
client : Client ,
39
42
certificate_rx : mpsc:: Receiver < Certificate > ,
40
43
41
44
definitions : Vec < CustomResourceDefinition > ,
42
- options : CustomResourceDefinitionMaintainerOptions ,
45
+ options : CustomResourceDefinitionMaintainerOptions < ' a > ,
43
46
44
47
initial_reconcile_tx : oneshot:: Sender < ( ) > ,
45
48
}
46
49
47
- impl CustomResourceDefinitionMaintainer {
50
+ impl < ' a > CustomResourceDefinitionMaintainer < ' a > {
48
51
/// Creates and returns a new [`CustomResourceDefinitionMaintainer`] which manages one or more
49
52
/// custom resource definitions.
50
53
///
@@ -79,10 +82,10 @@ impl CustomResourceDefinitionMaintainer {
79
82
///
80
83
/// ```no_run
81
84
/// # use stackable_operator::crd::s3::{S3Connection, S3ConnectionVersion, S3Bucket, S3BucketVersion};
82
- /// # use stackable_webhook::x509_cert::Certificate;
83
85
/// # use tokio::sync::mpsc::channel;
86
+ /// # use x509_cert::Certificate;
84
87
/// # use kube::Client;
85
- /// use stackable_operator::crd ::maintainer::{
88
+ /// use stackable_webhook ::maintainer::{
86
89
/// CustomResourceDefinitionMaintainerOptions,
87
90
/// CustomResourceDefinitionMaintainer,
88
91
/// };
@@ -91,9 +94,8 @@ impl CustomResourceDefinitionMaintainer {
91
94
/// # async fn main() {
92
95
/// # let (certificate_tx, certificate_rx) = channel(1);
93
96
/// 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",
97
99
/// webhook_https_port: 8443,
98
100
/// disabled: true,
99
101
/// };
@@ -117,7 +119,7 @@ impl CustomResourceDefinitionMaintainer {
117
119
client : Client ,
118
120
certificate_rx : mpsc:: Receiver < Certificate > ,
119
121
definitions : impl IntoIterator < Item = CustomResourceDefinition > ,
120
- options : CustomResourceDefinitionMaintainerOptions ,
122
+ options : CustomResourceDefinitionMaintainerOptions < ' a > ,
121
123
) -> ( Self , oneshot:: Receiver < ( ) > ) {
122
124
let ( initial_reconcile_tx, initial_reconcile_rx) = oneshot:: channel ( ) ;
123
125
@@ -139,10 +141,9 @@ impl CustomResourceDefinitionMaintainer {
139
141
/// [`std::task::Poll::Ready`] and thus doesn't consume any resources.
140
142
pub async fn run ( mut self ) -> Result < ( ) , Error > {
141
143
let CustomResourceDefinitionMaintainerOptions {
142
- operator_service_name,
143
144
operator_namespace,
144
- field_manager ,
145
- webhook_https_port : https_port ,
145
+ webhook_https_port ,
146
+ operator_name ,
146
147
disabled,
147
148
} = self . options ;
148
149
@@ -173,7 +174,7 @@ impl CustomResourceDefinitionMaintainer {
173
174
174
175
let crd_api: Api < CustomResourceDefinition > = Api :: all ( self . client . clone ( ) ) ;
175
176
176
- for mut crd in self . definitions . iter ( ) . cloned ( ) {
177
+ for crd in self . definitions . iter_mut ( ) {
177
178
let crd_kind = & crd. spec . names . kind ;
178
179
let crd_name = crd. name_any ( ) ;
179
180
@@ -195,10 +196,10 @@ impl CustomResourceDefinitionMaintainer {
195
196
conversion_review_versions : vec ! [ "v1" . to_owned( ) ] ,
196
197
client_config : Some ( WebhookClientConfig {
197
198
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 ( ) ,
200
201
path : Some ( format ! ( "/convert/{crd_name}" ) ) ,
201
- port : Some ( https_port . into ( ) ) ,
202
+ port : Some ( webhook_https_port . into ( ) ) ,
202
203
} ) ,
203
204
// Here, ByteString takes care of encoding the provided content as
204
205
// base64.
@@ -210,7 +211,7 @@ impl CustomResourceDefinitionMaintainer {
210
211
211
212
// Deploy the updated CRDs using a server-side apply.
212
213
let patch = Patch :: Apply ( & crd) ;
213
- let patch_params = PatchParams :: apply ( & field_manager ) ;
214
+ let patch_params = PatchParams :: apply ( operator_name ) ;
214
215
crd_api
215
216
. patch ( & crd_name, & patch_params, & patch)
216
217
. await
@@ -233,15 +234,12 @@ impl CustomResourceDefinitionMaintainer {
233
234
234
235
// TODO (@Techassi): Make this a builder instead
235
236
/// 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 ,
239
240
240
241
/// 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 ,
245
243
246
244
/// The HTTPS port the conversion webhook listens on.
247
245
pub webhook_https_port : u16 ,
0 commit comments