Skip to content

Commit 1424dbc

Browse files
bgartziYair Podemsky
authored andcommitted
rust: Update minimum toolchain to 1.88
Minimum rust version was set to 1.85. Fedora is way above that threshold at the moment. Future EL releases will be above that as well. While on it, fix some of the linter errors that arise from the minimum version update. Signed-off-by: Beñat Gartzia Arruabarrena <bgartzia@redhat.com>
1 parent 4115644 commit 1424dbc

8 files changed

Lines changed: 89 additions & 115 deletions

File tree

attestation-key-register/src/main.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async fn handle_registration(
4040
client: Client,
4141
addr: Option<SocketAddr>,
4242
) -> Result<impl warp::Reply, Infallible> {
43-
info!("Received registration request: {:?}", registration);
43+
info!("Received registration request: {registration:?}");
4444

4545
let api: Api<AttestationKey> = Api::default_namespaced(client);
4646

@@ -50,8 +50,7 @@ async fn handle_registration(
5050
if key.spec.public_key == registration.public_key {
5151
let existing_name = key.metadata.name.unwrap_or_default();
5252
error!(
53-
"Duplicate public key detected: already exists in AttestationKey '{}'",
54-
existing_name
53+
"Duplicate public key detected: already exists in AttestationKey '{existing_name}'"
5554
);
5655
return Ok(reply::with_status(
5756
reply::json(&serde_json::json!({
@@ -64,11 +63,11 @@ async fn handle_registration(
6463
}
6564
}
6665
Err(e) => {
67-
error!("Failed to list AttestationKeys: {}", e);
66+
error!("Failed to list AttestationKeys: {e}");
6867
return Ok(reply::with_status(
6968
reply::json(&serde_json::json!({
7069
"status": "error",
71-
"message": format!("Failed to check for existing keys: {}", e),
70+
"message": format!("Failed to check for existing keys: {e}"),
7271
})),
7372
StatusCode::INTERNAL_SERVER_ERROR,
7473
));
@@ -106,11 +105,11 @@ async fn handle_registration(
106105
))
107106
}
108107
Err(e) => {
109-
error!("Failed to create AttestationKey: {}", e);
108+
error!("Failed to create AttestationKey: {e}");
110109
Ok(reply::with_status(
111110
reply::json(&serde_json::json!({
112111
"status": "error",
113-
"message": format!("Failed to create AttestationKey: {}", e),
112+
"message": format!("Failed to create AttestationKey: {e}"),
114113
})),
115114
StatusCode::INTERNAL_SERVER_ERROR,
116115
))
@@ -145,7 +144,7 @@ async fn main() -> anyhow::Result<()> {
145144
.and_then(handle_registration);
146145

147146
let addr = SocketAddr::from(([0, 0, 0, 0], args.port));
148-
info!("Listening on {}", addr);
147+
info!("Listening on {addr}");
149148

150149
warp::serve(register).run(addr).await;
151150

operator/src/attestation_key_register.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ async fn ak_reconcile(
135135
client: Arc<Client>,
136136
) -> Result<Action, ControllerError> {
137137
let ak_name = ak.metadata.name.clone().unwrap_or_default();
138-
info!("Attestation Key reconciliation for: {}", ak_name);
138+
info!("Attestation Key reconciliation for: {ak_name}");
139139

140140
let client = Arc::unwrap_or_clone(client);
141141
let machines: Api<Machine> = Api::default_namespaced(client.clone());
142142
let lp = ListParams::default();
143143
let machine_list: ObjectList<Machine> = machines.list(&lp).await.map_err(|e| {
144-
eprintln!("Error fetching machine list: {}", e);
144+
eprintln!("Error fetching machine list: {e}");
145145
ControllerError::Anyhow(e.into())
146146
})?;
147147
for machine in &machine_list.items {
@@ -182,15 +182,15 @@ async fn machine_reconcile(
182182
let aks: Api<AttestationKey> = Api::default_namespaced(client.clone());
183183
let lp = ListParams::default();
184184
let ak_list: ObjectList<AttestationKey> = aks.list(&lp).await.map_err(|e| {
185-
eprintln!("Error fetching attestation key list: {}", e);
185+
eprintln!("Error fetching attestation key list: {e}");
186186
ControllerError::Anyhow(e.into())
187187
})?;
188188
for ak in ak_list.items {
189-
if let Some(ak_address) = &ak.spec.address {
190-
if *ak_address == machine_address {
191-
approve_ak(&ak, &machine, client.clone()).await?;
192-
return Ok(Action::await_change());
193-
}
189+
if let Some(ak_address) = &ak.spec.address
190+
&& *ak_address == machine_address
191+
{
192+
approve_ak(&ak, &machine, client.clone()).await?;
193+
return Ok(Action::await_change());
194194
}
195195
}
196196
Ok(Action::await_change())
@@ -315,10 +315,7 @@ async fn secret_reconcile(
315315
return Ok(Action::await_change());
316316
}
317317

318-
info!(
319-
"Secret reconciliation for AttestationKey secret: {}",
320-
secret_name
321-
);
318+
info!("Secret reconciliation for AttestationKey secret: {secret_name}");
322319

323320
let secrets: Api<Secret> = Api::default_namespaced(Arc::unwrap_or_clone(client.clone()));
324321
finalizer(&secrets, ATTESTATION_KEY_SECRET_FINALIZER, secret, |ev| async move {
@@ -330,15 +327,14 @@ async fn secret_reconcile(
330327
.await
331328
.map(|_| Action::await_change())
332329
.map_err(|e| {
333-
eprintln!("Error updating attestation key volumes on secret apply: {}", e);
330+
eprintln!("Error updating attestation key volumes on secret apply: {e}");
334331
finalizer::Error::<ControllerError>::ApplyFailed(e.into())
335332
})
336333
}
337334
Event::Cleanup(secret) => {
338335
let secret_name = secret.metadata.name.clone().unwrap_or_default();
339336
info!(
340-
"AttestationKey secret {} is being deleted, updating trustee deployment volumes",
341-
secret_name
337+
"AttestationKey secret {secret_name} is being deleted, updating trustee deployment volumes"
342338
);
343339
let client = Arc::unwrap_or_clone(client);
344340
// Update trustee deployment - secrets with deletion_timestamp will be filtered out
@@ -347,8 +343,7 @@ async fn secret_reconcile(
347343
.map(|_| Action::await_change())
348344
.map_err(|e| {
349345
eprintln!(
350-
"Error updating attestation key volumes during secret deletion: {}",
351-
e
346+
"Error updating attestation key volumes during secret deletion: {e}"
352347
);
353348
finalizer::Error::<ControllerError>::CleanupFailed(e.into())
354349
})

operator/src/reference_values.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,13 @@ pub async fn handle_new_image(
297297
let config_maps: Api<ConfigMap> = Api::default_namespaced(ctx.client.clone());
298298
let mut image_pcrs_map = config_maps.get(PCR_CONFIG_MAP).await?;
299299
let mut image_pcrs = get_image_pcrs(image_pcrs_map.clone())?;
300-
if let Some(pcr) = image_pcrs.0.get(resource_name) {
301-
if pcr.reference == boot_image {
302-
info!("Image {boot_image} was to be allowed, but already was allowed");
303-
return trustee::update_reference_values(ctx)
304-
.await
305-
.map(|_| COMMITTED_REASON);
306-
}
300+
if let Some(pcr) = image_pcrs.0.get(resource_name)
301+
&& pcr.reference == boot_image
302+
{
303+
info!("Image {boot_image} was to be allowed, but already was allowed");
304+
return trustee::update_reference_values(ctx)
305+
.await
306+
.map(|_| COMMITTED_REASON);
307307
}
308308
let image_ref: oci_client::Reference = boot_image.parse()?;
309309
if image_ref.digest().is_none() {

operator/src/trustee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub async fn update_attestation_keys(client: Client) -> Result<()> {
254254
name: secret_name.to_string(),
255255
items: Some(vec![KeyToPath {
256256
key: "public_key".to_string(),
257-
path: format!("{}.pub", secret_name),
257+
path: format!("{secret_name}.pub"),
258258
..Default::default()
259259
}]),
260260
..Default::default()

test_utils/src/lib.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,12 @@ impl TestContext {
225225
async move {
226226
let deployment = api.get(&name).await?;
227227

228-
if let Some(status) = &deployment.status {
229-
if let Some(available_replicas) = status.available_replicas {
230-
if available_replicas == 1 {
231-
test_info!(&tn, "{} deployment has 1 available replica", name);
232-
return Ok(());
233-
}
234-
}
228+
if let Some(status) = &deployment.status
229+
&& let Some(available_replicas) = status.available_replicas
230+
&& available_replicas == 1
231+
{
232+
test_info!(&tn, "{} deployment has 1 available replica", name);
233+
return Ok(());
235234
}
236235

237236
Err(anyhow::anyhow!(
@@ -357,40 +356,40 @@ impl TestContext {
357356

358357
let sa_src = workspace_root.join("config/rbac/service_account.yaml");
359358
let sa_content = std::fs::read_to_string(&sa_src)?
360-
.replace("namespace: system", &format!("namespace: {}", ns));
359+
.replace("namespace: system", &format!("namespace: {ns}"));
361360
let sa_dst = rbac_temp_dir.join("service_account.yaml");
362361
std::fs::write(&sa_dst, sa_content)?;
363362

364363
let role_path = rbac_temp_dir.join("role.yaml");
365364
let role_content = std::fs::read_to_string(&role_path)?.replace(
366365
"name: trusted-cluster-operator-role",
367-
&format!("name: {}-trusted-cluster-operator-role", ns),
366+
&format!("name: {ns}-trusted-cluster-operator-role"),
368367
);
369368
std::fs::write(&role_path, role_content)?;
370369

371370
let rb_src = workspace_root.join("config/rbac/role_binding.yaml");
372371
let rb_content = std::fs::read_to_string(&rb_src)?
373372
.replace(
374373
"name: manager-rolebinding",
375-
&format!("name: {}-manager-rolebinding", ns),
374+
&format!("name: {ns}-manager-rolebinding"),
376375
)
377376
.replace(
378377
"name: trusted-cluster-operator-role",
379-
&format!("name: {}-trusted-cluster-operator-role", ns),
378+
&format!("name: {ns}-trusted-cluster-operator-role"),
380379
)
381-
.replace("namespace: system", &format!("namespace: {}", ns));
380+
.replace("namespace: system", &format!("namespace: {ns}"));
382381
let rb_dst = rbac_temp_dir.join("role_binding.yaml");
383382
std::fs::write(&rb_dst, rb_content)?;
384383

385384
let le_role_src = workspace_root.join("config/rbac/leader_election_role.yaml");
386385
let le_role_content = std::fs::read_to_string(&le_role_src)?
387-
.replace("namespace: system", &format!("namespace: {}", ns));
386+
.replace("namespace: system", &format!("namespace: {ns}"));
388387
let le_role_dst = rbac_temp_dir.join("leader_election_role.yaml");
389388
std::fs::write(&le_role_dst, le_role_content)?;
390389

391390
let le_rb_src = workspace_root.join("config/rbac/leader_election_role_binding.yaml");
392391
let le_rb_content = std::fs::read_to_string(&le_rb_src)?
393-
.replace("namespace: system", &format!("namespace: {}", ns));
392+
.replace("namespace: system", &format!("namespace: {ns}"));
394393
let le_rb_dst = rbac_temp_dir.join("leader_election_role_binding.yaml");
395394
std::fs::write(&le_rb_dst, le_rb_content)?;
396395

@@ -399,16 +398,15 @@ impl TestContext {
399398
r#"# SPDX-FileCopyrightText: Generated for testing
400399
# SPDX-License-Identifier: CC0-1.0
401400
402-
namespace: {}
401+
namespace: {ns}
403402
404403
resources:
405404
- service_account.yaml
406405
- role.yaml
407406
- role_binding.yaml
408407
- leader_election_role.yaml
409408
- leader_election_role_binding.yaml
410-
"#,
411-
ns
409+
"#
412410
);
413411

414412
let temp_kustomization_path = rbac_temp_dir.join("kustomization.yaml");
@@ -436,19 +434,19 @@ resources:
436434
&self.test_name,
437435
"Updating CR manifest with publicTrusteeAddr"
438436
);
439-
let trustee_addr = format!("kbs-service.{}.svc.cluster.local:8080", ns);
437+
let trustee_addr = format!("kbs-service.{ns}.svc.cluster.local:8080");
440438
let cr_manifest_path = manifests_path.join("trusted_execution_cluster_cr.yaml");
441439

442440
let cr_content = std::fs::read_to_string(&cr_manifest_path)?;
443441
let mut cr_value: serde_yaml::Value = serde_yaml::from_str(&cr_content)?;
444442

445-
if let Some(spec) = cr_value.get_mut("spec") {
446-
if let Some(spec_map) = spec.as_mapping_mut() {
447-
spec_map.insert(
448-
serde_yaml::Value::String("publicTrusteeAddr".to_string()),
449-
serde_yaml::Value::String(trustee_addr.clone()),
450-
);
451-
}
443+
if let Some(spec) = cr_value.get_mut("spec")
444+
&& let Some(spec_map) = spec.as_mapping_mut()
445+
{
446+
spec_map.insert(
447+
serde_yaml::Value::String("publicTrusteeAddr".to_string()),
448+
serde_yaml::Value::String(trustee_addr.clone()),
449+
);
452450
}
453451

454452
let updated_content = serde_yaml::to_string(&cr_value)?;
@@ -494,8 +492,7 @@ resources:
494492
.with_timeout(Duration::from_secs(60))
495493
.with_interval(Duration::from_secs(5))
496494
.with_error_message(format!(
497-
"image-pcrs ConfigMap in the namespace {} not found",
498-
ns
495+
"image-pcrs ConfigMap in the namespace {ns} not found"
499496
));
500497

501498
let test_name_owned = self.test_name.clone();

test_utils/src/virt.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ pub fn generate_ssh_key_pair() -> anyhow::Result<(String, String, std::path::Pat
4949
let stderr = String::from_utf8_lossy(&ssh_add_output.stderr);
5050
// Clean up the key file if ssh-add fails
5151
let _ = fs::remove_file(&key_path);
52-
return Err(anyhow::anyhow!(
53-
"Failed to add SSH key to agent: {}",
54-
stderr
55-
));
52+
return Err(anyhow::anyhow!("Failed to add SSH key to agent: {stderr}"));
5653
}
5754

5855
Ok((private_key_str, public_key_str, key_path))
@@ -138,10 +135,8 @@ pub fn generate_ignition_config(
138135
serde_json::to_value(&config).expect("Failed to serialize ignition config");
139136

140137
// Add attestation key registration field
141-
let attestation_url = format!(
142-
"http://attestation-key-register.{}.svc.cluster.local:8001/register-ak",
143-
namespace
144-
);
138+
let attestation_url =
139+
format!("http://attestation-key-register.{namespace}.svc.cluster.local:8001/register-ak");
145140

146141
if let Some(obj) = ignition_json.as_object_mut() {
147142
obj.insert(
@@ -309,8 +304,7 @@ pub async fn wait_for_vm_running(
309304
.with_timeout(Duration::from_secs(timeout_secs))
310305
.with_interval(Duration::from_secs(5))
311306
.with_error_message(format!(
312-
"VirtualMachine {} did not reach Running phase after {} seconds",
313-
vm_name, timeout_secs
307+
"VirtualMachine {vm_name} did not reach Running phase after {timeout_secs} seconds"
314308
));
315309

316310
poller
@@ -321,17 +315,15 @@ pub async fn wait_for_vm_running(
321315
let vm = api.get(&name).await?;
322316

323317
// Check VM status phase
324-
if let Some(status) = vm.status {
325-
if let Some(phase) = status.printable_status {
326-
if phase.as_str() == "Running" {
327-
return Ok(());
328-
}
329-
}
318+
if let Some(status) = vm.status
319+
&& let Some(phase) = status.printable_status
320+
&& phase.as_str() == "Running"
321+
{
322+
return Ok(());
330323
}
331324

332325
Err(anyhow::anyhow!(
333-
"VirtualMachine {} is not in Running phase yet",
334-
name
326+
"VirtualMachine {name} is not in Running phase yet"
335327
))
336328
}
337329
})
@@ -344,7 +336,7 @@ pub async fn virtctl_ssh_exec(
344336
key_path: &Path,
345337
command: &str,
346338
) -> anyhow::Result<String> {
347-
let _vm_target = format!("core@vmi/{}/{}", vm_name, namespace);
339+
let _vm_target = format!("core@vmi/{vm_name}/{namespace}");
348340
let full_cmd = format!(
349341
"virtctl ssh -i {} core@vmi/{}/{} -t '-o IdentitiesOnly=yes' -t '-o StrictHostKeyChecking=no' --known-hosts /dev/null -c '{}'",
350342
key_path.display(),
@@ -356,7 +348,7 @@ pub async fn virtctl_ssh_exec(
356348
let output = Command::new("sh").arg("-c").arg(full_cmd).output().await?;
357349
if !output.status.success() {
358350
let stderr = String::from_utf8_lossy(&output.stderr);
359-
return Err(anyhow::anyhow!("virtctl ssh command failed: {}", stderr));
351+
return Err(anyhow::anyhow!("virtctl ssh command failed: {stderr}"));
360352
}
361353

362354
Ok(String::from_utf8_lossy(&output.stdout).to_string())
@@ -392,8 +384,7 @@ async fn wait_for_vm_ssh(
392384
.with_timeout(Duration::from_secs(timeout_secs))
393385
.with_interval(Duration::from_secs(10))
394386
.with_error_message(format!(
395-
"SSH access to VM {}/{} did not become {}available after {} seconds",
396-
namespace, vm_name, avail_prefix, timeout_secs
387+
"SSH access to VM {namespace}/{vm_name} did not become {avail_prefix}available after {timeout_secs} seconds",
397388
));
398389

399390
poller

0 commit comments

Comments
 (0)