Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement proper vm name passing #10

Merged
merged 2 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/admin/admin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ message RegistryResponse {

message ApplicationRequest {
string AppName = 1;
optional string VmName = 2;
}

message ApplicationResponse {
Expand Down
8 changes: 2 additions & 6 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ impl AdminClient {
Ok(response.into_inner().cmd_status)
}

pub async fn start(&self, app: String, vm: Option<String>) -> anyhow::Result<()> {
let app_name = match vm {
Some(vm_name) => format!("{app}:{vm_name}"),
None => app,
};
let request = pb::admin::ApplicationRequest { app_name };
pub async fn start(&self, app_name: String, vm_name: Option<String>) -> anyhow::Result<()> {
let request = pb::admin::ApplicationRequest { app_name, vm_name };
let response = self.connect_to().await?.start_application(request).await?;
// Ok(response.into_inner().cmd_status)
Ok(())
Expand Down
7 changes: 4 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@
];
};
in
{
rec {
givc-app = pkgs.callPackage ./nixos/packages/givc-app.nix { inherit src; };
givc-agent = pkgs.callPackage ./nixos/packages/givc-agent.nix { inherit src; };
givc-admin = pkgs.callPackage ./nixos/packages/givc-admin.nix { inherit src; };
givc-admin-rs = pkgs.callPackage ./nixos/packages/givc-admin-rs.nix {
inherit crane;
src = ./.;
};
givc-cli = givc-admin-rs.cli;
};
};
flake = {
Expand All @@ -83,8 +84,8 @@

# Overlays
overlays.default = _final: prev: {
src = ./.;
givc-app = prev.callPackage ./nixos/packages/givc-app.nix { pkgs = prev; };
inherit (self.packages.${prev.stdenv.hostPlatform.system}) givc-app;
givc-cli = self.packages.${prev.stdenv.hostPlatform.system}.givc-admin-rs.cli;
};
};
};
Expand Down
10 changes: 10 additions & 0 deletions nixos/packages/givc-admin-rs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ let
givc = craneLib.buildPackage (
commonArgs
// {
outputs = [
"out"
"cli"
"agent"
];
cargoArtifacts = craneLib.buildDepsOnly commonArgs;

# Additional environment variables or build phases/hooks can be set
Expand All @@ -39,6 +44,11 @@ let
# Avoid issue with source filtering, put symlink back into source tree
ln -sf ../api $sourceRoot/common/api
'';
postInstall = ''
mkdir -p $cli/bin $agent/bin
mv $out/bin/givc-cli $cli/bin/givc-cli
mv $out/bin/givc-agent $agent/bin/givc-agent
'';
}
);
in
Expand Down
2 changes: 1 addition & 1 deletion nixos/tests/admin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ in
testScript =
{ nodes, ... }:
let
cli = "${self'.packages.givc-admin-rs}/bin/givc-cli";
cli = "${self'.packages.givc-admin-rs.cli}/bin/givc-cli";
expected = "givc-ghaf-host.service"; # Name which we _expect_ to see registered in admin server's registry
in
# FIXME: why it so bizzare? (derived from name in cert)
Expand Down
11 changes: 2 additions & 9 deletions src/admin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,12 @@ impl AdminServiceImpl {
self.registry.register(entry)
}

fn parse_app_vm_pair(app_and_vm: &str) -> (&str, Option<&str>) {
if let Some((app, vm)) = app_and_vm.split_once(":") {
(app, Some(vm))
} else {
(app_and_vm, None)
}
}

pub async fn start_app(&self, req: ApplicationRequest) -> anyhow::Result<()> {
if self.state != State::VmsRegistered {
info!("not all required system-vms are registered")
}
let (name, vm) = Self::parse_app_vm_pair(&req.app_name);
let name = req.app_name;
let vm = req.vm_name.as_deref();
let vm_name = format_vm_name(&name, vm);
let systemd_agent = format_service_name(&name, vm);

Expand Down