feat: adding Redis support version

This commit is contained in:
Pierre Mavro
2020-11-25 22:36:29 +01:00
committed by Pierre Mavro
parent b686035926
commit 015cd22e29
6 changed files with 98 additions and 22 deletions

23
Cargo.lock generated
View File

@@ -1729,6 +1729,7 @@ dependencies = [
"rusoto_s3",
"rusoto_sts",
"rust-crypto",
"semver 0.11.0",
"serde",
"serde_derive",
"serde_json",
@@ -2252,7 +2253,7 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
"semver 0.9.0",
]
[[package]]
@@ -2315,7 +2316,16 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
"semver-parser 0.7.0",
]
[[package]]
name = "semver"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6"
dependencies = [
"semver-parser 0.10.1",
]
[[package]]
@@ -2324,6 +2334,15 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "semver-parser"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428"
dependencies = [
"pest",
]
[[package]]
name = "serde"
version = "1.0.117"

View File

@@ -19,6 +19,7 @@ retry = "1.0.0"
dns-lookup = "1.0.3"
rand = "0.7.3"
gethostname = "0.2.1"
semver = "0.11.0"
reqwest = { version = "0.10.8", features = ["blocking"] }
# FIXME use https://crates.io/crates/blocking instead of runtime.rs

View File

@@ -1,7 +1,6 @@
use tera::Context as TeraContext;
use crate::cloud_provider::aws::databases::utilities;
use crate::cloud_provider::aws::kubernetes::EKS;
use crate::cloud_provider::aws::{common, AWS};
use crate::cloud_provider::environment::Environment;
use crate::cloud_provider::kubernetes::Kubernetes;
@@ -11,15 +10,10 @@ use crate::cloud_provider::service::{
};
use crate::cloud_provider::DeploymentTarget;
use crate::cmd::helm::Timeout;
use crate::cmd::kubectl::{
kubectl_exec_create_namespace, kubectl_exec_delete_namespace, kubectl_exec_delete_secret,
};
use crate::constants::{AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY};
use crate::error::{
cast_simple_error_to_engine_error, EngineError, EngineErrorCause, EngineErrorScope,
};
use crate::error::{cast_simple_error_to_engine_error, EngineError, EngineErrorCause};
use crate::models::Context;
use std::path::Path;
use std::collections::HashMap;
pub struct Redis {
context: Context,
@@ -131,6 +125,11 @@ impl Redis {
context.insert("database_fqdn", &self.options.host.as_str());
context.insert("database_id", &self.id());
context.insert(
"resource_expiration_in_seconds",
&self.context.resource_expiration_in_seconds(),
);
context
}
@@ -272,7 +271,16 @@ impl Service for Redis {
}
fn version(&self) -> &str {
self.version.as_str()
let mut redis_managed_versions = HashMap::with_capacity(2);
redis_managed_versions.insert(5, "5.0.6");
redis_managed_versions.insert(6, "6.x");
// todo: return Result instead to better handle not supported version and avoid trying to deploy a non supported version
match utilities::check_version(redis_managed_versions, self.version.as_str()) {
Ok(v) => v,
Err(e) => e,
}
.as_ref()
}
fn action(&self) -> &Action {

View File

@@ -4,6 +4,8 @@ use crate::cloud_provider::kubernetes::Kubernetes;
use crate::cmd::kubectl::{kubectl_exec_create_namespace, kubectl_exec_delete_secret};
use crate::constants::{AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY};
use crate::error::SimpleError;
use semver::{SemVerError, Version};
use std::collections::HashMap;
// generate the kubernetes config path
pub fn get_kubernetes_config_path(
@@ -74,3 +76,42 @@ pub fn delete_terraform_tfstate_secret(
}
}
}
pub fn check_version(
all_versions: HashMap<u64, &str>,
version_to_check: &str,
) -> Result<str, SemVerError> {
match Version::parse(version_to_check) {
Ok(version) => match all_versions.get(&version.major) {
Some(version) => Ok(**version.clone()),
None => Err(SemVerError::ParseError("version not supported".to_string())),
},
Err(e) => Err(e),
}
}
#[cfg(test)]
mod tests {
use crate::cloud_provider::aws::databases::utilities::check_version;
use std::collections::HashMap;
#[test]
fn check_redis_version() {
let mut redis_managed_versions = HashMap::with_capacity(2);
redis_managed_versions.insert(5, "5.0.6");
redis_managed_versions.insert(6, "6.x");
assert_eq!(
check_version(redis_managed_versions.clone(), "5").unwrap(),
"5.0.6"
);
assert_eq!(
check_version(redis_managed_versions.clone(), "5.0").unwrap(),
"5.0.6"
);
assert_eq!(
check_version(redis_managed_versions.clone(), "6.0").unwrap(),
"6.x"
);
}
}

View File

@@ -3,7 +3,7 @@ use std::rc::Rc;
use chrono::{DateTime, Utc};
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use rand::Rng;
use serde::{Deserialize, Serialize};
use crate::build_platform::{Build, BuildOptions, GitRepository, Image};
@@ -12,7 +12,6 @@ use crate::cloud_provider::service::{DatabaseOptions, StatefulService, Stateless
use crate::cloud_provider::CloudProvider;
use crate::cloud_provider::Kind as CPKind;
use crate::git::Credentials;
use crate::models::DatabaseKind::Mongodb;
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
pub enum EnvironmentAction {

View File

@@ -7,8 +7,8 @@ use qovery_engine::models::{
Action, Clone2, Context, Database, DatabaseKind, Environment, EnvironmentAction,
EnvironmentVariable, Kind,
};
use qovery_engine::transaction::{TransactionResult};
use test_utilities::aws::{context};
use qovery_engine::transaction::TransactionResult;
use test_utilities::aws::context;
use test_utilities::utilities::{init, is_pod_restarted};
// to check overload between several databases and apps
@@ -725,7 +725,7 @@ fn test_redis_configuration(context: Context, mut environment: Environment, vers
let database_username = "superuser".to_string();
let database_password = generate_id();
// while waiting the info to be given directly in the database info, we're using this
let is_elasticcache = match environment.kind {
let is_elasticache = match environment.kind {
Kind::Production => true,
Kind::Development => false,
};
@@ -744,7 +744,7 @@ fn test_redis_configuration(context: Context, mut environment: Environment, vers
total_cpus: "500m".to_string(),
total_ram_in_mib: 512,
disk_size_in_gib: 10,
database_instance_type: "db.t2.medium".to_string(),
database_instance_type: "cache.t3.micro".to_string(),
database_disk_type: "gp2".to_string(),
}];
environment.applications = environment
@@ -767,7 +767,7 @@ fn test_redis_configuration(context: Context, mut environment: Environment, vers
// },
EnvironmentVariable {
key: "IS_ELASTICCACHE".to_string(),
value: is_elasticcache.to_string(),
value: is_elasticache.to_string(),
},
EnvironmentVariable {
key: "REDIS_HOST".to_string(),
@@ -825,14 +825,22 @@ fn redis_v6_deploy_a_working_environment() {
test_redis_configuration(context, environment, "6.0");
}
// test Redis 5.0 with production environment (Elasticcache)
// test Redis 5.0 with production environment (Elasticache)
#[test]
#[ignore]
fn redis_v3_6_deploy_a_working_environment_with_production() {
fn redis_v5_0_deploy_a_working_environment_with_production() {
let context = context();
let mut environment = test_utilities::aws::working_minimal_environment(&context);
environment.kind = Kind::Production;
test_redis_configuration(context, environment, "5.0");
}
// test Redis 5.0 with production environment (Elasticache)
#[test]
#[ignore]
fn redis_v6_0_deploy_a_working_environment_with_production() {
let context = context();
let mut environment = test_utilities::aws::working_minimal_environment(&context);
environment.kind = Kind::Production;
test_redis_configuration(context, environment, "6.0");
}