Compare commits
14 Commits
379ae5e80f
...
a117fcbba6
Author | SHA1 | Date | |
---|---|---|---|
a117fcbba6 | |||
4b6e843d5d | |||
31477b6beb | |||
40ee96d714 | |||
eaa96d1d5b | |||
847927364f | |||
1e278e592f | |||
85da15881e | |||
21bb89a20f | |||
3dab736239 | |||
d594e1a84b | |||
3717d54bb0 | |||
54a02b1855 | |||
06aab3b1ca |
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1425,6 +1425,7 @@ name = "lldap-controller"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
"cynic",
|
"cynic",
|
||||||
"futures",
|
"futures",
|
||||||
|
|
|
@ -30,6 +30,7 @@ tracing = "0.1.41"
|
||||||
thiserror = "2.0.12"
|
thiserror = "2.0.12"
|
||||||
chrono = "0.4.40"
|
chrono = "0.4.40"
|
||||||
passwords = "3.1.16"
|
passwords = "3.1.16"
|
||||||
|
async-trait = "0.1.88"
|
||||||
reqwest = { version = "0.12.14", default-features = false, features = [
|
reqwest = { version = "0.12.14", default-features = false, features = [
|
||||||
"json",
|
"json",
|
||||||
"rustls-tls",
|
"rustls-tls",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
apiVersion: lldap.huizinga.dev/v1
|
apiVersion: lldap.huizinga.dev/v1
|
||||||
kind: ServiceUser
|
kind: ServiceUser
|
||||||
metadata:
|
metadata:
|
||||||
name: test-user
|
name: authelia
|
||||||
spec: {}
|
spec:
|
||||||
|
passwordManager: false
|
|
@ -86,30 +86,6 @@ pub struct GetGroups {
|
||||||
pub groups: Vec<Group>,
|
pub groups: Vec<Group>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(cynic::QueryVariables, Debug)]
|
|
||||||
pub struct CreateGroupVariables<'a> {
|
|
||||||
pub name: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
|
||||||
#[cynic(graphql_type = "Mutation", variables = "CreateGroupVariables")]
|
|
||||||
pub struct CreateGroup {
|
|
||||||
#[arguments(name: $name)]
|
|
||||||
pub create_group: Group,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(cynic::QueryVariables, Debug)]
|
|
||||||
pub struct DeleteGroupVariables {
|
|
||||||
pub id: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
|
||||||
#[cynic(graphql_type = "Mutation", variables = "DeleteGroupVariables")]
|
|
||||||
pub struct DeleteGroup {
|
|
||||||
#[arguments(groupId: $id)]
|
|
||||||
pub delete_group: Success,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use cynic::{MutationBuilder, QueryBuilder};
|
use cynic::{MutationBuilder, QueryBuilder};
|
||||||
|
@ -163,18 +139,4 @@ mod tests {
|
||||||
|
|
||||||
insta::assert_snapshot!(operation.query);
|
insta::assert_snapshot!(operation.query);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn create_group_gql_output() {
|
|
||||||
let operation = CreateGroup::build(CreateGroupVariables { name: "group" });
|
|
||||||
|
|
||||||
insta::assert_snapshot!(operation.query);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn delete_group_gql_output() {
|
|
||||||
let operation = DeleteGroup::build(DeleteGroupVariables { id: 0 });
|
|
||||||
|
|
||||||
insta::assert_snapshot!(operation.query);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
---
|
|
||||||
source: queries/src/lib.rs
|
|
||||||
expression: operation.query
|
|
||||||
---
|
|
||||||
mutation CreateGroup($name: String!) {
|
|
||||||
createGroup(name: $name) {
|
|
||||||
id
|
|
||||||
displayName
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
---
|
|
||||||
source: queries/src/lib.rs
|
|
||||||
expression: operation.query
|
|
||||||
---
|
|
||||||
mutation DeleteGroup($id: Int!) {
|
|
||||||
deleteGroup(groupId: $id) {
|
|
||||||
ok
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,8 +2,7 @@ use kube::CustomResourceExt;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
print!(
|
print!(
|
||||||
"{}---\n{}",
|
"{}",
|
||||||
serde_yaml::to_string(&lldap_controller::resources::ServiceUser::crd()).unwrap(),
|
serde_yaml::to_string(&lldap_controller::resources::ServiceUser::crd()).unwrap()
|
||||||
serde_yaml::to_string(&lldap_controller::resources::Group::crd()).unwrap()
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
use async_trait::async_trait;
|
||||||
use k8s_openapi::api::core::v1::Secret;
|
use k8s_openapi::api::core::v1::Secret;
|
||||||
use kube::runtime::events::{Event, EventType, Recorder, Reporter};
|
use kube::runtime::events::{Event, EventType, Recorder, Reporter};
|
||||||
use kube::{Resource, ResourceExt};
|
use kube::{Resource, ResourceExt};
|
||||||
|
|
||||||
use crate::lldap::LldapConfig;
|
use crate::lldap::LldapConfig;
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
pub client: kube::Client,
|
pub client: kube::Client,
|
||||||
pub lldap_config: LldapConfig,
|
pub lldap_config: LldapConfig,
|
||||||
|
@ -26,7 +26,7 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(async_fn_in_trait)]
|
#[async_trait]
|
||||||
pub trait ControllerEvents {
|
pub trait ControllerEvents {
|
||||||
type Error;
|
type Error;
|
||||||
|
|
||||||
|
@ -38,23 +38,16 @@ pub trait ControllerEvents {
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync;
|
T: Resource<DynamicType = ()> + Sync;
|
||||||
|
|
||||||
async fn group_created<T>(&self, obj: &T, name: &str) -> Result<(), Self::Error>
|
|
||||||
where
|
|
||||||
T: Resource<DynamicType = ()> + Sync;
|
|
||||||
|
|
||||||
async fn user_deleted<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
async fn user_deleted<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync;
|
T: Resource<DynamicType = ()> + Sync;
|
||||||
|
|
||||||
async fn group_deleted<T>(&self, obj: &T, name: &str) -> Result<(), Self::Error>
|
|
||||||
where
|
|
||||||
T: Resource<DynamicType = ()> + Sync;
|
|
||||||
|
|
||||||
async fn user_not_found<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
async fn user_not_found<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync;
|
T: Resource<DynamicType = ()> + Sync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
impl ControllerEvents for Recorder {
|
impl ControllerEvents for Recorder {
|
||||||
type Error = kube::Error;
|
type Error = kube::Error;
|
||||||
|
|
||||||
|
@ -92,23 +85,6 @@ impl ControllerEvents for Recorder {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn group_created<T>(&self, obj: &T, name: &str) -> Result<(), Self::Error>
|
|
||||||
where
|
|
||||||
T: Resource<DynamicType = ()> + Sync,
|
|
||||||
{
|
|
||||||
self.publish(
|
|
||||||
&Event {
|
|
||||||
type_: EventType::Normal,
|
|
||||||
reason: "GroupCreated".into(),
|
|
||||||
note: Some(format!("Created group '{name}'")),
|
|
||||||
action: "GroupCreated".into(),
|
|
||||||
secondary: None,
|
|
||||||
},
|
|
||||||
&obj.object_ref(&()),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn user_deleted<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
async fn user_deleted<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync,
|
T: Resource<DynamicType = ()> + Sync,
|
||||||
|
@ -126,23 +102,6 @@ impl ControllerEvents for Recorder {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn group_deleted<T>(&self, obj: &T, name: &str) -> Result<(), Self::Error>
|
|
||||||
where
|
|
||||||
T: Resource<DynamicType = ()> + Sync,
|
|
||||||
{
|
|
||||||
self.publish(
|
|
||||||
&Event {
|
|
||||||
type_: EventType::Normal,
|
|
||||||
reason: "GroupDeleted".into(),
|
|
||||||
note: Some(format!("Deleted group '{name}'")),
|
|
||||||
action: "GroupDeleted".into(),
|
|
||||||
secondary: None,
|
|
||||||
},
|
|
||||||
&obj.object_ref(&()),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn user_not_found<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
async fn user_not_found<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync,
|
T: Resource<DynamicType = ()> + Sync,
|
||||||
|
|
34
src/lldap.rs
34
src/lldap.rs
|
@ -8,10 +8,9 @@ use lldap_auth::opaque::AuthenticationError;
|
||||||
use lldap_auth::registration::ServerRegistrationStartResponse;
|
use lldap_auth::registration::ServerRegistrationStartResponse;
|
||||||
use lldap_auth::{opaque, registration};
|
use lldap_auth::{opaque, registration};
|
||||||
use queries::{
|
use queries::{
|
||||||
AddUserToGroup, AddUserToGroupVariables, CreateGroup, CreateGroupVariables, CreateUser,
|
AddUserToGroup, AddUserToGroupVariables, CreateUser, CreateUserVariables, DeleteUser,
|
||||||
CreateUserVariables, DeleteGroup, DeleteGroupVariables, DeleteUser, DeleteUserVariables,
|
DeleteUserVariables, GetGroups, GetUser, GetUserVariables, Group, RemoveUserFromGroup,
|
||||||
GetGroups, GetUser, GetUserVariables, Group, RemoveUserFromGroup, RemoveUserFromGroupVariables,
|
RemoveUserFromGroupVariables, User,
|
||||||
User,
|
|
||||||
};
|
};
|
||||||
use reqwest::header::{AUTHORIZATION, HeaderMap, HeaderValue};
|
use reqwest::header::{AUTHORIZATION, HeaderMap, HeaderValue};
|
||||||
use tracing::{debug, trace};
|
use tracing::{debug, trace};
|
||||||
|
@ -42,7 +41,6 @@ fn check_graphql_errors<T>(response: GraphQlResponse<T>) -> Result<T> {
|
||||||
.expect("Data should be valid if there are no error"))
|
.expect("Data should be valid if there are no error"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct LldapConfig {
|
pub struct LldapConfig {
|
||||||
username: String,
|
username: String,
|
||||||
password: String,
|
password: String,
|
||||||
|
@ -152,32 +150,6 @@ impl LldapClient {
|
||||||
Ok(check_graphql_errors(response)?.groups)
|
Ok(check_graphql_errors(response)?.groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_group(&self, name: &str) -> Result<Group> {
|
|
||||||
let operation = CreateGroup::build(CreateGroupVariables { name });
|
|
||||||
|
|
||||||
let response = self
|
|
||||||
.client
|
|
||||||
.post(format!("{}/api/graphql", self.url))
|
|
||||||
.run_graphql(operation)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(check_graphql_errors(response)?.create_group)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete_group(&self, id: i32) -> Result<()> {
|
|
||||||
let operation = DeleteGroup::build(DeleteGroupVariables { id });
|
|
||||||
|
|
||||||
let response = self
|
|
||||||
.client
|
|
||||||
.post(format!("{}/api/graphql", self.url))
|
|
||||||
.run_graphql(operation)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
check_graphql_errors(response)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn add_user_to_group(&self, username: &str, group: i32) -> Result<()> {
|
pub async fn add_user_to_group(&self, username: &str, group: i32) -> Result<()> {
|
||||||
let operation = AddUserToGroup::build(AddUserToGroupVariables { username, group });
|
let operation = AddUserToGroup::build(AddUserToGroupVariables { username, group });
|
||||||
|
|
||||||
|
|
48
src/main.rs
48
src/main.rs
|
@ -3,47 +3,30 @@ use std::time::Duration;
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use k8s_openapi::api::core::v1::Secret;
|
use k8s_openapi::api::core::v1::Secret;
|
||||||
use kube::runtime::controller::{self, Action};
|
use kube::runtime::Controller;
|
||||||
use kube::runtime::reflector::ObjectRef;
|
use kube::runtime::controller::Action;
|
||||||
use kube::runtime::{Controller, watcher};
|
use kube::{Api, Client as KubeClient};
|
||||||
use kube::{Api, Client as KubeClient, Resource};
|
|
||||||
use lldap_controller::context::Context;
|
use lldap_controller::context::Context;
|
||||||
use lldap_controller::lldap::LldapConfig;
|
use lldap_controller::lldap::LldapConfig;
|
||||||
use lldap_controller::resources::{self, Error, Group, ServiceUser, reconcile};
|
use lldap_controller::resources::{self, ServiceUser, reconcile};
|
||||||
use tracing::{debug, info, warn};
|
use tracing::{debug, info, warn};
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
use tracing_subscriber::util::SubscriberInitExt;
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
use tracing_subscriber::{EnvFilter, Registry};
|
use tracing_subscriber::{EnvFilter, Registry};
|
||||||
|
|
||||||
fn error_policy<T>(_obj: Arc<T>, err: &resources::Error, _ctx: Arc<Context>) -> Action {
|
fn error_policy(_obj: Arc<ServiceUser>, err: &resources::Error, _ctx: Arc<Context>) -> Action {
|
||||||
warn!("error: {}", err);
|
warn!("error: {}", err);
|
||||||
Action::requeue(Duration::from_secs(5))
|
Action::requeue(Duration::from_secs(5))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn log_status<T>(
|
|
||||||
res: Result<(ObjectRef<T>, Action), controller::Error<Error, watcher::Error>>,
|
|
||||||
) where
|
|
||||||
T: Resource,
|
|
||||||
{
|
|
||||||
match res {
|
|
||||||
Ok(obj) => debug!("reconciled {:?}", obj.0.name),
|
|
||||||
Err(err) => warn!("reconcile failed: {}", err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
|
let logger = tracing_subscriber::fmt::layer().json();
|
||||||
let env_filter = EnvFilter::try_from_default_env()
|
let env_filter = EnvFilter::try_from_default_env()
|
||||||
.or_else(|_| EnvFilter::try_new("info"))
|
.or_else(|_| EnvFilter::try_new("info"))
|
||||||
.expect("Fallback should be valid");
|
.expect("Fallback should be valid");
|
||||||
|
|
||||||
if std::env::var("CARGO").is_ok() {
|
|
||||||
let logger = tracing_subscriber::fmt::layer().compact();
|
|
||||||
Registry::default().with(logger).with(env_filter).init();
|
Registry::default().with(logger).with(env_filter).init();
|
||||||
} else {
|
|
||||||
let logger = tracing_subscriber::fmt::layer().json();
|
|
||||||
Registry::default().with(logger).with(env_filter).init();
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("Starting controller");
|
info!("Starting controller");
|
||||||
|
|
||||||
|
@ -58,20 +41,17 @@ async fn main() -> anyhow::Result<()> {
|
||||||
let service_users = Api::<ServiceUser>::all(client.clone());
|
let service_users = Api::<ServiceUser>::all(client.clone());
|
||||||
let secrets = Api::<Secret>::all(client.clone());
|
let secrets = Api::<Secret>::all(client.clone());
|
||||||
|
|
||||||
let service_user_controller = Controller::new(service_users, Default::default())
|
Controller::new(service_users.clone(), Default::default())
|
||||||
.owns(secrets, Default::default())
|
.owns(secrets, Default::default())
|
||||||
.shutdown_on_signal()
|
|
||||||
.run(reconcile, error_policy, Arc::new(data.clone()))
|
|
||||||
.for_each(log_status);
|
|
||||||
|
|
||||||
let groups = Api::<Group>::all(client.clone());
|
|
||||||
|
|
||||||
let group_controller = Controller::new(groups, Default::default())
|
|
||||||
.shutdown_on_signal()
|
.shutdown_on_signal()
|
||||||
.run(reconcile, error_policy, Arc::new(data))
|
.run(reconcile, error_policy, Arc::new(data))
|
||||||
.for_each(log_status);
|
.for_each(|res| async move {
|
||||||
|
match res {
|
||||||
tokio::join!(service_user_controller, group_controller);
|
Ok(obj) => debug!("reconciled {:?}", obj.0.name),
|
||||||
|
Err(err) => warn!("reconcile failed: {}", err),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
use std::sync::Arc;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use kube::CustomResource;
|
|
||||||
use kube::runtime::controller::Action;
|
|
||||||
use schemars::JsonSchema;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use tracing::{debug, trace};
|
|
||||||
|
|
||||||
use super::{Error, Reconcile, Result};
|
|
||||||
use crate::context::{Context, ControllerEvents};
|
|
||||||
|
|
||||||
#[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)]
|
|
||||||
#[kube(kind = "Group", group = "lldap.huizinga.dev", version = "v1")]
|
|
||||||
#[kube(
|
|
||||||
shortname = "lg",
|
|
||||||
doc = "Custom resource for managing Groups inside of LLDAP"
|
|
||||||
)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct GroupSpec {}
|
|
||||||
|
|
||||||
impl Reconcile for Group {
|
|
||||||
async fn reconcile(self: Arc<Self>, ctx: Arc<Context>) -> Result<Action> {
|
|
||||||
let name = self
|
|
||||||
.metadata
|
|
||||||
.name
|
|
||||||
.clone()
|
|
||||||
.ok_or(Error::MissingObjectKey(".metadata.name"))?;
|
|
||||||
|
|
||||||
debug!(name, "Apply");
|
|
||||||
|
|
||||||
let lldap_client = ctx.lldap_config.build_client().await?;
|
|
||||||
|
|
||||||
trace!(name, "Get existing groups");
|
|
||||||
let groups = lldap_client.get_groups().await?;
|
|
||||||
|
|
||||||
if !groups.iter().any(|group| group.display_name == name) {
|
|
||||||
trace!("Group does not exist yet");
|
|
||||||
|
|
||||||
lldap_client.create_group(&name).await?;
|
|
||||||
|
|
||||||
ctx.recorder.group_created(self.as_ref(), &name).await?;
|
|
||||||
} else {
|
|
||||||
trace!("Group already exists");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Action::requeue(Duration::from_secs(3600)))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn cleanup(self: Arc<Self>, ctx: Arc<Context>) -> Result<Action> {
|
|
||||||
let name = self
|
|
||||||
.metadata
|
|
||||||
.name
|
|
||||||
.clone()
|
|
||||||
.ok_or(Error::MissingObjectKey(".metadata.name"))?;
|
|
||||||
|
|
||||||
debug!(name, "Cleanup");
|
|
||||||
|
|
||||||
let lldap_client = ctx.lldap_config.build_client().await?;
|
|
||||||
|
|
||||||
trace!(name, "Get existing groups");
|
|
||||||
let groups = lldap_client.get_groups().await?;
|
|
||||||
|
|
||||||
if let Some(group) = groups.iter().find(|group| group.display_name == name) {
|
|
||||||
trace!(name, "Deleting group");
|
|
||||||
|
|
||||||
lldap_client.delete_group(group.id).await?;
|
|
||||||
|
|
||||||
ctx.recorder.group_deleted(self.as_ref(), &name).await?;
|
|
||||||
} else {
|
|
||||||
trace!(name, "Group does not exist")
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Action::await_change())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +1,10 @@
|
||||||
mod group;
|
|
||||||
mod service_user;
|
mod service_user;
|
||||||
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use k8s_openapi::NamespaceResourceScope;
|
||||||
use kube::runtime::controller::Action;
|
use kube::runtime::controller::Action;
|
||||||
use kube::runtime::finalizer;
|
use kube::runtime::finalizer;
|
||||||
use kube::{Api, Resource, ResourceExt};
|
use kube::{Api, Resource, ResourceExt};
|
||||||
|
@ -11,7 +12,6 @@ use serde::Serialize;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use tracing::{debug, instrument};
|
use tracing::{debug, instrument};
|
||||||
|
|
||||||
pub use self::group::Group;
|
|
||||||
pub use self::service_user::ServiceUser;
|
pub use self::service_user::ServiceUser;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::lldap;
|
use crate::lldap;
|
||||||
|
@ -38,6 +38,7 @@ impl From<finalizer::Error<Self>> for Error {
|
||||||
|
|
||||||
type Result<T, E = Error> = std::result::Result<T, E>;
|
type Result<T, E = Error> = std::result::Result<T, E>;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
trait Reconcile {
|
trait Reconcile {
|
||||||
async fn reconcile(self: Arc<Self>, ctx: Arc<Context>) -> Result<Action>;
|
async fn reconcile(self: Arc<Self>, ctx: Arc<Context>) -> Result<Action>;
|
||||||
|
|
||||||
|
@ -47,12 +48,19 @@ trait Reconcile {
|
||||||
#[instrument(skip(obj, ctx))]
|
#[instrument(skip(obj, ctx))]
|
||||||
pub async fn reconcile<T>(obj: Arc<T>, ctx: Arc<Context>) -> Result<Action>
|
pub async fn reconcile<T>(obj: Arc<T>, ctx: Arc<Context>) -> Result<Action>
|
||||||
where
|
where
|
||||||
T: Resource + ResourceExt + Clone + Serialize + DeserializeOwned + fmt::Debug + Reconcile,
|
T: Resource<Scope = NamespaceResourceScope>
|
||||||
|
+ ResourceExt
|
||||||
|
+ Clone
|
||||||
|
+ Serialize
|
||||||
|
+ DeserializeOwned
|
||||||
|
+ fmt::Debug
|
||||||
|
+ Reconcile,
|
||||||
<T as Resource>::DynamicType: Default,
|
<T as Resource>::DynamicType: Default,
|
||||||
{
|
{
|
||||||
debug!(name = obj.name_any(), "Reconcile");
|
debug!(name = obj.name_any(), "Reconcile");
|
||||||
|
|
||||||
let service_users = Api::<T>::all(ctx.client.clone());
|
let namespace = obj.namespace().expect("Resource is namespace scoped");
|
||||||
|
let service_users = Api::<T>::namespaced(ctx.client.clone(), &namespace);
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
finalizer(&service_users, &ctx.controller_name, obj, |event| async {
|
finalizer(&service_users, &ctx.controller_name, obj, |event| async {
|
||||||
|
|
|
@ -3,6 +3,7 @@ use std::str::from_utf8;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use async_trait::async_trait;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use k8s_openapi::api::core::v1::Secret;
|
use k8s_openapi::api::core::v1::Secret;
|
||||||
use k8s_openapi::apimachinery::pkg::apis::meta::v1::OwnerReference;
|
use k8s_openapi::apimachinery::pkg::apis::meta::v1::OwnerReference;
|
||||||
|
@ -75,6 +76,7 @@ fn format_username(name: &str, namespace: &str) -> String {
|
||||||
format!("{name}.{namespace}")
|
format!("{name}.{namespace}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
impl Reconcile for ServiceUser {
|
impl Reconcile for ServiceUser {
|
||||||
async fn reconcile(self: Arc<Self>, ctx: Arc<Context>) -> Result<Action> {
|
async fn reconcile(self: Arc<Self>, ctx: Arc<Context>) -> Result<Action> {
|
||||||
let name = self
|
let name = self
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
apiVersion: lldap.huizinga.dev/v1
|
|
||||||
kind: Group
|
|
||||||
metadata:
|
|
||||||
name: test-group
|
|
||||||
spec: {}
|
|
Loading…
Reference in New Issue
Block a user