This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Webhooks for Controller Manager API #55
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
//! Defines types for registering controllers with runtime. | ||
use crate::{operator::Operator, store::Store}; | ||
|
||
// use std::sync::Arc; | ||
#[cfg(feature = "admission-webhook")] | ||
use warp::Filter; | ||
pub mod tasks; | ||
use tasks::{controller_tasks, OperatorTask}; | ||
|
||
|
@@ -20,23 +22,53 @@ pub struct Manager { | |
controllers: Vec<Controller>, | ||
controller_tasks: Vec<OperatorTask>, | ||
store: Store, | ||
#[cfg(feature = "admission-webhook")] | ||
filter: warp::filters::BoxedFilter<(warp::reply::WithStatus<warp::reply::Json>,)>, | ||
} | ||
|
||
#[cfg(feature = "admission-webhook")] | ||
fn not_found() -> warp::reply::WithStatus<warp::reply::Json> { | ||
warp::reply::with_status(warp::reply::json(&()), warp::http::StatusCode::NOT_FOUND) | ||
} | ||
|
||
impl Manager { | ||
/// Create a new controller manager. | ||
pub fn new(kubeconfig: &kube::Config) -> Self { | ||
#[cfg(feature = "admission-webhook")] | ||
let filter = { warp::any().map(not_found).boxed() }; | ||
|
||
Manager { | ||
controllers: vec![], | ||
controller_tasks: vec![], | ||
kubeconfig: kubeconfig.clone(), | ||
store: Store::new(), | ||
#[cfg(feature = "admission-webhook")] | ||
filter, | ||
} | ||
} | ||
|
||
/// Register a controller with the manager. | ||
pub fn register_controller<C: Operator>(&mut self, builder: ControllerBuilder<C>) { | ||
#[cfg(feature = "admission-webhook")] | ||
for endpoint in builder.webhooks.values() { | ||
// Create temporary variable w/ throwaway filter of correct type. | ||
let mut temp = warp::any().map(not_found).boxed(); | ||
|
||
// Swap self.filter into temporary. | ||
std::mem::swap(&mut temp, &mut self.filter); | ||
|
||
// Compose new filter from new endpoint and temporary (now holding original self.filter). | ||
let mut new_filter = endpoint.clone().or(temp).unify().boxed(); | ||
|
||
// Swap new filter back into self.filter. | ||
std::mem::swap(&mut new_filter, &mut self.filter); | ||
|
||
// Throwaway filter stored in new_filter implicitly dropped. | ||
} | ||
|
||
let (controller, tasks) = | ||
controller_tasks(self.kubeconfig.clone(), builder, self.store.clone()); | ||
|
||
self.controllers.push(controller); | ||
self.controller_tasks.extend(tasks); | ||
} | ||
|
@@ -62,6 +94,16 @@ impl Manager { | |
} | ||
} | ||
|
||
#[cfg(feature = "admission-webhook")] | ||
{ | ||
let task = warp::serve(self.filter) | ||
// .tls() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Figure out where to load certs from. |
||
// .cert(tls.cert) | ||
// .key(tls.private_key) | ||
.run(([0, 0, 0, 0], 8443)); | ||
tasks.push(task.boxed()); | ||
} | ||
|
||
futures::future::join_all(tasks).await; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figure out how to remove the original trait method, but still support the old API.