 
 (defn get-service->instances
   "Returns a map of scheduler/Service records -> map of scheduler/ServiceInstance records."
-  [scheduler-config]
-  (pc/map-from-keys #(instances-breakdown! scheduler-config %)
-                    (get-services scheduler-config)))
+  [scheduler]
+  (pc/map-from-keys #(instances-breakdown! scheduler %)
+                    (get-services scheduler)))
 
 ; The Waiter Scheduler protocol implementation for Kubernetes
 (defrecord KubernetesScheduler [api-server-url

(let [kill-restart-threshold-exceeded-pod-thread-pool (Executors/newFixedThreadPool 1)]
  (defn kill-restart-threshold-exceeded-pod
    "Processes killing of a frequently restarting pod (service instance)."
    [scheduler-config {:keys [k8s/pod-name k8s/restart-count service-id] :as instance}]
    (au/execute
      (fn kill-restart-threshold-exceeded-pod-task []
        (try
          (log/info "deleting frequently restarting pod"
                    {:pod-name pod-name :restart-count restart-count :service-id service-id})
          (hard-delete-service-instance scheduler-config instance)
          (catch Exception ex
            (log/error ex "error in deleting frequently restarting pod" pod-name))))
      kill-restart-threshold-exceeded-pod-thread-pool)))

(defn pod->ServiceInstance
  "Convert a Kubernetes Pod JSON response into a Waiter Service Instance record."
  [{:keys [api-server-url leader?-fn restart-kill-threshold] :as scheduler-config} pod]
  (try
    (let [;; waiter-app is the first container we register
          primary-container-restart-count (or (get-in pod [:status :containerStatuses 0 :restartCount]) 0)

   - it has restarted too many times (reached the restart-expiry-threshold threshold)
   - the primary container (waiter-apps) has not transitioned to running state in container-running-grace-secs seconds
   - the pod has the waiter/pod-expired=true annotation."
  [{:keys [container-running-grace-secs restart-expiry-threshold watch-state] :as scheduler}
   service-id instance-id restart-count {:keys [waiter/pod-expired waiter/revision-timestamp]}
   primary-container-status pod-started-at]
  (let [rs-revision-timestamp-path [:service-id->service service-id :k8s/replicaset-annotations :waiter/revision-timestamp]
