fix: helm uninstall when no chart is deployed and do vpc cidr

This commit is contained in:
Pierre Mavro
2021-08-17 12:14:31 +02:00
committed by Pierre Mavro
parent 7d4e676597
commit b6ada31fb5
5 changed files with 42 additions and 8 deletions

View File

@@ -46,7 +46,7 @@ variable "test_cluster" {
variable "vpc_name" {
description = "VPC name, should be unique"
default = "{{ vpc_name }}"
default = "{{ do_vpc_name }}"
type = string
}
@@ -54,7 +54,7 @@ variable "vpc_name" {
variable "cidr_block" {
description = "CIDR block for VPC segmentation"
default = "{{ vpc_cidr_block }}"
default = "{{ do_vpc_cidr_block }}"
type = string
}

View File

@@ -142,7 +142,7 @@ impl<'a> DOKS<'a> {
context.insert("space_bucket_kubeconfig", &space_kubeconfig_bucket);
// Digital Ocean: Network
context.insert("vpc_name", self.options.vpc_name.as_str());
context.insert("do_vpc_name", self.options.vpc_name.as_str());
let vpc_cidr_block = match self.options.vpc_cidr_set {
// VPC subnet is not set, getting a non used subnet
VpcInitKind::Autodetect => {
@@ -177,7 +177,7 @@ impl<'a> DOKS<'a> {
}
VpcInitKind::Manual => self.options.vpc_cidr_block.clone(),
};
context.insert("vpc_cidr_block", vpc_cidr_block.as_str());
context.insert("do_vpc_cidr_block", vpc_cidr_block.as_str());
// DNS
let managed_dns_list = vec![self.dns_provider.name()];
@@ -521,7 +521,7 @@ impl<'a> Kubernetes for DOKS<'a> {
// Kubeconfig bucket
if let Err(e) = self.spaces.create_bucket(self.kubeconfig_bucket_name().as_str()) {
let message = format!(
"Cannot create object storage bucket {} for cluster {} with id {}",
"cannot create object storage bucket {} for cluster {} with id {}",
self.kubeconfig_bucket_name(),
self.name(),
self.id()
@@ -533,7 +533,7 @@ impl<'a> Kubernetes for DOKS<'a> {
// Logs bucket
if let Err(e) = self.spaces.create_bucket(self.logs_bucket_name().as_str()) {
let message = format!(
"Cannot create object storage bucket {} for cluster {} with id {}",
"cannot create object storage bucket {} for cluster {} with id {}",
self.logs_bucket_name(),
self.name(),
self.id()

View File

@@ -2,6 +2,7 @@ use crate::cloud_provider::helm::HelmAction::Deploy;
use crate::cloud_provider::helm::HelmChartNamespaces::KubeSystem;
use crate::cmd::helm::{
helm_exec_uninstall_with_chart_info, helm_exec_upgrade_with_chart_info, helm_upgrade_diff_with_chart_info,
is_chart_deployed,
};
use crate::cmd::kubectl::{
kubectl_exec_get_configmap, kubectl_exec_get_events, kubectl_exec_rollout_restart_deployment,
@@ -158,7 +159,20 @@ pub trait HelmChart: Send {
helm_exec_upgrade_with_chart_info(kubernetes_config, &environment_variables, self.get_chart_info())?
}
HelmAction::Destroy => {
helm_exec_uninstall_with_chart_info(kubernetes_config, &environment_variables, self.get_chart_info())?
let chart_info = self.get_chart_info();
match is_chart_deployed(
kubernetes_config,
environment_variables.clone(),
Some(get_chart_namespace(chart_info.namespace.clone()).as_str()),
chart_info.name.clone(),
) {
Ok(deployed) => {
if deployed {
helm_exec_uninstall_with_chart_info(kubernetes_config, &environment_variables, chart_info)?
}
}
Err(e) => return Err(e),
};
}
HelmAction::Skip => {}
}

View File

@@ -686,6 +686,26 @@ where
.map(|helm_history_row| helm_history_row.clone()))
}
pub fn is_chart_deployed<P>(
kubernetes_config: P,
envs: Vec<(&str, &str)>,
namespace: Option<&str>,
chart_name: String,
) -> Result<bool, SimpleError>
where
P: AsRef<Path>,
{
let deployed_charts = helm_list(kubernetes_config, envs, namespace)?;
for chart in deployed_charts {
if chart.name == chart_name {
return Ok(true);
}
}
Ok(false)
}
/// List deployed helm charts
///
/// # Arguments

View File

@@ -103,7 +103,7 @@ pub fn cloud_provider_digitalocean(context: &Context) -> DO {
pub fn do_kubernetes_cluster_options(secrets: FuncTestsSecrets, cluster_name: String) -> DoksOptions {
DoksOptions {
vpc_cidr_block: "".to_string(), // vpc_cidr_set to autodetect will fil this empty string
vpc_cidr_block: "should-not-bet-set".to_string(), // vpc_cidr_set to autodetect will fil this empty string
vpc_cidr_set: VpcInitKind::Autodetect,
vpc_name: cluster_name,
qovery_api_url: secrets.QOVERY_API_URL.unwrap(),