fix(opnsense-config): ensure load balancer service configuration is idempotent #129
No reviewers
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: NationTech/harmony#129
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "idempotent-load-balancer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The previous implementation blindly added HAProxy components without checking for existing configurations on the same port, which caused duplicate entries and errors when a service was updated.
This commit refactors the logic to a robust "remove-then-add" strategy. The configure_service method now finds and removes any existing frontend and its dependent components (backend, servers, health check) before adding the new, complete service definition.
This change makes the process fully idempotent, preventing configuration drift and ensuring a predictable state.
@ -35,3 +31,1 @@
if !self.list_services().await.contains(service) {
self.add_service(service).await?;
}
self.add_service(service).await?;
we might want to rename this
add_or_update_service
instead of justadd_service
@ -46,0 +53,4 @@
if let Some(existing_backend) = existing_backend {
backend.uuid = existing_backend.uuid.clone(); // This breaks the `frontend` config
// as it is now relying on a stale uuid
As of now, the first time you add a load balancer service, everything will work as expected.
Though if you run it again, as we update in place the existing backend and we reuse its uuid, the frontend will be referring to a non-existent uuid for the
default_backend
(seeharmony/src/infra/opnsense/load_balancer.rs
on line 323). So we need to fix this before merging.@ -28,3 +27,2 @@
"TODO : the current implementation does not check / cleanup / merge with existing haproxy services properly. Make sure to manually verify that the configuration is correct after executing any operation here"
);
let mut config = self.opnsense_config.write().await;
let mut load_balancer = config.load_balancer();
For now we only merge the existing config with the service (if it already exists). Should we also remove stale services?
Ouais j'y repense un peu et c'est pas evident. Il y a beaucoup de cas.
Il faut simplifier. Probablement que la seule logique qui est raisonnable d'implementer maintenant c'est de prendre controle des ports et reset la config pour ces ports la chaque fois. Donc la logique serait probablement quelque chose comme :
WIP: fix: merge existing services in load balancer configto fix: remove existing services (by bind address) in load balancer configfix: remove existing services (by bind address) in load balancer configto fix(opnsense-config): ensure load balancer service configuration is idempotent3ecda84530
toa31b459f33