From 2b95facc6fba925c8900e55b69f927174b85ea74 Mon Sep 17 00:00:00 2001 From: "alex.lyn" Date: Thu, 3 Jul 2025 09:53:28 +0800 Subject: [PATCH] kata-type: Relax Mandatory source Field Check in Guest-Pull Mode Previously, the source field was subject to mandatory checks. However, in guest-pull mode, this field doesn't consistently provide useful information. Our practical experience has shown that relying on this field for critical data isn't always necessary. In other aspect, not all cases need mandatory check for KataVirtualVolume. based on this fact, we'd better to make from_base64 do only one thing and remove the validate(). Of course, We also keep the previous capability to make it easy for possible cases which use such method and we rename it clearly with from_base64_and_validate. This commit relaxes the mandatory checks on the KataVirtualVolume specifically for guest-pull mode, acknowledging its diminished utility in this context. Signed-off-by: alex.lyn --- src/libs/kata-types/src/mount.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libs/kata-types/src/mount.rs b/src/libs/kata-types/src/mount.rs index b557d8cdb1..00b3b62a3e 100644 --- a/src/libs/kata-types/src/mount.rs +++ b/src/libs/kata-types/src/mount.rs @@ -387,7 +387,15 @@ impl KataVirtualVolume { pub fn from_base64(value: &str) -> Result { let json = base64::decode(value)?; let volume: KataVirtualVolume = serde_json::from_slice(&json)?; + + Ok(volume) + } + + /// Decode and deserialize a virtual volume object from base64 encoded json string and validate it. + pub fn from_base64_and_validate(value: &str) -> Result { + let volume = Self::from_base64(value)?; volume.validate()?; + Ok(volume) } } @@ -650,7 +658,8 @@ mod tests { volume.direct_volume = Some(DirectAssignedVolume { metadata }); let value = volume.to_base64().unwrap(); - let volume2: KataVirtualVolume = KataVirtualVolume::from_base64(value.as_str()).unwrap(); + let volume2: KataVirtualVolume = + KataVirtualVolume::from_base64_and_validate(value.as_str()).unwrap(); assert_eq!(volume.volume_type, volume2.volume_type); assert_eq!(volume.source, volume2.source); assert_eq!(volume.fs_type, volume2.fs_type);