Skip to content

Commit d1659ac

Browse files
committed
JsonInstance update with new field and requeue Action reconcil
1 parent c495ee9 commit d1659ac

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

resources/epsilon_instance-definition.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ spec:
4646
ip:
4747
nullable: true
4848
type: string
49+
online:
50+
format: int32
51+
type: integer
4952
slots:
5053
format: int32
5154
type: integer
@@ -67,6 +70,7 @@ spec:
6770
- close
6871
- content
6972
- hub
73+
- online
7074
- slots
7175
- state
7276
- t

src/controller/definitions/epsilon_instance.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,33 @@ pub struct EpsilonInstanceStatus {
4040
pub state: EpsilonState,
4141

4242
pub slots: i32,
43+
pub online: i32,
4344

4445
pub close: bool,
4546
}
4647

4748
impl EpsilonInstance {
4849
pub async fn to_json(&self) -> Result<InstanceJson, EpsilonError> {
50+
let status = self
51+
.status
52+
.as_ref()
53+
.ok_or(EpsilonError::RetrieveStatusError)?.clone();
54+
4955
Ok(InstanceJson {
5056
name: self.get_name(),
5157
template: self.spec.template.clone(),
52-
state: self.get_state(),
5358

54-
slots: self
55-
.status
56-
.as_ref()
57-
.ok_or(EpsilonError::RetrieveStatusError)?
58-
.slots,
59+
content: status.content,
5960

61+
hub: status.hub,
62+
63+
t: status.t,
64+
state: self.get_state(),
65+
66+
slots: status.slots,
6067
online_count: self.get_online_count().await.unwrap_or(0),
68+
69+
ip: status.ip,
6170
})
6271
}
6372

@@ -137,7 +146,17 @@ impl VectorOfInstance for Vec<Arc<EpsilonInstance>> {
137146
pub struct InstanceJson {
138147
pub name: String,
139148
pub template: String,
149+
150+
pub content: String,
151+
152+
pub hub: bool,
153+
154+
#[serde(rename = "type")]
155+
pub t: InstanceType,
140156
pub state: EpsilonState,
157+
141158
pub slots: i32,
142159
pub online_count: i32,
160+
161+
pub ip: Option<String>
143162
}

src/controller/epsilon_controller.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use serde_json::json;
2121
use std::collections::BTreeMap;
2222
use std::env;
2323
use std::sync::Arc;
24+
use std::time::Duration;
2425

2526
pub struct EpsilonController {
2627
context: Arc<Context>,
@@ -57,7 +58,7 @@ impl EpsilonController {
5758
.run(Self::reconcile, Self::on_error, clone_context)
5859
.for_each(|res| async move {
5960
match res {
60-
Ok(_) => {}
61+
Ok(_) => debug!("Sync successful"),
6162
Err(e) => debug!("Reconcile failed: {:?}", e),
6263
}
6364
})
@@ -202,6 +203,7 @@ impl EpsilonController {
202203
content: String::from(""),
203204

204205
slots: template.slots,
206+
online: 0,
205207

206208
close: state == EpsilonState::Stopping,
207209

@@ -212,6 +214,10 @@ impl EpsilonController {
212214
status.ip = pod_ip;
213215
status.state = state;
214216

217+
if state == EpsilonState::Running {
218+
status.online = epsilon_instance.get_online_count().await.unwrap_or(0);
219+
}
220+
215221
status
216222
}
217223
};
@@ -247,7 +253,7 @@ impl EpsilonController {
247253
}
248254
};
249255

250-
Ok(Action::await_change())
256+
Ok(Action::requeue(Duration::from_secs(30)))
251257
}
252258

253259
fn on_error(error: &Error, _context: Arc<Context>) -> Action {

0 commit comments

Comments
 (0)