Skip to content

Commit e7f383a

Browse files
committed
Get instance 👍
1 parent e596eaf commit e7f383a

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/epsilon/server/instance_provider.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ impl InstanceProvider {
4444
Ok(self.kube.delete_pod(name).await?)
4545
}
4646

47+
pub async fn get_instance(&self, instance_name: &str) -> EResult<Instance> {
48+
let pod = self.kube.get_pod(instance_name).await?;
49+
let instance = Instance::from_pod(pod);
50+
51+
Ok(instance)
52+
}
53+
4754
pub async fn get_instances(
4855
&self,
4956
instance_type: &InstanceType,
@@ -221,3 +228,13 @@ pub async fn get_all(instance_provider: &State<Arc<InstanceProvider>>) -> String
221228

222229
json!({ "instances": json_array }).to_string()
223230
}
231+
232+
#[rocket::get("/get_from_name/<instance_name>")]
233+
pub async fn get_from_name(
234+
instance_name: &str,
235+
instance_provider: &State<Arc<InstanceProvider>>,
236+
) -> String {
237+
let instance = instance_provider.get_instance(instance_name).await.unwrap();
238+
239+
serde_json::to_string(&instance.to_json().await).unwrap()
240+
}

src/k8s/kube.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ impl Kube {
8282
"name": "epsilon-configuration"
8383
}
8484
}],
85+
"env": [{
86+
"name": "NAME",
87+
"valueFrom": {
88+
"fieldRef": {
89+
"fieldPath": "metadata.name"
90+
}
91+
}
92+
}],
8593
"ports": [
8694
{
8795
"containerPort": port,
@@ -150,6 +158,10 @@ impl Kube {
150158
Ok(pods.items)
151159
}
152160

161+
pub async fn get_pod(&self, pod_name: &str) -> Result<Pod, Error> {
162+
Ok(self.pods.get(pod_name).await?)
163+
}
164+
153165
pub async fn patch_pod(&self, name: &str, patch: &Value) -> Result<(), Error> {
154166
let parameters = PatchParams::default();
155167

src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ async fn main() -> EResult<()> {
100100
HubTask::init(&epsilon_api, &instance_provider, &queue_provider).await?,
101101
2000,
102102
)
103-
.ignite_task(
104-
CleanTask::init(&epsilon_api, &instance_provider, &queue_provider).await?,
105-
10000,
106-
)
103+
// .ignite_task(
104+
// CleanTask::init(&epsilon_api, &instance_provider, &queue_provider).await?,
105+
// 10000,
106+
// )
107107
.ignite_task(
108108
QueueTask::init(&epsilon_api, &instance_provider, &queue_provider).await?,
109109
2000,
@@ -131,6 +131,7 @@ async fn main() -> EResult<()> {
131131
epsilon::server::instance_provider::in_game,
132132
epsilon::server::instance_provider::get,
133133
epsilon::server::instance_provider::get_all
134+
epsilon::server::instance_provider::get_from_name
134135
],
135136
)
136137
.launch()

0 commit comments

Comments
 (0)