Skip to content

Commit

Permalink
use replace_status on set_status_detached
Browse files Browse the repository at this point in the history
  • Loading branch information
evanharmon committed Sep 6, 2024
1 parent 344a595 commit f7abdbe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion eip_operator/src/controller/eip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl k8s_controller::Context for Context {
if let Some(association_id) = status.association_id {
crate::aws::disassociate_eip(&self.ec2_client, &association_id).await?;
}
crate::eip::set_status_detached(&eip_api, &eip.name_unchecked()).await?;
crate::eip::set_status_detached(&eip_api, &eip).await?;
}
}

Expand Down
4 changes: 2 additions & 2 deletions eip_operator/src/controller/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl k8s_controller::Context for Context {
&node_eip_name
);
crate::aws::disassociate_eip(&self.ec2_client, &node_eip_name).await?;
crate::eip::set_status_detached(&eip_api, &node_eip_name).await?;
crate::eip::set_status_detached(&eip_api, &eip).await?;

return Ok(None);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ impl k8s_controller::Context for Context {
crate::aws::disassociate_eip(&self.ec2_client, &association_id).await?;
}
}
crate::eip::set_status_detached(&eip_api, &eip.name_unchecked()).await?;
crate::eip::set_status_detached(&eip_api, &eip).await?;
}
Ok(None)
}
Expand Down
2 changes: 1 addition & 1 deletion eip_operator/src/controller/pod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl k8s_controller::Context for Context {
crate::aws::disassociate_eip(&self.ec2_client, &association_id).await?;
}
}
crate::eip::set_status_detached(&eip_api, &eip.name_unchecked()).await?;
crate::eip::set_status_detached(&eip_api, &eip).await?;
}
if should_autocreate_eip(pod) {
event!(Level::INFO, should_autocreate_eip = true);
Expand Down
35 changes: 16 additions & 19 deletions eip_operator/src/eip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,30 +421,27 @@ pub(crate) async fn set_status_should_attach(
serde_json::to_vec(&eip.clone())?,
)
.await?;
// let result = api.patch_status(name, &params, &patch).await;
event!(Level::INFO, "Done updating status before attaching EIP.");
Ok(result)
}

/// Unsets the eni and privateIpAddress fields in the Eip status.
#[instrument(skip(api), err)]
pub(crate) async fn set_status_detached(api: &Api<Eip>, name: &str) -> Result<Eip, kube::Error> {
pub(crate) async fn set_status_detached(api: &Api<Eip>, eip: &Eip) -> Result<Eip, Error> {
event!(Level::INFO, "Updating status for detached EIP.");
let patch = serde_json::json!({
"apiVersion": Eip::version(),
"kind": "Eip",
"status": {
"eni": None::<String>,
"privateIpAddress": None::<String>,
"resourceId": None::<String>,
"associationId": None::<String>,
}
});
let patch = Patch::Merge(&patch);
let params = PatchParams::default();
let result = api.patch_status(name, &params, &patch).await;
if result.is_ok() {
event!(Level::INFO, "Done updating status for detached EIP.");
}
result
let mut eip = eip.clone();
let status = eip.status.as_mut().ok_or(Error::MissingEipStatus)?;
status.association_id = None::<String>;
status.eni = None::<String>;
status.private_ip_address = None::<String>;
status.resource_id = None::<String>;
let result = api
.replace_status(
&eip.name_unchecked(),
&PostParams::default(),
serde_json::to_vec(&eip.clone())?,
)
.await?;
event!(Level::INFO, "Done updating status for detached EIP.");
Ok(result)
}

0 comments on commit f7abdbe

Please sign in to comment.