diff --git a/apps/lenra/lib/lenra/services/openfaas_services.ex b/apps/lenra/lib/lenra/services/openfaas_services.ex index b3978e55..7e9eff3a 100644 --- a/apps/lenra/lib/lenra/services/openfaas_services.ex +++ b/apps/lenra/lib/lenra/services/openfaas_services.ex @@ -37,13 +37,13 @@ defmodule Lenra.OpenfaasServices do "image" => Apps.image_name(service_name, build_number), "service" => get_function_name(service_name, build_number), "secrets" => Application.fetch_env!(:lenra, :faas_secrets), - "limits" => %{ - "memory" => "384Mi", - "cpu" => "100m" - }, "requests" => %{ - "memory" => "256Mi", - "cpu" => "50m" + "cpu" => Application.fetch_env!(:application_runner, :faas_request_cpu), + "memory" => Application.fetch_env!(:application_runner, :faas_request_memory) + }, + "limits" => %{ + "cpu" => Application.fetch_env!(:application_runner, :faas_limit_cpu), + "memory" => Application.fetch_env!(:application_runner, :faas_limit_memory) }, "labels" => %{ @min_scale_label => @min_scale_default, diff --git a/config/config.exs b/config/config.exs index 69c3d4d3..3247b95a 100644 --- a/config/config.exs +++ b/config/config.exs @@ -105,7 +105,11 @@ config :application_runner, listeners_timeout: 1 * 60 * 60 * 1000, view_timeout: 1 * 30 * 1000, manifest_timeout: 1 * 30 * 1000, - scale_to_zero: false + scale_to_zero: false, + faas_request_cpu: System.get_env("FAAS_REQUEST_CPU", "50m"), + faas_request_memory: System.get_env("FAAS_REQUEST_MEMORY", "128Mi"), + faas_limit_cpu: System.get_env("FAAS_LIMIT_CPU", "100m"), + faas_limit_memory: System.get_env("FAAS_LIMIT_MEMORY", "256Mi") config :application_runner, :mongo, hostname: System.get_env("MONGO_HOSTNAME", "localhost"), diff --git a/config/runtime.exs b/config/runtime.exs index f9bea61e..8208fc75 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -90,7 +90,11 @@ if config_env() == :prod do username: System.get_env("MONGO_USERNAME"), password: System.get_env("MONGO_PASSWORD"), ssl: System.get_env("MONGO_SSL", "false"), - auth_source: System.get_env("MONGO_AUTH_SOURCE") + auth_source: System.get_env("MONGO_AUTH_SOURCE"), + faas_request_cpu: System.get_env("FAAS_REQUEST_CPU", "50m"), + faas_request_memory: System.get_env("FAAS_REQUEST_MEMORY", "128Mi"), + faas_limit_cpu: System.get_env("FAAS_LIMIT_CPU", "100m"), + faas_limit_memory: System.get_env("FAAS_LIMIT_MEMORY", "256Mi") # Do not print debug messages in production config :logger, level: String.to_atom(System.get_env("LOG_LEVEL", "info")) diff --git a/docs/env-variables.md b/docs/env-variables.md index 74b3ccb1..3f07098c 100644 --- a/docs/env-variables.md +++ b/docs/env-variables.md @@ -21,6 +21,10 @@ This document provides a list of the environment variables that need to be set f - `FAAS_URL`: The URL for the FaaS service. - `FAAS_AUTH`: The authentication for the FaaS service. - `FAAS_REGISTRY`: The registry for the FaaS service. +- `FAAS_REQUEST_CPU`: The CPU request for the FaaS service. Default is "50m". +- `FAAS_REQUEST_MEMORY`: The memory request for the FaaS service. Default is "128Mi". +- `FAAS_LIMIT_CPU`: The CPU limit for the FaaS service. Default is "100m". +- `FAAS_LIMIT_MEMORY`: The memory limit for the FaaS service. Default is "256Mi". ## Pipeline Configuration diff --git a/libs/application_runner/config/config.exs b/libs/application_runner/config/config.exs index 733a7744..8abe5f37 100644 --- a/libs/application_runner/config/config.exs +++ b/libs/application_runner/config/config.exs @@ -27,7 +27,11 @@ config :application_runner, faas_url: System.get_env("FAAS_URL", "https://openfaas-dev.lenra.me"), faas_auth: System.get_env("FAAS_AUTH", "Basic YWRtaW46Z0Q4VjNHR1YxeUpS"), faas_registry: System.get_env("FAAS_REGISTRY", "registry.gitlab.com/lenra/platform/lenra-ci"), - scale_to_zero: true + scale_to_zero: true, + faas_request_cpu: System.get_env("FAAS_REQUEST_CPU", "50m"), + faas_request_memory: System.get_env("FAAS_REQUEST_MEMORY", "128Mi"), + faas_limit_cpu: System.get_env("FAAS_LIMIT_CPU", "100m"), + faas_limit_memory: System.get_env("FAAS_LIMIT_MEMORY", "256Mi") config :application_runner, :mongo, hostname: "localhost", diff --git a/libs/application_runner/lib/services/application_services.ex b/libs/application_runner/lib/services/application_services.ex index 03338c23..3cb08191 100644 --- a/libs/application_runner/lib/services/application_services.ex +++ b/libs/application_runner/lib/services/application_services.ex @@ -184,13 +184,13 @@ defmodule ApplicationRunner.ApplicationServices do "image" => image_name, "service" => function_name, "secrets" => Application.fetch_env!(:lenra, :faas_secrets), - "limits" => %{ - "memory" => "256Mi", - "cpu" => "100m" - }, "requests" => %{ - "memory" => "128Mi", - "cpu" => "50m" + "cpu" => Application.fetch_env!(:application_runner, :faas_request_cpu), + "memory" => Application.fetch_env!(:application_runner, :faas_request_memory) + }, + "limits" => %{ + "cpu" => Application.fetch_env!(:application_runner, :faas_limit_cpu), + "memory" => Application.fetch_env!(:application_runner, :faas_limit_memory) }, "labels" => %{ @min_scale_label => @min_scale_default, @@ -287,13 +287,13 @@ defmodule ApplicationRunner.ApplicationServices do Jason.encode!(%{ "image" => app["image"], "service" => function_name, - "limits" => %{ - "memory" => "256Mi", - "cpu" => "100m" - }, "requests" => %{ - "memory" => "128Mi", - "cpu" => "50m" + "cpu" => Application.fetch_env!(:application_runner, :faas_request_cpu), + "memory" => Application.fetch_env!(:application_runner, :faas_request_memory) + }, + "limits" => %{ + "cpu" => Application.fetch_env!(:application_runner, :faas_limit_cpu), + "memory" => Application.fetch_env!(:application_runner, :faas_limit_memory) }, "labels" => Map.merge(Map.get(app, :labels, %{}), labels) })