Skip to content

Commit 7144f17

Browse files
committed
api: Make Machine IP a status field, not spec
Not really something specifiers decide. Signed-off-by: Jakob Naucke <[email protected]>
1 parent f43bfa1 commit 7144f17

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

api/v1alpha1/crds.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ type MachineSpec struct {
109109
// Machine ID, typically a UUID
110110
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
111111
Id *string `json:"id"`
112-
// Machine address
113-
Address *string `json:"address"`
114112
}
115113

116114
// MachineStatus defines the observed state of Machine.
@@ -119,6 +117,9 @@ type MachineStatus struct {
119117
// +listMapKey=type
120118
// +optional
121119
Conditions []metav1.Condition `json:"conditions,omitempty"`
120+
// Machine address
121+
// +optional
122+
Address *string `json:"address,omitempty"`
122123
}
123124

124125
// +kubebuilder:object:root=true

register-server/src/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::net::SocketAddr;
1818
use uuid::Uuid;
1919
use warp::{http::StatusCode, reply, Filter};
2020

21-
use trusted_cluster_operator_lib::{Machine, MachineSpec, TrustedExecutionCluster};
21+
use trusted_cluster_operator_lib::*;
2222

2323
#[derive(Parser)]
2424
#[command(name = "register-server")]
@@ -142,7 +142,8 @@ async fn create_machine(client: Client, uuid: &str, client_ip: &str) -> anyhow::
142142
let machine_list = machines.list(&Default::default()).await?;
143143

144144
for existing_machine in machine_list.items {
145-
if existing_machine.spec.address == client_ip {
145+
let existing_address = existing_machine.status.and_then(|s| s.address);
146+
if existing_address.map(|a| a == client_ip).unwrap_or(false) {
146147
if let Some(name) = &existing_machine.metadata.name {
147148
info!("Found existing machine {name} with IP {client_ip}, deleting...");
148149
machines.delete(name, &Default::default()).await?;
@@ -159,9 +160,11 @@ async fn create_machine(client: Client, uuid: &str, client_ip: &str) -> anyhow::
159160
},
160161
spec: MachineSpec {
161162
id: uuid.to_string(),
162-
address: client_ip.to_string(),
163163
},
164-
status: None,
164+
status: Some(MachineStatus {
165+
address: Some(client_ip.to_string()),
166+
conditions: None,
167+
}),
165168
};
166169

167170
machines.create(&Default::default(), &machine).await?;

0 commit comments

Comments
 (0)