Skip to content

Commit 22e198c

Browse files
feat(rust): adjustments for public eks
1 parent 8339029 commit 22e198c

File tree

9 files changed

+73
-36
lines changed

9 files changed

+73
-36
lines changed

implementations/rust/ockam/ockam_api/src/orchestrator/ai_platform/controller_client.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,23 @@ impl AiPlatformApi for ControllerClient {
4848
.tell(ctx, "zones", req)
4949
.await
5050
.into_diagnostic()?
51-
.miette_success("delete zone")
51+
.miette_success("delete zone")?;
52+
53+
// Check if the zone was deleted successfully by attempting to list zones
54+
let max_timeout = std::time::Duration::from_secs(20);
55+
let start_time = std::time::Instant::now();
56+
loop {
57+
let zones = self.list_zones(ctx, cluster).await?;
58+
if zones.iter().all(|zone| zone.zone != zone_name) {
59+
break;
60+
}
61+
if start_time.elapsed() > max_timeout {
62+
return Err(miette::miette!("Timeout while waiting for zone deletion"));
63+
}
64+
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
65+
}
66+
67+
Ok(())
5268
}
5369

5470
async fn deploy_zone(

implementations/rust/ockam/ockam_api/src/orchestrator/ai_platform/node_service_client.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,14 @@ impl AiPlatformApi for InMemoryNode {
212212
is_public: Option<bool>,
213213
) -> miette::Result<EcrCredentials> {
214214
let url = format!("{}/api/{}/ecr", *AI_API_BASE_URL, cluster);
215+
let is_public = is_public.unwrap_or(false);
216+
// TODO: remove once latest provisioner gets deployed
217+
let region = if is_public { "us-east-1" } else { "us-west-2" };
215218

216219
let body = serde_json::json!({
217220
"image_name": image_name,
218-
"is_public": is_public.unwrap_or(false),
221+
"is_public": is_public,
222+
"region": region,
219223
});
220224

221225
let client = reqwest::Client::new();

implementations/rust/ockam/ockam_api/src/orchestrator/ai_platform/requests.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ impl DeleteSecret {
149149
pub struct ProvisionEcr {
150150
#[n(1)] pub image_name: String,
151151
#[n(2)] pub is_public: bool,
152+
#[n(3)] pub region: String,
152153
}
153154

154155
impl Encodable for ProvisionEcr {
@@ -165,9 +166,16 @@ impl Decodable for ProvisionEcr {
165166

166167
impl ProvisionEcr {
167168
pub fn new(image_name: &str, is_public: bool) -> Self {
169+
// TODO: remove once latest provisioner gets deployed
170+
let region = if is_public {
171+
"us-east-1".to_string()
172+
} else {
173+
"us-west-2".to_string()
174+
};
168175
Self {
169176
image_name: image_name.to_string(),
170177
is_public,
178+
region,
171179
}
172180
}
173181
}

implementations/rust/ockam/ockam_api/src/orchestrator/ai_platform/responses.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl Display for Cluster {
4444
#[cbor(map)]
4545
pub struct Zone {
4646
#[n(1)] pub zone: String,
47+
#[serde(alias="customer")]
4748
#[n(2)] pub cluster: String,
4849
}
4950

@@ -113,7 +114,8 @@ impl Decodable for SecretList {
113114
#[rustfmt::skip]
114115
#[cbor(map)]
115116
pub struct EcrCredentials {
116-
#[n(1)] pub customer: String,
117+
#[serde(alias="customer")]
118+
#[n(1)] pub cluster: String,
117119
#[n(2)] pub image_name: String,
118120
#[n(3)] pub repository_uri: String,
119121
#[n(4)] pub auth_token: String,

implementations/rust/ockam/ockam_command/src/cluster/create.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ pub struct CreateCommand {
4343
pub use_public_ecr: bool,
4444

4545
// === Specific args for the HTTP API endpoint
46-
/// Force the command to use the HTTP API.
47-
/// By default, the command will use the Orchestrator API.
48-
#[arg(long)]
49-
pub use_http_api: bool,
50-
5146
/// The Cluster that will be used to set up the Zone.
5247
/// If not set, it will be retrieved from the enrolled user data.
5348
#[arg(long)]
5449
pub cluster: Option<String>,
5550

51+
/// Force the command to use the HTTP API.
52+
/// By default, the command will use the Orchestrator API.
53+
#[arg(long)]
54+
pub use_http_api: bool,
55+
5656
/// The API endpoint of the Ockam AI Platform.
5757
/// Defaults to `http://localhost:30080`.
5858
#[arg(long)]
@@ -76,8 +76,12 @@ impl InMemoryNodeCommand for CreateNodeCommand {
7676

7777
async fn run(&self, node: Arc<InMemoryNode>) -> miette::Result<()> {
7878
let ctx = node.ctx();
79-
let api_client = get_api_client(&node, self.command.use_http_api).await?;
80-
let cluster = api_client.get_cluster(ctx).await?.into_inner();
79+
let use_http_api = self.command.use_http_api || self.command.api_endpoint.is_some();
80+
let api_client = get_api_client(&node, use_http_api).await?;
81+
let cluster = match &self.command.cluster {
82+
None => api_client.get_cluster(ctx).await?.into_inner(),
83+
Some(cluster) => cluster.to_string(),
84+
};
8185
let zone_config = self
8286
.command
8387
.process_images(ctx, &self.opts, &*api_client, &cluster)
@@ -281,7 +285,7 @@ impl CreateCommand {
281285
api_client
282286
.create_zone(ctx, cluster, &self.zone_name)
283287
.await?;
284-
// TODO: how do we pass the secrets to the command? maybe as a json/yaml file?
288+
// TODO: how do we pass the secrets to the command?
285289
// api_client.create_secret(ctx, cluster, &self.zone_name, secret_name, secret_fields).await?;
286290

287291
let zone_config_json = serde_json::to_value(&zone_config).into_diagnostic()?;

implementations/rust/ockam/ockam_command/src/cluster/delete.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ pub struct DeleteCommand {
2727
pub zone_name: String,
2828

2929
// === Specific args for the HTTP API endpoint
30-
/// Force the command to use the HTTP API.
31-
/// By default, the command will use the Orchestrator API.
32-
#[arg(long)]
33-
pub use_http_api: bool,
34-
3530
/// The Cluster that will be used to set up the Zone.
3631
/// If not set, it will be retrieved from the enrolled user data.
3732
#[arg(long)]
3833
pub cluster: Option<String>,
3934

35+
/// Force the command to use the HTTP API.
36+
/// By default, the command will use the Orchestrator API.
37+
#[arg(long)]
38+
pub use_http_api: bool,
39+
4040
/// The API endpoint of the Ockam AI Platform.
4141
/// Defaults to `http://localhost:30080`.
4242
#[arg(long)]
@@ -60,8 +60,12 @@ impl InMemoryNodeCommand for DeployNodeCommand {
6060

6161
async fn run(&self, node: Arc<InMemoryNode>) -> miette::Result<()> {
6262
let ctx = node.ctx();
63-
let api_client = get_api_client(&node, self.command.use_http_api).await?;
64-
let cluster = api_client.get_cluster(ctx).await?.into_inner();
63+
let use_http_api = self.command.use_http_api || self.command.api_endpoint.is_some();
64+
let api_client = get_api_client(&node, use_http_api).await?;
65+
let cluster = match &self.command.cluster {
66+
None => api_client.get_cluster(ctx).await?.into_inner(),
67+
Some(cluster) => cluster.to_string(),
68+
};
6569
api_client
6670
.delete_zone(ctx, &cluster, &self.command.zone_name)
6771
.await?;

implementations/rust/ockam/ockam_command/src/cluster/inlet.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use ockam::transport::SchemeHostnamePort;
1414
use ockam_abac::PolicyExpression;
1515
use ockam_api::cli_state::OCKAM_HOME;
1616
use ockam_api::nodes::InMemoryNode;
17+
use ockam_api::orchestrator::ai_platform::node_service_client::AI_API_BASE_URL_ENV;
1718
use ockam_api::CliState;
1819
use ockam_node::Context;
1920

@@ -74,6 +75,11 @@ pub struct InletCommand {
7475
/// By default, the command will use the Orchestrator API.
7576
#[arg(long)]
7677
pub use_http_api: bool,
78+
79+
/// The API endpoint of the Ockam AI Platform.
80+
/// Defaults to `http://localhost:30080`.
81+
#[arg(long)]
82+
pub api_endpoint: Option<String>,
7783
}
7884

7985
#[derive(Clone)]
@@ -84,8 +90,16 @@ struct InletNodeCommand {
8490

8591
#[async_trait]
8692
impl InMemoryNodeCommand for InletNodeCommand {
93+
async fn init(&self) -> miette::Result<()> {
94+
if let Some(api_endpoint) = &self.command.api_endpoint {
95+
std::env::set_var(AI_API_BASE_URL_ENV, api_endpoint);
96+
}
97+
Ok(())
98+
}
99+
87100
async fn run(&self, node: Arc<InMemoryNode>) -> miette::Result<()> {
88-
let api_client = get_api_client(&node, self.command.use_http_api).await?;
101+
let use_http_api = self.command.use_http_api || self.command.api_endpoint.is_some();
102+
let api_client = get_api_client(&node, use_http_api).await?;
89103
let cluster = match &self.command.cluster {
90104
None => api_client.get_cluster(node.ctx()).await?.into_inner(),
91105
Some(cluster) => cluster.to_string(),

implementations/rust/ockam/ockam_command/src/cluster/outlet.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ before_help = docs::before_help(PREVIEW_TAG),
2828
after_long_help = docs::after_help(AFTER_LONG_HELP)
2929
)]
3030
pub struct OutletCommand {
31-
/// The Cluster that hosts the Zone.
32-
#[arg(long)]
33-
pub cluster: Option<String>,
34-
35-
/// The name of the Zone to connect to
36-
#[arg(long)]
37-
pub zone_name: String,
38-
3931
// == Node Options ==
4032
#[arg(long, env = "ENROLLMENT_TICKET", value_name = "ENROLLMENT TICKET")]
4133
#[arg(help = docs::about("\
@@ -70,12 +62,6 @@ pub struct OutletCommand {
7062
id = "POLICY_EXPRESSION"
7163
)]
7264
pub allow: Option<PolicyExpression>,
73-
74-
// === Specific args for the HTTP API endpoint
75-
/// Force the command to use the HTTP API.
76-
/// By default, the command will use the Orchestrator API.
77-
#[arg(long)]
78-
pub use_http_api: bool,
7965
}
8066

8167
#[derive(Clone)]

implementations/rust/ockam/ockam_command/src/enroll/handler.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use ockam_api::colors::{color_primary, color_uri, color_warn, OckamColor};
2626
use ockam_api::enroll::enrollment::{EnrollStatus, Enrollment};
2727
use ockam_api::enroll::oidc_service::OidcService;
2828
use ockam_api::nodes::InMemoryNode;
29-
use ockam_api::orchestrator::ai_platform::api::AiPlatformApi;
3029
use ockam_api::orchestrator::enroll::auth0::*;
3130
use ockam_api::orchestrator::project::Project;
3231
use ockam_api::orchestrator::project::ProjectsOrchestratorApi;
@@ -349,13 +348,13 @@ impl EnrollHandler {
349348
controller: &ControllerClient,
350349
token: OidcToken,
351350
) -> miette::Result<Option<String>> {
352-
let mut cluster: Option<String> = None;
351+
let cluster: Option<String> = None;
353352
let reply = if self.is_ai_cloud_account {
354353
let reply = controller.enroll_ai_with_oidc_token(ctx, token).await?;
355354
// if let AiEnrollStatus::EnrolledSuccessfully(c) = &reply {
356355
// cluster = Some(c.to_string());
357356
// }
358-
cluster = Some(controller.get_cluster(ctx).await?.into_inner()); // TODO: remove once enroll_ai_with_oidc_token is fixed
357+
// cluster = Some(controller.get_cluster(ctx).await?.into_inner()); // TODO: remove once enroll_ai_with_oidc_token is fixed
359358
reply.into()
360359
} else {
361360
controller.enroll_with_oidc_token(ctx, token).await?

0 commit comments

Comments
 (0)