Katkat

Implement Kubernetes Service Dependency Queries

AppleMachine Learning Engineer · Onsite

Last 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.

  1. Filtering: Implement filterServices(services, criteria) where criteria may 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.

  1. Dependency traversal: Implement getDependencyChain(services, rootId) that returns all transitive dependencies reachable from rootId, including each dependency's status. The implementation should handle missing dependencies and cycles gracefully.

  2. Status query along a chain: Implement queryStatusAlongDependencyChain(services, rootId) that reports the status of every service along every dependency path starting at rootId. The result should make it easy to identify whether a degraded or down dependency may affect the root service.

  3. 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.