Skip to content

Commit

Permalink
fix: resolve minio url within k8s when using loopback cluster ip
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterPtato committed Apr 15, 2024
1 parent 9a54bc9 commit 7036aad
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
35 changes: 31 additions & 4 deletions lib/bolt/core/src/context/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use async_recursion::async_recursion;
use std::{
collections::HashMap,
hash::{Hash, Hasher},
net::Ipv4Addr,
path::{Path, PathBuf},
sync::{Arc, Weak},
};
Expand Down Expand Up @@ -1366,10 +1367,36 @@ async fn add_s3_env(
format!("S3_{provider_upper}_ENDPOINT_INTERNAL_{s3_dep_name}"),
s3_config.endpoint_internal,
));
env.push((
format!("S3_{provider_upper}_ENDPOINT_EXTERNAL_{s3_dep_name}"),
s3_config.endpoint_external,
));
// External endpoint
{
let mut external_endpoint = s3_config.endpoint_external;

// Switch to internal k8s url if public ip is loopback
if let (
s3_util::Provider::Minio,
config::ns::ClusterKind::SingleNode {
public_ip,
minio_port,
..
},
) = (provider, &project_ctx.ns().cluster.kind)
{
let is_loopback = public_ip
.parse::<Ipv4Addr>()
.ok()
.map(|ip| ip.is_loopback())
.unwrap_or_default();

if is_loopback {
external_endpoint = format!("http://minio.minio.svc.cluster.local:{minio_port}");
}
}

env.push((
format!("S3_{provider_upper}_ENDPOINT_EXTERNAL_{s3_dep_name}",),
external_endpoint,
));
}
env.push((
format!("S3_{provider_upper}_REGION_{s3_dep_name}"),
s3_config.region,
Expand Down
9 changes: 8 additions & 1 deletion lib/bolt/core/src/dep/terraform/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ pub async fn project(ctx: &ProjectContext) {
pub async fn gen_bolt_tf(ctx: &ProjectContext, plan_id: &str) -> Result<()> {
// Configure the backend
let backend = match ctx.ns().terraform.backend {
ns::TerraformBackend::Local {} => String::new(),
ns::TerraformBackend::Local {} => indoc!(
"
terraform {
backend \"local\" {}
}
"
)
.to_string(),
ns::TerraformBackend::Postgres {} => indoc!(
"
terraform {
Expand Down

0 comments on commit 7036aad

Please sign in to comment.