diff --git a/src/main/cljc/dda/c4k_common/postgres.cljc b/src/main/cljc/dda/c4k_common/postgres.cljc index 14c2000..9adbcd4 100644 --- a/src/main/cljc/dda/c4k_common/postgres.cljc +++ b/src/main/cljc/dda/c4k_common/postgres.cljc @@ -39,8 +39,12 @@ (yaml/from-string (yaml/load-resource (str "postgres/config-" (name postgres-size) ".yaml"))) (assoc-in [:data :postgres-db] db-name)))) -(defn generate-deployment [] - (yaml/from-string (yaml/load-resource "postgres/deployment.yaml"))) +(defn generate-deployment [& args] + (let [{:keys [postgres-image] + :or {postgres-image "postgres:13"}} args] + (-> + (yaml/from-string (yaml/load-resource "postgres/deployment.yaml")) + (assoc-in [:spec :template :spec :containers 0 :image] postgres-image)))) (defn generate-persistent-volume [config] (let [{:keys [postgres-data-volume-path]} config] diff --git a/src/main/resources/postgres/deployment.yaml b/src/main/resources/postgres/deployment.yaml index 95f7410..5b4bb4d 100644 --- a/src/main/resources/postgres/deployment.yaml +++ b/src/main/resources/postgres/deployment.yaml @@ -14,7 +14,7 @@ spec: app: postgresql spec: containers: - - image: postgres:13 + - image: postgres name: postgresql env: - name: POSTGRES_USER diff --git a/src/test/cljc/dda/c4k_common/postgres_test.cljc b/src/test/cljc/dda/c4k_common/postgres_test.cljc index 9bf29ec..967476e 100644 --- a/src/test/cljc/dda/c4k_common/postgres_test.cljc +++ b/src/test/cljc/dda/c4k_common/postgres_test.cljc @@ -39,3 +39,30 @@ :data {:postgres-user "eHgtdXM=", :postgres-password "eHgtcHc="}} (cut/generate-secret {:postgres-db-user "xx-us" :postgres-db-password "xx-pw"})))) + +(deftest should-generate-deployment + (is (= [{:image "postgres:14" + :name "postgresql" + :env + [{:name "POSTGRES_USER" + :valueFrom + {:secretKeyRef + {:name "postgres-secret", :key "postgres-user"}}} + {:name "POSTGRES_PASSWORD" + :valueFrom + {:secretKeyRef + {:name "postgres-secret", :key "postgres-password"}}} + {:name "POSTGRES_DB" + :valueFrom + {:configMapKeyRef + {:name "postgres-config", :key "postgres-db"}}}] + :ports [{:containerPort 5432, :name "postgresql"}] + :volumeMounts + [{:name "postgres-config-volume" + :mountPath "/etc/postgresql/postgresql.conf" + :subPath "postgresql.conf" + :readOnly true} + {:name "postgre-data-volume" + :mountPath "/var/lib/postgresql/data"}]}] + (get-in (cut/generate-deployment :postgres-image "postgres:14") + [:spec :template :spec :containers]))))