Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions operator/src/reference_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,23 @@ async fn image_reconcile(
.await
.map_err(|e| -> ControllerError { e.into() })?;

let uid_owns = |uid: &String| {
let refs = image.metadata.owner_references.as_ref();
refs.map(|os| os.iter().any(|o| o.uid == *uid))
};
let cluster_owns = |cluster: &TrustedExecutionCluster| {
let uid = cluster.metadata.uid.as_ref();
uid.and_then(uid_owns).unwrap_or(false)
};

if let Some(ref cluster) = cluster
&& !cluster_owns(cluster)
{
adopt_approved_image(kube_client.clone(), &name, cluster)
Comment thread
alicefr marked this conversation as resolved.
.await
.map_err(|e| -> ControllerError { e.into() })?;
}

let images: Api<ApprovedImage> = Api::default_namespaced(kube_client.clone());
finalizer(&images, APPROVED_IMAGE_FINALIZER, image, |ev| async {
match ev {
Expand Down Expand Up @@ -277,19 +294,6 @@ async fn image_add_reconcile(
info!("TrustedExecutionCluster is being deleted, deferring image processing for {name}");
return Ok(Action::requeue(Duration::from_secs(5)));
}
let uid_owns = |uid: &String| {
let refs = image.metadata.owner_references.as_ref();
refs.map(|os| os.iter().any(|o| o.uid == *uid))
};
let cluster_owns = |cluster: &TrustedExecutionCluster| {
let uid = cluster.metadata.uid.as_ref();
uid.and_then(uid_owns).unwrap_or(false)
};
// Adopt the image by adding TEC as owner reference if not already owned
if !cluster_owns(&cluster) {
adopt_approved_image(client.clone(), name, &cluster).await?;
}

let (action, reason) = match handle_new_image(client.clone(), image).await {
Ok(reason) => (Action::await_change(), reason),
Err(e) => {
Expand Down
Loading