Skip to content

Commit

Permalink
Less noisy workload deletion (#535)
Browse files Browse the repository at this point in the history
* Less noisy workload deletion

Signed-off-by: Kevin Dorosh <kevin.dorosh@solo.io>

* Update log to warn

Signed-off-by: Kevin Dorosh <kevin.dorosh@solo.io>

* Less noisy pod initial updates

Signed-off-by: Kevin Dorosh <kevin.dorosh@solo.io>

* Less noisy pod initial updates

Signed-off-by: Kevin Dorosh <kevin.dorosh@solo.io>

* Less noisy pod initial updates

Signed-off-by: Kevin Dorosh <kevin.dorosh@solo.io>

* Less noisy pod initial updates

Signed-off-by: Kevin Dorosh <kevin.dorosh@solo.io>

---------

Signed-off-by: Kevin Dorosh <kevin.dorosh@solo.io>
  • Loading branch information
Kevin Dorosh authored May 26, 2023
1 parent d638f3f commit 0b91907
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/workload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,20 +1170,40 @@ impl WorkloadStore {
}

fn remove(&mut self, xds_name: String) {
self.remove_workload(&xds_name); // remove workload by UID; if xds_name is a service then this will no-op
// remove workload by UID; if xds_name is a service then this will no-op
if self.remove_workload(&xds_name) {
// we removed a workload, no reason to attempt to remove a service with the same name
return;
}
let parts = xds_name.split_once('/');
if parts.is_none() {
// we don't have ns/hostname or network/IP xds primary key for service
// we don't have namespace/hostname xds primary key for service
warn!(
"tried to remove service keyed by {} but it did not have the expected namespace/hostname format",
xds_name
);
return;
}
let (network, hostname) = parts.unwrap();
if hostname.split_once('/').is_some() {
// avoid trying to delete obvious workload UIDs as a service,
// which can result in noisy logs when new workloads are added
// (we remove then add workloads on initial update)
//
// we can make this assumption because namespaces and hostnames cannot have `/` in them
trace!(
"xds_name {} is obviously not a service, not attempting to delete as such",
xds_name
);
return;
}
self.remove_service(network, hostname);
}

fn remove_workload(&mut self, uid: &str) {
fn remove_workload(&mut self, uid: &str) -> bool {
let Some(prev) = self.workloads_by_uid.remove(uid) else {
trace!("tried to remove workload keyed by {} but it was not found; presumably it was a service", uid);
return;
return false;
};
let prev = prev.read().unwrap();
for wip in prev.workload_ips.iter() {
Expand All @@ -1206,6 +1226,7 @@ impl WorkloadStore {
}
}
}
true
}

fn remove_service(&mut self, namespace: &str, hostname: &str) {
Expand Down

0 comments on commit 0b91907

Please sign in to comment.