Implement Kubernetes Service Dependency Queries
AppleMachine Learning Engineer · OnsiteLast updated
This question evaluates proficiency with data structures and algorithms for service inventory operations, including deterministic filtering, attribute matching, graph traversal for transitive dependency resolution, and status propagation across service graphs.
You are given an in-memory inventory of Kubernetes-like services. Each service has the following fields:
Service {
id: string // unique, for example "namespace/name"
name: string
namespace: string
attributes: map<string, string>
status: one of {"Healthy", "Degraded", "Down", "Unknown"}
dependencies: list<string> // service IDs this service depends on
}
Implement a small query library for this inventory.
- Filtering: Implement
filterServices(services, criteria)wherecriteriamay include:
- an optional namespace,
- a set of required attribute key-value pairs, all of which must match,
- an optional set of allowed statuses.
Return all matching services in deterministic order, sorted by service ID.
-
Dependency traversal: Implement
getDependencyChain(services, rootId)that returns all transitive dependencies reachable fromrootId, including each dependency's status. The implementation should handle missing dependencies and cycles gracefully. -
Status query along a chain: Implement
queryStatusAlongDependencyChain(services, rootId)that reports the status of every service along every dependency path starting atrootId. The result should make it easy to identify whether a degraded or down dependency may affect the root service. -
Design extension: Suppose this query library is exposed as a Model Context Protocol-style tool server for an AI agent. Describe how the agent should call the tools and how you would reduce noisy or irrelevant results.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.