Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 60b2220

Browse files
committed
feat: add scaffolding for tcproute and udproute ctrls
Signed-off-by: Shane Utt <[email protected]>
1 parent 0da66d1 commit 60b2220

File tree

4 files changed

+173
-1
lines changed

4 files changed

+173
-1
lines changed

controlplane/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ mod gateway_utils;
2121
mod gatewayclass_controller;
2222
mod gatewayclass_utils;
2323
mod route_utils;
24+
mod tcproute_controller;
2425
mod traits;
26+
mod udproute_controller;
2527

2628
pub use gateway_controller::controller as gateway_controller;
2729
pub use gatewayclass_controller::controller as gatewayclass_controller;
30+
pub use tcproute_controller::controller as tcproute_controller;
31+
pub use udproute_controller::controller as udproute_controller;
2832

2933
use kube::Client;
3034
use thiserror::Error;

controlplane/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ pub async fn run() {
5252

5353
if let Err(error) = try_join!(
5454
gateway_controller(ctx.clone()),
55-
gatewayclass_controller(ctx),
55+
gatewayclass_controller(ctx.clone()),
56+
tcproute_controller(ctx.clone()),
57+
udproute_controller(ctx),
5658
setup_health_checks(IpAddr::from(Ipv4Addr::new(0, 0, 0, 0)), 8080)
5759
) {
5860
error!("failed to start controllers: {error:?}");
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
use futures::StreamExt;
18+
use std::{sync::Arc, time::Duration};
19+
20+
use crate::{Context, Error, Result};
21+
22+
use gateway_api::apis::experimental::tcproutes::TCPRoute;
23+
use kube::{
24+
api::{Api, ListParams},
25+
runtime::{Controller, controller::Action, watcher::Config},
26+
};
27+
use tracing::{debug, info, warn};
28+
29+
pub async fn reconcile(tcproute: Arc<TCPRoute>, ctx: Arc<Context>) -> Result<Action> {
30+
let _client = ctx.client.clone();
31+
32+
let name = tcproute
33+
.metadata
34+
.name
35+
.clone()
36+
.ok_or(Error::InvalidConfigError(
37+
"no name provided for tcproute".to_string(),
38+
))?;
39+
40+
let ns = tcproute
41+
.metadata
42+
.namespace
43+
.clone()
44+
.ok_or(Error::InvalidConfigError(
45+
"invalid namespace for tcproute".to_string(),
46+
))?;
47+
48+
debug!("reconciling tcproute {}/{}", ns, name);
49+
50+
// TODO - implement cleanup
51+
52+
// TODO - check if the route is managed by our GatewayClass
53+
54+
// TODO - validation (port, protocol, etc.)
55+
56+
// TODO - dataplane configuration
57+
58+
info!("TODO: tcproute controller unimplemented");
59+
Ok(Action::await_change())
60+
}
61+
62+
pub async fn controller(ctx: Context) -> Result<()> {
63+
let tcproute_api = Api::<TCPRoute>::all(ctx.client.clone());
64+
65+
tcproute_api
66+
.list(&ListParams::default())
67+
.await
68+
.map_err(Error::CRDNotFoundError)?;
69+
70+
Controller::new(tcproute_api, Config::default().any_semantic())
71+
.shutdown_on_signal()
72+
.run(reconcile, error_policy, Arc::new(ctx))
73+
.filter_map(|x| async move { std::result::Result::ok(x) })
74+
.for_each(|_| futures::future::ready(()))
75+
.await;
76+
77+
Ok(())
78+
}
79+
80+
fn error_policy(_: Arc<TCPRoute>, error: &Error, _: Arc<Context>) -> Action {
81+
warn!("reconcile failed: {:?}", error);
82+
Action::requeue(Duration::from_secs(5))
83+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
use futures::StreamExt;
18+
use std::{sync::Arc, time::Duration};
19+
20+
use crate::{Context, Error, Result};
21+
22+
use gateway_api::apis::experimental::udproutes::UDPRoute;
23+
use kube::{
24+
api::{Api, ListParams},
25+
runtime::{Controller, controller::Action, watcher::Config},
26+
};
27+
use tracing::{debug, info, warn};
28+
29+
pub async fn reconcile(udproute: Arc<UDPRoute>, ctx: Arc<Context>) -> Result<Action> {
30+
let _client = ctx.client.clone();
31+
32+
let name = udproute
33+
.metadata
34+
.name
35+
.clone()
36+
.ok_or(Error::InvalidConfigError(
37+
"no name provided for udproute".to_string(),
38+
))?;
39+
40+
let ns = udproute
41+
.metadata
42+
.namespace
43+
.clone()
44+
.ok_or(Error::InvalidConfigError(
45+
"invalid namespace for udproute".to_string(),
46+
))?;
47+
48+
debug!("reconciling udproute {}/{}", ns, name);
49+
50+
// TODO - implement cleanup
51+
52+
// TODO - check if the route is managed by our GatewayClass
53+
54+
// TODO - validation (port, protocol, etc.)
55+
56+
// TODO - dataplane configuration
57+
58+
info!("TODO: udproute controller unimplemented");
59+
Ok(Action::await_change())
60+
}
61+
62+
pub async fn controller(ctx: Context) -> Result<()> {
63+
let udproute_api = Api::<UDPRoute>::all(ctx.client.clone());
64+
65+
udproute_api
66+
.list(&ListParams::default())
67+
.await
68+
.map_err(Error::CRDNotFoundError)?;
69+
70+
Controller::new(udproute_api, Config::default().any_semantic())
71+
.shutdown_on_signal()
72+
.run(reconcile, error_policy, Arc::new(ctx))
73+
.filter_map(|x| async move { std::result::Result::ok(x) })
74+
.for_each(|_| futures::future::ready(()))
75+
.await;
76+
77+
Ok(())
78+
}
79+
80+
fn error_policy(_: Arc<UDPRoute>, error: &Error, _: Arc<Context>) -> Action {
81+
warn!("reconcile failed: {:?}", error);
82+
Action::requeue(Duration::from_secs(5))
83+
}

0 commit comments

Comments
 (0)