@@ -30,6 +30,8 @@ use crate::crd::generated::cert_manager::certificates::{
3030 CertificateIssuerRef , CertificateSecretTemplate ,
3131} ;
3232
33+ const V26_0_0 : Version = Version :: new ( 26 , 0 , 0 ) ;
34+
3335pub const LAST_KNOWN_ACTIVE_GENERATION_ANNOTATION : & str =
3436 "materialize.cloud/last-known-active-generation" ;
3537
@@ -500,13 +502,15 @@ pub mod v1alpha1 {
500502 parse_image_ref ( & self . spec . environmentd_image_ref ) ,
501503 current_environmentd_version,
502504 ) {
503- // We deny upgrades past 1 major version of the last successful rollout.
504- new_environmentd_version. major <= current_environmentd_version. major + 1
505- } else {
506- // If we couldn't parse either versions, we allow the upgrade since environmentd
507- // will still be able to determine if the upgrade is allowed or not.
508- true
505+ if current_environmentd_version >= V26_0_0 {
506+ // We deny upgrades past 1 major version of the last successful rollout
507+ return new_environmentd_version. major
508+ <= current_environmentd_version. major + 1 ;
509+ }
509510 }
511+ // If we fail any of the preconditions for the check (e.g. we couldn't parse either version),
512+ // we still allow the upgrade since environmentd will still error if the upgrade is not allowed.
513+ true
510514 }
511515
512516 pub fn managed_resource_meta ( & self , name : String ) -> ObjectMeta {
@@ -669,4 +673,51 @@ mod tests {
669673 mz. spec . environmentd_image_ref = "my.private.registry:5000:v0.33.3" . to_owned ( ) ;
670674 assert ! ( !mz. meets_minimum_version( & Version :: parse( "0.34.0" ) . unwrap( ) ) ) ;
671675 }
676+
677+ #[ mz_ore:: test]
678+ fn within_upgrade_window ( ) {
679+ use super :: v1alpha1:: MaterializeStatus ;
680+
681+ let mut mz = Materialize {
682+ spec : MaterializeSpec {
683+ environmentd_image_ref : "materialize/environmentd:v26.0.0" . to_owned ( ) ,
684+ ..Default :: default ( )
685+ } ,
686+ metadata : ObjectMeta {
687+ ..Default :: default ( )
688+ } ,
689+ status : Some ( MaterializeStatus {
690+ last_completed_rollout_environmentd_image_ref : Some (
691+ "materialize/environmentd:v26.0.0" . to_owned ( ) ,
692+ ) ,
693+ ..Default :: default ( )
694+ } ) ,
695+ } ;
696+
697+ // Pass: upgrading from 26.0.0 to 27.7.3 (within 1 major version)
698+ mz. spec . environmentd_image_ref = "materialize/environmentd:v27.7.3" . to_owned ( ) ;
699+ assert ! ( mz. within_upgrade_window( ) ) ;
700+
701+ // Pass: upgrading from 26.0.0 to 27.7.8-dev.0 (within 1 major version, pre-release)
702+ mz. spec . environmentd_image_ref = "materialize/environmentd:v27.7.8-dev.0" . to_owned ( ) ;
703+ assert ! ( mz. within_upgrade_window( ) ) ;
704+
705+ // Fail: upgrading from 26.0.0 to 28.0.1 (more than 1 major version)
706+ mz. spec . environmentd_image_ref = "materialize/environmentd:v28.0.1" . to_owned ( ) ;
707+ assert ! ( !mz. within_upgrade_window( ) ) ;
708+
709+ // Pass: upgrading from 26.0.0 to 28.0.1.not_a_valid_version (invalid version, defaults to true)
710+ mz. spec . environmentd_image_ref =
711+ "materialize/environmentd:v28.0.1.not_a_valid_version" . to_owned ( ) ;
712+ assert ! ( mz. within_upgrade_window( ) ) ;
713+
714+ // Pass: upgrading from 0.147.5 to 26.1.0 (any version before 26.0.0 passes)
715+ mz. status
716+ . as_mut ( )
717+ . unwrap ( )
718+ . last_completed_rollout_environmentd_image_ref =
719+ Some ( "materialize/environmentd:v0.147.5" . to_owned ( ) ) ;
720+ mz. spec . environmentd_image_ref = "materialize/environmentd:v26.1.0" . to_owned ( ) ;
721+ assert ! ( mz. within_upgrade_window( ) ) ;
722+ }
672723}
0 commit comments