feat: add support for setting multiple address
I did it like this, due to the fact that it would have been a pain to work out syntax for labels. So I moved the url to annotations
This commit is contained in:
parent
29ff12f115
commit
0439f362dd
3 changed files with 27 additions and 2 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -745,6 +745,15 @@ dependencies = [
|
|||
"hashbrown 0.16.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
|
|
@ -970,6 +979,7 @@ dependencies = [
|
|||
"either",
|
||||
"evalexpr",
|
||||
"futures",
|
||||
"itertools",
|
||||
"k8s-openapi",
|
||||
"kube",
|
||||
"nix",
|
||||
|
|
|
|||
|
|
@ -43,3 +43,4 @@ strip-ansi-escapes = "0.2.1"
|
|||
evalexpr = { version = "13.1.0", features = ["regex"] }
|
||||
async-trait = "0.1.89"
|
||||
tokio-util = { version = "0.7.18", features = ["rt"] }
|
||||
itertools = "0.14.0"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use std::{collections::HashMap, fmt, sync::Arc, time::Duration};
|
|||
|
||||
use async_trait::async_trait;
|
||||
use futures::StreamExt;
|
||||
use itertools::Itertools;
|
||||
use k8s_openapi::api::{apps::v1::Deployment, core::v1::Service};
|
||||
use kube::{
|
||||
api::{ListParams, ObjectList, Patch, PatchParams},
|
||||
|
|
@ -347,15 +348,28 @@ fn filter_label_value<R>(res: &R, addr: &str, port: &str) -> bool
|
|||
where
|
||||
R: ResourceExt,
|
||||
{
|
||||
let labels_iter = res.labels().iter();
|
||||
let annotations_iter = res.annotations().iter();
|
||||
let iters = labels_iter.merge(annotations_iter);
|
||||
|
||||
let mut found_port = false;
|
||||
res.labels()
|
||||
.iter()
|
||||
iters
|
||||
.filter(|(key, value)| match key.as_str() {
|
||||
MAIN_LABEL => value.as_str() == addr,
|
||||
PORT_LABEL => {
|
||||
found_port = true;
|
||||
value.as_str() == port
|
||||
}
|
||||
URL_ANNOTATION => value
|
||||
.lines()
|
||||
.find(|str| {
|
||||
if str.find(':').is_some() {
|
||||
str == &format!("{addr}:{port}").as_str()
|
||||
} else {
|
||||
str == &addr
|
||||
}
|
||||
})
|
||||
.is_some(),
|
||||
_ => false,
|
||||
})
|
||||
.count()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue