diff --git a/src/main/cljc/dda/c4k_website/website.cljc b/src/main/cljc/dda/c4k_website/website.cljc index ab7d439..e4f4419 100644 --- a/src/main/cljc/dda/c4k_website/website.cljc +++ b/src/main/cljc/dda/c4k_website/website.cljc @@ -27,9 +27,23 @@ (s/def ::gitea-repo string?) (s/def ::branchname string?) (s/def ::username string?) +(s/def ::build-cpu-request string?) +(s/def ::build-memory-request string?) +(s/def ::build-cpu-limit string?) +(s/def ::build-memory-limit string?) -(def websitedata? (s/keys :req-un [::unique-name ::fqdns ::gitea-host ::gitea-repo ::branchname] - :opt-un [::issuer ::volume-size ::sha256sum-output])) +(def websitedata? (s/keys :req-un [::unique-name + ::fqdns + ::gitea-host + ::gitea-repo + ::branchname] + :opt-un [::issuer + ::volume-size + ::sha256sum-output + ::build-cpu-request + ::build-cpu-limit + ::build-memory-request + ::build-memory-limit])) (def websiteauth? (s/keys :req-un [::unique-name ::username ::authtoken])) @@ -105,11 +119,16 @@ (defn-spec replace-build-data pred/map-or-seq? [resource-file string? config flattened-and-reduced-config?] - (let [{:keys [sha256sum-output]} config] + (let [{:keys [sha256sum-output build-cpu-request build-cpu-limit build-memory-request build-memory-limit] + :or {build-cpu-request "1000m" build-cpu-limit "1700m" build-memory-request "256Mi" build-memory-limit "512Mi"}} config] (-> - (replace-common-data resource-file config) + (replace-common-data resource-file config) (cm/replace-all-matching-values-by-new-value "CHECK_SUM" (get-hash-from-sha256sum-output sha256sum-output)) - (cm/replace-all-matching-values-by-new-value "SCRIPT_FILE" (get-file-name-from-sha256sum-output sha256sum-output))))) + (cm/replace-all-matching-values-by-new-value "SCRIPT_FILE" (get-file-name-from-sha256sum-output sha256sum-output)) + (cm/replace-all-matching-values-by-new-value "BUILD_CPU_REQUEST" build-cpu-request) + (cm/replace-all-matching-values-by-new-value "BUILD_CPU_LIMIT" build-cpu-limit) + (cm/replace-all-matching-values-by-new-value "BUILD_MEMORY_REQUEST" build-memory-request) + (cm/replace-all-matching-values-by-new-value "BUILD_MEMORY_LIMIT" build-memory-limit)))) #?(:cljs (defmethod yaml/load-resource :website [resource-name] diff --git a/src/main/cljs/dda/c4k_website/browser.cljs b/src/main/cljs/dda/c4k_website/browser.cljs index e78316f..38bc381 100644 --- a/src/main/cljs/dda/c4k_website/browser.cljs +++ b/src/main/cljs/dda/c4k_website/browser.cljs @@ -43,8 +43,12 @@ :fqdns [\"example.org\" \"www.example.org\"], :gitea-host \"githost.org\", :gitea-repo \"repo\", - :branchname \"main\"}]}" - "11"))) + :branchname \"main\", + :build-cpu-request \"1500m\", + :build-cpu-limit \"3000m\", + :build-memory-request \"512Mi\", + :build-memory-limit \"1024Mi\"}]}" + "16"))) (generate-group "credentials" (br/generate-text-area diff --git a/src/main/resources/website/nginx-deployment.yaml b/src/main/resources/website/nginx-deployment.yaml index e32a007..234bc7e 100644 --- a/src/main/resources/website/nginx-deployment.yaml +++ b/src/main/resources/website/nginx-deployment.yaml @@ -33,6 +33,13 @@ spec: - image: domaindrivenarchitecture/c4k-website-build name: NAME-init-build-container imagePullPolicy: IfNotPresent + resources: + requests: + cpu: BUILD_CPU_REQUEST + memory: BUILD_MEMORY_REQUEST + limits: + cpu: BUILD_CPU_LIMIT + memory: BUILD_MEMORY_LIMIT command: ["/entrypoint.sh"] envFrom: - secretRef: diff --git a/src/main/resources/website/website-build-cron.yaml b/src/main/resources/website/website-build-cron.yaml index 7bcae2a..371444c 100644 --- a/src/main/resources/website/website-build-cron.yaml +++ b/src/main/resources/website/website-build-cron.yaml @@ -16,6 +16,13 @@ spec: - image: domaindrivenarchitecture/c4k-website-build name: NAME-build-app imagePullPolicy: IfNotPresent + resources: + requests: + cpu: BUILD_CPU_REQUEST + memory: BUILD_MEMORY_REQUEST + limits: + cpu: BUILD_CPU_LIMIT + memory: BUILD_MEMORY_LIMIT command: ["/entrypoint.sh"] envFrom: - secretRef: diff --git a/src/test/cljc/dda/c4k_website/website_test.cljc b/src/test/cljc/dda/c4k_website/website_test.cljc index fbb0148..1ed2908 100644 --- a/src/test/cljc/dda/c4k_website/website_test.cljc +++ b/src/test/cljc/dda/c4k_website/website_test.cljc @@ -101,6 +101,7 @@ [{:image "domaindrivenarchitecture/c4k-website-build", :name "test-io-init-build-container", :imagePullPolicy "IfNotPresent", + :resources {:requests {:cpu "1000m", :memory "256Mi"}, :limits {:cpu "1700m", :memory "512Mi"}}, :command ["/entrypoint.sh"], :envFrom [{:secretRef {:name "test-io-secret"}}], :env [{:name "SHA256SUM", :value "123456789ab123cd345de"} {:name "SCRIPTFILE", :value "script-file-name.sh"}], @@ -125,6 +126,34 @@ :branchname "main", :unique-name "test.io"})))) +(deftest should-generate-resource-requests + (is (= {:requests {:cpu "1000m", :memory "256Mi"}, :limits {:cpu "1700m", :memory "512Mi"}} + (-> (cut/generate-nginx-deployment {:authtoken "abedjgbasdodj", + :gitea-host "gitlab.de", + :username "someuser", + :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], + :gitea-repo "repo", + :sha256sum-output "123456789ab123cd345de script-file-name.sh", + :issuer "staging", + :branchname "main", + :unique-name "test.io"}) + :spec :template :spec :initContainers first :resources ))) + (is (= {:requests {:cpu "1500m", :memory "512Mi"}, :limits {:cpu "3000m", :memory "1024Mi"}} + (-> (cut/generate-nginx-deployment {:authtoken "abedjgbasdodj", + :gitea-host "gitlab.de", + :username "someuser", + :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], + :gitea-repo "repo", + :sha256sum-output "123456789ab123cd345de script-file-name.sh", + :issuer "staging", + :branchname "main", + :unique-name "test.io" + :build-cpu-request "1500m" + :build-cpu-limit "3000m" + :build-memory-request "512Mi" + :build-memory-limit "1024Mi"}) + :spec :template :spec :initContainers first :resources)))) + (deftest should-generate-nginx-service (is (= {:name-c1 "test-io-service", :name-c2 "test-org-service", @@ -163,6 +192,7 @@ [{:image "domaindrivenarchitecture/c4k-website-build", :name "test-io-build-app", :imagePullPolicy "IfNotPresent", + :resources {:requests {:cpu "1000m", :memory "256Mi"}, :limits {:cpu "1700m", :memory "512Mi"}}, :command ["/entrypoint.sh"], :envFrom [{:secretRef {:name "test-io-secret"}}], :env [{:name "SHA256SUM", :value "123456789ab123cd345de"} {:name "SCRIPTFILE", :value "script-file-name.sh"}],