diff --git a/lib/aws/bootstrap/helm-alertmanager-discord.tf b/lib/aws/bootstrap/helm-alertmanager-discord.tf index e1895366..4e3c161a 100644 --- a/lib/aws/bootstrap/helm-alertmanager-discord.tf +++ b/lib/aws/bootstrap/helm-alertmanager-discord.tf @@ -6,12 +6,6 @@ resource "helm_release" "alertmanager_discord" { atomic = true max_history = 50 - // make a fake arg to avoid TF to validate update on failure because of the atomic option - set { - name = "fake" - value = timestamp() - } - set { name = "replicaCount" value = "1" @@ -43,6 +37,11 @@ resource "helm_release" "alertmanager_discord" { value = "50Mi" } + set { + name = "forced_upgrade" + value = var.forced_upgrade + } + depends_on = [ aws_eks_cluster.eks_cluster, helm_release.aws_vpc_cni, diff --git a/lib/aws/bootstrap/helm-aws-iam-eks-user-mapper.tf b/lib/aws/bootstrap/helm-aws-iam-eks-user-mapper.tf index c1024234..6bb270c7 100644 --- a/lib/aws/bootstrap/helm-aws-iam-eks-user-mapper.tf +++ b/lib/aws/bootstrap/helm-aws-iam-eks-user-mapper.tf @@ -40,12 +40,6 @@ resource "helm_release" "iam_eks_user_mapper" { atomic = true max_history = 50 - // make a fake arg to avoid TF to validate update on failure because of the atomic option - set { - name = "fake" - value = timestamp() - } - set { name = "aws.accessKey" value = aws_iam_access_key.iam_eks_user_mapper.id @@ -87,6 +81,11 @@ resource "helm_release" "iam_eks_user_mapper" { value = "32Mi" } + set { + name = "forced_upgrade" + value = var.forced_upgrade + } + depends_on = [ aws_eks_cluster.eks_cluster, helm_release.aws_vpc_cni, diff --git a/lib/aws/bootstrap/helm-aws-node-term-handler.tf b/lib/aws/bootstrap/helm-aws-node-term-handler.tf index b6f75d2b..0fdb8a0d 100644 --- a/lib/aws/bootstrap/helm-aws-node-term-handler.tf +++ b/lib/aws/bootstrap/helm-aws-node-term-handler.tf @@ -5,12 +5,6 @@ resource "helm_release" "aws_node_term_handler" { atomic = true max_history = 50 - // make a fake arg to avoid TF to validate update on failure because of the atomic option - set { - name = "fake" - value = timestamp() - } - set { name = "nameOverride" value = "aws-node-term-handler" @@ -56,6 +50,11 @@ resource "helm_release" "aws_node_term_handler" { value = "120" } + set { + name = "forced_upgrade" + value = var.forced_upgrade + } + depends_on = [ aws_eks_cluster.eks_cluster, helm_release.aws_vpc_cni, diff --git a/lib/aws/bootstrap/helm-aws-vpc-cni.j2.tf b/lib/aws/bootstrap/helm-aws-vpc-cni.j2.tf index e4e2344d..d88ea1a7 100644 --- a/lib/aws/bootstrap/helm-aws-vpc-cni.j2.tf +++ b/lib/aws/bootstrap/helm-aws-vpc-cni.j2.tf @@ -26,12 +26,6 @@ resource "helm_release" "aws_vpc_cni" { atomic = true max_history = 50 - // make a fake arg to avoid TF to validate update on failure because of the atomic option - set { - name = "fake" - value = timestamp() - } - set { name = "image.region" value = var.region @@ -88,6 +82,11 @@ resource "helm_release" "aws_vpc_cni" { value = "128Mi" } + set { + name = "forced_upgrade" + value = var.forced_upgrade + } + depends_on = [ aws_eks_cluster.eks_cluster, null_resource.delete_aws_managed_cni, diff --git a/lib/aws/bootstrap/helm-calico.tf b/lib/aws/bootstrap/helm-calico.tf index 4a1e092e..7f7571b3 100644 --- a/lib/aws/bootstrap/helm-calico.tf +++ b/lib/aws/bootstrap/helm-calico.tf @@ -6,10 +6,9 @@ resource "helm_release" "calico" { atomic = true max_history = 50 - // make a fake arg to avoid TF to validate update on failure because of the atomic option set { - name = "fake" - value = timestamp() + name = "forced_upgrade" + value = var.forced_upgrade } depends_on = [ diff --git a/lib/aws/bootstrap/helm-cert-manager.j2.tf b/lib/aws/bootstrap/helm-cert-manager.j2.tf index 4e772db5..26f33d89 100644 --- a/lib/aws/bootstrap/helm-cert-manager.j2.tf +++ b/lib/aws/bootstrap/helm-cert-manager.j2.tf @@ -9,11 +9,6 @@ resource "helm_release" "cert_manager" { values = [file("chart_values/cert-manager.yaml")] - set { - name = "fake" - value = timestamp() - } - set { name = "installCRDs" value = "true" @@ -103,6 +98,11 @@ resource "helm_release" "cert_manager" { value = "1Gi" } + set { + name = "forced_upgrade" + value = var.forced_upgrade + } + depends_on = [ aws_eks_cluster.eks_cluster, helm_release.cluster_autoscaler, @@ -139,6 +139,11 @@ resource "helm_release" "cert_manager_config" { value = "{{ managed_dns_domains_terraform_format }}" } + set { + name = "forced_upgrade" + value = var.forced_upgrade + } + {% if external_dns_provider == "cloudflare" %} set { name = "provider.cloudflare.apiToken" diff --git a/lib/aws/bootstrap/helm-cluster-autoscaler.tf b/lib/aws/bootstrap/helm-cluster-autoscaler.tf index ef14f0f2..6f675640 100644 --- a/lib/aws/bootstrap/helm-cluster-autoscaler.tf +++ b/lib/aws/bootstrap/helm-cluster-autoscaler.tf @@ -44,12 +44,6 @@ resource "helm_release" "cluster_autoscaler" { atomic = true max_history = 50 - // make a fake arg to avoid TF to validate update on failure because of the atomic option - set { - name = "fake" - value = timestamp() - } - set { name = "cloudProvider" value = "aws" @@ -125,6 +119,11 @@ resource "helm_release" "cluster_autoscaler" { value = "300Mi" } + set { + name = "forced_upgrade" + value = var.forced_upgrade + } + depends_on = [ aws_iam_user.iam_eks_cluster_autoscaler, aws_iam_access_key.iam_eks_cluster_autoscaler, diff --git a/lib/aws/bootstrap/helm-coredns-config.j2.tf b/lib/aws/bootstrap/helm-coredns-config.j2.tf index 9af6702e..6708a7d6 100644 --- a/lib/aws/bootstrap/helm-coredns-config.j2.tf +++ b/lib/aws/bootstrap/helm-coredns-config.j2.tf @@ -21,12 +21,6 @@ resource "helm_release" "coredns-config" { max_history = 50 force_update = true - // make a fake arg to avoid TF to validate update on failure because of the atomic option - set { - name = "fake" - value = timestamp() - } - set { name = "managed_dns" value = "{{ managed_dns_domains_terraform_format }}" @@ -37,6 +31,11 @@ resource "helm_release" "coredns-config" { value = "{{ managed_dns_resolvers_terraform_format }}" } + set { + name = "forced_upgrade" + value = var.forced_upgrade + } + provisioner "local-exec" { command = < EKS<'a> { &self.context.resource_expiration_in_seconds(), ) } + context.insert("force_upgrade", &self.context.requires_forced_upgrade()); // DNS configuration context.insert("managed_dns", &managed_dns_list); diff --git a/src/models.rs b/src/models.rs index 38815d62..91c88541 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1006,6 +1006,16 @@ impl Context { } } + pub fn requires_forced_upgrade(&self) -> bool { + match &self.metadata { + Some(meta) => match meta.forced_upgrade { + Some(true) => true, + _ => false, + }, + _ => false, + } + } + pub fn is_test_cluster(&self) -> bool { self.test_cluster } @@ -1038,6 +1048,7 @@ pub struct Metadata { pub dry_run_deploy: Option, pub resource_expiration_in_seconds: Option, pub docker_build_options: Option, + pub forced_upgrade: Option, } impl Metadata { @@ -1045,11 +1056,13 @@ impl Metadata { dry_run_deploy: Option, resource_expiration_in_seconds: Option, docker_build_options: Option, + forced_upgrade: Option, ) -> Self { Metadata { dry_run_deploy, resource_expiration_in_seconds, docker_build_options, + forced_upgrade, } } } diff --git a/test_utilities/src/utilities.rs b/test_utilities/src/utilities.rs index 9e4ed8e9..86c24be8 100644 --- a/test_utilities/src/utilities.rs +++ b/test_utilities/src/utilities.rs @@ -49,6 +49,12 @@ pub fn context() -> Context { } }, docker_build_options: Some("--network host".to_string()), + forced_upgrade: Option::from({ + match env::var_os("forced_upgrade") { + Some(_) => true, + None => false, + } + }), }; Context::new(execution_id, home_dir, lib_root_dir, true, None, Option::from(metadata)) diff --git a/tests/README.md b/tests/README.md index 487bc00e..89e35bf7 100644 --- a/tests/README.md +++ b/tests/README.md @@ -25,9 +25,18 @@ Others option will also be necessary and can be found in the `FuncTestsSecrets` * VAULT_TOKEN= ### TTL -By default all deployed tests resources are tagged with a TTL, to be automatically cleaned with [Pleco](https://github.com/Qovery/pleco) if a test fail for some reasons. +By default, all deployed tests resources are tagged with a TTL, to be automatically cleaned with [Pleco](https://github.com/Qovery/pleco) if a test fail for some reasons. This ttl is set by default to 1h, but you can override it with a `ttl` environment variable in seconds like: `ttl=7200`. ### Terraform dry run -If you just want to render Terraform without applying changes, you can set `dry_run_deploy` environment variable to anything to enable it like `dry_run_deploy=true`. \ No newline at end of file +If you just want to render Terraform without applying changes, you can set `dry_run_deploy` environment variable to anything to enable it like `dry_run_deploy=true`. + +### Forced upgrade +By default, helm charts are applied only when they do not exist or when they receive an update. + +During chart upgrade or atomic rollback, Terraform is not able to catch those changes and requires an upgrade. +In order to perform it, you need the variable `forced_upgrade` to `true` to ensure everything is up to date. + +The advantage of having it set to `false` by default, is the deployment speed as only helm changes are applied, the drawback is you can't +be 100% sure of what you've deployed is what you asked for on your infra. \ No newline at end of file