Make the Easy Change Hard
16 days ago
- #Rust
- #Software Development
- #Kubernetes
- The article discusses a software development adage: 'make the hard change easy, then make the easy change' by refactoring code before implementing changes.
- The author describes doing the opposite in SimKube: making an easy change hard first, then tackling the hard change, due to complexities in Kubernetes resource ownership.
- In Kubernetes, resources can own others via OwnerReferences, which SimKube's tracer component monitors to track changes in a cluster for simulation replay.
- A problem arises when tracking both parent and child resources (e.g., Deployments and ReplicaSets), leading to duplicates in simulations because both the tracer and Kubernetes controller create the same resources.
- The solution involves modifying the tracer to ignore resources owned by other tracked resources, requiring a significant refactor from using Arc<Mutex<TraceStore>> to channel-based communication for better performance and design.
- The refactor introduces challenges with Rust's async programming, including decisions between std and tokio primitives, mutable receivers in channels, and ensuring 'static lifetimes for dynamically created channels.
- Ultimately, the author realizes filtering owned resources at export time, rather than ingest time, is necessary to avoid race conditions, leading to further refactoring.
- The changes are released in SimKube 2.4.0, improving resource tracking and simulation accuracy.