Skip to content

Commit

Permalink
fix: ip-info test (#631)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
MasterPtato committed Apr 19, 2024
1 parent 8228371 commit 5fc1e16
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/bolt-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ jobs:
run: nix-shell --pure --run "bolt init --yes ci"

- name: Bolt Test
run: nix-shell --pure --run "bolt test -c 4 -t 120"
run: nix-shell --pure --run "bolt test"

- name: K3D Cleanup
if: always()
run: nix-shell --pure --run "k3d cluster delete rivet-ci"

- name: Force Parallel Failure
if: failure()
Expand Down
16 changes: 15 additions & 1 deletion lib/bolt/core/src/tasks/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ pub async fn gen_spec(
"data": secret_data
}));

let (volumes, volume_mounts) = build_volumes(&ctx, run_context, svcs).await;
let (volumes, volume_mounts) = build_volumes(&ctx, run_context, svcs, k8s_svc_name).await;

let metadata = json!({
"name": k8s_svc_name,
Expand Down Expand Up @@ -918,11 +918,25 @@ pub async fn build_volumes(
project_ctx: &ProjectContext,
run_context: &RunContext,
svcs: &[&ServiceContext],
k8s_svc_name: &str,
) -> (Vec<serde_json::Value>, Vec<serde_json::Value>) {
// Shared data between containers
let mut volumes = Vec::<serde_json::Value>::new();
let mut volume_mounts = Vec::<serde_json::Value>::new();

// TODO: Move this to reading vanilla config inside service instead of populating this
// Add static config
volumes.push(json!({
"name": "rivet-etc",
"configMap": {
"name": format!("rivet-etc-{}", k8s_svc_name),
}
}));
volume_mounts.push(json!({
"name": "rivet-etc",
"mountPath": "/etc/rivet"
}));

// Volumes
volumes.push(json!({
"name": "rivet-src",
Expand Down
12 changes: 2 additions & 10 deletions svc/pkg/ip/ops/info/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,13 @@ async fn fetch_ip_info_io(
tracing::info!("found cached ip info");
ip_info_raw
} else {
let api_url =
if let Some(ip_info_token) = util::env::read_secret_opt(&["ip_info", "token"]).await? {
format!("https://ipinfo.io/{}?token={}", ip_str, ip_info_token)
} else {
format!("https://ipinfo.io/{}", ip_str)
};

// Fetch IP data from external service
tracing::info!(?ip_str, "fetching fresh ip info");

let client = reqwest::Client::new();
let req = client.get(format!("https://ipinfo.io/{}", ip_str));

let req = if let Ok(token) = util::env::read_secret(&["ip_info", "token"]).await {
let req = if let Some(token) = util::env::read_secret_opt(&["ip_info", "token"]).await? {
req.query(&[("token", token)])
} else {
req
Expand All @@ -75,9 +68,8 @@ async fn fetch_ip_info_io(
if !ip_info_res.status().is_success() {
let status = ip_info_res.status();
let body = ip_info_res.text().await?;
tracing::error!(?status, %body, "failed to fetch ip info");

bail!("ip info error");
bail!(format!("ip info error ({status}): {body}"));
};

let ip_info_raw = ip_info_res.json::<serde_json::Value>().await?;
Expand Down

0 comments on commit 5fc1e16

Please sign in to comment.