mirror of
https://github.com/jlengrand/engine.git
synced 2026-03-10 08:11:21 +00:00
Merge pull request #431 from Qovery/db_mode
Use database mode instead of relying on env mode
This commit is contained in:
committed by
GitHub
parent
1f39c0b1d6
commit
d3ce271304
@@ -158,12 +158,7 @@ impl Service for Application {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
let mut context = default_tera_context(self, target.kubernetes, target.environment);
|
||||
let commit_id = self.image().commit_id.as_str();
|
||||
|
||||
context.insert("helm_app_version", &commit_id[..7]);
|
||||
|
||||
@@ -2,7 +2,6 @@ use std::collections::HashMap;
|
||||
|
||||
use tera::Context as TeraContext;
|
||||
|
||||
use crate::cloud_provider::environment::Kind;
|
||||
use crate::cloud_provider::service::{
|
||||
check_service_version, default_tera_context, delete_stateful_service, deploy_stateful_service, get_tfstate_name,
|
||||
get_tfstate_suffix, scale_down_database, send_progress_on_long_task, Action, Backup, Create, Database,
|
||||
@@ -16,6 +15,7 @@ use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::cmd::kubectl;
|
||||
use crate::error::{EngineError, EngineErrorScope, StringError};
|
||||
use crate::models::DatabaseMode::MANAGED;
|
||||
use crate::models::{Context, Listen, Listener, Listeners};
|
||||
|
||||
pub struct MongoDB {
|
||||
@@ -69,7 +69,11 @@ impl MongoDB {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulService for MongoDB {}
|
||||
impl StatefulService for MongoDB {
|
||||
fn is_managed_service(&self) -> bool {
|
||||
self.options.mode == MANAGED
|
||||
}
|
||||
}
|
||||
|
||||
impl Service for MongoDB {
|
||||
fn context(&self) -> &Context {
|
||||
@@ -133,17 +137,9 @@ impl Service for MongoDB {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let is_managed_services = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let mut context = default_tera_context(self, target.kubernetes, target.environment);
|
||||
|
||||
// we need the kubernetes config file to store tfstates file in kube secrets
|
||||
let kube_config_file_path = kubernetes.config_file_path()?;
|
||||
@@ -157,7 +153,7 @@ impl Service for MongoDB {
|
||||
|
||||
context.insert("namespace", environment.namespace());
|
||||
|
||||
let version = self.matching_correct_version(is_managed_services)?;
|
||||
let version = self.matching_correct_version(self.is_managed_service())?;
|
||||
context.insert("version", &version);
|
||||
|
||||
for (k, v) in kubernetes.cloud_provider().tera_context_environment_variables() {
|
||||
@@ -400,7 +396,7 @@ fn get_managed_mongodb_version(requested_version: String) -> Result<String, Stri
|
||||
mod tests_mongodb {
|
||||
use crate::cloud_provider::aws::databases::mongodb::{get_mongodb_version, MongoDB};
|
||||
use crate::cloud_provider::service::{Action, DatabaseOptions, Service};
|
||||
use crate::models::Context;
|
||||
use crate::models::{Context, DatabaseMode};
|
||||
|
||||
#[test]
|
||||
fn check_mongodb_version() {
|
||||
@@ -449,6 +445,7 @@ mod tests_mongodb {
|
||||
password: "".to_string(),
|
||||
host: "".to_string(),
|
||||
port: 5432,
|
||||
mode: DatabaseMode::CONTAINER,
|
||||
disk_size_in_gib: 10,
|
||||
database_disk_type: "gp2".to_string(),
|
||||
activate_high_availability: false,
|
||||
|
||||
@@ -3,7 +3,6 @@ use std::collections::HashMap;
|
||||
use tera::Context as TeraContext;
|
||||
|
||||
use crate::cloud_provider::aws::databases::utilities::{get_parameter_group_from_version, rds_name_sanitizer};
|
||||
use crate::cloud_provider::environment::Kind;
|
||||
use crate::cloud_provider::service::{
|
||||
check_service_version, default_tera_context, delete_stateful_service, deploy_stateful_service, get_tfstate_name,
|
||||
get_tfstate_suffix, scale_down_database, send_progress_on_long_task, Action, Backup, Create, Database,
|
||||
@@ -17,6 +16,7 @@ use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::cmd::kubectl;
|
||||
use crate::error::{EngineError, EngineErrorCause, EngineErrorScope, StringError};
|
||||
use crate::models::DatabaseMode::MANAGED;
|
||||
use crate::models::{Context, DatabaseKind, Listen, Listener, Listeners};
|
||||
|
||||
pub struct MySQL {
|
||||
@@ -70,7 +70,11 @@ impl MySQL {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulService for MySQL {}
|
||||
impl StatefulService for MySQL {
|
||||
fn is_managed_service(&self) -> bool {
|
||||
self.options.mode == MANAGED
|
||||
}
|
||||
}
|
||||
|
||||
impl Service for MySQL {
|
||||
fn context(&self) -> &Context {
|
||||
@@ -129,18 +133,10 @@ impl Service for MySQL {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
let is_managed_services = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
// we need the kubernetes config file to store tfstates file in kube secrets
|
||||
let kube_config_file_path = kubernetes.config_file_path()?;
|
||||
context.insert("kubeconfig_path", &kube_config_file_path);
|
||||
@@ -153,10 +149,10 @@ impl Service for MySQL {
|
||||
|
||||
context.insert("namespace", environment.namespace());
|
||||
|
||||
let version = &self.matching_correct_version(is_managed_services)?;
|
||||
let version = &self.matching_correct_version(self.is_managed_service())?;
|
||||
context.insert("version", &version);
|
||||
|
||||
if is_managed_services {
|
||||
if self.is_managed_service() {
|
||||
let parameter_group_family = match get_parameter_group_from_version(&version, DatabaseKind::Mysql) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
@@ -420,7 +416,7 @@ fn get_managed_mysql_version(requested_version: String) -> Result<String, String
|
||||
mod tests_mysql {
|
||||
use crate::cloud_provider::aws::databases::mysql::{get_mysql_version, MySQL};
|
||||
use crate::cloud_provider::service::{Action, DatabaseOptions, Service};
|
||||
use crate::models::Context;
|
||||
use crate::models::{Context, DatabaseMode};
|
||||
|
||||
#[test]
|
||||
fn check_mysql_version() {
|
||||
@@ -471,6 +467,7 @@ mod tests_mysql {
|
||||
password: "".to_string(),
|
||||
host: "".to_string(),
|
||||
port: 3306,
|
||||
mode: DatabaseMode::MANAGED,
|
||||
disk_size_in_gib: 10,
|
||||
database_disk_type: "gp2".to_string(),
|
||||
activate_high_availability: false,
|
||||
|
||||
@@ -3,7 +3,6 @@ use std::collections::HashMap;
|
||||
use tera::Context as TeraContext;
|
||||
|
||||
use crate::cloud_provider::aws::databases::utilities::rds_name_sanitizer;
|
||||
use crate::cloud_provider::environment::Kind;
|
||||
use crate::cloud_provider::service::{
|
||||
check_service_version, default_tera_context, delete_stateful_service, deploy_stateful_service, get_tfstate_name,
|
||||
get_tfstate_suffix, scale_down_database, send_progress_on_long_task, Action, Backup, Create, Database,
|
||||
@@ -17,6 +16,7 @@ use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::cmd::kubectl;
|
||||
use crate::error::{EngineError, EngineErrorScope, StringError};
|
||||
use crate::models::DatabaseMode::MANAGED;
|
||||
use crate::models::{Context, Listen, Listener, Listeners};
|
||||
|
||||
pub struct PostgreSQL {
|
||||
@@ -70,7 +70,11 @@ impl PostgreSQL {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulService for PostgreSQL {}
|
||||
impl StatefulService for PostgreSQL {
|
||||
fn is_managed_service(&self) -> bool {
|
||||
self.options.mode == MANAGED
|
||||
}
|
||||
}
|
||||
|
||||
impl Service for PostgreSQL {
|
||||
fn context(&self) -> &Context {
|
||||
@@ -129,16 +133,8 @@ impl Service for PostgreSQL {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let is_managed_services = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
// we need the kubernetes config file to store tfstates file in kube secrets
|
||||
@@ -153,7 +149,7 @@ impl Service for PostgreSQL {
|
||||
|
||||
context.insert("namespace", environment.namespace());
|
||||
|
||||
let version = self.matching_correct_version(is_managed_services)?;
|
||||
let version = self.matching_correct_version(self.is_managed_service())?;
|
||||
context.insert("version", &version);
|
||||
|
||||
for (k, v) in kubernetes.cloud_provider().tera_context_environment_variables() {
|
||||
@@ -410,7 +406,7 @@ fn get_managed_postgres_version(requested_version: String) -> Result<String, Str
|
||||
mod tests_postgres {
|
||||
use crate::cloud_provider::aws::databases::postgresql::{get_postgres_version, PostgreSQL};
|
||||
use crate::cloud_provider::service::{Action, DatabaseOptions, Service};
|
||||
use crate::models::Context;
|
||||
use crate::models::{Context, DatabaseMode};
|
||||
|
||||
#[test]
|
||||
fn check_postgres_version() {
|
||||
@@ -464,6 +460,7 @@ mod tests_postgres {
|
||||
password: "".to_string(),
|
||||
host: "".to_string(),
|
||||
port: 5432,
|
||||
mode: DatabaseMode::MANAGED,
|
||||
disk_size_in_gib: 10,
|
||||
database_disk_type: "gp2".to_string(),
|
||||
activate_high_availability: false,
|
||||
|
||||
@@ -2,7 +2,6 @@ use std::collections::HashMap;
|
||||
|
||||
use tera::Context as TeraContext;
|
||||
|
||||
use crate::cloud_provider::environment::Kind;
|
||||
use crate::cloud_provider::service::{
|
||||
check_service_version, default_tera_context, delete_stateful_service, deploy_stateful_service, get_tfstate_name,
|
||||
get_tfstate_suffix, scale_down_database, send_progress_on_long_task, Action, Backup, Create, Database,
|
||||
@@ -14,6 +13,7 @@ use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::cmd::kubectl;
|
||||
use crate::error::{EngineError, EngineErrorCause, EngineErrorScope, StringError};
|
||||
use crate::models::DatabaseMode::MANAGED;
|
||||
use crate::models::{Context, Listen, Listener, Listeners};
|
||||
|
||||
pub struct Redis {
|
||||
@@ -67,7 +67,11 @@ impl Redis {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulService for Redis {}
|
||||
impl StatefulService for Redis {
|
||||
fn is_managed_service(&self) -> bool {
|
||||
self.options.mode == MANAGED
|
||||
}
|
||||
}
|
||||
|
||||
impl Service for Redis {
|
||||
fn context(&self) -> &Context {
|
||||
@@ -132,16 +136,8 @@ impl Service for Redis {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let is_managed_services = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
// we need the kubernetes config file to store tfstates file in kube secrets
|
||||
@@ -154,7 +150,7 @@ impl Service for Redis {
|
||||
kubernetes.cloud_provider().credentials_environment_variables(),
|
||||
);
|
||||
|
||||
let version = self.matching_correct_version(is_managed_services)?;
|
||||
let version = self.matching_correct_version(self.is_managed_service())?;
|
||||
|
||||
let parameter_group_name = if version.starts_with("5.") {
|
||||
"default.redis5.0"
|
||||
@@ -407,7 +403,7 @@ fn get_managed_redis_version(requested_version: String) -> Result<String, String
|
||||
mod tests {
|
||||
use crate::cloud_provider::aws::databases::redis::{get_redis_version, Redis};
|
||||
use crate::cloud_provider::service::{Action, DatabaseOptions, Service};
|
||||
use crate::models::Context;
|
||||
use crate::models::{Context, DatabaseMode};
|
||||
|
||||
#[test]
|
||||
fn check_redis_version() {
|
||||
@@ -457,6 +453,7 @@ mod tests {
|
||||
password: "".to_string(),
|
||||
host: "".to_string(),
|
||||
port: 5432,
|
||||
mode: DatabaseMode::MANAGED,
|
||||
disk_size_in_gib: 10,
|
||||
database_disk_type: "gp2".to_string(),
|
||||
activate_high_availability: false,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use tera::Context as TeraContext;
|
||||
|
||||
use crate::cloud_provider::environment::Kind;
|
||||
use crate::cloud_provider::models::{CustomDomain, CustomDomainDataTemplate, Route, RouteDataTemplate};
|
||||
use crate::cloud_provider::service::{
|
||||
default_tera_context, delete_router, delete_stateless_service, send_progress_on_long_task, Action, Create, Delete,
|
||||
@@ -101,11 +100,8 @@ impl Service for Router {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
let applications = environment
|
||||
@@ -156,18 +152,6 @@ impl Service for Router {
|
||||
context.insert("nginx_requests_memory", "128Mi");
|
||||
context.insert("nginx_limit_cpu", "200m");
|
||||
context.insert("nginx_limit_memory", "128Mi");
|
||||
match environment.kind {
|
||||
Kind::Production => {
|
||||
context.insert("nginx_enable_horizontal_autoscaler", "true");
|
||||
context.insert("nginx_minimum_replicas", "2");
|
||||
context.insert("nginx_requests_cpu", "250m");
|
||||
context.insert("nginx_requests_memory", "384Mi");
|
||||
context.insert("nginx_limit_cpu", "1");
|
||||
context.insert("nginx_limit_memory", "384Mi");
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
let kubernetes_config_file_path = kubernetes.config_file_path();
|
||||
|
||||
match kubernetes_config_file_path {
|
||||
@@ -274,11 +258,8 @@ impl StatelessService for Router {}
|
||||
impl Create for Router {
|
||||
fn on_create(&self, target: &DeploymentTarget) -> Result<(), EngineError> {
|
||||
info!("AWS.router.on_create() called for {}", self.name());
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let workspace_dir = self.workspace_directory();
|
||||
let helm_release_name = self.helm_release_name();
|
||||
|
||||
|
||||
@@ -160,11 +160,8 @@ impl Service for Application {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
let commit_id = self.image.commit_id.as_str();
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::cmd::kubectl;
|
||||
use crate::error::{EngineError, EngineErrorScope};
|
||||
use crate::models::DatabaseMode::MANAGED;
|
||||
use crate::models::{Context, Listen, Listener, Listeners};
|
||||
|
||||
pub struct MongoDB {
|
||||
@@ -64,7 +65,11 @@ impl MongoDB {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulService for MongoDB {}
|
||||
impl StatefulService for MongoDB {
|
||||
fn is_managed_service(&self) -> bool {
|
||||
self.options.mode == MANAGED
|
||||
}
|
||||
}
|
||||
|
||||
impl Service for MongoDB {
|
||||
fn context(&self) -> &Context {
|
||||
@@ -120,11 +125,8 @@ impl Service for MongoDB {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
// we need the kubernetes config file to store tfstates file in kube secrets
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::cmd::kubectl;
|
||||
use crate::error::{EngineError, EngineErrorScope};
|
||||
use crate::models::DatabaseMode::MANAGED;
|
||||
use crate::models::{Context, Listen, Listener, Listeners};
|
||||
|
||||
pub struct MySQL {
|
||||
@@ -64,7 +65,11 @@ impl MySQL {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulService for MySQL {}
|
||||
impl StatefulService for MySQL {
|
||||
fn is_managed_service(&self) -> bool {
|
||||
self.options.mode == MANAGED
|
||||
}
|
||||
}
|
||||
|
||||
impl Service for MySQL {
|
||||
fn context(&self) -> &Context {
|
||||
@@ -120,11 +125,8 @@ impl Service for MySQL {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
// we need the kubernetes config file to store tfstates file in kube secrets
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::cmd::kubectl;
|
||||
use crate::error::{EngineError, EngineErrorScope};
|
||||
use crate::models::DatabaseMode::MANAGED;
|
||||
use crate::models::{Context, Listen, Listener, Listeners};
|
||||
|
||||
pub struct PostgreSQL {
|
||||
@@ -64,7 +65,11 @@ impl PostgreSQL {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulService for PostgreSQL {}
|
||||
impl StatefulService for PostgreSQL {
|
||||
fn is_managed_service(&self) -> bool {
|
||||
self.options.mode == MANAGED
|
||||
}
|
||||
}
|
||||
|
||||
impl Service for PostgreSQL {
|
||||
fn context(&self) -> &Context {
|
||||
@@ -120,11 +125,8 @@ impl Service for PostgreSQL {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
// we need the kubernetes config file to store tfstates file in kube secrets
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::cmd::kubectl;
|
||||
use crate::error::{EngineError, EngineErrorScope};
|
||||
use crate::models::DatabaseMode::MANAGED;
|
||||
use crate::models::{Context, Listen, Listener, Listeners};
|
||||
|
||||
pub struct Redis {
|
||||
@@ -64,7 +65,11 @@ impl Redis {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulService for Redis {}
|
||||
impl StatefulService for Redis {
|
||||
fn is_managed_service(&self) -> bool {
|
||||
self.options.mode == MANAGED
|
||||
}
|
||||
}
|
||||
|
||||
impl Service for Redis {
|
||||
fn context(&self) -> &Context {
|
||||
@@ -120,11 +125,8 @@ impl Service for Redis {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
// we need the kubernetes config file to store tfstates file in kube secrets
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use tera::Context as TeraContext;
|
||||
|
||||
use crate::cloud_provider::environment::Kind;
|
||||
use crate::cloud_provider::models::{CustomDomain, CustomDomainDataTemplate, Route, RouteDataTemplate};
|
||||
use crate::cloud_provider::service::{
|
||||
default_tera_context, delete_router, delete_stateless_service, send_progress_on_long_task, Action, Create, Delete,
|
||||
@@ -101,11 +100,8 @@ impl Service for Router {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
context.insert("doks_cluster_id", kubernetes.id());
|
||||
|
||||
@@ -167,18 +163,6 @@ impl Service for Router {
|
||||
context.insert("nginx_requests_memory", "128Mi");
|
||||
context.insert("nginx_limit_cpu", "200m");
|
||||
context.insert("nginx_limit_memory", "128Mi");
|
||||
match environment.kind {
|
||||
Kind::Production => {
|
||||
context.insert("nginx_enable_horizontal_autoscaler", "true");
|
||||
context.insert("nginx_minimum_replicas", "2");
|
||||
context.insert("nginx_requests_cpu", "250m");
|
||||
context.insert("nginx_requests_memory", "384Mi");
|
||||
context.insert("nginx_limit_cpu", "1");
|
||||
context.insert("nginx_limit_memory", "384Mi");
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
let kubernetes_config_file_path = kubernetes.config_file_path();
|
||||
|
||||
match kubernetes_config_file_path {
|
||||
@@ -292,10 +276,8 @@ impl StatelessService for Router {}
|
||||
impl Create for Router {
|
||||
fn on_create(&self, target: &DeploymentTarget) -> Result<(), EngineError> {
|
||||
info!("DigitalOcean.router.on_create() called for {}", self.name());
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (k, env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (k, env),
|
||||
};
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
|
||||
let workspace_dir = self.workspace_directory();
|
||||
let helm_release_name = self.helm_release_name();
|
||||
|
||||
@@ -4,7 +4,6 @@ use crate::unit_conversion::cpu_string_to_float;
|
||||
|
||||
pub struct Environment {
|
||||
namespace: String,
|
||||
pub kind: Kind,
|
||||
pub id: String,
|
||||
pub project_id: String,
|
||||
pub owner_id: String,
|
||||
@@ -15,7 +14,6 @@ pub struct Environment {
|
||||
|
||||
impl Environment {
|
||||
pub fn new(
|
||||
kind: Kind,
|
||||
id: &str,
|
||||
project_id: &str,
|
||||
owner_id: &str,
|
||||
@@ -25,7 +23,6 @@ impl Environment {
|
||||
) -> Self {
|
||||
Environment {
|
||||
namespace: format!("{}-{}", project_id, id),
|
||||
kind,
|
||||
id: id.to_string(),
|
||||
project_id: project_id.to_string(),
|
||||
owner_id: owner_id.to_string(),
|
||||
@@ -76,50 +73,30 @@ impl Environment {
|
||||
|
||||
let mut total_cpu_for_stateful_services: f32 = 0.0;
|
||||
let mut total_ram_in_mib_for_stateful_services: u32 = 0;
|
||||
|
||||
match self.kind {
|
||||
Kind::Development => {
|
||||
// development means stateful services are running on Kubernetes
|
||||
for service in &self.stateful_services {
|
||||
match *service.action() {
|
||||
Action::Create | Action::Nothing => {
|
||||
total_cpu_for_stateful_services += cpu_string_to_float(&service.total_cpus());
|
||||
total_ram_in_mib_for_stateful_services += &service.total_ram_in_mib();
|
||||
}
|
||||
Action::Delete | Action::Pause => {}
|
||||
}
|
||||
}
|
||||
for service in &self.stateful_services {
|
||||
if service.is_managed_service() {
|
||||
// If it is a managed service, we don't care of its resources as it is not managed by us
|
||||
continue;
|
||||
}
|
||||
Kind::Production => {} // production means databases are running on managed services - so it consumes 0 cpu
|
||||
};
|
||||
|
||||
match self.kind {
|
||||
crate::cloud_provider::environment::Kind::Production => {}
|
||||
crate::cloud_provider::environment::Kind::Development => {
|
||||
for service in &self.stateful_services {
|
||||
match *service.action() {
|
||||
Action::Create | Action::Nothing => {
|
||||
required_pods += service.total_instances();
|
||||
}
|
||||
Action::Delete | Action::Pause => {}
|
||||
}
|
||||
match service.action() {
|
||||
Action::Pause | Action::Delete => {
|
||||
total_cpu_for_stateful_services += cpu_string_to_float(service.total_cpus());
|
||||
total_ram_in_mib_for_stateful_services += service.total_ram_in_mib();
|
||||
required_pods += service.total_instances();
|
||||
}
|
||||
Action::Create | Action::Nothing => {}
|
||||
}
|
||||
}
|
||||
|
||||
EnvironmentResources {
|
||||
pods: required_pods,
|
||||
cpu: total_cpu_for_stateless_services + total_cpu_for_stateful_services,
|
||||
ram_in_mib: total_ram_in_mib_for_stateless_services + total_ram_in_mib_for_stateless_services,
|
||||
ram_in_mib: total_ram_in_mib_for_stateless_services + total_ram_in_mib_for_stateful_services,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Kind {
|
||||
Production,
|
||||
Development,
|
||||
}
|
||||
|
||||
pub struct EnvironmentResources {
|
||||
pub pods: u16,
|
||||
pub cpu: f32,
|
||||
|
||||
@@ -170,18 +170,18 @@ pub fn deploy_environment(kubernetes: &dyn Kubernetes, environment: &Environment
|
||||
let listeners_helper = ListenersHelper::new(kubernetes.listeners());
|
||||
|
||||
let stateful_deployment_target = match kubernetes.kind() {
|
||||
Kind::Eks => match environment.kind {
|
||||
crate::cloud_provider::environment::Kind::Production => {
|
||||
DeploymentTarget::ManagedServices(kubernetes, environment)
|
||||
}
|
||||
crate::cloud_provider::environment::Kind::Development => {
|
||||
DeploymentTarget::SelfHosted(kubernetes, environment)
|
||||
}
|
||||
Kind::Eks => DeploymentTarget {
|
||||
kubernetes,
|
||||
environment,
|
||||
},
|
||||
Kind::Doks => DeploymentTarget {
|
||||
kubernetes,
|
||||
environment,
|
||||
},
|
||||
Kind::ScwKapsule => DeploymentTarget {
|
||||
kubernetes,
|
||||
environment,
|
||||
},
|
||||
// FIXME: We don't have any managed service on DO for now
|
||||
Kind::Doks => DeploymentTarget::SelfHosted(kubernetes, environment),
|
||||
// TODO(benjaminch): We don't have any managed service on Scaleway for now
|
||||
Kind::ScwKapsule => DeploymentTarget::SelfHosted(kubernetes, environment),
|
||||
};
|
||||
|
||||
// do not deploy if there is not enough resources
|
||||
@@ -216,7 +216,10 @@ pub fn deploy_environment(kubernetes: &dyn Kubernetes, environment: &Environment
|
||||
thread::sleep(std::time::Duration::from_millis(100));
|
||||
|
||||
// stateless services are deployed on kubernetes, that's why we choose the deployment target SelfHosted.
|
||||
let stateless_deployment_target = DeploymentTarget::SelfHosted(kubernetes, environment);
|
||||
let stateless_deployment_target = DeploymentTarget {
|
||||
kubernetes,
|
||||
environment,
|
||||
};
|
||||
|
||||
// create all stateless services (router, application...)
|
||||
for service in &environment.stateless_services {
|
||||
@@ -278,11 +281,9 @@ pub fn deploy_environment_error(kubernetes: &dyn Kubernetes, environment: &Envir
|
||||
kubernetes.context().execution_id(),
|
||||
));
|
||||
|
||||
let stateful_deployment_target = match environment.kind {
|
||||
crate::cloud_provider::environment::Kind::Production => {
|
||||
DeploymentTarget::ManagedServices(kubernetes, environment)
|
||||
}
|
||||
crate::cloud_provider::environment::Kind::Development => DeploymentTarget::SelfHosted(kubernetes, environment),
|
||||
let stateful_deployment_target = DeploymentTarget {
|
||||
kubernetes,
|
||||
environment,
|
||||
};
|
||||
|
||||
// clean up all stateful services (database)
|
||||
@@ -302,7 +303,10 @@ pub fn deploy_environment_error(kubernetes: &dyn Kubernetes, environment: &Envir
|
||||
thread::sleep(std::time::Duration::from_millis(100));
|
||||
|
||||
// stateless services are deployed on kubernetes, that's why we choose the deployment target SelfHosted.
|
||||
let stateless_deployment_target = DeploymentTarget::SelfHosted(kubernetes, environment);
|
||||
let stateless_deployment_target = DeploymentTarget {
|
||||
kubernetes,
|
||||
environment,
|
||||
};
|
||||
|
||||
// clean up all stateless services (router, application...)
|
||||
for service in &environment.stateless_services {
|
||||
@@ -324,15 +328,16 @@ pub fn deploy_environment_error(kubernetes: &dyn Kubernetes, environment: &Envir
|
||||
pub fn pause_environment(kubernetes: &dyn Kubernetes, environment: &Environment) -> Result<(), EngineError> {
|
||||
let listeners_helper = ListenersHelper::new(kubernetes.listeners());
|
||||
|
||||
let stateful_deployment_target = match environment.kind {
|
||||
crate::cloud_provider::environment::Kind::Production => {
|
||||
DeploymentTarget::ManagedServices(kubernetes, environment)
|
||||
}
|
||||
crate::cloud_provider::environment::Kind::Development => DeploymentTarget::SelfHosted(kubernetes, environment),
|
||||
let stateful_deployment_target = DeploymentTarget {
|
||||
kubernetes,
|
||||
environment,
|
||||
};
|
||||
|
||||
// stateless services are deployed on kubernetes, that's why we choose the deployment target SelfHosted.
|
||||
let stateless_deployment_target = DeploymentTarget::SelfHosted(kubernetes, environment);
|
||||
let stateless_deployment_target = DeploymentTarget {
|
||||
kubernetes,
|
||||
environment,
|
||||
};
|
||||
|
||||
// create all stateless services (router, application...)
|
||||
for service in &environment.stateless_services {
|
||||
@@ -401,15 +406,16 @@ pub fn pause_environment(kubernetes: &dyn Kubernetes, environment: &Environment)
|
||||
pub fn delete_environment(kubernetes: &dyn Kubernetes, environment: &Environment) -> Result<(), EngineError> {
|
||||
let listeners_helper = ListenersHelper::new(kubernetes.listeners());
|
||||
|
||||
let stateful_deployment_target = match environment.kind {
|
||||
crate::cloud_provider::environment::Kind::Production => {
|
||||
DeploymentTarget::ManagedServices(kubernetes, environment)
|
||||
}
|
||||
crate::cloud_provider::environment::Kind::Development => DeploymentTarget::SelfHosted(kubernetes, environment),
|
||||
let stateful_deployment_target = DeploymentTarget {
|
||||
kubernetes,
|
||||
environment,
|
||||
};
|
||||
|
||||
// stateless services are deployed on kubernetes, that's why we choose the deployment target SelfHosted.
|
||||
let stateless_deployment_target = DeploymentTarget::SelfHosted(kubernetes, environment);
|
||||
let stateless_deployment_target = DeploymentTarget {
|
||||
kubernetes,
|
||||
environment,
|
||||
};
|
||||
|
||||
// delete all stateless services (router, application...)
|
||||
for service in &environment.stateless_services {
|
||||
|
||||
@@ -82,9 +82,7 @@ impl TerraformStateCredentials {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum DeploymentTarget<'a> {
|
||||
// ManagedService = Managed by the Cloud Provider (eg. RDS, DynamoDB...)
|
||||
ManagedServices(&'a dyn Kubernetes, &'a Environment),
|
||||
// SelfHosted = Kubernetes or anything else that implies management on our side
|
||||
SelfHosted(&'a dyn Kubernetes, &'a Environment),
|
||||
pub struct DeploymentTarget<'a> {
|
||||
pub kubernetes: &'a dyn Kubernetes,
|
||||
pub environment: &'a Environment,
|
||||
}
|
||||
|
||||
@@ -161,11 +161,8 @@ impl Service for Application {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
let commit_id = self.image().commit_id.as_str();
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::cmd::kubectl;
|
||||
use crate::error::{EngineError, EngineErrorScope};
|
||||
use crate::models::DatabaseMode::MANAGED;
|
||||
use crate::models::{Context, Listen, Listener, Listeners};
|
||||
|
||||
pub struct MongoDB {
|
||||
@@ -64,7 +65,11 @@ impl MongoDB {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulService for MongoDB {}
|
||||
impl StatefulService for MongoDB {
|
||||
fn is_managed_service(&self) -> bool {
|
||||
self.options.mode == MANAGED
|
||||
}
|
||||
}
|
||||
|
||||
impl Service for MongoDB {
|
||||
fn context(&self) -> &Context {
|
||||
@@ -120,10 +125,8 @@ impl Service for MongoDB {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use tera::Context as TeraContext;
|
||||
|
||||
use crate::cloud_provider::environment::Kind;
|
||||
use crate::cloud_provider::service::{
|
||||
check_service_version, default_tera_context, delete_stateful_service, deploy_stateful_service, get_tfstate_name,
|
||||
get_tfstate_suffix, scale_down_database, send_progress_on_long_task, Action, Backup, Create, Database,
|
||||
@@ -14,6 +13,7 @@ use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::cmd::kubectl;
|
||||
use crate::error::{EngineError, EngineErrorCause, EngineErrorScope, StringError};
|
||||
use crate::models::DatabaseMode::MANAGED;
|
||||
use crate::models::{Context, Listen, Listener, Listeners};
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
@@ -96,7 +96,11 @@ impl MySQL {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulService for MySQL {}
|
||||
impl StatefulService for MySQL {
|
||||
fn is_managed_service(&self) -> bool {
|
||||
self.options.mode == MANAGED
|
||||
}
|
||||
}
|
||||
|
||||
impl Service for MySQL {
|
||||
fn context(&self) -> &Context {
|
||||
@@ -152,18 +156,11 @@ impl Service for MySQL {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
let is_managed_services = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
// we need the kubernetes config file to store tfstates file in kube secrets
|
||||
let kube_config_file_path = kubernetes.config_file_path()?;
|
||||
context.insert("kubeconfig_path", &kube_config_file_path);
|
||||
@@ -176,7 +173,7 @@ impl Service for MySQL {
|
||||
|
||||
context.insert("namespace", environment.namespace());
|
||||
|
||||
let version = &self.matching_correct_version(is_managed_services)?;
|
||||
let version = &self.matching_correct_version(self.is_managed_service())?;
|
||||
context.insert("version_major", &version.to_major_version_string());
|
||||
context.insert("version", &version.to_string()); // Scaleway needs to have major version only
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use tera::Context as TeraContext;
|
||||
|
||||
use crate::cloud_provider::environment::Kind;
|
||||
use crate::cloud_provider::service::{
|
||||
check_service_version, default_tera_context, delete_stateful_service, deploy_stateful_service, get_tfstate_name,
|
||||
get_tfstate_suffix, scale_down_database, send_progress_on_long_task, Action, Backup, Create, Database,
|
||||
@@ -14,6 +13,7 @@ use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::cmd::kubectl;
|
||||
use crate::error::{EngineError, EngineErrorCause, EngineErrorScope, StringError};
|
||||
use crate::models::DatabaseMode::MANAGED;
|
||||
use crate::models::{Context, Listen, Listener, Listeners};
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
@@ -105,7 +105,11 @@ impl PostgreSQL {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulService for PostgreSQL {}
|
||||
impl StatefulService for PostgreSQL {
|
||||
fn is_managed_service(&self) -> bool {
|
||||
self.options.mode == MANAGED
|
||||
}
|
||||
}
|
||||
|
||||
impl Service for PostgreSQL {
|
||||
fn context(&self) -> &Context {
|
||||
@@ -161,18 +165,11 @@ impl Service for PostgreSQL {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
let is_managed_services = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
// we need the kubernetes config file to store tfstates file in kube secrets
|
||||
let kube_config_file_path = kubernetes.config_file_path()?;
|
||||
context.insert("kubeconfig_path", &kube_config_file_path);
|
||||
@@ -185,7 +182,7 @@ impl Service for PostgreSQL {
|
||||
|
||||
context.insert("namespace", environment.namespace());
|
||||
|
||||
let version = &self.matching_correct_version(is_managed_services)?;
|
||||
let version = &self.matching_correct_version(self.is_managed_service())?;
|
||||
context.insert("version_major", &version.to_major_version_string());
|
||||
context.insert("version", &version.to_string()); // Scaleway needs to have major version only
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::cmd::kubectl;
|
||||
use crate::error::{EngineError, EngineErrorScope};
|
||||
use crate::models::DatabaseMode::MANAGED;
|
||||
use crate::models::{Context, Listen, Listener, Listeners};
|
||||
|
||||
pub struct Redis {
|
||||
@@ -64,7 +65,11 @@ impl Redis {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulService for Redis {}
|
||||
impl StatefulService for Redis {
|
||||
fn is_managed_service(&self) -> bool {
|
||||
self.options.mode == MANAGED
|
||||
}
|
||||
}
|
||||
|
||||
impl Service for Redis {
|
||||
fn context(&self) -> &Context {
|
||||
@@ -120,10 +125,8 @@ impl Service for Redis {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
|
||||
@@ -100,10 +100,8 @@ impl Service for Router {
|
||||
}
|
||||
|
||||
fn tera_context(&self, target: &DeploymentTarget) -> Result<TeraContext, EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
|
||||
let mut context = default_tera_context(self, kubernetes, environment);
|
||||
|
||||
@@ -224,10 +222,8 @@ impl StatelessService for Router {}
|
||||
impl Create for Router {
|
||||
fn on_create(&self, target: &DeploymentTarget) -> Result<(), EngineError> {
|
||||
info!("SCW.router.on_create() called for {}", self.name());
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
|
||||
let workspace_dir = self.workspace_directory();
|
||||
let helm_release_name = self.helm_release_name();
|
||||
|
||||
@@ -18,7 +18,9 @@ use crate::cmd::structs::LabelsContent;
|
||||
use crate::error::{cast_simple_error_to_engine_error, StringError};
|
||||
use crate::error::{EngineError, EngineErrorCause, EngineErrorScope};
|
||||
use crate::models::ProgressLevel::Info;
|
||||
use crate::models::{Context, Listen, Listeners, ListenersHelper, ProgressInfo, ProgressLevel, ProgressScope};
|
||||
use crate::models::{
|
||||
Context, DatabaseMode, Listen, Listeners, ListenersHelper, ProgressInfo, ProgressLevel, ProgressScope,
|
||||
};
|
||||
|
||||
pub trait Service {
|
||||
fn context(&self) -> &Context;
|
||||
@@ -126,6 +128,8 @@ pub trait StatefulService: Service + Create + Pause + Delete + Backup + Clone +
|
||||
crate::cloud_provider::service::Action::Nothing => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_managed_service(&self) -> bool;
|
||||
}
|
||||
|
||||
pub trait Application: StatelessService {
|
||||
@@ -230,6 +234,7 @@ pub struct DatabaseOptions {
|
||||
pub password: String,
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
pub mode: DatabaseMode,
|
||||
pub disk_size_in_gib: u32,
|
||||
pub database_disk_type: String,
|
||||
pub activate_high_availability: bool,
|
||||
@@ -271,21 +276,18 @@ pub fn debug_logs<T>(service: &T, deployment_target: &DeploymentTarget) -> Vec<S
|
||||
where
|
||||
T: Service + ?Sized,
|
||||
{
|
||||
match deployment_target {
|
||||
DeploymentTarget::ManagedServices(_, _) => Vec::new(), // TODO retrieve logs from managed service?
|
||||
DeploymentTarget::SelfHosted(kubernetes, environment) => {
|
||||
match get_stateless_resource_information_for_user(*kubernetes, *environment, service) {
|
||||
Ok(lines) => lines,
|
||||
Err(err) => {
|
||||
error!(
|
||||
"error while retrieving debug logs from {} {}; error: {:?}",
|
||||
service.service_type().name(),
|
||||
service.name_with_id(),
|
||||
err
|
||||
);
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
let kubernetes = deployment_target.kubernetes;
|
||||
let environment = deployment_target.environment;
|
||||
match get_stateless_resource_information_for_user(kubernetes, environment, service) {
|
||||
Ok(lines) => lines,
|
||||
Err(err) => {
|
||||
error!(
|
||||
"error while retrieving debug logs from {} {}; error: {:?}",
|
||||
service.service_type().name(),
|
||||
service.name_with_id(),
|
||||
err
|
||||
);
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,11 +357,8 @@ pub fn deploy_stateless_service<T>(
|
||||
where
|
||||
T: Service + Helm,
|
||||
{
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let workspace_dir = service.workspace_directory();
|
||||
let tera_context = service.tera_context(target)?;
|
||||
|
||||
@@ -436,11 +435,8 @@ pub fn deploy_stateless_service_error<T>(target: &DeploymentTarget, service: &T)
|
||||
where
|
||||
T: Service + Helm,
|
||||
{
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let kubernetes_config_file_path = kubernetes.config_file_path()?;
|
||||
let helm_release_name = service.helm_release_name();
|
||||
|
||||
@@ -476,14 +472,13 @@ pub fn scale_down_database(
|
||||
service: &impl Database,
|
||||
replicas_count: usize,
|
||||
) -> Result<(), EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(_, _) => {
|
||||
info!("Doing nothing for pause database as it is a managed service");
|
||||
return Ok(());
|
||||
}
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
if service.is_managed_service() {
|
||||
info!("Doing nothing for pause database as it is a managed service");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let scaledown_ret = kubectl_exec_scale_replicas_by_selector(
|
||||
kubernetes.config_file_path()?,
|
||||
kubernetes.cloud_provider().credentials_environment_variables(),
|
||||
@@ -506,17 +501,8 @@ pub fn scale_down_application(
|
||||
replicas_count: usize,
|
||||
scaling_kind: ScalingKind,
|
||||
) -> Result<(), EngineError> {
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(_, _) => {
|
||||
return Err(EngineError {
|
||||
cause: EngineErrorCause::Internal,
|
||||
scope: EngineErrorScope::Engine,
|
||||
execution_id: service.context().execution_id().to_string(),
|
||||
message: Some(format!("Cannot scale down managed service: {}", service.name_with_id())),
|
||||
})
|
||||
}
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let scaledown_ret = kubectl_exec_scale_replicas_by_selector(
|
||||
kubernetes.config_file_path()?,
|
||||
kubernetes.cloud_provider().credentials_environment_variables(),
|
||||
@@ -546,11 +532,8 @@ pub fn delete_stateless_service<T>(target: &DeploymentTarget, service: &T, is_er
|
||||
where
|
||||
T: Service + Helm,
|
||||
{
|
||||
let (kubernetes, environment) = match target {
|
||||
DeploymentTarget::ManagedServices(k, env) => (*k, *env),
|
||||
DeploymentTarget::SelfHosted(k, env) => (*k, *env),
|
||||
};
|
||||
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
let helm_release_name = service.helm_release_name();
|
||||
|
||||
if is_error {
|
||||
@@ -568,159 +551,156 @@ where
|
||||
T: StatefulService + Helm + Terraform,
|
||||
{
|
||||
let workspace_dir = service.workspace_directory();
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
if service.is_managed_service() {
|
||||
info!(
|
||||
"deploy {} with name {} on {}",
|
||||
service.service_type().name(),
|
||||
service.name_with_id(),
|
||||
kubernetes.cloud_provider().kind().name()
|
||||
);
|
||||
|
||||
match target {
|
||||
DeploymentTarget::ManagedServices(kubernetes, _) => {
|
||||
// use terraform
|
||||
info!(
|
||||
"deploy {} with name {} on {}",
|
||||
service.service_type().name(),
|
||||
service.name_with_id(),
|
||||
kubernetes.cloud_provider().kind().name()
|
||||
);
|
||||
let context = service.tera_context(target)?;
|
||||
|
||||
let context = service.tera_context(target)?;
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.terraform_common_resource_dir_path(),
|
||||
&workspace_dir,
|
||||
&context,
|
||||
),
|
||||
)?;
|
||||
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.terraform_common_resource_dir_path(),
|
||||
&workspace_dir,
|
||||
&context,
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.terraform_resource_dir_path(),
|
||||
workspace_dir.as_str(),
|
||||
&context,
|
||||
),
|
||||
)?;
|
||||
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.helm_chart_external_name_service_dir(),
|
||||
format!("{}/{}", workspace_dir, "external-name-svc"),
|
||||
&context,
|
||||
),
|
||||
)?;
|
||||
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::cmd::terraform::terraform_init_validate_plan_apply(
|
||||
workspace_dir.as_str(),
|
||||
service.context().is_dry_run_deploy(),
|
||||
),
|
||||
)?;
|
||||
} else {
|
||||
// use helm
|
||||
info!(
|
||||
"deploy {} with name {} on {:?} Kubernetes cluster id {}",
|
||||
service.service_type().name(),
|
||||
service.name_with_id(),
|
||||
kubernetes.cloud_provider().kind().name(),
|
||||
kubernetes.id()
|
||||
);
|
||||
|
||||
let context = service.tera_context(target)?;
|
||||
let kubernetes_config_file_path = kubernetes.config_file_path()?;
|
||||
|
||||
// default chart
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.helm_chart_dir(),
|
||||
workspace_dir.as_str(),
|
||||
&context,
|
||||
),
|
||||
)?;
|
||||
|
||||
// overwrite with our chart values
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.helm_chart_values_dir(),
|
||||
workspace_dir.as_str(),
|
||||
&context,
|
||||
),
|
||||
)?;
|
||||
|
||||
// define labels to add to namespace
|
||||
let namespace_labels = service.context().resource_expiration_in_seconds().map(|_| {
|
||||
vec![
|
||||
(LabelsContent {
|
||||
name: "ttl".into(),
|
||||
value: format!("{}", service.context().resource_expiration_in_seconds().unwrap()),
|
||||
}),
|
||||
]
|
||||
});
|
||||
|
||||
// create a namespace with labels if it does not exist
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::cmd::kubectl::kubectl_exec_create_namespace(
|
||||
kubernetes_config_file_path.as_str(),
|
||||
environment.namespace(),
|
||||
namespace_labels,
|
||||
kubernetes.cloud_provider().credentials_environment_variables(),
|
||||
),
|
||||
)?;
|
||||
|
||||
// do exec helm upgrade and return the last deployment status
|
||||
let helm_history_row = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::cmd::helm::helm_exec_with_upgrade_history(
|
||||
kubernetes_config_file_path.as_str(),
|
||||
environment.namespace(),
|
||||
service.helm_release_name().as_str(),
|
||||
workspace_dir.as_str(),
|
||||
service.start_timeout(),
|
||||
kubernetes.cloud_provider().credentials_environment_variables(),
|
||||
),
|
||||
)?;
|
||||
|
||||
// check deployment status
|
||||
if helm_history_row.is_none() || !helm_history_row.unwrap().is_successfully_deployed() {
|
||||
return Err(service.engine_error(
|
||||
EngineErrorCause::Internal,
|
||||
format!(
|
||||
"{} service fails to be deployed (before start)",
|
||||
service.service_type().name()
|
||||
),
|
||||
)?;
|
||||
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.terraform_resource_dir_path(),
|
||||
workspace_dir.as_str(),
|
||||
&context,
|
||||
),
|
||||
)?;
|
||||
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.helm_chart_external_name_service_dir(),
|
||||
format!("{}/{}", workspace_dir, "external-name-svc"),
|
||||
&context,
|
||||
),
|
||||
)?;
|
||||
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::cmd::terraform::terraform_init_validate_plan_apply(
|
||||
workspace_dir.as_str(),
|
||||
service.context().is_dry_run_deploy(),
|
||||
),
|
||||
)?;
|
||||
));
|
||||
}
|
||||
DeploymentTarget::SelfHosted(kubernetes, environment) => {
|
||||
// use helm
|
||||
info!(
|
||||
"deploy {} with name {} on {:?} Kubernetes cluster id {}",
|
||||
service.service_type().name(),
|
||||
service.name_with_id(),
|
||||
kubernetes.cloud_provider().kind().name(),
|
||||
kubernetes.id()
|
||||
);
|
||||
|
||||
let context = service.tera_context(target)?;
|
||||
let kubernetes_config_file_path = kubernetes.config_file_path()?;
|
||||
|
||||
// default chart
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.helm_chart_dir(),
|
||||
workspace_dir.as_str(),
|
||||
&context,
|
||||
),
|
||||
)?;
|
||||
|
||||
// overwrite with our chart values
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.helm_chart_values_dir(),
|
||||
workspace_dir.as_str(),
|
||||
&context,
|
||||
),
|
||||
)?;
|
||||
|
||||
// define labels to add to namespace
|
||||
let namespace_labels = service.context().resource_expiration_in_seconds().map(|_| {
|
||||
vec![
|
||||
(LabelsContent {
|
||||
name: "ttl".into(),
|
||||
value: format!("{}", service.context().resource_expiration_in_seconds().unwrap()),
|
||||
}),
|
||||
]
|
||||
});
|
||||
|
||||
// create a namespace with labels if it does not exist
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::cmd::kubectl::kubectl_exec_create_namespace(
|
||||
kubernetes_config_file_path.as_str(),
|
||||
environment.namespace(),
|
||||
namespace_labels,
|
||||
kubernetes.cloud_provider().credentials_environment_variables(),
|
||||
),
|
||||
)?;
|
||||
|
||||
// do exec helm upgrade and return the last deployment status
|
||||
let helm_history_row = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::cmd::helm::helm_exec_with_upgrade_history(
|
||||
kubernetes_config_file_path.as_str(),
|
||||
environment.namespace(),
|
||||
service.helm_release_name().as_str(),
|
||||
workspace_dir.as_str(),
|
||||
service.start_timeout(),
|
||||
kubernetes.cloud_provider().credentials_environment_variables(),
|
||||
),
|
||||
)?;
|
||||
|
||||
// check deployment status
|
||||
if helm_history_row.is_none() || !helm_history_row.unwrap().is_successfully_deployed() {
|
||||
// check app status
|
||||
match crate::cmd::kubectl::kubectl_exec_is_pod_ready_with_retry(
|
||||
kubernetes_config_file_path.as_str(),
|
||||
environment.namespace(),
|
||||
service.selector().as_str(),
|
||||
kubernetes.cloud_provider().credentials_environment_variables(),
|
||||
) {
|
||||
Ok(Some(true)) => {}
|
||||
_ => {
|
||||
return Err(service.engine_error(
|
||||
EngineErrorCause::Internal,
|
||||
format!(
|
||||
"{} service fails to be deployed (before start)",
|
||||
service.service_type().name()
|
||||
"{} database {} failed to start after several retries",
|
||||
service.service_type().name(),
|
||||
service.name_with_id()
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
// check app status
|
||||
match crate::cmd::kubectl::kubectl_exec_is_pod_ready_with_retry(
|
||||
kubernetes_config_file_path.as_str(),
|
||||
environment.namespace(),
|
||||
service.selector().as_str(),
|
||||
kubernetes.cloud_provider().credentials_environment_variables(),
|
||||
) {
|
||||
Ok(Some(true)) => {}
|
||||
_ => {
|
||||
return Err(service.engine_error(
|
||||
EngineErrorCause::Internal,
|
||||
format!(
|
||||
"{} database {} failed to start after several retries",
|
||||
service.service_type().name(),
|
||||
service.name_with_id()
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,74 +711,70 @@ pub fn delete_stateful_service<T>(target: &DeploymentTarget, service: &T) -> Res
|
||||
where
|
||||
T: StatefulService + Helm + Terraform,
|
||||
{
|
||||
match target {
|
||||
DeploymentTarget::ManagedServices(kubernetes, environment) => {
|
||||
let workspace_dir = service.workspace_directory();
|
||||
let tera_context = service.tera_context(target)?;
|
||||
let kubernetes = target.kubernetes;
|
||||
let environment = target.environment;
|
||||
if service.is_managed_service() {
|
||||
let workspace_dir = service.workspace_directory();
|
||||
let tera_context = service.tera_context(target)?;
|
||||
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.terraform_common_resource_dir_path(),
|
||||
workspace_dir.as_str(),
|
||||
&tera_context,
|
||||
),
|
||||
)?;
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.terraform_common_resource_dir_path(),
|
||||
workspace_dir.as_str(),
|
||||
&tera_context,
|
||||
),
|
||||
)?;
|
||||
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.terraform_resource_dir_path(),
|
||||
workspace_dir.as_str(),
|
||||
&tera_context,
|
||||
),
|
||||
)?;
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.terraform_resource_dir_path(),
|
||||
workspace_dir.as_str(),
|
||||
&tera_context,
|
||||
),
|
||||
)?;
|
||||
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.helm_chart_external_name_service_dir(),
|
||||
format!("{}/{}", workspace_dir, "external-name-svc"),
|
||||
&tera_context,
|
||||
),
|
||||
)?;
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.helm_chart_external_name_service_dir(),
|
||||
format!("{}/{}", workspace_dir, "external-name-svc"),
|
||||
&tera_context,
|
||||
),
|
||||
)?;
|
||||
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.helm_chart_external_name_service_dir(),
|
||||
workspace_dir.as_str(),
|
||||
&tera_context,
|
||||
),
|
||||
)?;
|
||||
let _ = cast_simple_error_to_engine_error(
|
||||
service.engine_error_scope(),
|
||||
service.context().execution_id(),
|
||||
crate::template::generate_and_copy_all_files_into_dir(
|
||||
service.helm_chart_external_name_service_dir(),
|
||||
workspace_dir.as_str(),
|
||||
&tera_context,
|
||||
),
|
||||
)?;
|
||||
|
||||
match crate::cmd::terraform::terraform_init_validate_destroy(workspace_dir.as_str(), true) {
|
||||
Ok(_) => {
|
||||
info!("deleting secret containing tfstates");
|
||||
let _ = delete_terraform_tfstate_secret(
|
||||
*kubernetes,
|
||||
environment.namespace(),
|
||||
&get_tfstate_name(service),
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
let message = format!("{:?}", e);
|
||||
error!("{}", message);
|
||||
match crate::cmd::terraform::terraform_init_validate_destroy(workspace_dir.as_str(), true) {
|
||||
Ok(_) => {
|
||||
info!("deleting secret containing tfstates");
|
||||
let _ =
|
||||
delete_terraform_tfstate_secret(kubernetes, environment.namespace(), &get_tfstate_name(service));
|
||||
}
|
||||
Err(e) => {
|
||||
let message = format!("{:?}", e);
|
||||
error!("{}", message);
|
||||
|
||||
return Err(service.engine_error(EngineErrorCause::Internal, message));
|
||||
}
|
||||
return Err(service.engine_error(EngineErrorCause::Internal, message));
|
||||
}
|
||||
}
|
||||
DeploymentTarget::SelfHosted(kubernetes, environment) => {
|
||||
let helm_release_name = service.helm_release_name();
|
||||
|
||||
// clean the resource
|
||||
let _ = helm_uninstall_release(*kubernetes, *environment, helm_release_name.as_str())?;
|
||||
}
|
||||
} else {
|
||||
// If not managed, we use helm to deploy
|
||||
let helm_release_name = service.helm_release_name();
|
||||
// clean the resource
|
||||
let _ = helm_uninstall_release(kubernetes, environment, helm_release_name.as_str())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -33,7 +33,6 @@ pub type FailoverEnvironment = Environment;
|
||||
pub struct Environment {
|
||||
pub execution_id: String,
|
||||
pub id: String,
|
||||
pub kind: Kind,
|
||||
pub owner_id: String,
|
||||
pub project_id: String,
|
||||
pub organization_id: String,
|
||||
@@ -91,10 +90,6 @@ impl Environment {
|
||||
let stateful_services = databases;
|
||||
|
||||
crate::cloud_provider::environment::Environment::new(
|
||||
match self.kind {
|
||||
Kind::Production => crate::cloud_provider::environment::Kind::Production,
|
||||
Kind::Development => crate::cloud_provider::environment::Kind::Development,
|
||||
},
|
||||
self.id.as_str(),
|
||||
self.project_id.as_str(),
|
||||
self.owner_id.as_str(),
|
||||
@@ -105,13 +100,6 @@ impl Environment {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
pub enum Kind {
|
||||
Production,
|
||||
Development,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
pub enum Action {
|
||||
@@ -531,6 +519,12 @@ pub struct Route {
|
||||
pub application_name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
|
||||
pub enum DatabaseMode {
|
||||
MANAGED,
|
||||
CONTAINER,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct Database {
|
||||
pub kind: DatabaseKind,
|
||||
@@ -554,6 +548,7 @@ pub struct Database {
|
||||
pub activate_backups: bool,
|
||||
#[serde(default)] // => false if not present in input
|
||||
pub publicly_accessible: bool,
|
||||
pub mode: DatabaseMode,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
@@ -563,6 +558,7 @@ impl Database {
|
||||
cloud_provider: &dyn CloudProvider,
|
||||
) -> Option<Box<dyn StatefulService>> {
|
||||
let database_options = DatabaseOptions {
|
||||
mode: self.mode.clone(),
|
||||
login: self.username.clone(),
|
||||
password: self.password.clone(),
|
||||
host: self.fqdn.clone(),
|
||||
|
||||
@@ -5,12 +5,13 @@ use chrono::Utc;
|
||||
|
||||
use qovery_engine::cloud_provider::utilities::sanitize_name;
|
||||
use qovery_engine::models::{
|
||||
Action, Application, Context, Database, DatabaseKind, Environment, GitCredentials, Kind, Route, Router, Storage,
|
||||
Action, Application, Context, Database, DatabaseKind, Environment, GitCredentials, Route, Router, Storage,
|
||||
StorageType,
|
||||
};
|
||||
|
||||
use crate::utilities::{generate_id, generate_password};
|
||||
use base64;
|
||||
use qovery_engine::models::DatabaseMode::CONTAINER;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
pub fn execution_id() -> String {
|
||||
@@ -65,7 +66,6 @@ pub fn environment_3_apps_3_routers_3_databases(
|
||||
Environment {
|
||||
execution_id: context.execution_id().to_string(),
|
||||
id: generate_id(),
|
||||
kind: Kind::Development,
|
||||
owner_id: generate_id(),
|
||||
project_id: generate_id(),
|
||||
organization_id: organization_id.to_string(),
|
||||
@@ -243,6 +243,7 @@ pub fn environment_3_apps_3_routers_3_databases(
|
||||
activate_high_availability: false,
|
||||
activate_backups: false,
|
||||
publicly_accessible: false,
|
||||
mode: CONTAINER,
|
||||
},
|
||||
Database {
|
||||
kind: DatabaseKind::Postgresql,
|
||||
@@ -263,6 +264,7 @@ pub fn environment_3_apps_3_routers_3_databases(
|
||||
activate_high_availability: false,
|
||||
activate_backups: false,
|
||||
publicly_accessible: false,
|
||||
mode: CONTAINER,
|
||||
},
|
||||
Database {
|
||||
kind: DatabaseKind::Mongodb,
|
||||
@@ -283,6 +285,7 @@ pub fn environment_3_apps_3_routers_3_databases(
|
||||
activate_high_availability: false,
|
||||
activate_backups: false,
|
||||
publicly_accessible: false,
|
||||
mode: CONTAINER,
|
||||
},
|
||||
],
|
||||
clone_from_environment_id: None,
|
||||
@@ -294,7 +297,6 @@ pub fn working_minimal_environment(context: &Context, organization_id: &str, tes
|
||||
Environment {
|
||||
execution_id: context.execution_id().to_string(),
|
||||
id: generate_id(),
|
||||
kind: Kind::Development,
|
||||
owner_id: generate_id(),
|
||||
project_id: generate_id(),
|
||||
organization_id: organization_id.to_string(),
|
||||
@@ -362,7 +364,6 @@ pub fn environnement_2_app_2_routers_1_psql(
|
||||
Environment {
|
||||
execution_id: context.execution_id().to_string(),
|
||||
id: generate_id(),
|
||||
kind: Kind::Development,
|
||||
owner_id: generate_id(),
|
||||
project_id: generate_id(),
|
||||
organization_id: organization_id.to_string(),
|
||||
@@ -386,6 +387,7 @@ pub fn environnement_2_app_2_routers_1_psql(
|
||||
activate_high_availability: false,
|
||||
activate_backups: false,
|
||||
publicly_accessible: false,
|
||||
mode: CONTAINER,
|
||||
}],
|
||||
applications: vec![
|
||||
Application {
|
||||
@@ -517,7 +519,6 @@ pub fn echo_app_environment(context: &Context, organization_id: &str, test_domai
|
||||
Environment {
|
||||
execution_id: context.execution_id().to_string(),
|
||||
id: generate_id(),
|
||||
kind: Kind::Development,
|
||||
owner_id: generate_id(),
|
||||
project_id: generate_id(),
|
||||
organization_id: organization_id.to_string(),
|
||||
@@ -571,7 +572,6 @@ pub fn environment_only_http_server(context: &Context, organization_id: &str) ->
|
||||
Environment {
|
||||
execution_id: context.execution_id().to_string(),
|
||||
id: generate_id(),
|
||||
kind: Kind::Development,
|
||||
owner_id: generate_id(),
|
||||
project_id: generate_id(),
|
||||
organization_id: organization_id.to_string(),
|
||||
@@ -612,7 +612,6 @@ pub fn environment_only_http_server_router(context: &Context, organization_id: &
|
||||
Environment {
|
||||
execution_id: context.execution_id().to_string(),
|
||||
id: generate_id(),
|
||||
kind: Kind::Development,
|
||||
owner_id: generate_id(),
|
||||
project_id: generate_id(),
|
||||
organization_id: organization_id.to_string(),
|
||||
|
||||
@@ -2,7 +2,9 @@ extern crate test_utilities;
|
||||
|
||||
use ::function_name::named;
|
||||
use qovery_engine::cloud_provider::Kind as ProviderKind;
|
||||
use qovery_engine::models::{Action, Clone2, Context, Database, DatabaseKind, Environment, EnvironmentAction, Kind};
|
||||
use qovery_engine::models::{
|
||||
Action, Clone2, Context, Database, DatabaseKind, DatabaseMode, Environment, EnvironmentAction,
|
||||
};
|
||||
use qovery_engine::transaction::TransactionResult;
|
||||
use test_utilities::utilities::{init, FuncTestsSecrets};
|
||||
use tracing::{span, Level};
|
||||
@@ -13,6 +15,7 @@ use self::test_utilities::aws::{
|
||||
AWS_DATABASE_DISK_TYPE, AWS_DATABASE_INSTANCE_TYPE, AWS_KUBE_TEST_CLUSTER_ID, AWS_QOVERY_ORGANIZATION_ID,
|
||||
};
|
||||
use self::test_utilities::utilities::{context, engine_run_test, generate_id, get_pods, is_pod_restarted_env};
|
||||
use qovery_engine::models::DatabaseMode::{CONTAINER, MANAGED};
|
||||
|
||||
/**
|
||||
**
|
||||
@@ -152,7 +155,7 @@ fn postgresql_failover_dev_environment_with_all_options() {
|
||||
.DEFAULT_TEST_DOMAIN
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets");
|
||||
|
||||
let mut environment = test_utilities::common::environnement_2_app_2_routers_1_psql(
|
||||
let environment = test_utilities::common::environnement_2_app_2_routers_1_psql(
|
||||
&context,
|
||||
AWS_QOVERY_ORGANIZATION_ID,
|
||||
test_domain.as_str(),
|
||||
@@ -178,8 +181,6 @@ fn postgresql_failover_dev_environment_with_all_options() {
|
||||
AWS_DATABASE_DISK_TYPE,
|
||||
);
|
||||
|
||||
environment.kind = Kind::Development;
|
||||
environment_delete.kind = Kind::Development;
|
||||
environment_delete.action = Action::Delete;
|
||||
|
||||
let ea = EnvironmentAction::Environment(environment.clone());
|
||||
@@ -250,7 +251,7 @@ fn postgresql_deploy_a_working_development_environment_with_all_options() {
|
||||
.as_ref()
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets");
|
||||
|
||||
let mut environment = test_utilities::common::environnement_2_app_2_routers_1_psql(
|
||||
let environment = test_utilities::common::environnement_2_app_2_routers_1_psql(
|
||||
&context,
|
||||
AWS_QOVERY_ORGANIZATION_ID,
|
||||
test_domain.as_str(),
|
||||
@@ -266,8 +267,6 @@ fn postgresql_deploy_a_working_development_environment_with_all_options() {
|
||||
AWS_DATABASE_DISK_TYPE,
|
||||
);
|
||||
|
||||
environment.kind = Kind::Development;
|
||||
environment_delete.kind = Kind::Development;
|
||||
environment_delete.action = Action::Delete;
|
||||
|
||||
let ea = EnvironmentAction::Environment(environment);
|
||||
@@ -354,6 +353,7 @@ fn postgresql_deploy_a_working_environment_and_redeploy() {
|
||||
activate_high_availability: false,
|
||||
activate_backups: false,
|
||||
publicly_accessible: false,
|
||||
mode: CONTAINER,
|
||||
}];
|
||||
environment.applications = environment
|
||||
.applications
|
||||
@@ -428,6 +428,7 @@ fn test_postgresql_configuration(
|
||||
secrets: FuncTestsSecrets,
|
||||
version: &str,
|
||||
test_name: &str,
|
||||
database_mode: DatabaseMode,
|
||||
) {
|
||||
engine_run_test(|| {
|
||||
init();
|
||||
@@ -443,11 +444,6 @@ fn test_postgresql_configuration(
|
||||
let database_username = "superuser".to_string();
|
||||
let database_password = generate_id();
|
||||
|
||||
let _is_rds = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
environment.databases = vec![Database {
|
||||
kind: DatabaseKind::Postgresql,
|
||||
action: Action::Create,
|
||||
@@ -467,6 +463,7 @@ fn test_postgresql_configuration(
|
||||
activate_high_availability: false,
|
||||
activate_backups: false,
|
||||
publicly_accessible: false,
|
||||
mode: database_mode,
|
||||
}];
|
||||
environment.applications = environment
|
||||
.applications
|
||||
@@ -526,7 +523,7 @@ fn postgresql_v10_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_postgresql_configuration(context, environment, secrets, "10", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "10", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-aws-self-hosted")]
|
||||
@@ -545,7 +542,7 @@ fn postgresql_v11_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_postgresql_configuration(context, environment, secrets, "11", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "11", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-aws-self-hosted")]
|
||||
@@ -563,7 +560,7 @@ fn postgresql_v12_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_postgresql_configuration(context, environment, secrets, "12", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "12", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
// Postgres production environment
|
||||
@@ -573,7 +570,7 @@ fn postgresql_v12_deploy_a_working_dev_environment() {
|
||||
fn postgresql_v10_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = test_utilities::common::working_minimal_environment(
|
||||
let environment = test_utilities::common::working_minimal_environment(
|
||||
&context,
|
||||
AWS_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -582,8 +579,7 @@ fn postgresql_v10_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_postgresql_configuration(context, environment, secrets, "10", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "10", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-aws-managed-services")]
|
||||
@@ -592,7 +588,7 @@ fn postgresql_v10_deploy_a_working_prod_environment() {
|
||||
fn postgresql_v11_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = test_utilities::common::working_minimal_environment(
|
||||
let environment = test_utilities::common::working_minimal_environment(
|
||||
&context,
|
||||
AWS_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -601,8 +597,7 @@ fn postgresql_v11_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_postgresql_configuration(context, environment, secrets, "11", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "11", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-aws-managed-services")]
|
||||
@@ -611,7 +606,7 @@ fn postgresql_v11_deploy_a_working_prod_environment() {
|
||||
fn postgresql_v12_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = test_utilities::common::working_minimal_environment(
|
||||
let environment = test_utilities::common::working_minimal_environment(
|
||||
&context,
|
||||
AWS_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -620,8 +615,7 @@ fn postgresql_v12_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_postgresql_configuration(context, environment, secrets, "12", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "12", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -636,6 +630,7 @@ fn test_mongodb_configuration(
|
||||
secrets: FuncTestsSecrets,
|
||||
version: &str,
|
||||
test_name: &str,
|
||||
database_mode: DatabaseMode,
|
||||
) {
|
||||
engine_run_test(|| {
|
||||
init();
|
||||
@@ -654,11 +649,6 @@ fn test_mongodb_configuration(
|
||||
"mongodb://{}:{}@{}:{}/{}",
|
||||
database_username, database_password, database_host, database_port, database_db_name
|
||||
);
|
||||
// while waiting the info to be given directly in the database info, we're using this
|
||||
let is_documentdb = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
environment.databases = vec![Database {
|
||||
kind: DatabaseKind::Mongodb,
|
||||
@@ -679,6 +669,7 @@ fn test_mongodb_configuration(
|
||||
activate_high_availability: false,
|
||||
activate_backups: false,
|
||||
publicly_accessible: false,
|
||||
mode: database_mode.clone(),
|
||||
}];
|
||||
environment.applications = environment
|
||||
.applications
|
||||
@@ -689,7 +680,7 @@ fn test_mongodb_configuration(
|
||||
app.private_port = Some(1234);
|
||||
app.dockerfile_path = Some(format!("Dockerfile-{}", version));
|
||||
app.environment_vars = btreemap! {
|
||||
"IS_DOCUMENTDB".to_string() => base64::encode(is_documentdb.to_string()),
|
||||
"IS_DOCUMENTDB".to_string() => base64::encode((database_mode == MANAGED).to_string()),
|
||||
"QOVERY_DATABASE_TESTING_DATABASE_FQDN".to_string() => base64::encode(database_host.clone()),
|
||||
"QOVERY_DATABASE_MY_DDB_CONNECTION_URI".to_string() => base64::encode(database_uri.clone()),
|
||||
"QOVERY_DATABASE_TESTING_DATABASE_PORT".to_string() => base64::encode(database_port.to_string()),
|
||||
@@ -741,7 +732,7 @@ fn mongodb_v3_6_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mongodb_configuration(context, environment, secrets, "3.6", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "3.6", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-aws-self-hosted")]
|
||||
@@ -759,7 +750,7 @@ fn mongodb_v4_0_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mongodb_configuration(context, environment, secrets, "4.0", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "4.0", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-aws-self-hosted")]
|
||||
@@ -777,7 +768,7 @@ fn mongodb_v4_2_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mongodb_configuration(context, environment, secrets, "4.2", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "4.2", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-aws-self-hosted")]
|
||||
@@ -795,7 +786,7 @@ fn mongodb_v4_4_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mongodb_configuration(context, environment, secrets, "4.4", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "4.4", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
// MongoDB production environment (DocumentDB)
|
||||
@@ -805,7 +796,7 @@ fn mongodb_v4_4_deploy_a_working_dev_environment() {
|
||||
fn mongodb_v3_6_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = test_utilities::common::working_minimal_environment(
|
||||
let environment = test_utilities::common::working_minimal_environment(
|
||||
&context,
|
||||
AWS_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -814,8 +805,7 @@ fn mongodb_v3_6_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_mongodb_configuration(context, environment, secrets, "3.6", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "3.6", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-aws-managed-services")]
|
||||
@@ -824,7 +814,7 @@ fn mongodb_v3_6_deploy_a_working_prod_environment() {
|
||||
fn mongodb_v4_0_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = test_utilities::common::working_minimal_environment(
|
||||
let environment = test_utilities::common::working_minimal_environment(
|
||||
&context,
|
||||
AWS_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -833,8 +823,7 @@ fn mongodb_v4_0_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_mongodb_configuration(context, environment, secrets, "4.0", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "4.0", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -849,6 +838,7 @@ fn test_mysql_configuration(
|
||||
secrets: FuncTestsSecrets,
|
||||
version: &str,
|
||||
test_name: &str,
|
||||
database_mode: DatabaseMode,
|
||||
) {
|
||||
engine_run_test(|| {
|
||||
init();
|
||||
@@ -866,11 +856,6 @@ fn test_mysql_configuration(
|
||||
let database_username = "superuser".to_string();
|
||||
let database_password = generate_id();
|
||||
|
||||
let _is_rds = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
environment.databases = vec![Database {
|
||||
kind: DatabaseKind::Mysql,
|
||||
action: Action::Create,
|
||||
@@ -890,6 +875,7 @@ fn test_mysql_configuration(
|
||||
activate_high_availability: false,
|
||||
activate_backups: false,
|
||||
publicly_accessible: false,
|
||||
mode: database_mode,
|
||||
}];
|
||||
environment.applications = environment
|
||||
.applications
|
||||
@@ -950,7 +936,7 @@ fn mysql_v5_7_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mysql_configuration(context, environment, secrets, "5.7", function_name!());
|
||||
test_mysql_configuration(context, environment, secrets, "5.7", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-aws-self-hosted")]
|
||||
@@ -968,7 +954,7 @@ fn mysql_v8_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mysql_configuration(context, environment, secrets, "8.0", function_name!());
|
||||
test_mysql_configuration(context, environment, secrets, "8.0", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
// MySQL production environment (RDS)
|
||||
@@ -978,7 +964,7 @@ fn mysql_v8_deploy_a_working_dev_environment() {
|
||||
fn mysql_v5_7_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = test_utilities::common::working_minimal_environment(
|
||||
let environment = test_utilities::common::working_minimal_environment(
|
||||
&context,
|
||||
AWS_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -987,8 +973,7 @@ fn mysql_v5_7_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_mysql_configuration(context, environment, secrets, "5.7", function_name!());
|
||||
test_mysql_configuration(context, environment, secrets, "5.7", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-aws-managed-services")]
|
||||
@@ -997,7 +982,7 @@ fn mysql_v5_7_deploy_a_working_prod_environment() {
|
||||
fn mysql_v8_0_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = test_utilities::common::working_minimal_environment(
|
||||
let environment = test_utilities::common::working_minimal_environment(
|
||||
&context,
|
||||
AWS_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -1006,8 +991,7 @@ fn mysql_v8_0_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_mysql_configuration(context, environment, secrets, "8.0", function_name!());
|
||||
test_mysql_configuration(context, environment, secrets, "8.0", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1022,6 +1006,7 @@ fn test_redis_configuration(
|
||||
secrets: FuncTestsSecrets,
|
||||
version: &str,
|
||||
test_name: &str,
|
||||
database_mode: DatabaseMode,
|
||||
) {
|
||||
engine_run_test(|| {
|
||||
init();
|
||||
@@ -1038,11 +1023,6 @@ fn test_redis_configuration(
|
||||
let database_username = "superuser".to_string();
|
||||
let database_password = generate_id();
|
||||
|
||||
let is_elasticache = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
environment.databases = vec![Database {
|
||||
kind: DatabaseKind::Redis,
|
||||
action: Action::Create,
|
||||
@@ -1062,6 +1042,7 @@ fn test_redis_configuration(
|
||||
activate_high_availability: false,
|
||||
activate_backups: false,
|
||||
publicly_accessible: false,
|
||||
mode: database_mode.clone(),
|
||||
}];
|
||||
environment.applications = environment
|
||||
.applications
|
||||
@@ -1073,7 +1054,7 @@ fn test_redis_configuration(
|
||||
app.private_port = Some(1234);
|
||||
app.dockerfile_path = Some(format!("Dockerfile-{}", version));
|
||||
app.environment_vars = btreemap! {
|
||||
"IS_ELASTICCACHE".to_string() => base64::encode(is_elasticache.to_string()),
|
||||
"IS_ELASTICCACHE".to_string() => base64::encode((database_mode == MANAGED).to_string()),
|
||||
"REDIS_HOST".to_string() => base64::encode(database_host.clone()),
|
||||
"REDIS_PORT".to_string() => base64::encode(database_port.clone().to_string()),
|
||||
"REDIS_USERNAME".to_string() => base64::encode(database_username.clone()),
|
||||
@@ -1123,7 +1104,7 @@ fn redis_v5_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_redis_configuration(context, environment, secrets, "5", function_name!());
|
||||
test_redis_configuration(context, environment, secrets, "5", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-aws-self-hosted")]
|
||||
@@ -1141,7 +1122,7 @@ fn redis_v6_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_redis_configuration(context, environment, secrets, "6", function_name!());
|
||||
test_redis_configuration(context, environment, secrets, "6", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
// Redis production environment (Elasticache)
|
||||
@@ -1151,7 +1132,7 @@ fn redis_v6_deploy_a_working_dev_environment() {
|
||||
fn redis_v5_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = test_utilities::common::working_minimal_environment(
|
||||
let environment = test_utilities::common::working_minimal_environment(
|
||||
&context,
|
||||
AWS_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -1160,8 +1141,7 @@ fn redis_v5_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_redis_configuration(context, environment, secrets, "5", function_name!());
|
||||
test_redis_configuration(context, environment, secrets, "5", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-aws-managed-services")]
|
||||
@@ -1170,7 +1150,7 @@ fn redis_v5_deploy_a_working_prod_environment() {
|
||||
fn redis_v6_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = test_utilities::common::working_minimal_environment(
|
||||
let environment = test_utilities::common::working_minimal_environment(
|
||||
&context,
|
||||
AWS_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -1179,6 +1159,5 @@ fn redis_v6_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_redis_configuration(context, environment, secrets, "6", function_name!());
|
||||
test_redis_configuration(context, environment, secrets, "6", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,14 @@ use tracing::{span, warn, Level};
|
||||
|
||||
use qovery_engine::cloud_provider::Kind as ProviderKind;
|
||||
use qovery_engine::models::{
|
||||
Action, Application, Clone2, Context, Database, DatabaseKind, Environment, EnvironmentAction, Kind,
|
||||
Action, Application, Clone2, Context, Database, DatabaseKind, DatabaseMode, Environment, EnvironmentAction,
|
||||
};
|
||||
use qovery_engine::transaction::TransactionResult;
|
||||
use test_utilities::utilities::{
|
||||
context, engine_run_test, generate_id, get_pods, init, is_pod_restarted_env, FuncTestsSecrets,
|
||||
};
|
||||
|
||||
use qovery_engine::models::DatabaseMode::{CONTAINER, MANAGED};
|
||||
use test_utilities::common::working_minimal_environment;
|
||||
use test_utilities::digitalocean::{
|
||||
clean_environments, delete_environment, deploy_environment, pause_environment, DO_KUBE_TEST_CLUSTER_ID,
|
||||
@@ -169,7 +170,7 @@ fn postgresql_failover_dev_environment_with_all_options() {
|
||||
.DEFAULT_TEST_DOMAIN
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets");
|
||||
|
||||
let mut environment = test_utilities::common::environnement_2_app_2_routers_1_psql(
|
||||
let environment = test_utilities::common::environnement_2_app_2_routers_1_psql(
|
||||
&context,
|
||||
DO_QOVERY_ORGANIZATION_ID,
|
||||
test_domain.as_str(),
|
||||
@@ -195,8 +196,6 @@ fn postgresql_failover_dev_environment_with_all_options() {
|
||||
DO_SELF_HOSTED_DATABASE_DISK_TYPE,
|
||||
);
|
||||
|
||||
environment.kind = Kind::Development;
|
||||
environment_delete.kind = Kind::Development;
|
||||
environment_delete.action = Action::Delete;
|
||||
|
||||
let env_action = EnvironmentAction::Environment(environment.clone());
|
||||
@@ -273,7 +272,7 @@ fn postgresql_deploy_a_working_development_environment_with_all_options() {
|
||||
.as_ref()
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets");
|
||||
|
||||
let mut environment = test_utilities::common::environnement_2_app_2_routers_1_psql(
|
||||
let environment = test_utilities::common::environnement_2_app_2_routers_1_psql(
|
||||
&context,
|
||||
DO_QOVERY_ORGANIZATION_ID,
|
||||
test_domain.as_str(),
|
||||
@@ -289,8 +288,6 @@ fn postgresql_deploy_a_working_development_environment_with_all_options() {
|
||||
DO_SELF_HOSTED_DATABASE_DISK_TYPE,
|
||||
);
|
||||
|
||||
environment.kind = Kind::Development;
|
||||
environment_delete.kind = Kind::Development;
|
||||
environment_delete.action = Action::Delete;
|
||||
|
||||
let env_action = EnvironmentAction::Environment(environment.clone());
|
||||
@@ -356,10 +353,7 @@ fn postgresql_deploy_a_working_environment_and_redeploy() {
|
||||
.as_str(),
|
||||
);
|
||||
|
||||
let is_managed_db = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
let database_mode = CONTAINER;
|
||||
|
||||
let app_name = format!("postgresql-app-{}", generate_id());
|
||||
let database_host = format!(
|
||||
@@ -388,13 +382,14 @@ fn postgresql_deploy_a_working_environment_and_redeploy() {
|
||||
total_cpus: "500m".to_string(),
|
||||
total_ram_in_mib: 512,
|
||||
disk_size_in_gib: 10,
|
||||
database_instance_type: if is_managed_db {
|
||||
mode: database_mode.clone(),
|
||||
database_instance_type: if database_mode == MANAGED {
|
||||
DO_MANAGED_DATABASE_INSTANCE_TYPE
|
||||
} else {
|
||||
DO_SELF_HOSTED_DATABASE_INSTANCE_TYPE
|
||||
}
|
||||
.to_string(),
|
||||
database_disk_type: if is_managed_db {
|
||||
database_disk_type: if database_mode == MANAGED {
|
||||
DO_MANAGED_DATABASE_DISK_TYPE
|
||||
} else {
|
||||
DO_SELF_HOSTED_DATABASE_DISK_TYPE
|
||||
@@ -482,6 +477,7 @@ fn test_postgresql_configuration(
|
||||
secrets: FuncTestsSecrets,
|
||||
version: &str,
|
||||
test_name: &str,
|
||||
database_mode: DatabaseMode,
|
||||
) {
|
||||
engine_run_test(|| {
|
||||
init();
|
||||
@@ -501,11 +497,6 @@ fn test_postgresql_configuration(
|
||||
let database_username = "superuser".to_string();
|
||||
let database_password = generate_id();
|
||||
|
||||
let is_managed_db = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
environment.databases = vec![Database {
|
||||
kind: DatabaseKind::Postgresql,
|
||||
action: Action::Create,
|
||||
@@ -520,13 +511,14 @@ fn test_postgresql_configuration(
|
||||
total_cpus: "100m".to_string(),
|
||||
total_ram_in_mib: 512,
|
||||
disk_size_in_gib: 10,
|
||||
database_instance_type: if is_managed_db {
|
||||
mode: database_mode.clone(),
|
||||
database_instance_type: if database_mode == MANAGED {
|
||||
DO_MANAGED_DATABASE_INSTANCE_TYPE
|
||||
} else {
|
||||
DO_SELF_HOSTED_DATABASE_INSTANCE_TYPE
|
||||
}
|
||||
.to_string(),
|
||||
database_disk_type: if is_managed_db {
|
||||
database_disk_type: if database_mode == MANAGED {
|
||||
DO_MANAGED_DATABASE_DISK_TYPE
|
||||
} else {
|
||||
DO_SELF_HOSTED_DATABASE_DISK_TYPE
|
||||
@@ -601,7 +593,7 @@ fn postgresql_v10_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_postgresql_configuration(context, environment, secrets, "10", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "10", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-do-self-hosted")]
|
||||
@@ -620,7 +612,7 @@ fn postgresql_v11_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_postgresql_configuration(context, environment, secrets, "11", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "11", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-do-self-hosted")]
|
||||
@@ -639,7 +631,7 @@ fn postgresql_v12_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_postgresql_configuration(context, environment, secrets, "12", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "12", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -654,6 +646,7 @@ fn test_mongodb_configuration(
|
||||
secrets: FuncTestsSecrets,
|
||||
version: &str,
|
||||
test_name: &str,
|
||||
database_mode: DatabaseMode,
|
||||
) {
|
||||
engine_run_test(|| {
|
||||
init();
|
||||
@@ -662,11 +655,6 @@ fn test_mongodb_configuration(
|
||||
let _enter = span.enter();
|
||||
let context_for_delete = context.clone_not_same_execution_id();
|
||||
|
||||
let is_managed_db = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
let app_name = format!("mongodb-app-{}", generate_id());
|
||||
let database_host = format!(
|
||||
"mongodb-{}.{}",
|
||||
@@ -696,13 +684,14 @@ fn test_mongodb_configuration(
|
||||
total_cpus: "500m".to_string(),
|
||||
total_ram_in_mib: 512,
|
||||
disk_size_in_gib: 10,
|
||||
database_instance_type: if is_managed_db {
|
||||
mode: database_mode.clone(),
|
||||
database_instance_type: if database_mode == MANAGED {
|
||||
DO_MANAGED_DATABASE_INSTANCE_TYPE
|
||||
} else {
|
||||
DO_SELF_HOSTED_DATABASE_INSTANCE_TYPE
|
||||
}
|
||||
.to_string(),
|
||||
database_disk_type: if is_managed_db {
|
||||
database_disk_type: if database_mode == MANAGED {
|
||||
DO_MANAGED_DATABASE_DISK_TYPE
|
||||
} else {
|
||||
DO_SELF_HOSTED_DATABASE_DISK_TYPE
|
||||
@@ -780,7 +769,7 @@ fn mongodb_v3_6_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mongodb_configuration(context, environment, secrets, "3.6", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "3.6", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-do-self-hosted")]
|
||||
@@ -799,7 +788,7 @@ fn mongodb_v4_0_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mongodb_configuration(context, environment, secrets, "4.0", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "4.0", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-do-self-hosted")]
|
||||
@@ -818,7 +807,7 @@ fn mongodb_v4_2_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mongodb_configuration(context, environment, secrets, "4.2", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "4.2", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-do-self-hosted")]
|
||||
@@ -837,7 +826,7 @@ fn mongodb_v4_4_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mongodb_configuration(context, environment, secrets, "4.4", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "4.4", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -852,6 +841,7 @@ fn test_mysql_configuration(
|
||||
secrets: FuncTestsSecrets,
|
||||
version: &str,
|
||||
test_name: &str,
|
||||
database_mode: DatabaseMode,
|
||||
) {
|
||||
engine_run_test(|| {
|
||||
init();
|
||||
@@ -873,11 +863,6 @@ fn test_mysql_configuration(
|
||||
let database_username = "superuser".to_string();
|
||||
let database_password = generate_id();
|
||||
|
||||
let is_managed_db = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
environment.databases = vec![Database {
|
||||
kind: DatabaseKind::Mysql,
|
||||
action: Action::Create,
|
||||
@@ -892,13 +877,14 @@ fn test_mysql_configuration(
|
||||
total_cpus: "500m".to_string(),
|
||||
total_ram_in_mib: 512,
|
||||
disk_size_in_gib: 10,
|
||||
database_instance_type: if is_managed_db {
|
||||
mode: database_mode.clone(),
|
||||
database_instance_type: if database_mode == MANAGED {
|
||||
DO_MANAGED_DATABASE_INSTANCE_TYPE
|
||||
} else {
|
||||
DO_SELF_HOSTED_DATABASE_INSTANCE_TYPE
|
||||
}
|
||||
.to_string(),
|
||||
database_disk_type: if is_managed_db {
|
||||
database_disk_type: if database_mode == MANAGED {
|
||||
DO_MANAGED_DATABASE_DISK_TYPE
|
||||
} else {
|
||||
DO_SELF_HOSTED_DATABASE_DISK_TYPE
|
||||
@@ -973,7 +959,7 @@ fn mysql_v5_7_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mysql_configuration(context, environment, secrets, "5.7", function_name!());
|
||||
test_mysql_configuration(context, environment, secrets, "5.7", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-do-self-hosted")]
|
||||
@@ -992,7 +978,7 @@ fn mysql_v8_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mysql_configuration(context, environment, secrets, "8.0", function_name!());
|
||||
test_mysql_configuration(context, environment, secrets, "8.0", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
// MySQL production environment
|
||||
@@ -1009,6 +995,7 @@ fn test_redis_configuration(
|
||||
secrets: FuncTestsSecrets,
|
||||
version: &str,
|
||||
test_name: &str,
|
||||
database_mode: DatabaseMode,
|
||||
) {
|
||||
engine_run_test(|| {
|
||||
init();
|
||||
@@ -1029,11 +1016,6 @@ fn test_redis_configuration(
|
||||
let database_username = "superuser".to_string();
|
||||
let database_password = generate_id();
|
||||
|
||||
let is_managed_db = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
environment.databases = vec![Database {
|
||||
kind: DatabaseKind::Redis,
|
||||
action: Action::Create,
|
||||
@@ -1048,13 +1030,14 @@ fn test_redis_configuration(
|
||||
total_cpus: "500m".to_string(),
|
||||
total_ram_in_mib: 512,
|
||||
disk_size_in_gib: 10,
|
||||
database_instance_type: if is_managed_db {
|
||||
mode: database_mode.clone(),
|
||||
database_instance_type: if database_mode == MANAGED {
|
||||
DO_MANAGED_DATABASE_INSTANCE_TYPE
|
||||
} else {
|
||||
DO_SELF_HOSTED_DATABASE_INSTANCE_TYPE
|
||||
}
|
||||
.to_string(),
|
||||
database_disk_type: if is_managed_db {
|
||||
database_disk_type: if database_mode == MANAGED {
|
||||
DO_MANAGED_DATABASE_DISK_TYPE
|
||||
} else {
|
||||
DO_SELF_HOSTED_DATABASE_DISK_TYPE
|
||||
@@ -1129,7 +1112,7 @@ fn redis_v5_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_redis_configuration(context, environment, secrets, "5", function_name!());
|
||||
test_redis_configuration(context, environment, secrets, "5", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-do-self-hosted")]
|
||||
@@ -1148,5 +1131,5 @@ fn redis_v6_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_redis_configuration(context, environment, secrets, "6", function_name!());
|
||||
test_redis_configuration(context, environment, secrets, "6", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,14 @@ use tracing::{span, warn, Level};
|
||||
|
||||
use qovery_engine::cloud_provider::Kind as ProviderKind;
|
||||
use qovery_engine::models::{
|
||||
Action, Application, Clone2, Context, Database, DatabaseKind, Environment, EnvironmentAction, Kind,
|
||||
Action, Application, Clone2, Context, Database, DatabaseKind, DatabaseMode, Environment, EnvironmentAction,
|
||||
};
|
||||
use qovery_engine::transaction::TransactionResult;
|
||||
use test_utilities::utilities::{
|
||||
context, engine_run_test, generate_id, generate_password, get_pods, init, is_pod_restarted_env, FuncTestsSecrets,
|
||||
};
|
||||
|
||||
use qovery_engine::models::DatabaseMode::{CONTAINER, MANAGED};
|
||||
use test_utilities::common::working_minimal_environment;
|
||||
use test_utilities::scaleway::{
|
||||
clean_environments, delete_environment, deploy_environment, pause_environment, SCW_KUBE_TEST_CLUSTER_ID,
|
||||
@@ -166,7 +167,7 @@ fn postgresql_failover_dev_environment_with_all_options() {
|
||||
.DEFAULT_TEST_DOMAIN
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets");
|
||||
|
||||
let mut environment = test_utilities::common::environnement_2_app_2_routers_1_psql(
|
||||
let environment = test_utilities::common::environnement_2_app_2_routers_1_psql(
|
||||
&context,
|
||||
SCW_QOVERY_ORGANIZATION_ID,
|
||||
test_domain.as_str(),
|
||||
@@ -192,8 +193,6 @@ fn postgresql_failover_dev_environment_with_all_options() {
|
||||
SCW_SELF_HOSTED_DATABASE_DISK_TYPE,
|
||||
);
|
||||
|
||||
environment.kind = Kind::Development;
|
||||
environment_delete.kind = Kind::Development;
|
||||
environment_delete.action = Action::Delete;
|
||||
|
||||
let env_action = EnvironmentAction::Environment(environment.clone());
|
||||
@@ -269,7 +268,7 @@ fn postgresql_deploy_a_working_development_environment_with_all_options() {
|
||||
.as_ref()
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets");
|
||||
|
||||
let mut environment = test_utilities::common::environnement_2_app_2_routers_1_psql(
|
||||
let environment = test_utilities::common::environnement_2_app_2_routers_1_psql(
|
||||
&context,
|
||||
SCW_QOVERY_ORGANIZATION_ID,
|
||||
test_domain.as_str(),
|
||||
@@ -284,8 +283,6 @@ fn postgresql_deploy_a_working_development_environment_with_all_options() {
|
||||
SCW_SELF_HOSTED_DATABASE_DISK_TYPE,
|
||||
);
|
||||
|
||||
environment.kind = Kind::Development;
|
||||
environment_delete.kind = Kind::Development;
|
||||
environment_delete.action = Action::Delete;
|
||||
|
||||
let env_action = EnvironmentAction::Environment(environment.clone());
|
||||
@@ -358,10 +355,7 @@ fn postgresql_deploy_a_working_environment_and_redeploy() {
|
||||
let database_username = "superuser".to_string();
|
||||
let database_password = generate_password(true);
|
||||
|
||||
let is_managed_db = match environment.kind {
|
||||
Kind::Development => false,
|
||||
Kind::Production => true,
|
||||
};
|
||||
let database_mode = CONTAINER;
|
||||
|
||||
environment.databases = vec![Database {
|
||||
kind: DatabaseKind::Postgresql,
|
||||
@@ -377,13 +371,14 @@ fn postgresql_deploy_a_working_environment_and_redeploy() {
|
||||
total_cpus: "500m".to_string(),
|
||||
total_ram_in_mib: 512,
|
||||
disk_size_in_gib: 10,
|
||||
database_instance_type: if is_managed_db {
|
||||
mode: database_mode.clone(),
|
||||
database_instance_type: if database_mode == MANAGED {
|
||||
SCW_MANAGED_DATABASE_INSTANCE_TYPE
|
||||
} else {
|
||||
SCW_SELF_HOSTED_DATABASE_INSTANCE_TYPE
|
||||
}
|
||||
.to_string(),
|
||||
database_disk_type: if is_managed_db {
|
||||
database_disk_type: if database_mode == MANAGED {
|
||||
SCW_MANAGED_DATABASE_DISK_TYPE
|
||||
} else {
|
||||
SCW_SELF_HOSTED_DATABASE_DISK_TYPE
|
||||
@@ -471,6 +466,7 @@ fn test_postgresql_configuration(
|
||||
secrets: FuncTestsSecrets,
|
||||
version: &str,
|
||||
test_name: &str,
|
||||
database_mode: DatabaseMode,
|
||||
) {
|
||||
engine_run_test(|| {
|
||||
init();
|
||||
@@ -490,11 +486,6 @@ fn test_postgresql_configuration(
|
||||
let database_username = "superuser".to_string();
|
||||
let database_password = generate_password(true);
|
||||
|
||||
let is_managed_db = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
environment.databases = vec![Database {
|
||||
kind: DatabaseKind::Postgresql,
|
||||
action: Action::Create,
|
||||
@@ -509,13 +500,14 @@ fn test_postgresql_configuration(
|
||||
total_cpus: "500m".to_string(),
|
||||
total_ram_in_mib: 512,
|
||||
disk_size_in_gib: 10,
|
||||
database_instance_type: if is_managed_db {
|
||||
mode: database_mode.clone(),
|
||||
database_instance_type: if database_mode == MANAGED {
|
||||
SCW_MANAGED_DATABASE_INSTANCE_TYPE
|
||||
} else {
|
||||
SCW_SELF_HOSTED_DATABASE_INSTANCE_TYPE
|
||||
}
|
||||
.to_string(),
|
||||
database_disk_type: if is_managed_db {
|
||||
database_disk_type: if database_mode == MANAGED {
|
||||
SCW_MANAGED_DATABASE_DISK_TYPE
|
||||
} else {
|
||||
SCW_SELF_HOSTED_DATABASE_DISK_TYPE
|
||||
@@ -589,7 +581,7 @@ fn postgresql_v10_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_postgresql_configuration(context, environment, secrets, "10", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "10", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-scw-self-hosted")]
|
||||
@@ -607,7 +599,7 @@ fn postgresql_v11_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_postgresql_configuration(context, environment, secrets, "11", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "11", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-scw-self-hosted")]
|
||||
@@ -625,7 +617,7 @@ fn postgresql_v12_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_postgresql_configuration(context, environment, secrets, "12", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "12", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
// Postgres production environment
|
||||
@@ -635,7 +627,7 @@ fn postgresql_v12_deploy_a_working_dev_environment() {
|
||||
fn postgresql_v10_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = working_minimal_environment(
|
||||
let environment = working_minimal_environment(
|
||||
&context,
|
||||
SCW_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -644,8 +636,7 @@ fn postgresql_v10_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_postgresql_configuration(context, environment, secrets, "10", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "10", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-scw-managed-services")]
|
||||
@@ -654,7 +645,7 @@ fn postgresql_v10_deploy_a_working_prod_environment() {
|
||||
fn postgresql_v11_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = working_minimal_environment(
|
||||
let environment = working_minimal_environment(
|
||||
&context,
|
||||
SCW_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -663,8 +654,7 @@ fn postgresql_v11_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_postgresql_configuration(context, environment, secrets, "11", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "11", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-scw-managed-services")]
|
||||
@@ -673,7 +663,7 @@ fn postgresql_v11_deploy_a_working_prod_environment() {
|
||||
fn postgresql_v12_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = working_minimal_environment(
|
||||
let environment = working_minimal_environment(
|
||||
&context,
|
||||
SCW_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -682,8 +672,7 @@ fn postgresql_v12_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_postgresql_configuration(context, environment, secrets, "12", function_name!());
|
||||
test_postgresql_configuration(context, environment, secrets, "12", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -698,6 +687,7 @@ fn test_mongodb_configuration(
|
||||
secrets: FuncTestsSecrets,
|
||||
version: &str,
|
||||
test_name: &str,
|
||||
database_mode: DatabaseMode,
|
||||
) {
|
||||
engine_run_test(|| {
|
||||
init();
|
||||
@@ -721,11 +711,6 @@ fn test_mongodb_configuration(
|
||||
database_username, database_password, database_host, database_port, database_db_name
|
||||
);
|
||||
|
||||
let is_managed_db = match environment.kind {
|
||||
Kind::Development => false,
|
||||
Kind::Production => true,
|
||||
};
|
||||
|
||||
environment.databases = vec![Database {
|
||||
kind: DatabaseKind::Mongodb,
|
||||
action: Action::Create,
|
||||
@@ -740,13 +725,14 @@ fn test_mongodb_configuration(
|
||||
total_cpus: "500m".to_string(),
|
||||
total_ram_in_mib: 512,
|
||||
disk_size_in_gib: 10,
|
||||
database_instance_type: if is_managed_db {
|
||||
mode: database_mode.clone(),
|
||||
database_instance_type: if database_mode == MANAGED {
|
||||
SCW_MANAGED_DATABASE_INSTANCE_TYPE
|
||||
} else {
|
||||
SCW_SELF_HOSTED_DATABASE_INSTANCE_TYPE
|
||||
}
|
||||
.to_string(),
|
||||
database_disk_type: if is_managed_db {
|
||||
database_disk_type: if database_mode == MANAGED {
|
||||
SCW_MANAGED_DATABASE_DISK_TYPE
|
||||
} else {
|
||||
SCW_SELF_HOSTED_DATABASE_DISK_TYPE
|
||||
@@ -823,7 +809,7 @@ fn mongodb_v3_6_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mongodb_configuration(context, environment, secrets, "3.6", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "3.6", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-scw-self-hosted")]
|
||||
@@ -841,7 +827,7 @@ fn mongodb_v4_0_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mongodb_configuration(context, environment, secrets, "4.0", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "4.0", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-scw-self-hosted")]
|
||||
@@ -859,7 +845,7 @@ fn mongodb_v4_2_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mongodb_configuration(context, environment, secrets, "4.2", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "4.2", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-scw-self-hosted")]
|
||||
@@ -877,7 +863,7 @@ fn mongodb_v4_4_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mongodb_configuration(context, environment, secrets, "4.4", function_name!());
|
||||
test_mongodb_configuration(context, environment, secrets, "4.4", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -892,6 +878,7 @@ fn test_mysql_configuration(
|
||||
secrets: FuncTestsSecrets,
|
||||
version: &str,
|
||||
test_name: &str,
|
||||
database_mode: DatabaseMode,
|
||||
) {
|
||||
engine_run_test(|| {
|
||||
init();
|
||||
@@ -913,11 +900,6 @@ fn test_mysql_configuration(
|
||||
let database_username = "superuser".to_string();
|
||||
let database_password = generate_password(true);
|
||||
|
||||
let is_managed_db = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
environment.databases = vec![Database {
|
||||
kind: DatabaseKind::Mysql,
|
||||
action: Action::Create,
|
||||
@@ -932,13 +914,14 @@ fn test_mysql_configuration(
|
||||
total_cpus: "500m".to_string(),
|
||||
total_ram_in_mib: 512,
|
||||
disk_size_in_gib: 10,
|
||||
database_instance_type: if is_managed_db {
|
||||
mode: database_mode.clone(),
|
||||
database_instance_type: if database_mode == MANAGED {
|
||||
SCW_MANAGED_DATABASE_INSTANCE_TYPE
|
||||
} else {
|
||||
SCW_SELF_HOSTED_DATABASE_INSTANCE_TYPE
|
||||
}
|
||||
.to_string(),
|
||||
database_disk_type: if is_managed_db {
|
||||
database_disk_type: if database_mode == MANAGED {
|
||||
SCW_MANAGED_DATABASE_DISK_TYPE
|
||||
} else {
|
||||
SCW_SELF_HOSTED_DATABASE_DISK_TYPE
|
||||
@@ -1012,7 +995,7 @@ fn mysql_v5_7_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mysql_configuration(context, environment, secrets, "5.7", function_name!());
|
||||
test_mysql_configuration(context, environment, secrets, "5.7", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-scw-self-hosted")]
|
||||
@@ -1030,7 +1013,7 @@ fn mysql_v8_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_mysql_configuration(context, environment, secrets, "8.0", function_name!());
|
||||
test_mysql_configuration(context, environment, secrets, "8.0", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
// MySQL production environment (RDS)
|
||||
@@ -1040,7 +1023,7 @@ fn mysql_v8_deploy_a_working_dev_environment() {
|
||||
fn mysql_v8_deploy_a_working_prod_environment() {
|
||||
let context = context();
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
let mut environment = test_utilities::common::working_minimal_environment(
|
||||
let environment = test_utilities::common::working_minimal_environment(
|
||||
&context,
|
||||
SCW_QOVERY_ORGANIZATION_ID,
|
||||
secrets
|
||||
@@ -1049,8 +1032,7 @@ fn mysql_v8_deploy_a_working_prod_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
environment.kind = Kind::Production;
|
||||
test_mysql_configuration(context, environment, secrets, "8.0", function_name!());
|
||||
test_mysql_configuration(context, environment, secrets, "8.0", function_name!(), MANAGED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1065,6 +1047,7 @@ fn test_redis_configuration(
|
||||
secrets: FuncTestsSecrets,
|
||||
version: &str,
|
||||
test_name: &str,
|
||||
database_mode: DatabaseMode,
|
||||
) {
|
||||
engine_run_test(|| {
|
||||
init();
|
||||
@@ -1085,11 +1068,6 @@ fn test_redis_configuration(
|
||||
let database_username = "superuser".to_string();
|
||||
let database_password = generate_password(true);
|
||||
|
||||
let is_managed_db = match environment.kind {
|
||||
Kind::Production => true,
|
||||
Kind::Development => false,
|
||||
};
|
||||
|
||||
environment.databases = vec![Database {
|
||||
kind: DatabaseKind::Redis,
|
||||
action: Action::Create,
|
||||
@@ -1104,13 +1082,14 @@ fn test_redis_configuration(
|
||||
total_cpus: "500m".to_string(),
|
||||
total_ram_in_mib: 512,
|
||||
disk_size_in_gib: 10,
|
||||
database_instance_type: if is_managed_db {
|
||||
mode: database_mode.clone(),
|
||||
database_instance_type: if database_mode == MANAGED {
|
||||
SCW_MANAGED_DATABASE_INSTANCE_TYPE
|
||||
} else {
|
||||
SCW_SELF_HOSTED_DATABASE_INSTANCE_TYPE
|
||||
}
|
||||
.to_string(),
|
||||
database_disk_type: if is_managed_db {
|
||||
database_disk_type: if database_mode == MANAGED {
|
||||
SCW_MANAGED_DATABASE_DISK_TYPE
|
||||
} else {
|
||||
SCW_SELF_HOSTED_DATABASE_DISK_TYPE
|
||||
@@ -1130,7 +1109,7 @@ fn test_redis_configuration(
|
||||
app.private_port = Some(1234);
|
||||
app.dockerfile_path = Some(format!("Dockerfile-{}", version));
|
||||
app.environment_vars = btreemap! {
|
||||
"IS_ELASTICCACHE".to_string() => base64::encode(is_managed_db.to_string()),
|
||||
"IS_ELASTICCACHE".to_string() => base64::encode((database_mode == MANAGED).to_string()),
|
||||
"REDIS_HOST".to_string() => base64::encode(database_host.clone()),
|
||||
"REDIS_PORT".to_string() => base64::encode(database_port.clone().to_string()),
|
||||
"REDIS_USERNAME".to_string() => base64::encode(database_username.clone()),
|
||||
@@ -1185,7 +1164,7 @@ fn redis_v5_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_redis_configuration(context, environment, secrets, "5", function_name!());
|
||||
test_redis_configuration(context, environment, secrets, "5", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-scw-self-hosted")]
|
||||
@@ -1203,5 +1182,5 @@ fn redis_v6_deploy_a_working_dev_environment() {
|
||||
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
|
||||
.as_str(),
|
||||
);
|
||||
test_redis_configuration(context, environment, secrets, "6", function_name!());
|
||||
test_redis_configuration(context, environment, secrets, "6", function_name!(), CONTAINER);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user