Skip to content

Commit

Permalink
Only merge known resources from state
Browse files Browse the repository at this point in the history
  • Loading branch information
julienvincent committed Oct 29, 2023
1 parent afea066 commit 52da861
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/k16/kl/api/module.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down

0 comments on commit 52da861

Please sign in to comment.