Skip to content

Commit 47d4a92

Browse files
CopilotkorewaChino
andcommitted
Fix exit node selection to read annotation from service instead of exit node
- Changed logic to check Service annotations for exit-node-name instead of ExitNode annotations - Added parsing of namespace/name format using parse_provisioner_label_value - Added tests to validate the parse_provisioner_label_value function - All tests pass and clippy runs clean Co-authored-by: korewaChino <[email protected]>
1 parent 94a94d1 commit 47d4a92

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

src/daemon.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,14 +474,24 @@ async fn reconcile_svcs(obj: Arc<Service>, ctx: Arc<Context>) -> Result<Action,
474474

475475
let node_list = nodes.list(&ListParams::default().timeout(30)).await?;
476476

477-
// Find service binding of svc name/namespace?
478-
let named_exit_node = node_list.iter().find(|node| {
479-
node.metadata
480-
.annotations
481-
.as_ref()
482-
.map(|annotations| annotations.contains_key(EXIT_NODE_NAME_LABEL))
483-
.unwrap_or(false)
484-
});
477+
// Check if service has explicitly set an exit node name
478+
let named_exit_node = obj
479+
.metadata
480+
.annotations
481+
.as_ref()
482+
.and_then(|annotations| annotations.get(EXIT_NODE_NAME_LABEL))
483+
.and_then(|exit_node_name| {
484+
// Parse the exit node name, which can be in the format "namespace/name" or just "name"
485+
let service_namespace = obj.namespace().unwrap();
486+
let (target_namespace, target_name) =
487+
parse_provisioner_label_value(&service_namespace, exit_node_name);
488+
489+
// Find the exit node with the matching name and namespace
490+
node_list.iter().find(|node| {
491+
node.metadata.name.as_deref() == Some(target_name)
492+
&& node.metadata.namespace.as_deref() == Some(target_namespace)
493+
})
494+
});
485495

486496
// XXX: Exit node manifest generation starts here
487497
let node = {

src/ops.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,29 @@ impl ExitNodeProvisioner {
237237
Ok(Some(secret))
238238
}
239239
}
240+
241+
#[cfg(test)]
242+
mod tests {
243+
use super::*;
244+
245+
#[test]
246+
fn test_parse_provisioner_label_value_with_namespace() {
247+
let (namespace, name) = parse_provisioner_label_value("default", "kube-system/cappy-chisel");
248+
assert_eq!(namespace, "kube-system");
249+
assert_eq!(name, "cappy-chisel");
250+
}
251+
252+
#[test]
253+
fn test_parse_provisioner_label_value_without_namespace() {
254+
let (namespace, name) = parse_provisioner_label_value("default", "cappy-chisel");
255+
assert_eq!(namespace, "default");
256+
assert_eq!(name, "cappy-chisel");
257+
}
258+
259+
#[test]
260+
fn test_parse_provisioner_label_value_with_different_default_namespace() {
261+
let (namespace, name) = parse_provisioner_label_value("my-namespace", "exit-node-1");
262+
assert_eq!(namespace, "my-namespace");
263+
assert_eq!(name, "exit-node-1");
264+
}
265+
}

0 commit comments

Comments
 (0)