Skip to content

Commit

Permalink
Only generate routes with valid service + endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
julienvincent committed Oct 29, 2023
1 parent 892b35f commit af356f1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/k16/kl/api/fs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
file))

(defn from-modules-dir ^java.io.File [& segments]
(let [file (from-config-dir "modules" (flatten segments))]
(io/make-parents file)
file))
(from-config-dir "modules" (flatten segments)))

(defn get-config-file ^java.io.File []
(from-config-dir "config.edn"))
Expand Down
13 changes: 6 additions & 7 deletions src/k16/kl/api/proxy.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
(ns k16.kl.api.proxy
(:require
[clj-yaml.core :as yaml]
[clojure.java.io :as io]
[k16.kl.api.fs :as api.fs]
[meta-merge.core :as metamerge]))

(defn- get-proxies-projection-file [group-name]
(api.fs/from-config-dir "proxy/" group-name ".yaml"))
(api.fs/from-config-dir "proxy/" (str group-name ".yaml")))

(defn- route->traefik-rule [{:keys [host path-prefix]}]
(cond-> (str "Host(`" host "`)")
Expand Down Expand Up @@ -35,16 +34,16 @@
endpoint-name (or (:endpoint route)
(:default-endpoint service))]

(assoc-in acc [:http :routers (name route-name)]
{:rule (route->traefik-rule route)
:service (str (name service-name) "-" (name endpoint-name))})))
(if (and service-name endpoint-name)
(assoc-in acc [:http :routers (name route-name)]
{:rule (route->traefik-rule route)
:service (str (name service-name) "-" (name endpoint-name))})
acc)))
{}))]

(metamerge/meta-merge services routes)))

(defn write-proxy-config! [{:keys [group-name module]}]
(let [routes (build-routes module)
file (get-proxies-projection-file group-name)]

(io/make-parents file)
(spit file (yaml/generate-string routes))))
3 changes: 2 additions & 1 deletion src/k16/kl/commands/containers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@
:checked (get-in state [:containers container-name :enabled] true)})))
selected-containers (->> options
(prompt/list-checkbox "Select Services")
(map keyword)
set)

updated-state
(assoc state :containers
(->> (:containers module)
(map (fn [[container-name]]
(let [enabled (boolean (some #{(name container-name)} selected-containers))]
(let [enabled (boolean (some #{container-name} selected-containers))]
[container-name {:enabled enabled}])))
(into {})))]

Expand Down

0 comments on commit af356f1

Please sign in to comment.