@@ -30,6 +30,10 @@ struct CacheInputs {
3030 /// SHA256 digest of the source container image
3131 image_digest : String ,
3232
33+ /// Source image reference (e.g., "quay.io/centos-bootc/centos-bootc:stream9")
34+ /// This is crucial because it determines the upgrade source for the installed system
35+ source_imgref : String ,
36+
3337 /// Filesystem type used for installation (e.g., "ext4", "xfs", "btrfs")
3438 filesystem : Option < String > ,
3539
@@ -52,6 +56,10 @@ pub struct DiskImageMetadata {
5256 /// SHA256 digest of the source container image
5357 pub digest : String ,
5458
59+ /// Source image reference (e.g., "quay.io/centos-bootc/centos-bootc:stream9")
60+ /// This is crucial because it determines the upgrade source for the installed system
61+ pub source_imgref : String ,
62+
5563 /// Filesystem type used for installation (e.g., "ext4", "xfs", "btrfs")
5664 pub filesystem : Option < String > ,
5765
@@ -73,6 +81,7 @@ impl DiskImageMetadata {
7381 pub fn compute_cache_hash ( & self ) -> String {
7482 let inputs = CacheInputs {
7583 image_digest : self . digest . clone ( ) ,
84+ source_imgref : self . source_imgref . clone ( ) ,
7685 filesystem : self . filesystem . clone ( ) ,
7786 root_size : self . root_size . clone ( ) ,
7887 composefs_backend : self . composefs_backend ,
@@ -154,11 +163,12 @@ impl DiskImageMetadata {
154163}
155164
156165impl DiskImageMetadata {
157- /// Create new metadata from InstallOptions and image digest
158- pub fn from ( options : & InstallOptions , image : & str ) -> Self {
166+ /// Create new metadata from InstallOptions, image digest, and source imgref
167+ pub fn from ( options : & InstallOptions , image_digest : & str , source_imgref : & str ) -> Self {
159168 Self {
160169 version : 1 ,
161- digest : image. to_owned ( ) ,
170+ digest : image_digest. to_owned ( ) ,
171+ source_imgref : source_imgref. to_owned ( ) ,
162172 filesystem : options. filesystem . clone ( ) ,
163173 root_size : options. root_size . clone ( ) ,
164174 kernel_args : options. karg . clone ( ) ,
@@ -181,6 +191,7 @@ pub(crate) enum ValidationError {
181191pub fn check_cached_disk (
182192 path : & Path ,
183193 image_digest : & str ,
194+ source_imgref : & str ,
184195 install_options : & InstallOptions ,
185196) -> Result < Result < ( ) , ValidationError > > {
186197 if !path. exists ( ) {
@@ -189,7 +200,7 @@ pub fn check_cached_disk(
189200 }
190201
191202 // Create metadata for the current request to compute expected hash
192- let expected_meta = DiskImageMetadata :: from ( install_options, image_digest) ;
203+ let expected_meta = DiskImageMetadata :: from ( install_options, image_digest, source_imgref ) ;
193204 let expected_hash = expected_meta. compute_cache_hash ( ) ;
194205
195206 // Read the cache hash from the disk image
@@ -246,28 +257,31 @@ mod tests {
246257 root_size : Some ( "20G" . to_string ( ) ) ,
247258 ..Default :: default ( )
248259 } ;
249- let metadata1 = DiskImageMetadata :: from ( & install_options1, "sha256:abc123" ) ;
260+ let metadata1 =
261+ DiskImageMetadata :: from ( & install_options1, "sha256:abc123" , "quay.io/test/image:v1" ) ;
250262
251263 let install_options2 = InstallOptions {
252264 filesystem : Some ( "ext4" . to_string ( ) ) ,
253265 root_size : Some ( "20G" . to_string ( ) ) ,
254266 ..Default :: default ( )
255267 } ;
256- let metadata2 = DiskImageMetadata :: from ( & install_options2, "sha256:abc123" ) ;
268+ let metadata2 =
269+ DiskImageMetadata :: from ( & install_options2, "sha256:abc123" , "quay.io/test/image:v1" ) ;
257270
258271 // Same inputs should generate same hash
259272 assert_eq ! (
260273 metadata1. compute_cache_hash( ) ,
261274 metadata2. compute_cache_hash( )
262275 ) ;
263276
264- // Different inputs should generate different hashes
277+ // Different digest should generate different hashes
265278 let install_options3 = InstallOptions {
266279 filesystem : Some ( "ext4" . to_string ( ) ) ,
267280 root_size : Some ( "20G" . to_string ( ) ) ,
268281 ..Default :: default ( )
269282 } ;
270- let metadata3 = DiskImageMetadata :: from ( & install_options3, "sha256:xyz789" ) ;
283+ let metadata3 =
284+ DiskImageMetadata :: from ( & install_options3, "sha256:xyz789" , "quay.io/test/image:v1" ) ;
271285
272286 assert_ne ! (
273287 metadata1. compute_cache_hash( ) ,
@@ -280,18 +294,38 @@ mod tests {
280294 root_size : Some ( "20G" . to_string ( ) ) ,
281295 ..Default :: default ( )
282296 } ;
283- let metadata4 = DiskImageMetadata :: from ( & install_options4, "sha256:abc123" ) ;
297+ let metadata4 =
298+ DiskImageMetadata :: from ( & install_options4, "sha256:abc123" , "quay.io/test/image:v1" ) ;
284299
285300 assert_ne ! (
286301 metadata1. compute_cache_hash( ) ,
287302 metadata4. compute_cache_hash( )
288303 ) ;
304+
305+ // Different source imgref should generate different hash even with same digest
306+ let install_options5 = InstallOptions {
307+ filesystem : Some ( "ext4" . to_string ( ) ) ,
308+ root_size : Some ( "20G" . to_string ( ) ) ,
309+ ..Default :: default ( )
310+ } ;
311+ let metadata5 = DiskImageMetadata :: from (
312+ & install_options5,
313+ "sha256:abc123" ,
314+ "quay.io/different/image:latest" ,
315+ ) ;
316+
317+ assert_ne ! (
318+ metadata1. compute_cache_hash( ) ,
319+ metadata5. compute_cache_hash( ) ,
320+ "Different source imgrefs with same digest should generate different cache hashes"
321+ ) ;
289322 }
290323
291324 #[ test]
292325 fn test_cache_inputs_serialization ( ) -> Result < ( ) > {
293326 let inputs = CacheInputs {
294327 image_digest : "sha256:abc123" . to_string ( ) ,
328+ source_imgref : "quay.io/test/image:v1" . to_string ( ) ,
295329 filesystem : Some ( "ext4" . to_string ( ) ) ,
296330 root_size : Some ( "20G" . to_string ( ) ) ,
297331 kernel_args : vec ! [ "console=ttyS0" . to_string( ) ] ,
@@ -303,6 +337,7 @@ mod tests {
303337 let deserialized: CacheInputs = serde_json:: from_str ( & json) ?;
304338
305339 assert_eq ! ( inputs. image_digest, deserialized. image_digest) ;
340+ assert_eq ! ( inputs. source_imgref, deserialized. source_imgref) ;
306341 assert_eq ! ( inputs. filesystem, deserialized. filesystem) ;
307342 assert_eq ! ( inputs. root_size, deserialized. root_size) ;
308343 assert_eq ! ( inputs. kernel_args, deserialized. kernel_args) ;
0 commit comments