diff --git a/src/k16/kl/api/module.clj b/src/k16/kl/api/module.clj index 27f3222..0798deb 100644 --- a/src/k16/kl/api/module.clj +++ b/src/k16/kl/api/module.clj @@ -6,19 +6,40 @@ (set! *warn-on-reflection* true) +(defn- filter-by-known [left right] + (->> left + (filter (fn [[container-name]] + (contains? right container-name))) + (into {}))) + (defn- merge-modules [module-name root-module sub-modules] (let [state (api.state/get-state module-name) - merged + + merged-submodules (->> sub-modules (reduce (fn [acc [submodule-name]] (let [module-file (api.fs/from-submodule-dir module-name submodule-name "module.edn") module (api.fs/read-edn module-file)] (metamerge/meta-merge acc module))) - {}))] - (metamerge/meta-merge - merged - root-module - (select-keys state [:network :containers])))) + {})) + + merged-root + (metamerge/meta-merge merged-submodules root-module) + + state-containers + (filter-by-known (:containers state) (:containers merged-root)) + + state-services + (filter-by-known (get-in state [:network :services]) + (get-in merged-root [:network :services])) + + state-routes + (filter-by-known (get-in state [:network :routes]) + (get-in merged-root [:network :routes]))] + + (metamerge/meta-merge merged-root {:containers state-containers + :network {:services state-services + :routes state-routes}}))) (defn get-resolved-module [module-name modules] (let [root-module (api.fs/read-edn (api.fs/get-root-module-file module-name))]