-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Still need to test if drift works as expected with the API
- Loading branch information
Showing
11 changed files
with
204 additions
and
364 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 23 additions & 27 deletions
50
crates/k8s-codegen/templates/k8s_operator_controller_action_delete.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,32 @@ | ||
{% for controller in controllers %} | ||
{% if controller.http_method == "delete" %} | ||
pub async fn handle_{{ controller.operation_id }}( | ||
config: &Configuration, | ||
async fn handle_{{ controller.http_method }}( | ||
kube_client: &Api<{{ kind_struct }}>, | ||
{{ arg_name }}: &mut {{ kind_struct }}, | ||
kubernetes_api: Api<{{ kind_struct }}>, | ||
) -> Result<()> { | ||
let dto = convert_kube_type_to_dto({{ arg_name }}.clone()); | ||
let {{ resource_remote_ref }} = dto.{{ resource_remote_ref }}.clone().unwrap_or_default(); | ||
)-> Result<(), OperatorError> { | ||
let config = get_client_config().await?; | ||
let {{ resource_remote_ref }} = match {{ arg_name }}.clone().status { | ||
Some(status) => match status.clone().{{ resource_remote_ref}} { | ||
Some({{ resource_remote_ref }}) => {{ resource_remote_ref }}, | ||
None => { | ||
warn!("{{ kind_struct }} has no resource reference in status, cannot delete by id. Skipping..."); | ||
return Ok(()); | ||
} | ||
}, | ||
None => { | ||
warn!("{{ kind_struct }} has no status, cannot delete by id. Skipping..."); | ||
return Ok(()); | ||
} | ||
}; | ||
|
||
if {{ resource_remote_ref }}.is_empty() { | ||
warn!("{{ kind_struct }} has no {{ resource_remote_ref }}, cannot {{ controller.action_summary }}. Skipping..."); | ||
return Ok(()); | ||
if let Err(e) = {{ controller.operation_id }}(&config, &{{ resource_remote_ref }}).await { | ||
error!("Failed to delete {{ arg_name }}: {:?}", e); | ||
return Err(OperatorError::FailedToDelete{{ kind_struct }}(e.into())); | ||
} | ||
|
||
{{ controller.operation_id }}(&config, &{{ resource_remote_ref }}) | ||
.await | ||
.context("Failed to {{ controller.action_summary }}")?; | ||
|
||
remove_finalizer({{ arg_name }}, kubernetes_api.clone()).await?; | ||
let condition = create_condition( | ||
"Deleted", | ||
"UnavailableDeleted", | ||
"Deleted the resource", | ||
"Resource has has deleted", | ||
{{ arg_name }}.meta().generation, | ||
); | ||
let mut {{ arg_name }}_clone = {{ arg_name }}.clone(); | ||
if let Some(status) = {{ arg_name }}_clone.status.as_mut() { | ||
status.conditions.push(condition); | ||
status.observed_generation = {{ arg_name }}.meta().generation; | ||
} | ||
return update_status(kubernetes_api.clone(), {{ arg_name }}_clone).await; | ||
remove_finalizer({{ arg_name }}, kube_client.clone()).await?; | ||
info!("Successfully deleted {{ arg_name }}"); | ||
Ok(()) | ||
} | ||
{% endif %} | ||
{% endfor %} |
File renamed without changes.
Oops, something went wrong.