Skip to content

Commit

Permalink
chore: move networking config to pb clients (#1332)
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
NathanFlurry committed Nov 13, 2024
1 parent ff2c7e4 commit 0f64653
Show file tree
Hide file tree
Showing 27 changed files with 115 additions and 32 deletions.
4 changes: 3 additions & 1 deletion docker/dev-full/rivet-client/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"client_id": "fc67e54e-5d6a-4726-ab23-77b0e54f068f",
"datacenter_id": "f288913c-735d-4188-bf9b-2fcf6eac7b9c",
"network_ip": "127.0.0.1",
"actor_network_ip": "127.0.0.1",
"actor_vlan_ip": "127.0.0.1",
"actor_public_ip": "127.0.0.1",
"vector_socket_addr": "127.0.0.1:5030",
"flavor": "isolate",
"redirect_logs": false,
Expand Down
8 changes: 4 additions & 4 deletions packages/api/actor/src/route/actors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{

use super::GlobalQuery;

// MARK: GET /games/{}/environments/{}/actors/{}
// MARK: GET /actors/{}
pub async fn get(
ctx: Ctx<Auth>,
actor_id: Uuid,
Expand Down Expand Up @@ -50,7 +50,7 @@ pub async fn get_deprecated(
get(ctx, actor_id, watch_index, global).await
}

// MARK: POST /games/{}/environments/{}/actors
// MARK: POST /actors
pub async fn create(
ctx: Ctx<Auth>,
body: models::ActorCreateActorRequest,
Expand Down Expand Up @@ -196,7 +196,7 @@ pub async fn create_deprecated(
create(ctx, body, global).await
}

// MARK: DELETE /games/{}/environments/{}/actors/{}
// MARK: DELETE /actors/{}
#[derive(Debug, Clone, Deserialize)]
pub struct DeleteQuery {
#[serde(flatten)]
Expand Down Expand Up @@ -262,7 +262,7 @@ pub async fn destroy_deprecated(
.await
}

// MARK: GET /games/{}/environments/{}/actors
// MARK: GET /actors
#[derive(Debug, Clone, Deserialize)]
pub struct ListQuery {
#[serde(flatten)]
Expand Down
10 changes: 5 additions & 5 deletions packages/api/actor/src/route/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{

use super::GlobalQuery;

// MARK: GET /games/{}/environments/{}/builds/{}
// MARK: GET /builds/{}
pub async fn get(
ctx: Ctx<Auth>,
build_id: Uuid,
Expand Down Expand Up @@ -69,7 +69,7 @@ pub async fn get_deprecated(
get(ctx, build_id, watch_index, global).await
}

// MARK: GET /games/{}/environments/{}/builds
// MARK: GET /builds
#[derive(Debug, Clone, Deserialize)]
pub struct ListQuery {
#[serde(flatten)]
Expand Down Expand Up @@ -158,7 +158,7 @@ pub async fn list_deprecated(
.await
}

// MARK: PATCH /games/{}/environments/{}/builds/{}/tags
// MARK: PATCH /builds/{}/tags
pub async fn patch_tags(
ctx: Ctx<Auth>,
build_id: Uuid,
Expand Down Expand Up @@ -201,7 +201,7 @@ pub async fn patch_tags_deprecated(
patch_tags(ctx, build_id, body, global).await
}

// MARK: POST /games/{}/environments/{}/builds/prepare
// MARK: POST /builds/prepare
pub async fn create_build(
ctx: Ctx<Auth>,
body: models::ActorCreateBuildRequest,
Expand Down Expand Up @@ -310,7 +310,7 @@ pub async fn create_build_deprecated(
create_build(ctx, body, global).await
}

// MARK: POST /games/{}/builds/{}/complete
// MARK: POST /builds/{}/complete
pub async fn complete_build(
ctx: Ctx<Auth>,
build_id: Uuid,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/actor/src/route/dc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{

use super::GlobalQuery;

// MARK: GET /games/{}/environments/{}/datacenters
// MARK: GET /datacenters
pub async fn list(
ctx: Ctx<Auth>,
_watch_index: WatchIndexQuery,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/actor/src/route/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{

use super::GlobalQuery;

// MARK: GET /games/{}/environments/{}/actors/{}/logs
// MARK: GET /actors/{}/logs
#[derive(Debug, Deserialize)]
pub struct GetActorLogsQuery {
#[serde(flatten)]
Expand Down
1 change: 1 addition & 0 deletions packages/api/provision/src/route/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ pub async fn info(
datacenter_id: server.datacenter_id,
cluster_id: datacenter.cluster_id,
vlan_ip: unwrap_ref!(server.vlan_ip, "server should have vlan ip by now").to_string(),
public_ip: unwrap_ref!(server.public_ip, "server should have public ip by now").to_string(),
})
}
4 changes: 2 additions & 2 deletions packages/infra/client/manager/src/actor/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ impl Actor {
source: host_port,
// When no target port was selected, default to randomly selected host port
target: port.target.unwrap_or(host_port),
ip: ctx.config().network_ip,
ip: ctx.config().actor_network_ip,
protocol: port.protocol,
},
)
Expand All @@ -573,7 +573,7 @@ impl Actor {
source: host_port,
// When no target port was selected, default to randomly selected host port
target: port.target.unwrap_or(host_port),
ip: ctx.config().network_ip,
ip: ctx.config().actor_network_ip,
protocol: port.protocol,
},
)
Expand Down
29 changes: 27 additions & 2 deletions packages/infra/client/manager/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
net::{Ipv4Addr, SocketAddr},
net::{IpAddr, Ipv4Addr, SocketAddr},
path::{Path, PathBuf},
};

Expand All @@ -12,24 +12,46 @@ use uuid::Uuid;
pub struct Config {
pub client_id: Uuid,
pub datacenter_id: Uuid,
pub network_ip: Ipv4Addr,

pub vector_socket_addr: Option<SocketAddr>,

pub flavor: protocol::ClientFlavor,

/// Address to serve actor traffic on.
///
/// This will usually be the same as `actor_vlan_ip` unless the node is accessed within the
/// VLAN by a different IP.
pub actor_network_ip: Ipv4Addr,

/// Address to access this node in a VLAN.
///
/// This IP is used to route traffic from Game Guard.
pub actor_vlan_ip: IpAddr,

/// Address to access this node publicly.
///
/// This IP is used when providing the actor's IP & port for host networking.
pub actor_public_ip: IpAddr,

#[serde(default = "default_redirect_logs")]
pub redirect_logs: bool,

pub pegboard_ws_endpoint: Url,

pub api_public_endpoint: Url,

#[serde(default = "default_working_path")]
pub data_dir: PathBuf,

#[serde(default = "default_container_runner_binary_path")]
pub container_runner_binary_path: PathBuf,

#[serde(default = "default_isolate_runner_binary_path")]
pub isolate_runner_binary_path: PathBuf,

#[serde(default = "default_reserved_cpu")]
pub reserved_cpu: u64,

#[serde(default = "default_reserved_memory")]
pub reserved_memory: u64,
}
Expand All @@ -40,6 +62,9 @@ impl Config {
/// This holds information that the server needs in order to orchestrate nodes.
pub fn build_client_config(&self) -> pegboard::client_config::ClientConfig {
pegboard::client_config::ClientConfig {
actor_network_ip: self.actor_network_ip,
actor_vlan_ip: self.actor_vlan_ip,
actor_public_ip: self.actor_public_ip,
reserved_cpu: self.reserved_cpu,
reserved_memory: self.reserved_memory,
}
Expand Down
2 changes: 2 additions & 0 deletions packages/infra/client/manager/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ impl Ctx {
let isolate_runner = if let Some(isolate_runner_pid) = isolate_runner_pid {
let mut guard = self.isolate_runner.write().await;

tracing::info!(?isolate_runner_pid, "found old isolate runner");

let runner = runner::Handle::from_pid(
runner::Comms::socket(),
Pid::from_raw(isolate_runner_pid),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ cat << 'EOF' > /etc/rivet-client/config.json
{
"client_id": "___SERVER_ID___",
"datacenter_id": "___DATACENTER_ID___",
"network_ip": "___VLAN_IP___",
"actor_network_ip": "___VLAN_IP___",
"actor_vlan_ip": "___VLAN_IP___",
"actor_public_ip": "___PUBLIC_IP___",
"vector_socket_addr": "127.0.0.1:5021",
"flavor": "__FLAVOR__",
"pegboard_ws_endpoint": "127.0.0.1:5030"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ server_id=$(echo $response | jq -r '.server_id')
datacenter_id=$(echo $response | jq -r '.datacenter_id')
cluster_id=$(echo $response | jq -r '.cluster_id')
vlan_ip=$(echo $response | jq -r '.vlan_ip')
public_ip=$(echo $response | jq -r '.public_ip')

# Template initialize script
initialize_script="/usr/bin/rivet_initialize.sh"
Expand All @@ -21,6 +22,7 @@ sed -i "s/___SERVER_ID___/$server_id/g" $initialize_script
sed -i "s/___DATACENTER_ID___/$datacenter_id/g" $initialize_script
sed -i "s/___CLUSTER_ID___/$cluster_id/g" $initialize_script
sed -i "s/___VLAN_IP___/$vlan_ip/g" $initialize_script
sed -i "s/___PUBLIC_IP___/$public_ip/g" $initialize_script

# Run initialize script
"$initialize_script"
18 changes: 9 additions & 9 deletions packages/services/ds/src/ops/server/get.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, convert::TryInto, net::IpAddr};
use std::{collections::HashMap, convert::TryInto};

use chirp_workflow::prelude::*;

Expand Down Expand Up @@ -58,7 +58,7 @@ struct ServerNomad {
struct ServerPegboard {
server_id: Uuid,
running_ts: Option<i64>,
public_ip: Option<IpAddr>,
public_ip: Option<String>,
}

#[derive(sqlx::FromRow)]
Expand Down Expand Up @@ -173,12 +173,15 @@ pub async fn ds_server_get(ctx: &OperationCtx, input: &Input) -> GlobalResult<Ou
sql_fetch_all!(
[ctx, ServerPegboard]
"
SELECT ds.server_id, a.running_ts, s.public_ip
SELECT
ds.server_id AS server_id,
a.running_ts AS running_ts,
(c.config->>'actor_public_ip') AS public_ip
FROM db_ds.servers_pegboard AS ds
JOIN db_pegboard.actors AS a
ON ds.pegboard_actor_id = a.actor_id
JOIN db_cluster.servers AS s
ON a.client_id = s.server_id
JOIN db_pegboard.clients AS c
ON a.client_id = c.client_id
WHERE ds.server_id = ANY($1)
",
&input.server_ids,
Expand All @@ -203,10 +206,7 @@ pub async fn ds_server_get(ctx: &OperationCtx, input: &Input) -> GlobalResult<Ou
.iter()
.find(|x| x.server_id == server.server_id)
{
(
server_pb.running_ts.is_some(),
server_pb.public_ip.map(|x| x.to_string()),
)
(server_pb.running_ts.is_some(), server_pb.public_ip.clone())
} else {
// Neither nomad nor pegboard server attached
(false, None)
Expand Down
11 changes: 11 additions & 0 deletions packages/services/pegboard/src/client_config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
use serde::{Deserialize, Serialize};
use std::net::{IpAddr, Ipv4Addr};

#[derive(Debug, Serialize, Deserialize, Hash)]
pub struct ClientConfig {
/// See pegboard_manager::config::Config::actor_network_ip.
pub actor_network_ip: Ipv4Addr,

/// See pegboard_manager::config::Config::actor_vlan_ip.
pub actor_vlan_ip: IpAddr,

/// See pegboard_manager::config::Config::actor_public_ip.
pub actor_public_ip: IpAddr,

// Millicores
pub reserved_cpu: u64,

// MiB
pub reserved_memory: u64,
}
2 changes: 1 addition & 1 deletion scripts/manual_tests/actors_e2e_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ENDPOINT = Deno.env.get("RIVET_ENDPOINT") ?? "http://127.0.0.1:8080";
const BUILD = Deno.env.get("RIVET_BUILD") ??
resolve(
import.meta.dirname,
"../../resources/default-builds/js/test-js-echo/index.js",
"./fixtures/echo_http.js",
);

// Helper function to make HTTP requests
Expand Down
21 changes: 21 additions & 0 deletions scripts/manual_tests/fixtures/echo_http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
console.log(Deno.env.toObject());

const port = Deno.env.get("PORT_ds_http");
if (!port) throw new Error("missing PORT_ds_http");

console.log(`Starting server on ${port}`);
let server = Deno.serve({
handler,
port: parseInt(port),
});

await server.finished;

function handler(req) {
console.log("req");

return new Response(req.body, {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
1 change: 1 addition & 0 deletions sdks/fern/definition/provision/servers/__package__.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sdks/full/go/provision/servers/servers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions sdks/full/openapi/openapi.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions sdks/full/openapi_compat/openapi.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sdks/full/rust/docs/ProvisionServersGetInfoResponse.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0f64653

Please sign in to comment.